Example #1
0
class UserForm(forms.ModelForm):
  """Django form for the user profile.
  """

  class Meta:
    model = User
    css_prefix = 'user'
    fields = ['link_id', 'name']

  clean_link_id = cleaning.clean_user_not_exist('link_id')
Example #2
0
class GCIUserForm(gci_forms.GCIModelForm):
    """Django form for User model in GCI program.
  """
    class Meta:
        model = User
        css_prefix = 'user'
        fields = ['link_id']

    link_id = gci_forms.CharField(label='Username',
                                  help_text=LINK_ID_HELP_TEXT)
    clean_link_id = cleaning.clean_user_not_exist('link_id')
Example #3
0
class UserCreateForm(ModelForm):
  """Django form for the User profile.
  """

  class Meta:
    model = User
    fields = ['link_id', 'name']

  clean_link_id = cleaning.clean_user_not_exist('link_id')

  def templatePath(self):
    # TODO: This needs a more generic form.
    return 'modules/gsoc/_form.html'
Example #4
0
 def testCleanUserNotExist(self):
   """Tests that the user field can be cleaned for non-existent users.
   """
   field_name = 'test_user_not_exist'
   clean_field = cleaning.clean_user_not_exist(field_name)
   # Test that the value will be returned 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.assertEqual(clean_field(self.form), field_value)
   # Test that forms.ValidationError will be raised if the value of field
   # is an existent 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)
Example #5
0
 def testCleanUserNotExist(self):
     """Tests that the user field can be cleaned for non-existent users.
 """
     field_name = 'test_user_not_exist'
     clean_field = cleaning.clean_user_not_exist(field_name)
     # Test that the value will be returned 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.assertEqual(clean_field(self.form), field_value)
     # Test that forms.ValidationError will be raised if the value of field
     # is an existent 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)
Example #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
    """

    rights = access.Checker(params)
    rights['unspecified'] = ['deny']
    rights['any_access'] = ['allow']
    rights['create_profile'] = ['checkIsUnusedAccount']
    rights['edit_profile'] = ['checkHasUserEntity']
    rights['roles'] = ['checkIsUser']
    rights['requests'] = ['checkIsUser']
    rights['signIn'] = ['checkNotLoggedIn']
    rights['notification'] = ['checkIsUser']

    new_params = {}
    new_params['rights'] = rights
    new_params['logic'] = user_logic

    new_params['name'] = "User"
    new_params['module_name'] = "user_self"
    new_params['url_name'] = "user"

    new_params['create_template'] = 'soc/user/edit_profile.html'
    new_params['edit_template'] = 'soc/user/edit_profile.html'
    new_params['save_message'] = [ugettext('Profile saved.')]
    new_params['edit_redirect'] = '/%(url_name)s/edit_profile'

    # set the specific fields for the users profile page
    new_params['extra_dynaexclude'] = ['former_accounts', 
        'account', 'is_developer', 'status', 'agreed_to_tos_on']

    new_params['create_extra_dynaproperties'] = {
        'clean_agreed_to_tos': cleaning.clean_agrees_to_tos('agreed_to_tos'),
        'clean_link_id': cleaning.clean_user_not_exist('link_id'),}

    new_params['edit_extra_dynaproperties'] = {
        'clean_link_id': cleaning.clean_user_is_current('link_id', False),
        'agreed_to_tos_on': forms.DateTimeField(
          widget=widgets.ReadOnlyInput(attrs={'disabled':'true'}),
          required=False),
        'email_subscription': forms.BooleanField(required=False)
        }

    new_params['sidebar_heading'] = 'User (self)'
    new_params['sidebar'] = [
        (users.create_login_url("/"), 'Sign In', 'signIn'),
        ('/' + new_params['url_name'] + '/create_profile', 
            'Create Profile', 'create_profile'),
        ('/' + new_params['url_name'] + '/edit_profile', 
            'Edit Profile', 'edit_profile'),
        ('/' + new_params['url_name'] + '/roles', 'Roles', 'roles'),
        ('/' + new_params['url_name'] + '/requests', 'Requests', 'requests'),
        ]

    patterns = []

    page_name = ugettext("Create your profile")
    patterns += [(r'^%(url_name)s/(?P<access_type>create_profile)$',
                  'soc.views.models.%(module_name)s.create', page_name)]

    page_name = ugettext("Edit your profile")
    patterns += [(r'^%(url_name)s/(?P<access_type>edit_profile)$',
                  'soc.views.models.%(module_name)s.edit', page_name)]

    page_name = ugettext("List of your roles")
    patterns += [(r'^%(url_name)s/(?P<access_type>roles)$',
                   'soc.views.models.user_self.roles', page_name)]

    page_name = ugettext("List of your requests")
    patterns += [(r'^%(url_name)s/(?P<access_type>requests)$',
                   'soc.views.models.request.list_self', page_name)]

    new_params['django_patterns_defaults'] = patterns

    params = dicts.merge(params, new_params)

    super(View, self).__init__(params=params)
Example #7
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
    """

    rights = access.Checker(params)
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = ['checkIsDeveloper']
    rights['delete'] = ['checkIsDeveloper']
    rights['show'] = ['allow']
    rights['list'] = ['checkIsDeveloper']
    rights['list_developers'] = ['checkIsDeveloper']

    new_params = {}
    new_params['logic'] = soc.logic.models.user.logic
    new_params['rights'] = rights
    
    new_params['name'] = "User"

    new_params['edit_template'] = 'soc/user/edit.html'
    new_params['pickable'] = True
    new_params['cache_pick'] = True

    new_params['sidebar_heading'] = 'Users'

    new_params['extra_dynaexclude'] = ['former_accounts', 'agreed_to_tos',
        'agreed_to_tos_on', 'status']
    new_params['create_extra_dynaproperties'] = {
        'clean_link_id': cleaning.clean_user_not_exist('link_id'),
        'clean_account': cleaning.clean_user_account_not_in_use('account')}

    # recreate the choices for the edit form
    status_choices = []
    for choice in user_logic.getModel().status.choices:
      status_choices.append((choice, choice))

    new_params['edit_extra_dynaproperties'] = {
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
            required=True),
        'clean_link_id': cleaning.clean_link_id('link_id'),
        'agreed_to_tos_on': forms.DateTimeField(
            widget=widgets.ReadOnlyInput(attrs={'disabled':'true'}),
            required=False),
        'status': forms.ChoiceField(choices=status_choices),
        'clean_account': cleaning.clean_user_account('account'),
        'clean': cleaning.validate_user_edit('link_id', 'account'),
    }

    patterns = []

    patterns += [(r'^%(url_name)s/(?P<access_type>list_developers)$',
                  'soc.views.models.%(module_name)s.list_developers', 
                  "List Developers")]

    new_params['extra_django_patterns'] = patterns

    new_params['sidebar_developer'] = [('/%s/list_developers', 'List Developers',
                                        'list_developers')]

    new_params['public_field_prefetch'] = ['account']
    new_params['public_field_extra'] = lambda entity: {
        "email": entity.account.email(),
    }
    new_params['public_field_keys'] = ['email', 'name', 'link_id']
    new_params['public_field_names'] = ['Email', 'Public name', 'Link ID']

    params = dicts.merge(params, new_params)

    super(View, self).__init__(params=params)
