示例#1
0
 def testCleanPhoneNumber(self):
   """Tests that phone number can be cleaned.
   """
   field_name = 'test_phone_number'
   clean_field = cleaning.clean_phone_number(field_name)
   # Test that the phone number will be returned if it contains digits only
   field_value = '0010208636479'
   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 phone number contains non digits (except '+')
   field_value = '001-020-8636479'
   self.form.cleaned_data[field_name] = field_value
   self.assertRaises(forms.ValidationError, clean_field, self.form)
   # Test that the '+' will be replaced with 00 and then the modified number
   # will be returned if the phone number starts with a '+'
   field_value = '+10208636479'
   self.form.cleaned_data[field_name] = field_value
   expected = '00' + field_value[1:]
   self.assertEqual(clean_field(self.form), expected)
   # Test that forms.ValidationError will be raised if
   # a '+' is in the middle of the phone number
   field_value = '1+0208636479'
   self.form.cleaned_data[field_name] = field_value
   self.assertRaises(forms.ValidationError, clean_field, self.form)
   # Test that forms.ValidationError will be raised if
   # a '+' is at the end of the phone number
   field_value = '10208636479+'
   self.form.cleaned_data[field_name] = field_value
   self.assertRaises(forms.ValidationError, clean_field, self.form)
示例#2
0
 def testCleanPhoneNumber(self):
     """Tests that phone number can be cleaned.
 """
     field_name = 'test_phone_number'
     clean_field = cleaning.clean_phone_number(field_name)
     # Test that the phone number will be returned if it contains digits only
     field_value = '0010208636479'
     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 phone number contains non digits (except '+')
     field_value = '001-020-8636479'
     self.form.cleaned_data[field_name] = field_value
     self.assertRaises(forms.ValidationError, clean_field, self.form)
     # Test that the '+' will be replaced with 00 and then the modified number
     # will be returned if the phone number starts with a '+'
     field_value = '+10208636479'
     self.form.cleaned_data[field_name] = field_value
     expected = '00' + field_value[1:]
     self.assertEqual(clean_field(self.form), expected)
     # Test that forms.ValidationError will be raised if
     # a '+' is in the middle of the phone number
     field_value = '1+0208636479'
     self.form.cleaned_data[field_name] = field_value
     self.assertRaises(forms.ValidationError, clean_field, self.form)
     # Test that forms.ValidationError will be raised if
     # a '+' is at the end of the phone number
     field_value = '10208636479+'
     self.form.cleaned_data[field_name] = field_value
     self.assertRaises(forms.ValidationError, clean_field, self.form)
示例#3
0
  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['list_row'] = 'soc/group/list/row.html'
    new_params['list_heading'] = 'soc/group/list/heading.html'

    new_params['create_extra_dynaproperties'] = {
       'email': forms.fields.EmailField(required=True),
       'clean_phone': cleaning.clean_phone_number('phone'),
       'clean_contact_street': cleaning.clean_ascii_only('contact_street'),
       'clean_contact_city': cleaning.clean_ascii_only('contact_city'),
       'clean_contact_state': cleaning.clean_ascii_only('contact_state'),
       'clean_contact_postalcode': cleaning.clean_ascii_only(
          'contact_postalcode'),
       'clean_shipping_street': cleaning.clean_ascii_only('shipping_street'),
       'clean_shipping_city': cleaning.clean_ascii_only('shipping_city'),
       'clean_shipping_state': cleaning.clean_ascii_only('shipping_state'),
       'clean_shipping_postalcode': cleaning.clean_ascii_only(
          '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)
示例#4
0
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
示例#5
0
    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.

    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)/%(scope)s/%(lnp)s$',
                 '%(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['extra_django_patterns'] = patterns
        new_params['scope_redirect'] = redirects.getInviteRedirect
        new_params['manage_redirect'] = redirects.getListRolesRedirect

        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_ascii_only('given_name'),
            'clean_surname':
            cleaning.clean_ascii_only('surname'),
            'clean_phone':
            cleaning.clean_phone_number('phone'),
            'clean_res_street':
            cleaning.clean_ascii_only('res_street'),
            'clean_res_city':
            cleaning.clean_ascii_only('res_city'),
            'clean_res_state':
            cleaning.clean_ascii_only('res_state'),
            'clean_res_postalcode':
            cleaning.clean_ascii_only('res_postalcode'),
            'clean_ship_street':
            cleaning.clean_ascii_only('ship_street'),
            'clean_ship_city':
            cleaning.clean_ascii_only('ship_city'),
            'clean_ship_state':
            cleaning.clean_ascii_only('ship_state'),
            'clean_ship_postalcode':
            cleaning.clean_ascii_only('ship_postalcode'),
            'clean_home_page':
            cleaning.clean_url('home_page'),
            'clean_blog':
            cleaning.clean_url('blog'),
            'clean_photo_url':
            cleaning.clean_url('photo_url'),
            'scope_path':
            forms.CharField(widget=forms.HiddenInput, required=True),
        }

        new_params['extra_dynaexclude'] = [
            'user', 'status', 'agreed_to_tos_on'
        ]

        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

        if self._params.get('show_in_roles_overview'):
            # add to roles overview
            addRole(self)
