예제 #1
0
 def testCleanAgreesToTos(self):
   """Tests that the agrees_to_tos field can be cleaned.
   """
   field_name = 'agrees_to_tos'
   clean_field = cleaning.clean_agrees_to_tos(field_name)
   # Test that the value of the field will be returned
   # if there is no tos document
   field_value = 'Any value'
   self.form.cleaned_data = {field_name: field_value}
   self.assertEqual(clean_field(self.form), field_value)
   site = site_logic.getSingleton()
   document_properties = {
       'link_id': 'a_tos',
       'scope_path': site.link_id,
       'scope': site,
       'prefix': 'site',
       'author': self.user,
       'title': 'Home Page',
       'short_name': 'Home',
       'content': 'This is the Home Page',
       'modified_by': self.user,
       }
   document = document_logic.updateOrCreateFromFields(document_properties)
   site.tos = document
   site.put()
   # Test that True will be returned if there is a tos document and
   # the value of the field is not empty
   field_value = 'Any value'
   self.form.cleaned_data = {field_name: field_value}
   self.assertEqual(clean_field(self.form), True)
   # Test that None will be returned instead of ValidationError if there is
   # a tos document and the value of the field is empty
   field_value = ''
   self.form.cleaned_data = {field_name: field_value}
   self.assertEqual(clean_field(self.form), None)
   #self.assertRaises(forms.ValidationError, clean_field, self.form)
   # Test that None will be returned instead of ValidationError if there is
   # a tos document and the value of the field is False
   field_value = False
   self.form.cleaned_data = {field_name: field_value}
   self.assertEqual(clean_field(self.form), None)
예제 #2
0
 def testCleanAgreesToTos(self):
     """Tests that the agrees_to_tos field can be cleaned.
 """
     field_name = 'agrees_to_tos'
     clean_field = cleaning.clean_agrees_to_tos(field_name)
     # Test that the value of the field will be returned
     # if there is no tos document
     field_value = 'Any value'
     self.form.cleaned_data = {field_name: field_value}
     self.assertEqual(clean_field(self.form), field_value)
     site = site_logic.getSingleton()
     document_properties = {
         'link_id': 'a_tos',
         'scope_path': site.link_id,
         'scope': site,
         'prefix': 'site',
         'author': self.user,
         'title': 'Home Page',
         'short_name': 'Home',
         'content': 'This is the Home Page',
         'modified_by': self.user,
     }
     document = document_logic.updateOrCreateFromFields(document_properties)
     site.tos = document
     site.put()
     # Test that True will be returned if there is a tos document and
     # the value of the field is not empty
     field_value = 'Any value'
     self.form.cleaned_data = {field_name: field_value}
     self.assertEqual(clean_field(self.form), True)
     # Test that None will be returned instead of ValidationError if there is
     # a tos document and the value of the field is empty
     field_value = ''
     self.form.cleaned_data = {field_name: field_value}
     self.assertEqual(clean_field(self.form), None)
     #self.assertRaises(forms.ValidationError, clean_field, self.form)
     # Test that None will be returned instead of ValidationError if there is
     # a tos document and the value of the field is False
     field_value = False
     self.form.cleaned_data = {field_name: field_value}
     self.assertEqual(clean_field(self.form), None)
예제 #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['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)