Example #8
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
    """

        rights = access.Checker(params)
        rights['unspecified'] = ['deny']
        rights['any_access'] = ['allow']
        rights['create_profile'] = ['checkIsUnusedAccount']
        rights['edit_profile'] = ['checkHasUserEntity']
        rights['roles'] = ['checkIsUser']
        rights['requests'] = ['checkIsUser']
        rights['signIn'] = ['checkNotLoggedIn']
        rights['notification'] = ['checkIsUser']

        new_params = {}
        new_params['rights'] = rights
        new_params['logic'] = user_logic

        new_params['name'] = "User"
        new_params['module_name'] = "user_self"
        new_params['url_name'] = "user"

        new_params['create_template'] = 'soc/user/edit_profile.html'
        new_params['edit_template'] = 'soc/user/edit_profile.html'
        new_params['save_message'] = [ugettext('Profile saved.')]
        new_params['edit_redirect'] = '/%(url_name)s/edit_profile'

        # set the specific fields for the users profile page
        new_params['extra_dynaexclude'] = [
            'former_accounts', 'account', 'is_developer', 'status',
            'agreed_to_tos_on'
        ]

        new_params['create_extra_dynaproperties'] = {
            'clean_agreed_to_tos':
            cleaning.clean_agrees_to_tos('agreed_to_tos'),
            'clean_link_id': cleaning.clean_user_not_exist('link_id'),
        }

        new_params['edit_extra_dynaproperties'] = {
            'clean_link_id':
            cleaning.clean_user_is_current('link_id', False),
            'agreed_to_tos_on':
            forms.DateTimeField(
                widget=widgets.ReadOnlyInput(attrs={'disabled': 'true'}),
                required=False),
        }

        new_params['sidebar_heading'] = 'User (self)'
        new_params['sidebar'] = [
            (users.create_login_url("/"), 'Sign In', 'signIn'),
            ('/' + new_params['url_name'] + '/create_profile',
             'Create Profile', 'create_profile'),
            ('/' + new_params['url_name'] + '/edit_profile', 'Edit Profile',
             'edit_profile'),
            ('/' + new_params['url_name'] + '/roles', 'Roles', 'roles'),
            ('/' + new_params['url_name'] + '/requests', 'Requests',
             'requests'),
        ]

        patterns = []

        page_name = ugettext("Create your profile")
        patterns += [(r'^%(url_name)s/(?P<access_type>create_profile)$',
                      'soc.views.models.%(module_name)s.create', page_name)]

        page_name = ugettext("Edit your profile")
        patterns += [(r'^%(url_name)s/(?P<access_type>edit_profile)$',
                      'soc.views.models.%(module_name)s.edit', page_name)]

        page_name = ugettext("List of your roles")
        patterns += [(r'^%(url_name)s/(?P<access_type>roles)$',
                      'soc.views.models.user_self.roles', page_name)]

        page_name = ugettext("List of your requests")
        patterns += [(r'^%(url_name)s/(?P<access_type>requests)$',
                      'soc.views.models.request.list_self', page_name)]

        new_params['django_patterns_defaults'] = patterns

        params = dicts.merge(params, new_params)

        super(View, self).__init__(params=params)