def testCleanValidShippingChars(self): """Tests that the shipping fields can be cleaned. """ field_name = 'ascii' clean_field = cleaning.clean_valid_shipping_chars(field_name) # Test that the value will be returned if the value of field is valid field_value = 'ab12' self.form.cleaned_data = {field_name: field_value} self.assertEqual(clean_field(self.form), field_value) # Test that forms.ValidationError will be raised if the value of field # is not valid ascii field_value = u'\ua000' self.form.cleaned_data = {field_name: field_value} self.assertRaises(forms.ValidationError, clean_field, self.form)
def __init__(self, params={}): """Defines the fields and methods required for the base View class to provide the user with list, public, create, edit and delete views. Args: params: This dictionary should be filled with the parameters """ new_params = {} patterns = params.get('extra_django_patterns') if not patterns: patterns = [] if params.get('allow_requests_and_invites'): # add patterns concerning requests and invites patterns += [ (r'^%(url_name)s/(?P<access_type>invite)/%(scope)s$', '%(module_package)s.%(module_name)s.invite', 'Create invite for %(name)s'), (r'^%(url_name)s/(?P<access_type>accept_invite)/(?P<id>[0-9]*)$', '%(module_package)s.%(module_name)s.accept_invite', 'Accept invite for %(name)s'), (r'^%(url_name)s/(?P<access_type>process_request)/(?P<id>[0-9]*)$', '%(module_package)s.%(module_name)s.process_request', 'Process request'), (r'^%(url_name)s/(?P<access_type>request)/%(scope)s$', '%(module_package)s.%(module_name)s.role_request', 'Create a Request to become %(name)s') ] elif params.get('allow_invites'): # add patterns concerning only invites patterns += [ (r'^%(url_name)s/(?P<access_type>invite)/%(scope)s$', '%(module_package)s.%(module_name)s.invite', 'Create invite for %(name)s'), (r'^%(url_name)s/(?P<access_type>accept_invite)/(?P<id>[0-9]*)$', '%(module_package)s.%(module_name)s.accept_invite', 'Accept invite for %(name)s'), (r'^%(url_name)s/(?P<access_type>process_request)/(?P<id>[0-9]*)$', '%(module_package)s.%(module_name)s.process_request', 'Process request for %(name)s') ] # add manage pattern patterns += [ (r'^%(url_name)s/(?P<access_type>manage)/%(scope)s/%(lnp)s$', '%(module_package)s.%(module_name)s.manage', 'Manage a %(name)s'), ] new_params['logic'] = soc.logic.models.role.logic new_params['extra_django_patterns'] = patterns new_params['scope_redirect'] = redirects.getInviteRedirect new_params['manage_redirect'] = redirects.getListRolesRedirect new_params['name'] = "Role" new_params['module_name'] = 'role' new_params['create_template'] = 'soc/role/edit.html' new_params['edit_template'] = 'soc/role/edit.html' new_params['create_extra_dynaproperties'] = { 'latitude': forms.fields.FloatField(widget=forms.HiddenInput, required=False), 'longitude': forms.fields.FloatField(widget=forms.HiddenInput, required=False), 'email': forms.fields.EmailField(required=True), 'clean_link_id': cleaning.clean_existing_user('link_id'), 'clean_given_name': cleaning.clean_valid_shipping_chars('given_name'), 'clean_surname': cleaning.clean_valid_shipping_chars('surname'), 'clean_phone': cleaning.clean_phone_number('phone'), 'clean_res_street': cleaning.clean_valid_shipping_chars('res_street'), 'clean_res_street_extra': cleaning.clean_valid_shipping_chars('res_street_extra'), 'clean_res_city': cleaning.clean_valid_shipping_chars('res_city'), 'clean_res_state': cleaning.clean_valid_shipping_chars('res_state'), 'clean_res_postalcode': cleaning.clean_valid_shipping_chars('res_postalcode'), 'clean_ship_name': cleaning.clean_valid_shipping_chars('ship_name'), 'clean_ship_street': cleaning.clean_valid_shipping_chars('ship_street'), 'clean_ship_street_extra': cleaning.clean_valid_shipping_chars('ship_street_extra'), 'clean_ship_city': cleaning.clean_valid_shipping_chars('ship_city'), 'clean_ship_state': cleaning.clean_valid_shipping_chars('ship_state'), 'clean_ship_postalcode': cleaning.clean_valid_shipping_chars('ship_postalcode'), 'clean_home_page': cleaning.clean_url('home_page'), 'clean_blog': cleaning.clean_url('blog'), 'clean_photo_url': cleaning.clean_url('photo_url'), 'clean': cleaning.validate_role(), 'scope_path': forms.CharField(widget=forms.HiddenInput, required=True), } new_params['extra_dynaexclude'] = [ 'user', 'status', 'agreed_to_tos_on', 'mentor_for', 'org_admin_for', 'student_info' ] new_params['show_in_roles_overview'] = True # define the fields for the admin list new_params['admin_field_keys'] = [ 'link_id', 'given_name', 'surname', 'document_name', 'email', 'res_street', 'res_street_extra', 'res_city', 'res_state', 'res_country', 'res_postalcode', 'phone', 'recipient_name', 'shipping_street', 'shipping_street_extra', 'shipping_city', 'shipping_state', 'shipping_country', 'shipping_postalcode', 'birth_date', 'tshirt_style', 'tshirt_size', 'gender', 'group_name', 'status', 'account_name', ] new_params['admin_field_names'] = [ 'Link ID', 'Name', 'Surname', 'Name on Documents', 'Email', 'Street Address 1', 'Street Address 2', 'City', 'State', 'Country', 'Postal Code', 'Phone Number', 'Recipient Name', 'Shipping Street Address 1', 'Shipping Street Address 2', 'Shipping City', 'Shipping State', 'Shipping Country', 'Shipping Postal Code', 'Birth Date', 'T-Shirt Style', 'T-Shirt Size', 'Gender', 'Group Name', 'Status', 'Account Name', ] new_params['admin_field_prefetch'] = ['scope', 'user'] new_params['admin_field_extra'] = lambda entity: { 'group_name': entity.scope.name, 'birth_date': entity.birth_date.isoformat(), 'account_name': accounts.normalizeAccount(entity.user.account). email() } new_params['admin_field_hidden'] = ['tshirt_style', 'tshirt_size'] params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params=params) # add manage template template = 'soc/%(module_name)s/manage.html' % self._params self._params['manage_template'] = template # register this View addRole(self)
def __init__(self, params={}): """Defines the fields and methods required for the base View class to provide the user with list, public, create, edit and delete views. Args: params: This dictionary should be filled with the parameters """ new_params = {} patterns = params.get('extra_django_patterns') if not patterns: patterns = [] if params.get('allow_requests_and_invites'): # add patterns concerning requests and invites patterns += [(r'^%(url_name)s/(?P<access_type>invite)/%(scope)s$', '%(module_package)s.%(module_name)s.invite', 'Create invite for %(name)s'), (r'^%(url_name)s/(?P<access_type>accept_invite)/(?P<id>[0-9]*)$', '%(module_package)s.%(module_name)s.accept_invite', 'Accept invite for %(name)s'), (r'^%(url_name)s/(?P<access_type>process_request)/(?P<id>[0-9]*)$', '%(module_package)s.%(module_name)s.process_request', 'Process request'), (r'^%(url_name)s/(?P<access_type>request)/%(scope)s$', '%(module_package)s.%(module_name)s.role_request', 'Create a Request to become %(name)s')] elif params.get('allow_invites'): # add patterns concerning only invites patterns += [(r'^%(url_name)s/(?P<access_type>invite)/%(scope)s$', '%(module_package)s.%(module_name)s.invite', 'Create invite for %(name)s'), (r'^%(url_name)s/(?P<access_type>accept_invite)/(?P<id>[0-9]*)$', '%(module_package)s.%(module_name)s.accept_invite', 'Accept invite for %(name)s'), (r'^%(url_name)s/(?P<access_type>process_request)/(?P<id>[0-9]*)$', '%(module_package)s.%(module_name)s.process_request', 'Process request for %(name)s')] # add manage pattern patterns += [(r'^%(url_name)s/(?P<access_type>manage)/%(scope)s/%(lnp)s$', '%(module_package)s.%(module_name)s.manage', 'Manage a %(name)s'),] new_params['logic'] = soc.logic.models.role.logic new_params['extra_django_patterns'] = patterns new_params['scope_redirect'] = redirects.getInviteRedirect new_params['manage_redirect'] = redirects.getListRolesRedirect new_params['name'] = "Role" new_params['module_name'] = 'role' new_params['create_template'] = 'soc/role/edit.html' new_params['edit_template'] = 'soc/role/edit.html' new_params['create_extra_dynaproperties'] = { 'latitude':forms.fields.FloatField(widget=forms.HiddenInput, required=False), 'longitude': forms.fields.FloatField(widget=forms.HiddenInput, required=False), 'email': forms.fields.EmailField(required=True), 'clean_link_id': cleaning.clean_existing_user('link_id'), 'clean_given_name': cleaning.clean_valid_shipping_chars('given_name'), 'clean_surname': cleaning.clean_valid_shipping_chars('surname'), 'clean_phone': cleaning.clean_phone_number('phone'), 'clean_res_street': cleaning.clean_valid_shipping_chars('res_street'), 'clean_res_street_extra': cleaning.clean_valid_shipping_chars('res_street_extra'), 'clean_res_city': cleaning.clean_valid_shipping_chars('res_city'), 'clean_res_state': cleaning.clean_valid_shipping_chars('res_state'), 'clean_res_postalcode': cleaning.clean_valid_shipping_chars('res_postalcode'), 'clean_ship_name': cleaning.clean_valid_shipping_chars('ship_name'), 'clean_ship_street': cleaning.clean_valid_shipping_chars('ship_street'), 'clean_ship_street_extra': cleaning.clean_valid_shipping_chars( 'ship_street_extra'), 'clean_ship_city': cleaning.clean_valid_shipping_chars('ship_city'), 'clean_ship_state': cleaning.clean_valid_shipping_chars('ship_state'), 'clean_ship_postalcode': cleaning.clean_valid_shipping_chars('ship_postalcode'), 'clean_home_page': cleaning.clean_url('home_page'), 'clean_blog': cleaning.clean_url('blog'), 'clean_photo_url': cleaning.clean_url('photo_url'), 'clean': cleaning.validate_role(), 'scope_path': forms.CharField(widget=forms.HiddenInput, required=True), } new_params['extra_dynaexclude'] = ['user', 'status', 'agreed_to_tos_on', 'mentor_for', 'org_admin_for', 'student_info'] new_params['show_in_roles_overview'] = True # define the fields for the admin list new_params['admin_field_keys'] = [ 'link_id', 'given_name', 'surname', 'document_name', 'email', 'res_street', 'res_street_extra', 'res_city', 'res_state', 'res_country', 'res_postalcode', 'phone', 'recipient_name', 'shipping_street', 'shipping_street_extra', 'shipping_city', 'shipping_state', 'shipping_country', 'shipping_postalcode', 'birth_date', 'tshirt_style', 'tshirt_size', 'gender', 'group_name', 'status', 'account_name', ] new_params['admin_field_names'] = [ 'Link ID', 'Name', 'Surname', 'Name on Documents', 'Email', 'Street Address 1', 'Street Address 2', 'City', 'State', 'Country', 'Postal Code', 'Phone Number', 'Recipient Name', 'Shipping Street Address 1', 'Shipping Street Address 2', 'Shipping City', 'Shipping State', 'Shipping Country', 'Shipping Postal Code', 'Birth Date', 'T-Shirt Style', 'T-Shirt Size', 'Gender', 'Group Name', 'Status', 'Account Name', ] new_params['admin_field_prefetch'] = ['scope', 'user'] new_params['admin_field_extra'] = lambda entity: { 'group_name': entity.scope.name, 'birth_date': entity.birth_date.isoformat(), 'account_name': accounts.normalizeAccount(entity.user.account).email() } new_params['admin_field_hidden'] = ['tshirt_style', 'tshirt_size'] params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params=params) # add manage template template = 'soc/%(module_name)s/manage.html' % self._params self._params['manage_template'] = template # register this View addRole(self)
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['extra_dynaexclude'] = ['founder', 'home', 'tos', 'member_template', 'status'] new_params['edit_extra_dynaproperties'] = { 'founded_by': forms.CharField(widget=widgets.ReadOnlyInput(), required=False), } #set the extra_django_patterns and include the one from params patterns = params.get('extra_django_patterns', []) patterns += [ (r'^%(url_name)s/(?P<access_type>list_requests)/%(key_fields)s$', '%(module_package)s.%(module_name)s.list_requests', 'List of requests for %(name)s'), (r'^%(url_name)s/(?P<access_type>list_roles)/%(key_fields)s$', '%(module_package)s.%(module_name)s.list_roles', 'List of roles for %(name)s')] new_params['extra_django_patterns'] = patterns # TODO(tlarsen): Add support for Django style template lookup new_params['public_template'] = 'soc/group/public.html' new_params['create_extra_dynaproperties'] = { 'email': forms.fields.EmailField(required=True), 'clean_phone': cleaning.clean_phone_number('phone'), 'clean_contact_street': cleaning.clean_valid_shipping_chars('contact_street'), 'clean_contact_street_extra': cleaning.clean_valid_shipping_chars('contact_street_extra'), 'clean_contact_city': cleaning.clean_valid_shipping_chars('contact_city'), 'clean_contact_state': cleaning.clean_valid_shipping_chars('contact_state'), 'clean_contact_postalcode': cleaning.clean_valid_shipping_chars('contact_postalcode'), 'clean_shipping_street': cleaning.clean_valid_shipping_chars('shipping_street'), 'clean_shipping_street_extra': cleaning.clean_valid_shipping_chars('shipping_street_extra'), 'clean_shipping_city': cleaning.clean_valid_shipping_chars('shipping_city'), 'clean_shipping_state': cleaning.clean_valid_shipping_chars('shipping_state'), 'clean_shipping_postalcode': cleaning.clean_valid_shipping_chars('shipping_postalcode'), } new_params['role_views'] = {} new_params['public_field_keys'] = ["name", "link_id", "short_name"] new_params['public_field_names'] = ["Name", "Link ID", "Short name"] params = dicts.merge(params, new_params, sub_merge=True) 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 """ new_params = {} new_params['extra_dynaexclude'] = [ 'founder', 'home', 'tos', 'member_template', 'status' ] new_params['edit_extra_dynaproperties'] = { 'founded_by': forms.CharField(widget=widgets.ReadOnlyInput(), required=False), } #set the extra_django_patterns and include the one from params patterns = params.get('extra_django_patterns', []) patterns += [ (r'^%(url_name)s/(?P<access_type>list_requests)/%(key_fields)s$', '%(module_package)s.%(module_name)s.list_requests', 'List of requests for %(name)s'), (r'^%(url_name)s/(?P<access_type>list_roles)/%(key_fields)s$', '%(module_package)s.%(module_name)s.list_roles', 'List of roles for %(name)s') ] new_params['extra_django_patterns'] = patterns # TODO(tlarsen): Add support for Django style template lookup new_params['public_template'] = 'soc/group/public.html' new_params['create_extra_dynaproperties'] = { 'email': forms.fields.EmailField(required=True), 'clean_phone': cleaning.clean_phone_number('phone'), 'clean_contact_street': cleaning.clean_valid_shipping_chars('contact_street'), 'clean_contact_street_extra': cleaning.clean_valid_shipping_chars('contact_street_extra'), 'clean_contact_city': cleaning.clean_valid_shipping_chars('contact_city'), 'clean_contact_state': cleaning.clean_valid_shipping_chars('contact_state'), 'clean_contact_postalcode': cleaning.clean_valid_shipping_chars('contact_postalcode'), 'clean_shipping_street': cleaning.clean_valid_shipping_chars('shipping_street'), 'clean_shipping_street_extra': cleaning.clean_valid_shipping_chars('shipping_street_extra'), 'clean_shipping_city': cleaning.clean_valid_shipping_chars('shipping_city'), 'clean_shipping_state': cleaning.clean_valid_shipping_chars('shipping_state'), 'clean_shipping_postalcode': cleaning.clean_valid_shipping_chars('shipping_postalcode'), } new_params['role_views'] = {} new_params['public_field_keys'] = ["name", "link_id", "short_name"] new_params['public_field_names'] = ["Name", "Link ID", "Short name"] params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params=params)
class ProfileForm(forms.ModelForm): """Django form for profile page. """ class Meta: model = GSoCProfile css_prefix = 'gsoc_profile' exclude = ['link_id', 'user', 'scope', 'mentor_for', 'org_admin_for', 'student_info', 'agreed_to_tos_on', 'scope_path', 'status', 'name_on_documents', 'agreed_to_tos'] widgets = forms.choiceWidgets(GSoCProfile, ['res_country', 'ship_country', 'tshirt_style', 'tshirt_size', 'gender']) clean_given_name = cleaning.clean_valid_shipping_chars('given_name') clean_surname = cleaning.clean_valid_shipping_chars('surname') clean_phone = cleaning.clean_phone_number('phone') clean_res_street = cleaning.clean_valid_shipping_chars('res_street') clean_res_street_extra = cleaning.clean_valid_shipping_chars( 'res_street_extra') clean_res_city = cleaning.clean_valid_shipping_chars('res_city') clean_res_state = cleaning.clean_valid_shipping_chars('res_state') clean_res_postalcode = cleaning.clean_valid_shipping_chars( 'res_postalcode') clean_ship_name = cleaning.clean_valid_shipping_chars('ship_name') clean_ship_street = cleaning.clean_valid_shipping_chars('ship_street') clean_ship_street_extra = cleaning.clean_valid_shipping_chars( 'ship_street_extra') clean_ship_city = cleaning.clean_valid_shipping_chars('ship_city') clean_ship_state = cleaning.clean_valid_shipping_chars('ship_state') clean_ship_postalcode = cleaning.clean_valid_shipping_chars( 'ship_postalcode') clean_home_page = cleaning.clean_url('home_page') clean_blog = cleaning.clean_url('blog') clean_photo_url = cleaning.clean_url('photo_url') def clean(self): country = self.cleaned_data.get('res_country') state = self.cleaned_data.get('res_state') if country == 'United States' and (not state or len(state) != 2): self._errors['res_state'] = ["Please use a 2-letter state name"] country = self.cleaned_data.get('ship_country') state = self.cleaned_data.get('ship_state') if country == 'United States' and (not state or len(state) != 2): self._errors['ship_state'] = ["Please use a 2-letter state name"] return self.cleaned_data