class SiteForm(ModelForm): """Django form for the site settings. """ class Meta: model = Site exclude = ['link_id', 'scope', 'scope_path', 'home', 'xsrf_secret_key'] widgets = { 'active_program': django_widgets.Select(choices=lazy(getProgramMap, list)()), } def clean_tos(self): if self.cleaned_data['tos'] is None: return '' return self.cleaned_data['tos'] clean_noreply_email = cleaning.clean_empty_field('noreply_email')
def testCleanEmptyField(self): """Tests that empty field can be cleaned. """ field_name = 'test_empty_field' clean_field = cleaning.clean_empty_field(field_name) # Test that the same value will be returned, the cleaned_data of form # does not change and there is no error message if the value of field # is not empty field_value = 'v1_@?' cleaned_data_before = {field_name: field_value} self.form.cleaned_data = cleaned_data_before.copy() self.assertEqual(clean_field(self.form), field_value) self.assertEqual(self.form.cleaned_data, cleaned_data_before) self.assertEqual(self.form._errors, {}) # Test that None will be returned, the cleaned_data of form does not change # and there is no error message if the value of field is empty field_value = '' cleaned_data_before = {field_name: field_value} self.form.cleaned_data = cleaned_data_before.copy() self.assertEqual(clean_field(self.form), u'') self.assertEqual(self.form.cleaned_data, cleaned_data_before) self.assertEqual(self.form._errors, {})
class SiteForm(views_forms.ModelForm): """Django form for the site settings.""" def __init__(self, bound_field_class, request_data=None, **kwargs): super(SiteForm, self).__init__(bound_field_class, **kwargs) self.request_data = request_data class Meta: model = site.Site exclude = ['xsrf_secret_key'] # NOTE(nathaniel): There aren't really no choices, it's just that we # can't know what the choices are at module-load-time. For the moment # we have to set the available choices below in EditSitePage.context. widgets = {'active_program': django_widgets.Select(choices=[])} def clean_tos(self): return '' if self.cleaned_data['tos'] is None else self.cleaned_data[ 'tos'] def templatePath(self): return 'modules/gsoc/_form.html' clean_noreply_email = cleaning.clean_empty_field('noreply_email')
def __init__(self, params=None): """Defines the fields and methods required for the base View class to provide the user with list, public, create, edit and delete views. Params: params: a dict with params for this View """ rights = access.Checker(params) rights['unspecified'] = ['checkIsDeveloper'] rights['any_access'] = ['allow'] rights['show'] = ['checkIsDeveloper'] new_params = {} new_params['logic'] = soc.logic.models.site.logic new_params['rights'] = rights new_params['name'] = "Site Settings" new_params['name_plural'] = new_params['name'] new_params['document_prefix'] = 'site' new_params['name_short'] = "Site" new_params['sidebar_defaults'] = [('/%s/edit', 'Edit %(name)s', 'edit')] new_params['sidebar_heading'] = new_params['name_short'] new_params['edit_template'] = 'soc/site/edit.html' new_params['home_template'] = 'soc/site/home.html' new_params['create_extra_dynaproperties'] = { 'link_id': forms.CharField(widget=forms.HiddenInput, required=True), 'clean_noreply_email': cleaning.clean_empty_field('noreply_email'), } new_params['edit_extra_dynaproperties'] = { 'link_id': forms.CharField(widget=forms.HiddenInput, required=True), 'home_link_id': widgets.ReferenceField( reference_url='document', required=False, filter_fields={'prefix': new_params['document_prefix']}, label=ugettext('Home page Document link ID'), help_text=soc.models.work.Work.link_id.help_text), 'tos_link_id': widgets.ReferenceField( reference_url='document', required=False, filter_fields={'prefix': new_params['document_prefix']}, label=ugettext('Terms of Service Document link ID'), help_text=soc.models.work.Work.link_id.help_text), } patterns = [] page_name = "Home Page" patterns += [(r'^$', 'soc.views.models.%(module_name)s.main_public', page_name)] page_name = "Edit Site" patterns += [(r'^%(url_name)s/(?P<access_type>edit)$', 'soc.views.models.%(module_name)s.main_edit', page_name)] if soc.logic.system.isDebug(): patterns += [('^seed_db$', 'soc.models.seed_db.seed', "Seed DB"), ('^clear_db$', 'soc.models.seed_db.clear', "Clear DB"), ('^reseed_db$', 'soc.models.seed_db.reseed', "Reseed DB"), ('^seed_many$', 'soc.models.seed_db.seed_many', "Seed Many"), ('^new_seed_many$', 'soc.models.seed_db.new_seed_many', "New Seed Many"), ] new_params['extra_django_patterns'] = patterns params = dicts.merge(params, new_params) super(View, self).__init__(params=params)
def __init__(self, params=None): """Defines the fields and methods required for the base View class to provide the user with list, public, create, edit and delete views. Params: params: a dict with params for this View """ rights = access.Checker(params) rights["unspecified"] = ["checkIsDeveloper"] rights["any_access"] = ["allow"] rights["show"] = ["checkIsDeveloper"] new_params = {} new_params["logic"] = soc.logic.models.site.logic new_params["rights"] = rights new_params["name"] = "Site Settings" new_params["name_plural"] = new_params["name"] new_params["document_prefix"] = "site" new_params["name_short"] = "Site" new_params["sidebar_defaults"] = [("/%s/edit", "Edit %(name)s", "edit")] new_params["sidebar_heading"] = new_params["name_short"] new_params["edit_template"] = "soc/site/edit.html" new_params["home_template"] = "soc/site/home.html" new_params["create_extra_dynaproperties"] = { "link_id": forms.CharField(widget=forms.HiddenInput, required=True), "clean_noreply_email": cleaning.clean_empty_field("noreply_email"), } new_params["edit_extra_dynaproperties"] = { "link_id": forms.CharField(widget=forms.HiddenInput, required=True), "home_link_id": widgets.ReferenceField( reference_url="document", required=False, filter_fields={"prefix": new_params["document_prefix"]}, label=ugettext("Home page Document link ID"), help_text=soc.models.work.Work.link_id.help_text, ), "tos_link_id": widgets.ReferenceField( reference_url="document", required=False, filter_fields={"prefix": new_params["document_prefix"]}, label=ugettext("Terms of Service Document link ID"), help_text=soc.models.work.Work.link_id.help_text, ), } patterns = [] page_name = "Home Page" patterns += [(r"^$", "soc.views.models.%(module_name)s.main_public", page_name)] page_name = "Maintenance" patterns += [(r"^maintenance$", "soc.views.models.%(module_name)s.maintenance", page_name)] page_name = "Edit Site" patterns += [(r"^%(url_name)s/(?P<access_type>edit)$", "soc.views.models.%(module_name)s.main_edit", page_name)] if soc.logic.system.isDebug(): patterns += [ ("^seed_db$", "soc.models.seed_db.seed", "Seed DB"), ("^clear_db$", "soc.models.seed_db.clear", "Clear DB"), ("^reseed_db$", "soc.models.seed_db.reseed", "Reseed DB"), ("^seed_many$", "soc.models.seed_db.seed_many", "Seed Many"), ("^new_seed_many$", "soc.models.seed_db.new_seed_many", "New Seed Many"), ] new_params["extra_django_patterns"] = patterns params = dicts.merge(params, new_params) super(View, self).__init__(params=params)
def __init__(self, params=None): """Defines the fields and methods required for the base View class to provide the user with list, public, create, edit and delete views. Params: params: a dict with params for this View """ rights = access.Checker(params) rights['unspecified'] = ['checkIsDeveloper'] rights['any_access'] = ['allow'] rights['home'] = ['allow'] rights['show'] = ['checkIsDeveloper'] new_params = {} new_params['logic'] = soc.logic.models.site.logic new_params['rights'] = rights new_params['name'] = "Site Settings" new_params['name_plural'] = new_params['name'] new_params['document_prefix'] = 'site' new_params['name_short'] = "Site" new_params['sidebar_developer'] = [] new_params['sidebar_defaults'] = [('/%s/edit', 'Edit %(name)s', 'edit')] new_params['sidebar_heading'] = new_params['name_short'] new_params['edit_template'] = 'soc/site/edit.html' new_params['home_template'] = 'soc/site/home.html' new_params['create_extra_dynaproperties'] = { 'link_id': forms.CharField(widget=forms.HiddenInput, required=True), 'noreply_email': forms.EmailField(required=False), } new_params['edit_extra_dynaproperties'] = { 'link_id': forms.CharField(widget=forms.HiddenInput, required=True), 'home_link_id': widgets.ReferenceField( reference_url='document', required=False, filter_fields={'prefix': new_params['document_prefix']}, label=ugettext('Home page Document link ID'), help_text=soc.models.work.Work.link_id.help_text), 'tos_link_id': widgets.ReferenceField( reference_url='document', required=False, filter_fields={'prefix': new_params['document_prefix']}, label=ugettext('Terms of Service Document link ID'), help_text=soc.models.work.Work.link_id.help_text), 'clean_noreply_email': cleaning.clean_empty_field('noreply_email'), } # XSRF secret key is not editable by mere mortals. new_params['extra_dynaexclude'] = ['xsrf_secret_key'] patterns = [] page_name = "Home Page" patterns += [(r'^$', 'soc.views.models.%(module_name)s.main_public', page_name)] page_name = "Edit Site" patterns += [(r'^%(url_name)s/(?P<access_type>edit)$', 'soc.views.models.%(module_name)s.main_edit', page_name)] if soc.logic.system.isDebug(): patterns += [('^seed_db$', 'soc.models.seed_db.seed', "Seed DB"), ('^clear_db$', 'soc.models.seed_db.clear', "Clear DB"), ('^reseed_db$', 'soc.models.seed_db.reseed', "Reseed DB"), ('^seed_many$', 'soc.models.seed_db.seed_many', "Seed Many"), ('^new_seed_many$', 'soc.models.seed_db.new_seed_many', "New Seed Many"), ] new_params['extra_django_patterns'] = patterns params = dicts.merge(params, new_params) super(View, self).__init__(params=params)
def __init__(self, params=None): """Defines the fields and methods required for the base View class to provide the user with list, public, create, edit and delete views. Params: params: a dict with params for this View """ rights = access.GSoCChecker(params) rights['any_access'] = ['allow'] rights['show'] = ['allow'] rights['create'] = [('checkSeeded', ['checkHasRoleForScope', host_logic])] rights['edit'] = [('checkIsHostForProgram', [program_logic])] rights['delete'] = ['checkIsDeveloper'] rights['assign_slots'] = [('checkIsHostForProgram', [program_logic])] rights['slots'] = [('checkIsHostForProgram', [program_logic])] rights['show_duplicates'] = [('checkIsHostForProgram', [program_logic]) ] rights['assigned_proposals'] = [('checkIsHostForProgram', [program_logic])] rights['accepted_orgs'] = [('checkIsAfterEvent', [ 'accepted_organization_announced_deadline', '__all__', program_logic ])] rights['list_participants'] = [('checkIsHostForProgram', [program_logic])] rights['list_projects'] = [('checkIsAfterEvent', [ 'accepted_students_announced_deadline', '__all__', program_logic ])] new_params = {} new_params['logic'] = program_logic new_params['rights'] = rights new_params['name'] = "GSoC Program" new_params['module_name'] = "program" new_params['sidebar_grouping'] = 'Programs' new_params['document_prefix'] = 'gsoc_program' new_params['module_package'] = 'soc.modules.gsoc.views.models' new_params['url_prefix'] = 'gsoc' new_params['url_name'] = 'gsoc/program' new_params['extra_dynaexclude'] = ['slots_allocation'] new_params['create_dynafields'] = [ { 'name': 'org_tags', 'base': forms.fields.Field, 'widget': forms.widgets.Textarea, 'label': 'Predefined organization tags', 'required': False, 'group': ugettext('Manage organization tags'), 'help_text': ugettext( 'Enter predefined tags to be used by ' 'organization admins to tag their organizations. Each line ' 'should contain only one tag') }, ] new_params['create_extra_dynaproperties'] = { 'clean_org_tags': gsoc_cleaning.cleanTagsList('org_tags'), 'clean_facebook': cleaning.clean_url('facebook'), 'clean_twitter': cleaning.clean_url('twitter'), 'clean_blogger': cleaning.clean_url('blogger'), 'clean_email': cleaning.clean_empty_field('email'), 'clean_irc': cleaning.clean_empty_field('irc'), } new_params['org_app_logic'] = org_app_logic # used to list the participants in this program new_params['participants_logic'] = [(org_admin_logic, 'program'), (mentor_logic, 'program'), (student_logic, 'scope')] params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params)
def __init__(self, params=None): """Defines the fields and methods required for the base View class to provide the user with list, public, create, edit and delete views. Params: params: a dict with params for this View """ rights = access.GSoCChecker(params) rights['any_access'] = ['allow'] rights['show'] = ['allow'] rights['create'] = [('checkSeeded', ['checkHasRoleForScope', host_logic])] rights['edit'] = [('checkIsHostForProgram', [program_logic])] rights['delete'] = ['checkIsDeveloper'] rights['assign_slots'] = [('checkIsHostForProgram', [program_logic])] rights['slots'] = [('checkIsHostForProgram', [program_logic])] rights['show_duplicates'] = [('checkIsHostForProgram', [program_logic])] rights['assigned_proposals'] = [('checkIsHostForProgram', [program_logic])] rights['accepted_orgs'] = [('checkIsAfterEvent', ['accepted_organization_announced_deadline', '__all__', program_logic])] rights['list_participants'] = [('checkIsHostForProgram', [program_logic])] rights['list_projects'] = [('checkIsAfterEvent', ['accepted_students_announced_deadline', '__all__', program_logic])] new_params = {} new_params['logic'] = program_logic new_params['rights'] = rights new_params['name'] = "GSoC Program" new_params['module_name'] = "program" new_params['sidebar_grouping'] = 'Programs' new_params['document_prefix'] = 'gsoc_program' new_params['module_package'] = 'soc.modules.gsoc.views.models' new_params['url_prefix'] = 'gsoc' new_params['url_name'] = 'gsoc/program' new_params['extra_dynaexclude'] = ['slots_allocation'] new_params['create_dynafields'] = [ {'name': 'org_tags', 'base': forms.fields.Field, 'widget': forms.widgets.Textarea, 'label': 'Predefined organization tags', 'required': False, 'group': ugettext('Manage organization tags'), 'help_text': ugettext('Enter predefined tags to be used by ' 'organization admins to tag their organizations. Each line ' 'should contain only one tag')}, ] new_params['create_extra_dynaproperties'] = { 'clean_org_tags': gsoc_cleaning.cleanTagsList('org_tags'), 'clean_facebook': cleaning.clean_url('facebook'), 'clean_twitter': cleaning.clean_url('twitter'), 'clean_blogger': cleaning.clean_url('blogger'), 'clean_email': cleaning.clean_empty_field('email'), 'clean_irc': cleaning.clean_empty_field('irc'), } new_params['org_app_logic'] = org_app_logic # used to list the participants in this program new_params['participants_logic'] = [ (org_admin_logic, 'program'), (mentor_logic, 'program'), (student_logic, 'scope')] params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params)