示例#6
0
  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$',
        'soc.views.models.%(module_name)s.list_requests',
        'List of requests for %(name)s'),
        (r'^%(url_name)s/(?P<access_type>list_roles)/%(key_fields)s$',
        'soc.views.models.%(module_name)s.list_roles',
        'List of roles for %(name)s')]

    if params.get('group_applicant_url'):
      # add the applicant pattern
      patterns += [
          (r'^%(url_name)s/(?P<access_type>applicant)/%(key_fields)s$',
          'soc.views.models.%(module_name)s.applicant', 
          "%(name)s Creation via Accepted Application"),]

    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['list_row'] = 'soc/group/list/row.html'
    new_params['list_heading'] = 'soc/group/list/heading.html'

    new_params['create_extra_dynaproperties'] = {
       'email': forms.fields.EmailField(required=True),
       'clean_phone': cleaning.clean_phone_number('phone'),
       'clean_contact_street': cleaning.clean_ascii_only('contact_street'),
       'clean_contact_city': cleaning.clean_ascii_only('contact_city'),
       'clean_contact_state': cleaning.clean_ascii_only('contact_state'),
       'clean_contact_postalcode': cleaning.clean_ascii_only(
          'contact_postalcode'),
       'clean_shipping_street': cleaning.clean_ascii_only('shipping_street'),
       'clean_shipping_city': cleaning.clean_ascii_only('shipping_city'),
       'clean_shipping_state': cleaning.clean_ascii_only('shipping_state'),
       'clean_shipping_postalcode': cleaning.clean_ascii_only(
          'shipping_postalcode'),
       }

    new_params['role_views'] = {}

    params = dicts.merge(params, new_params, sub_merge=True)

    super(View, self).__init__(params=params)
