blob: 69ea0a56e80e7d5a0b92eca5ccede688dc4441de [file] [log] [blame]
# Copyright 2014 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Module containing the organization related views for Summer Of Code."""
from django import forms as django_forms
from django.utils import translation
from codein.request import error
from codein.request import render
from codein.views.helper import urls as ci_urls
from melange.request import links
from melange.templates import readonly
from melange.views import organization as organization_view
from soc.modules.gci.views import base
from soc.modules.gci.views import forms as gci_forms
from soc.modules.gci.views.helper import url_patterns as ci_url_patterns
from soc.views import forms
from soc.views import survey as survey_view
from soc.views import template
from soc.views.helper import lists
from soc.views.helper import url as url_helper
# TODO(daniel): fields should be explicitly included rather than excluded
# List of form fields which are not used by Code In programs
_UNUSED_FIELD_IDS = ['ideas_page']
# Field IDs to create organization profiles used by Code In programs
_CREATE_ORG_PROFILE_FIELD_IDS = set([
'org_id', 'name', 'description', 'tags', 'license',
'mailing_list', 'notifications_email', 'web_page', 'irc_channel',
'feed_url', 'google_plus', 'twitter', 'blog', 'facebook', 'is_veteran',
'backup_admin', 'terms_of_service'
])
# Field IDs to edit organization profiles used by Code In programs
_EDIT_ORG_PROFILE_FIELD_IDS = (
_CREATE_ORG_PROFILE_FIELD_IDS -
organization_view.ONLY_CREATE_ORG_PROFILE_FIELD_IDS)
_NOTIFICATIONS_EMAIL_HELP_TEXT = translation.ugettext(
'If entered, all notifications (such as task updates) for this '
'organization will be sent to this email address, in addition to those '
'users who subscribed to individual tasks.')
_TASK_INFO_MESSAGE_LABEL = translation.ugettext('Extra task information')
_TASK_INFO_MESSAGE_HELP_TEXT = translation.ugettext(
'Additional information for students to be displayed for each task.')
class CICreateOrgProfileFormFactory(organization_view.OrgProfileFormFactory):
"""Implementation of organization_view.OrgProfileFormFactory to be used
to create forms to create organization profiles for Code In programs.
"""
def create(self, request_data, **kwargs):
"""See organization_view.OrgProfileFormFactory.create for specification."""
form = organization_view._OrgProfileForm(
gci_forms.GCIBoundField, request_data,
template_path=gci_forms.TEMPLATE_PATH,
include_fields=_CREATE_ORG_PROFILE_FIELD_IDS,
**kwargs)
form.fields['notifications_email'].help_text = (
_NOTIFICATIONS_EMAIL_HELP_TEXT)
return form
CI_CREATE_ORG_PROFILE_FORM_FACTORY = CICreateOrgProfileFormFactory()
class CIEditOrgProfileFormFactory(organization_view.OrgProfileFormFactory):
"""Implementation of organization_view.OrgProfileFormFactory to be used
to create forms to edit organization profiles for Code In programs.
"""
def create(self, request_data, **kwargs):
"""See organization_view.OrgProfileFormFactory.create for specification."""
form = organization_view._OrgProfileForm(
gci_forms.GCIBoundField, request_data,
template_path=gci_forms.TEMPLATE_PATH,
include_fields=_EDIT_ORG_PROFILE_FIELD_IDS,
**kwargs)
form.fields['notifications_email'].help_text = (
_NOTIFICATIONS_EMAIL_HELP_TEXT)
return form
CI_EDIT_ORG_PROFILE_FORM_FACTORY = CIEditOrgProfileFormFactory()
class CIOrgApplicationFormFactory(survey_view.SurveyTakeFormFactory):
"""Implementation of survey_view.SurveyTakeFormFactory to be used to create
forms for organization applications for Code In programs.
"""
def create(self, survey, **kwargs):
"""See survey_view.SurveyTakeFormFactory.create for specification."""
return forms.SurveyTakeForm(
gci_forms.GCIBoundField, survey=survey,
template_path=gci_forms.TEMPLATE_PATH,
**kwargs)
CI_ORG_APPLICATION_FORM_FACTORY = CIOrgApplicationFormFactory()
class CIOrgApplicationReadonlyFactory(
organization_view.OrgApplicationReadonlyFactory):
def create(self, data, app_response):
"""See organization_view.OrgApplicationReadonlyFactory.create for
specification.
"""
builder = readonly.ReadonlyBuilder()
builder.setTemplatePath('codein/readonly/_readonly_template.html')
builder.setGroupTemplatePath('codein/readonly/_group.html')
builder.addGroupDescriptor(organization_view.GENERAL_INFO_GROUP_DESCRIPTOR)
builder.addGroupDescriptor(organization_view.CONTACT_GROUP_DESCRIPTOR)
builder.setValues(
organization_view.adaptOrgProfilePropertiesForForm(data.url_ndb_org))
# descriptor for survey response
if app_response:
builder.addGroupDescriptor(
readonly.SurveyGroupDescriptor(
organization_view.APP_RESPONSE_GROUP_TITLE, data.org_app))
builder.setValues(
survey_view.surveyResponseAsDict(data.org_app, app_response))
# remove unused fields
for field_id in _UNUSED_FIELD_IDS:
builder.removeField(field_id)
return builder.build(data)
CI_ORG_APPLICATION_READONLY_FACTORY = CIOrgApplicationReadonlyFactory()
class CIAppResponseReadonlyFactory(
organization_view.AppResponseReadonlyFactory):
"""Implementation of organization_view.AppResponseReadonlyFactory to be used
for organization application responses for Code In programs.
"""
def create(self, data, app_response):
"""See organization_view.AppResponseReadonlyFactory.create
for specification.
"""
builder = readonly.ReadonlyBuilder()
builder.setTemplatePath('codein/readonly/_readonly_template.html')
builder.setGroupTemplatePath('codein/readonly/_group.html')
builder.addGroupDescriptor(
readonly.SurveyGroupDescriptor(
organization_view.APP_RESPONSE_GROUP_TITLE, data.org_app))
builder.setValues(
survey_view.surveyResponseAsDict(data.org_app, app_response))
return builder.build(data)
CI_APP_RESPONSE_READONLY_FACTORY = CIAppResponseReadonlyFactory()
class CIOrgLogoFormFactory(organization_view.OrgLogoFormFactory):
"""Implementation of organization_view.OrgLogoFormFactory for Code In."""
def create(self, **kwargs):
return organization_view.OrgLogoForm(
gci_forms.GCIBoundField, template_path=gci_forms.TEMPLATE_PATH,
**kwargs)
CI_ORG_LOGO_FORM_FACTORY = CIOrgLogoFormFactory()
class CIOrgPreferencesForm(organization_view.OrgPreferencesForm):
"""Implementation of organization_view.OrgPreferencesForm for Code In."""
task_info_message = django_forms.CharField(
widget=django_forms.Textarea, label=_TASK_INFO_MESSAGE_LABEL,
help_text=_TASK_INFO_MESSAGE_HELP_TEXT, required=False)
def __init__(self, **kwargs):
"""Initializes a new instance of the form for the specified parameters."""
super(CIOrgPreferencesForm, self).__init__(
gci_forms.GCIBoundField, template_path=gci_forms.TEMPLATE_PATH,
org_messages_properties_field_keys=['task_info_message'], **kwargs)
class CIOrgPreferencesFormFactory(organization_view.OrgPreferencesFormFactory):
"""Implementation of organization_view.OrgPreferencesFormFactory to be used
to create forms for organization preferences for Code In programs.
"""
def create(self, **kwargs):
"""See organization_view.OrgPreferencesFormFactory.create for
specification.
"""
return CIOrgPreferencesForm(**kwargs)
CI_ORG_PREFERENCES_FORM_FACTORY = CIOrgPreferencesFormFactory()
class PublicOrganizationList(template.Template):
"""Public list of organizations participating in a specified program."""
def __init__(self, data):
"""See template.Template.__init__ for specification."""
super(PublicOrganizationList, self).__init__(data)
self._list_config = lists.ListConfiguration()
self._list_config.addPlainTextColumn(
'name', 'Name', lambda e, *args: e.name.strip())
self._list_config.addPlainTextColumn(
'tags', 'Tags', lambda e, *args: ', '.join(e.tags))
self._list_config.addPlainTextColumn('ideas', 'Ideas',
lambda e, *args: url_helper.urlize(e.ideas, name='[ideas page]'),
hidden=True)
self._list_config.setDefaultSort('name', 'asc')
def templatePath(self):
"""See template.Template.templatePath for specification."""
return '_list.html'
def context(self):
"""See template.Template.context for specification."""
list_configuration_response = lists.ListConfigurationResponse(
self.data, self._list_config, 0, 'List of organizations')
return {
'lists': [list_configuration_response],
'title': 'Accepted organizations'
}
class CIPublicOrganizationListFactory(
organization_view.PublicOrganizationListFactory):
"""Implementation of organization_view.PublicOrganizationListFactory to be
used to create public list of organizations for Code In programs.
"""
def create(self, data):
"""See organization_view.PublicOrganizationListFactory for specification."""
return PublicOrganizationList(data)
CI_PUBLIC_ORGANIZATION_LIST_FACTORY = CIPublicOrganizationListFactory()
ORG_PROFILE_CREATE_PAGE = organization_view.OrgProfileCreatePage(
base._GCI_INITIALIZER, links.LINKER, render.CI_RENDERER,
error.CI_ERROR_HANDLER, ci_url_patterns.CI_URL_PATTERN_CONSTRUCTOR,
ci_urls.UrlNames, 'codein/organization/org_profile_edit.html',
CI_CREATE_ORG_PROFILE_FORM_FACTORY)
ORG_PROFILE_EDIT_PAGE = organization_view.OrgProfileEditPage(
base._GCI_INITIALIZER, links.LINKER, render.CI_RENDERER,
error.CI_ERROR_HANDLER, ci_url_patterns.CI_URL_PATTERN_CONSTRUCTOR,
ci_urls.UrlNames, 'codein/organization/org_profile_edit.html',
CI_EDIT_ORG_PROFILE_FORM_FACTORY)
ORG_APPLICATION_LIST_PAGE = organization_view.OrgApplicationListPage(
base._GCI_INITIALIZER, links.LINKER, render.CI_RENDERER,
error.CI_ERROR_HANDLER, ci_url_patterns.CI_URL_PATTERN_CONSTRUCTOR,
ci_urls.UrlNames, 'soc/org_app/records.html',
'codein/organization/_org_application_list.html')
ORG_APPLICATION_SUBMIT_PAGE = organization_view.OrgApplicationSubmitPage(
base._GCI_INITIALIZER, links.LINKER, render.CI_RENDERER,
error.CI_ERROR_HANDLER, ci_url_patterns.CI_URL_PATTERN_CONSTRUCTOR,
ci_urls.UrlNames, 'modules/gci/org_app/take.html',
CI_ORG_APPLICATION_FORM_FACTORY)
ORG_APPLICATION_SHOW_PAGE = organization_view.OrgApplicationShowPage(
base._GCI_INITIALIZER, links.LINKER, render.CI_RENDERER,
error.CI_ERROR_HANDLER, ci_url_patterns.CI_URL_PATTERN_CONSTRUCTOR,
ci_urls.UrlNames, 'modules/gci/org_app/show.html',
CI_ORG_APPLICATION_READONLY_FACTORY)
ORG_APPLICATION_RESPONSE_SHOW_PAGE = (
organization_view.OrgApplicationResponseShowPage(
base._GCI_INITIALIZER, links.LINKER, render.CI_RENDERER,
error.CI_ERROR_HANDLER, ci_url_patterns.CI_URL_PATTERN_CONSTRUCTOR,
ci_urls.UrlNames, 'modules/gci/org_app/show.html',
CI_APP_RESPONSE_READONLY_FACTORY))
ORG_LOGO_EDIT_PAGE = organization_view.OrgLogoEditPage(
base._GCI_INITIALIZER, links.LINKER, render.CI_RENDERER,
error.CI_ERROR_HANDLER, ci_url_patterns.CI_URL_PATTERN_CONSTRUCTOR,
ci_urls.UrlNames, 'codein/organization/org_profile_edit.html',
CI_ORG_LOGO_FORM_FACTORY)
ORG_PREFERENCES_EDIT_PAGE = organization_view.OrgPreferencesEditPage(
base._GCI_INITIALIZER, links.LINKER, render.CI_RENDERER,
error.CI_ERROR_HANDLER, ci_url_patterns.CI_URL_PATTERN_CONSTRUCTOR,
ci_urls.UrlNames, 'codein/organization/org_preferences_edit.html',
CI_ORG_PREFERENCES_FORM_FACTORY)
PUBLIC_ORGANIZATION_LIST_PAGE = organization_view.PublicOrganizationListPage(
base._GCI_INITIALIZER, links.LINKER, render.CI_RENDERER,
error.CI_ERROR_HANDLER, ci_url_patterns.CI_URL_PATTERN_CONSTRUCTOR,
ci_urls.UrlNames, 'modules/gci/accepted_orgs/base.html',
CI_PUBLIC_ORGANIZATION_LIST_FACTORY)