예제 #1
0
 def testCleanUserIsCurrent(self):
   """Tests that the user field can be cleaned for current users.
   """
   field_name = 'test_user_is_current'
   clean_field = cleaning.clean_user_is_current(field_name)
   # Test that the user will be returned if the value of field is
   # an existent user's link_id
   field_value = self.user.user_id
   self.form.cleaned_data = {field_name: field_value}
   cleaned_data_after = clean_field(self.form)
   self.assertEqual(cleaned_data_after.user_id, self.user.user_id)
   # Test that forms.ValidationError will be raised if the value of field
   # is a user's link_id other than the current user's
   field_value = self.another_user.user_id
   self.form.cleaned_data = {field_name: field_value}
   self.assertRaises(forms.ValidationError, clean_field, self.form)
   # Test that forms.ValidationError will be raised if the value of field
   # is not an existent user's link_id
   field_value = 'non_existent_user'
   self.form.cleaned_data = {field_name: field_value}
   self.assertRaises(forms.ValidationError, clean_field, self.form)
예제 #2
0
 def testCleanUserIsCurrent(self):
     """Tests that the user field can be cleaned for current users.
 """
     field_name = 'test_user_is_current'
     clean_field = cleaning.clean_user_is_current(field_name)
     # Test that the user will be returned if the value of field is
     # an existent user's link_id
     field_value = self.user.user_id
     self.form.cleaned_data = {field_name: field_value}
     cleaned_data_after = clean_field(self.form)
     self.assertEqual(cleaned_data_after.user_id, self.user.user_id)
     # Test that forms.ValidationError will be raised if the value of field
     # is a user's link_id other than the current user's
     field_value = self.another_user.user_id
     self.form.cleaned_data = {field_name: field_value}
     self.assertRaises(forms.ValidationError, clean_field, self.form)
     # Test that forms.ValidationError will be raised if the value of field
     # is not an existent user's link_id
     field_value = 'non_existent_user'
     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
    """

    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)
예제 #4
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'] = [('checkHasActiveRoleForScope', student_logic.logic),
        ('checkIsMyEntity', [student_logic.logic, 'user', True])]
    rights['delete'] = ['checkIsDeveloper']
    rights['apply'] = [
        'checkIsUser',
        ('checkIsActivePeriod', ['student_signup', 'scope_path']),
        'checkIsNotParticipatingInProgramInScope',
        ]
    rights['manage'] = [
        ('checkIsAllowedToManageRole', [soc.logic.models.host.logic])]
    rights['list_projects'] = [
        ('checkHasActiveRoleForScope', student_logic.logic),
        ('checkIsAfterEvent', ['accepted_students_announced_deadline',
                               'scope_path'])]

    new_params = {}
    new_params['logic'] = soc.logic.models.student.logic
    new_params['group_logic'] = program_logic.logic
    new_params['group_view'] = program_view.view
    new_params['rights'] = rights

    new_params['scope_view'] = program_view
    new_params['scope_redirect'] = redirects.getCreateRedirect
    new_params['manage_redirect'] = redirects.getUserRolesRedirect

    new_params['name'] = "Student"
    new_params['module_name'] = "student"
    new_params['sidebar_grouping'] = 'Students'

    # add apply pattern
    patterns = [(r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$',
        'soc.views.models.%(module_name)s.apply',
        'Become a %(name)s'),
        (r'^%(url_name)s/(?P<access_type>list_projects)/%(scope)s$',
        'soc.views.models.%(module_name)s.list_projects',
        'List of my Student Projects'),]

    new_params['extra_django_patterns'] = patterns

    new_params['extra_dynaexclude'] = ['agreed_to_tos', 'school']

    current_year = time.gmtime().tm_year
    # the current year is not the minimum because a program could span
    # more than one year
    allowed_years = range(current_year-1, current_year+20)

    new_params['create_extra_dynaproperties'] = {
        'expected_graduation': forms.TypedChoiceField(
            choices=[(x,x) for x in allowed_years],
            coerce=lambda val: int(val)
            )
        } 

    new_params['create_dynafields'] = [
        {'name': 'scope_path',
         'base': forms.fields.CharField,
         'widget': forms.HiddenInput,
         'required': True,
         },
        {'name': 'student_agreement',
         'base': forms.fields.CharField,
         'required': False,
         'widget': widgets.AgreementField,
         'group': ugettext("5. Terms of Service"),
         },
        {'name': 'agreed_to_student_agreement',
         'base': forms.fields.BooleanField,
         'initial': False,
         'required':True,
         'label': ugettext('I agree to the Student Agreement'),
         'group': ugettext("5. Terms of Service"),
         },
        ]

    new_params['show_in_roles_overview'] = True

    params = dicts.merge(params, new_params)

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

    # create and store the special form for users
    updated_fields = {
        'link_id': forms.CharField(widget=forms.HiddenInput,
            required=True),
        'clean_link_id': cleaning.clean_user_is_current('link_id')
        }

    user_create_form = dynaform.extendDynaForm(
        dynaform = self._params['create_form'],
        dynaproperties = updated_fields)

    self._params['user_create_form'] = user_create_form
예제 #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.

    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)
예제 #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['create'] = ['checkIsDeveloper']
    rights['edit'] = [('checkIsMyActiveRole', student_logic.logic)]
    rights['delete'] = ['checkIsDeveloper']
    rights['apply'] = [
        'checkIsUser',
        ('checkIsActivePeriod', 
         ['student_signup', 'scope_path', program_logic.logic]),
        ('checkIsNotParticipatingInProgramInScope', [program_logic.logic,
        student_logic.logic, org_admin_logic.logic, mentor_logic.logic]),
        ]
    rights['manage'] = [('checkIsMyActiveRole', student_logic.logic)]

    new_params = {}
    new_params['logic'] = soc.logic.models.student.logic
    new_params['group_logic'] = program_logic.logic
    new_params['group_view'] = program_view.view
    new_params['rights'] = rights

    new_params['scope_view'] = program_view
    new_params['scope_redirect'] = redirects.getCreateRedirect
    new_params['manage_redirect'] = redirects.getUserRolesRedirect

    new_params['name'] = "Student"
    new_params['module_name'] = "student"
    new_params['sidebar_grouping'] = 'Students'

    new_params['create_template'] = 'soc/student/edit.html'
    new_params['edit_template'] = 'soc/student/edit.html'

    new_params['public_field_keys'] = ["name", "link_id", "scope_path"]
    new_params['public_field_names'] = ["Student Name", "Student ID", "Program ID"]

    # add apply pattern
    patterns = [(r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$',
        '%(module_package)s.%(module_name)s.apply',
        'Become a %(name)s'),]

    new_params['extra_django_patterns'] = patterns

    new_params['extra_dynaexclude'] = ['agreed_to_tos', 'school']

    current_year = time.gmtime().tm_year
    # the current year is not the minimum because a program could span
    # more than one year
    allowed_years = range(current_year-1, current_year+20)

    view_logic = params['logic'] if params else new_params['logic']

    new_params['create_extra_dynaproperties'] = {
        'expected_graduation': forms.TypedChoiceField(
            choices=[(x,x) for x in allowed_years],
            coerce=lambda val: int(val)
            ),
        'clean': cleaning.validate_student(view_logic.getScopeLogic().logic),
        'school_home_page': forms.fields.URLField(required=True),
        'clean_school_home_page': cleaning.clean_url('school_home_page'),
        }

    new_params['create_dynafields'] = [
        {'name': 'scope_path',
         'base': forms.fields.CharField,
         'widget': forms.HiddenInput,
         'required': True,
         },
        {'name': 'student_agreement',
         'base': forms.fields.CharField,
         'required': False,
         'widget': widgets.AgreementField,
         'group': ugettext("5. Terms of Service"),
         },
        {'name': 'agreed_to_student_agreement',
         'base': forms.fields.BooleanField,
         'initial': False,
         'required':True,
         'label': ugettext('I agree to the Student Agreement'),
         'group': ugettext("5. Terms of Service"),
         },
        ]

    # only if subclassed, so params is not empty
    new_params['show_in_roles_overview'] = bool(params)

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

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

    params = self.getParams()

    # create and store the special form for users
    updated_fields = {
        'link_id': forms.CharField(widget=forms.HiddenInput,
            required=True),
        'clean_link_id': cleaning.clean_user_is_current('link_id'),
        }

    user_create_form = dynaform.extendDynaForm(
        dynaform = params['create_form'],
        dynaproperties = updated_fields)

    params['user_create_form'] = user_create_form

    params['admin_field_keys'].extend([
        'school_name', 'school_country', 'school_home_page', 'school_type',
        'major', 'degree', 'grade', 'expected_graduation', 'program_knowledge',
        'can_we_contact_you'])
    params['admin_field_names'].extend([
        'School Name', 'School Country', 'School Homepage', 'School Type',
        'Major', 'Degree', 'Grade', 'Expected Graduation Year',
        'How did you hear about us?', 'Allowed to Contact?'])
    params['admin_field_hidden'].extend([
        'school_name', 'school_country', 'school_home_page', 'school_type',
        'major', 'degree', 'grade', 'expected_graduation', 'program_knowledge',
        'can_we_contact_you'])