示例#7
0
  def __init__(self, params=None):
    """

    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$',
          'soc.views.models.%(module_name)s.invite',
          'Create invite for %(name)s'),
          (r'^%(url_name)s/(?P<access_type>accept_invite)/%(scope)s/%(lnp)s$',
          'soc.views.models.%(module_name)s.accept_invite',
          'Accept invite for %(name)s'),
          (r'^%(url_name)s/(?P<access_type>process_request)/%(scope)s/%(lnp)s$',
          'soc.views.models.%(module_name)s.process_request',
          'Process request for %(name)s'),
          (r'^%(url_name)s/(?P<access_type>request)/%(scope)s$',
          'soc.views.models.%(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$',
          'soc.views.models.%(module_name)s.invite',
          'Create invite for %(name)s'),
          (r'^%(url_name)s/(?P<access_type>accept_invite)/%(scope)s/%(lnp)s$',
          'soc.views.models.%(module_name)s.accept_invite',
          'Accept invite for %(name)s'),
          (r'^%(url_name)s/(?P<access_type>process_request)/%(scope)s/%(lnp)s$',
          'soc.views.models.%(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$',
        'soc.views.models.%(module_name)s.manage',
        'Manage a %(name)s'),]

    new_params['extra_django_patterns'] = patterns
    new_params['scope_redirect'] = redirects.getInviteRedirect
    new_params['manage_redirect'] = redirects.getListRolesRedirect

    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_phone': cleaning.clean_phone_number('phone'),
       'clean_res_street': cleaning.clean_ascii_only('res_street'),
       'clean_res_city': cleaning.clean_ascii_only('res_city'),
       'clean_res_state': cleaning.clean_ascii_only('res_state'),
       'clean_res_postalcode': cleaning.clean_ascii_only('res_postalcode'),
       'clean_ship_street': cleaning.clean_ascii_only('ship_street'),
       'clean_ship_city': cleaning.clean_ascii_only('ship_city'),
       'clean_ship_state': cleaning.clean_ascii_only('ship_state'),
       'clean_ship_postalcode': cleaning.clean_ascii_only('ship_postalcode'),
       'clean_home_page': cleaning.clean_url('home_page'),
       'clean_blog': cleaning.clean_url('blog'),
       'clean_photo_url': cleaning.clean_url('photo_url'),
       'scope_path': forms.CharField(widget=forms.HiddenInput,
                                  required=True),
       }

    new_params['extra_dynaexclude'] = ['user', 'status', 'agreed_to_tos_on']

    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

    if self._params.get('show_in_roles_overview'):
      # add to roles overview
      addRole(self)
示例#8
0
    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)
示例#9
0
class ProfileForm(forms.ModelForm):
    """Django form for profile page.
  """

    TWO_LETTER_STATE_REQ = ['United States', 'Canada']

    def __init__(self, bound_field_class, request_data=None, **kwargs):
        super(ProfileForm, self).__init__(bound_field_class, **kwargs)
        self.fields['given_name'].group = "2. Contact Info (Private)"
        self.fields['surname'].group = "2. Contact Info (Private)"
        self.request_data = request_data
        self.program = request_data.program if request_data else None

    public_name = fields.CharField(required=True)

    clean_public_name = cleaning.clean_html_content('public_name')
    clean_name_on_documents = cleaning.clean_html_content('name_on_documents')
    clean_im_network = cleaning.clean_html_content('im_network')
    clean_im_handle = cleaning.clean_html_content('im_handle')
    clean_program_knowledge = cleaning.clean_html_content('program_knowledge')
    clean_email = cleaning.clean_email('email')
    clean_phone = cleaning.clean_phone_number('phone')

    def clean_given_name(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['given_name'])

    def clean_surname(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['surname'])

    def clean_res_street(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['res_street'])

    def clean_res_city(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['res_city'])

    def clean_res_street_extra(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['res_street_extra'])

    def clean_res_state(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['res_state'])

    def clean_res_postalcode(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['res_postalcode'])

    def clean_ship_name(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['ship_name'])

    def clean_ship_street(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['ship_street'])

    def clean_ship_street_extra(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['ship_street_extra'])

    def clean_ship_city(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['ship_city'])

    def clean_ship_state(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['ship_state'])

    def clean_ship_postalcode(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['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 in self.TWO_LETTER_STATE_REQ and (not state
                                                     or len(state) != 2):
            self._errors['res_state'] = [
                "Please use a 2-letter state/province name"
            ]

        country = self.cleaned_data.get('ship_country')
        state = self.cleaned_data.get('ship_state')
        if country in self.TWO_LETTER_STATE_REQ and (not state
                                                     or len(state) != 2):
            self._errors['ship_state'] = [
                "Please use a 2-letter state/province name"
            ]
        return self.cleaned_data
示例#10
0
  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)
示例#11
0
  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)