def clean_backup_admin_id(self): backup_admin = cleaning.clean_existing_user('backup_admin_id')(self) if not self.instance: cleaning.clean_users_not_same('backup_admin_id')(self) elif self.instance.main_admin.key() == backup_admin.key(): raise django_forms.ValidationError( 'You cannot enter the person who created the application here.') self.cleaned_data['backup_admin'] = backup_admin return backup_admin
def clean_backup_admin_id(self): backup_admin = cleaning.clean_existing_user('backup_admin_id')(self) if not self.instance: cleaning.clean_users_not_same('backup_admin_id')(self) else: main_admin_key = ndb.Key.from_old_key( org_app_record.OrgAppRecord.main_admin .get_value_for_datastore(self.instance)) if main_admin_key == backup_admin.key: raise django_forms.ValidationError( 'You cannot enter the person who created the application here.') self.cleaned_data['backup_admin'] = backup_admin.key.to_old_key() return backup_admin
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 """ new_params = {} new_params['logic'] = group_app_logic new_params['name'] = "Group Application" new_params['name_short'] = "Group App" # use the twoline templates for these questionnaires new_params['create_template'] = 'soc/models/twoline_edit.html' new_params['edit_template'] = 'soc/models/twoline_edit.html' patterns = [(r'^%(url_name)s/(?P<access_type>list_self)/%(scope)s$', 'soc.views.models.%(module_name)s.list_self', 'List my %(name_plural)s'), (r'^%(url_name)s/(?P<access_type>review_overview)/%(scope)s$', 'soc.views.models.%(module_name)s.review_overview', 'List of %(name_plural)s for reviewing'), (r'^%(url_name)s/(?P<access_type>review)/%(key_fields)s$', 'soc.views.models.%(module_name)s.review', 'Review %(name_short)s')] new_params['extra_django_patterns'] = patterns new_params['extra_dynaexclude'] = ['applicant', 'backup_admin', 'status', 'created_on', 'last_modified_on'] new_params['create_dynafields'] = [ {'name': 'backup_admin_link_id', 'base': widgets.ReferenceField, 'passthrough': ['reference_url', 'required', 'label'], 'reference_url': 'user', 'required': False, 'label': params['logic'].getModel().backup_admin.verbose_name, 'example_text': ugettext('The link_id of the backup admin'), }, ] new_params['create_extra_dynaproperties'] = { 'email': forms.fields.EmailField(required=True), 'clean_backup_admin_link_id': cleaning.clean_users_not_same('backup_admin_link_id'), } new_params['edit_extra_dynaproperties'] = { 'clean_link_id' : cleaning.clean_link_id('link_id'), } params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params=params)
def clean_backup_admin(self): """Cleans the backup admin field. Backup admin may not be equal to the Main admin if a SurveyRecord already exists otherwise it may not be equal to the current user. """ from soc.logic import cleaning if self.survey_record: backup_admin = cleaning.clean_existing_user('backup_admin')(self) main_admin = self.survey_record.main_admin if main_admin.key() == backup_admin.key(): #raise validation error, non valid backup admin raise forms.ValidationError('You may not enter the Main Admin here.') else: backup_admin = cleaning.clean_users_not_same('backup_admin')(self) return backup_admin
def testCleanUsersNotSame(self): """Tests that the user field can be cleaned for non current users. """ field_name = 'test_not_current_user' clean_field = cleaning.clean_users_not_same(field_name) # Test that forms.ValidationError will be raised if the value of field # is the current user's user_id field_value = self.user.user_id self.form.cleaned_data = {field_name: field_value} self.assertRaises(forms.ValidationError, clean_field, self.form) # Test that the user will be returned if the value of field is # a user's user_id other than the current user field_value = self.another_user.user_id self.form.cleaned_data = {field_name: field_value} self.assertEqual(clean_field(self.form).user_id, self.another_user.user_id) # Test that forms.ValidationError will be raised if the value of field # is not an existent user's user_id field_value = 'non_existent_user' self.form.cleaned_data = {field_name: field_value} self.assertRaises(forms.ValidationError, clean_field, self.form)
def clean_backup_admin(self): """Cleans the backup admin field. Backup admin may not be equal to the Main admin if a SurveyRecord already exists otherwise it may not be equal to the current user. """ from soc.logic import cleaning if self.survey_record: backup_admin = cleaning.clean_existing_user('backup_admin')(self) main_admin = self.survey_record.main_admin if main_admin.key() == backup_admin.key(): #raise validation error, non valid backup admin raise forms.ValidationError( 'You may not enter the Main Admin here.') else: backup_admin = cleaning.clean_users_not_same('backup_admin')(self) return backup_admin
def testCleanUsersNotSame(self): """Tests that the user field can be cleaned for non current users. """ field_name = 'test_not_current_user' clean_field = cleaning.clean_users_not_same(field_name) # Test that forms.ValidationError will be raised if the value of field # is the current user's user_id field_value = self.user.user_id self.form.cleaned_data = {field_name: field_value} self.assertRaises(forms.ValidationError, clean_field, self.form) # Test that the user will be returned if the value of field is # a user's user_id other than the current user field_value = self.another_user.user_id self.form.cleaned_data = {field_name: field_value} self.assertEqual( clean_field(self.form).user_id, self.another_user.user_id) # Test that forms.ValidationError will be raised if the value of field # is not an existent user's user_id field_value = 'non_existent_user' self.form.cleaned_data = {field_name: field_value} self.assertRaises(forms.ValidationError, clean_field, self.form)
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 """ new_params = {} new_params['logic'] = group_app_logic new_params['name'] = "Group Application" new_params['name_short'] = "Group App" # use the twoline templates for these questionnaires new_params['create_template'] = 'soc/models/twoline_edit.html' new_params['edit_template'] = 'soc/models/twoline_edit.html' patterns = [(r'^%(url_name)s/(?P<access_type>list_self)/%(scope)s$', 'soc.views.models.%(module_name)s.list_self', 'List my %(name_plural)s'), (r'^%(url_name)s/(?P<access_type>review_overview)/%(scope)s$', 'soc.views.models.%(module_name)s.review_overview', 'List of %(name_plural)s for reviewing'), (r'^%(url_name)s/(?P<access_type>review)/%(key_fields)s$', 'soc.views.models.%(module_name)s.review', 'Review %(name_short)s')] new_params['extra_django_patterns'] = patterns new_params['extra_dynaexclude'] = ['applicant', 'backup_admin', 'status', 'created_on', 'last_modified_on'] new_params['create_dynafields'] = [ {'name': 'backup_admin_link_id', 'base': widgets.ReferenceField, 'passthrough': ['reference_url', 'required', 'label'], 'reference_url': 'user', 'required': False, 'label': params['logic'].getModel().backup_admin.verbose_name, 'example_text': ugettext('The link_id of the backup admin'), }, ] new_params['create_extra_dynaproperties'] = { 'email': forms.fields.EmailField(required=True), 'clean_backup_admin_link_id': cleaning.clean_users_not_same('backup_admin_link_id'), } new_params['edit_extra_dynaproperties'] = { 'clean_link_id' : cleaning.clean_link_id('link_id'), } new_params['public_field_extra'] = lambda entity: { 'ideas': list_helper.urlize(entity.ideas), } new_params['public_field_keys'] = new_params['self_field_keys'] = [ "name", "link_id", "ideas", "status", ] new_params['public_field_names'] = new_params['self_field_names'] = [ "Name", "Link ID", "Ideas Page", "Status", ] new_params['self_field_extra'] = lambda entity: { 'ideas': list_helper.urlize(entity.ideas), 'status': "accepted" if entity.status == "accepted" else "rejected" if entity.status == "rejected" else "under review", } params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params=params)