コード例 #1
0
ファイル: notification.py プロジェクト: pombredanne/Melange-1
class CreateForm(helper.forms.BaseForm):
    """Form for creating a Notification.
  """

    # to user field
    to_user = forms.fields.CharField(label='To User')

    def __init__(self, *args, **kwargs):
        """ Calls super and then redefines the order in which the fields appear.

    for parameters see BaseForm.__init__()
    """
        super(CreateForm, self).__init__(*args, **kwargs)

        # set form fields order
        self.fields.keyOrder = ['to_user', 'subject', 'message']

    class Meta:
        """Inner Meta class that defines some behavior for the form.
    """
        model = notification_model.Notification
        fields = None

        # exclude the necessary fields from the form
        exclude = ['link_id', 'scope', 'scope_path', 'from_user', 'unread']

    clean_to_user = cleaning.clean_existing_user('to_user')
コード例 #2
0
ファイル: org_app.py プロジェクト: adviti/melange
  def clean_backup_admin_id(self):
    backup_admin = cleaning.clean_existing_user('backup_admin_id')(self)

    if not self.instance:
      cleaning.clean_users_not_same('backup_admin_id')(self)
    elif self.instance.main_admin.key() == backup_admin.key():
      raise django_forms.ValidationError(
          'You cannot enter the person who created the application here.')

    self.cleaned_data['backup_admin'] = backup_admin
    return backup_admin
コード例 #3
0
ファイル: org_app.py プロジェクト: rhyolight/nupic.son
  def clean_backup_admin_id(self):
    backup_admin = cleaning.clean_existing_user('backup_admin_id')(self)

    if not self.instance:
      cleaning.clean_users_not_same('backup_admin_id')(self)
    else:
      main_admin_key = ndb.Key.from_old_key(
          org_app_record.OrgAppRecord.main_admin
              .get_value_for_datastore(self.instance))
      if main_admin_key == backup_admin.key:
        raise django_forms.ValidationError(
            'You cannot enter the person who created the application here.')

    self.cleaned_data['backup_admin'] = backup_admin.key.to_old_key()
    return backup_admin
コード例 #4
0
ファイル: test_cleaning.py プロジェクト: rhyolight/nupic.son
 def testCleanExistingUser(self):
     """Tests that the user field can be cleaned for existing users.
 """
     field_name = 'test_existing_user'
     clean_field = cleaning.clean_existing_user(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 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)
コード例 #5
0
ファイル: test_cleaning.py プロジェクト: rhyolight/nupic.son
 def testCleanExistingUser(self):
   """Tests that the user field can be cleaned for existing users.
   """
   field_name = 'test_existing_user'
   clean_field = cleaning.clean_existing_user(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 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)
コード例 #6
0
ファイル: org_app_survey.py プロジェクト: SRabbelier/Melange
  def clean_backup_admin(self):
    """Cleans the backup admin field.

    Backup admin may not be equal to the Main admin if a SurveyRecord already
    exists otherwise it may not be equal to the current user.
    """

    from soc.logic import cleaning

    if self.survey_record:
      backup_admin = cleaning.clean_existing_user('backup_admin')(self)
      main_admin = self.survey_record.main_admin
      if main_admin.key() == backup_admin.key():
        #raise validation error, non valid backup admin
        raise forms.ValidationError('You may not enter the Main Admin here.')
    else:
      backup_admin = cleaning.clean_users_not_same('backup_admin')(self)

    return backup_admin
コード例 #7
0
ファイル: invite.py プロジェクト: adviti/melange
  def _clean_identifier(self, identifier):
    user_to_invite = None

    # first check if the field represents a valid link_id
    try:
      existing_user_cleaner = cleaning.clean_existing_user('identifier')
      user_to_invite = existing_user_cleaner(self)
    except gci_forms.ValidationError, e:
      if e.code != 'invalid':
        raise

      # otherwise check if the field represents a valid email address
      email_cleaner = cleaning.clean_email('identifier')
      try:
        email = email_cleaner(self)
      except gci_forms.ValidationError, e:
        if e.code != 'invalid':
          raise
        msg = ugettext(u'Enter a valid link_id or email address.')
        raise gci_forms.ValidationError(msg, code='invalid')
コード例 #8
0
    def clean_backup_admin(self):
        """Cleans the backup admin field.

    Backup admin may not be equal to the Main admin if a SurveyRecord already
    exists otherwise it may not be equal to the current user.
    """

        from soc.logic import cleaning

        if self.survey_record:
            backup_admin = cleaning.clean_existing_user('backup_admin')(self)
            main_admin = self.survey_record.main_admin
            if main_admin.key() == backup_admin.key():
                #raise validation error, non valid backup admin
                raise forms.ValidationError(
                    'You may not enter the Main Admin here.')
        else:
            backup_admin = cleaning.clean_users_not_same('backup_admin')(self)

        return backup_admin
コード例 #9
0
ファイル: request.py プロジェクト: jamslevy/gsoc
  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['listSelf'] = ['checkIsUser']
    rights['create'] = ['deny']
    rights['edit'] = ['checkIsDeveloper']
    rights['process_invite'] = ['checkIsMyGroupAcceptedRequest']
    rights['list'] = ['checkIsDeveloper']
    rights['delete'] = ['checkIsDeveloper']
    rights['roles'] = ['checkIsUser']

    new_params = {}
    new_params['rights'] = rights
    new_params['logic'] = soc.logic.models.request.logic

    new_params['name'] = "Request"

    new_params['sidebar_defaults'] = [('/%s/list', 'List %(name_plural)s', 
        'list')]

    new_params['create_template'] = ['soc/request/create.html']

    new_params['extra_dynaexclude'] = ['status', 'role_verbose', 'created_on']

    new_params['create_extra_dynaproperties'] = {
        'link_id': widgets.ReferenceField(reference_url='user'),
        'role': forms.CharField(widget=widgets.ReadOnlyInput(),
                                   required=True),
        'clean_link_id': cleaning.clean_existing_user('link_id'),
        }

    new_params['edit_extra_dynaproperties'] = {
        'scope_path': forms.CharField(widget=forms.HiddenInput,
                                        required=True),
        }

    patterns = [(r'^%(url_name)s/(?P<access_type>process_invite)/'
          '%(key_fields)s$',
          'soc.views.models.%(module_name)s.process_invite',
          'Process Invite to become')]

    new_params['extra_django_patterns'] = patterns

    new_params['invite_processing_template'] = 'soc/request/process_invite.html'
    new_params['request_processing_template'] = \
        'soc/request/process_request.html'

    params = dicts.merge(params, new_params)

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

    # create and store the special forms for invite and requests
    self._params['invite_form'] = self._params['create_form']

    updated_fields = {
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
            required=True),
        'group_id': forms.CharField(widget=widgets.ReadOnlyInput(),
            required=True)}

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

    self._params['request_form'] = request_form
コード例 #10
0
ファイル: role.py プロジェクト: praveen97uma/Melange
    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)
コード例 #11
0
ファイル: request.py プロジェクト: SRabbelier/Melange
  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'] = ['deny']
    rights['edit'] = ['checkIsDeveloper']
    rights['process_invite'] = [
        ('checkIsMyRequestWithStatus', [['group_accepted']])]
    rights['list'] = ['checkIsDeveloper']
    rights['delete'] = ['checkIsDeveloper']
    rights['roles'] = ['checkIsUser']

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

    new_params['name'] = 'Request'

    new_params['sidebar_developer'] = [('/%s/list', 'List %(name_plural)s',
        'list')]

    new_params['create_template'] = ['soc/request/create.html']

    new_params['extra_dynaexclude'] = ['user', 'role', 'group', 'status']

    patterns = [
        (r'^%(url_name)s/(?P<access_type>process_invite)/(?P<id>[0-9]*)$',
          'soc.views.models.%(module_name)s.process_invite',
          'Process Invite to become')]

    new_params['extra_django_patterns'] = patterns

    new_params['invite_processing_template'] = 'soc/request/process_invite.html'
    new_params['request_processing_template'] = \
        'soc/request/process_request.html'

    new_params['public_field_prefetch'] = ['user', 'group']
    new_params['public_field_extra'] = publicFieldExtra
    new_params['public_field_keys'] = ['role_name', 'user', 'for',
                                       'status', 'created_on']
    new_params['public_field_names'] = ['Role', 'User', 'For',
                                        'Status', 'Created On']

    params = dicts.merge(params, new_params)

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

    # create and store the special forms for invite and requests
    self._params['request_form'] = self._params['create_form']

    updated_fields = {
        'user_id': widgets.ReferenceField(reference_url='user'),
        'clean_user_id': cleaning.clean_existing_user('user_id'),
        }

    invite_form = dynaform.extendDynaForm(
        dynaform = self._params['create_form'],
        dynaproperties = updated_fields)
    # reverse the fields so that user_id field comes first
    invite_form.base_fields.keyOrder.reverse()

    self._params['invite_form'] = invite_form
コード例 #12
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['listSelf'] = ['checkIsUser']
        rights['create'] = ['deny']
        rights['edit'] = ['checkIsDeveloper']
        rights['process_invite'] = [('checkIsMyRequestWithStatus',
                                     [['group_accepted']])]
        rights['list'] = ['checkIsDeveloper']
        rights['delete'] = ['checkIsDeveloper']
        rights['roles'] = ['checkIsUser']

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

        new_params['name'] = "Request"

        new_params['sidebar_developer'] = [('/%s/list', 'List %(name_plural)s',
                                            'list')]

        new_params['create_template'] = ['soc/request/create.html']

        new_params['extra_dynaexclude'] = ['user', 'role', 'group', 'status']

        patterns = [
            (r'^%(url_name)s/(?P<access_type>process_invite)/(?P<id>[0-9]*)$',
             'soc.views.models.%(module_name)s.process_invite',
             'Process Invite to become')
        ]

        new_params['extra_django_patterns'] = patterns

        new_params[
            'invite_processing_template'] = 'soc/request/process_invite.html'
        new_params['request_processing_template'] = \
            'soc/request/process_request.html'

        new_params['public_field_extra'] = lambda entity: {
            "user": "******" % (entity.user.name, entity.user.link_id),
            "for": entity.group.name,
        }
        new_params['public_field_keys'] = [
            "role", "user", "for", "status", "created_on"
        ]
        new_params['public_field_names'] = [
            "Role", "User", "For", "Status", "Created On"
        ]

        params = dicts.merge(params, new_params)

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

        # create and store the special forms for invite and requests
        self._params['request_form'] = self._params['create_form']

        updated_fields = {
            'user_id': widgets.ReferenceField(reference_url='user'),
            'clean_user_id': cleaning.clean_existing_user('user_id'),
        }

        invite_form = dynaform.extendDynaForm(
            dynaform=self._params['create_form'],
            dynaproperties=updated_fields)
        # reverse the fields so that user_id field comes first
        invite_form.base_fields.keyOrder.reverse()

        self._params['invite_form'] = invite_form
コード例 #13
0
ファイル: settings.py プロジェクト: rhyolight/nupic.son
 def clean_view_as(self):
     """Cleans view_as field."""
     user = cleaning.clean_existing_user('view_as')(self)
     return user.key if user else None
コード例 #14
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)
コード例 #15
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)
コード例 #16
0
ファイル: host.py プロジェクト: SRabbelier/Melange
  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'] = [('checkHasRoleForScope', host_logic.logic)]
    rights['edit'] = [('checkIsMyActiveRole', host_logic.logic)]
    rights['invite'] = [('checkHasRoleForScope', host_logic.logic)]
    rights['list'] = ['checkIsDeveloper']
    rights['accept_invite'] = [
        ('checkIsMyRequestWithStatus', [['group_accepted']])]
    rights['process_request'] = [('checkCanProcessRequest', 
                                 [[host_logic.logic]])]
    rights['manage'] = [('checkIsAllowedToManageRole',
                         [host_logic.logic, host_logic.logic])]

    new_params = {}
    new_params['rights'] = rights
    new_params['logic'] = soc.logic.models.host.logic
    new_params['group_logic'] = sponsor_logic.logic
    new_params['group_view'] = soc.views.models.sponsor.view

    new_params['scope_view'] = sponsor_view

    new_params['name'] = "Program Administrator"
    new_params['module_name'] = "host"
    new_params['sidebar_grouping'] = 'Programs'

    new_params['extra_dynaexclude'] = ['agreed_to_tos']

    new_params['create_extra_dynaproperties'] = {
       'scope_path': forms.CharField(widget=forms.HiddenInput,
                                     required=True),
       'clean_link_id': cleaning.clean_existing_user('link_id'),
       'clean_home_page': cleaning.clean_url('home_page'),
       'clean_blog': cleaning.clean_url('blog'),
       'clean_photo_url': cleaning.clean_url('photo_url')}

    new_params['allow_invites'] = True
    new_params['show_in_roles_overview'] = True

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

    params = dicts.merge(params, new_params)

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

    # register the role with the group_view
    self._params['group_view'].registerRole(self._logic.role_name, self)

    # create and store the special form for invited users
    updated_fields = {
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
            required=False)}

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

    self._params['invited_create_form'] = invited_create_form
コード例 #17
0
ファイル: invite.py プロジェクト: pombredanne/Melange-1
        if e.code != 'invalid':
          raise
        msg = ugettext(u'Enter a valid link_id or email address.')
        raise djangoforms.ValidationError(msg, code='invalid')

      account = users.User(email_address)
      user_account = accounts.normalizeAccount(account)
      invited_user = User.all().filter('account', user_account).get()

      if not invited_user:
        raise djangoforms.ValidationError(
            "There is no user with that email address")

    # get the user entity that the invitation is to
    if not invited_user:
      existing_user_cleaner = cleaning.clean_existing_user('link_id')
      invited_user = existing_user_cleaner(self)

    self.request_data.invited_user = invited_user
    
    # check if the organization has already sent an invitation to the user
    query = db.Query(Request)
    query.filter('type', 'Invitation')
    query.filter('user', invited_user)
    query.filter('role', self.request_data.kwargs['role'])
    query.filter('group', self.request_data.organization)
    if query.get():
      raise djangoforms.ValidationError(
          'An invitation to this user has already been sent.')

    # check if the user that is invited does not have the role
コード例 #18
0
ファイル: settings.py プロジェクト: rhyolight/nupic.son
 def clean_view_as(self):
   """Cleans view_as field."""
   user = cleaning.clean_existing_user('view_as')(self)
   return user.key if user else None
コード例 #19
0
ファイル: role.py プロジェクト: SRabbelier/Melange
  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)
コード例 #20
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'] = [('checkHasRoleForScope', host_logic.logic)]
        rights['edit'] = [('checkIsMyActiveRole', host_logic.logic)]
        rights['invite'] = [('checkHasRoleForScope', host_logic.logic)]
        rights['list'] = ['checkIsDeveloper']
        rights['accept_invite'] = [('checkIsMyRequestWithStatus',
                                    [['group_accepted']])]
        rights['process_request'] = [('checkCanProcessRequest',
                                      [[host_logic.logic]])]
        rights['manage'] = [('checkIsAllowedToManageRole',
                             [host_logic.logic, host_logic.logic])]

        new_params = {}
        new_params['rights'] = rights
        new_params['logic'] = soc.logic.models.host.logic
        new_params['group_logic'] = sponsor_logic.logic
        new_params['group_view'] = soc.views.models.sponsor.view

        new_params['scope_view'] = sponsor_view

        new_params['name'] = "Program Administrator"
        new_params['module_name'] = "host"
        new_params['sidebar_grouping'] = 'Programs'

        new_params['extra_dynaexclude'] = ['agreed_to_tos']

        new_params['create_extra_dynaproperties'] = {
            'scope_path': forms.CharField(widget=forms.HiddenInput,
                                          required=True),
            'clean_link_id': cleaning.clean_existing_user('link_id'),
            'clean_home_page': cleaning.clean_url('home_page'),
            'clean_blog': cleaning.clean_url('blog'),
            'clean_photo_url': cleaning.clean_url('photo_url')
        }

        new_params['allow_invites'] = True
        new_params['show_in_roles_overview'] = True

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

        params = dicts.merge(params, new_params)

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

        # register the role with the group_view
        self._params['group_view'].registerRole(self._logic.role_name, self)

        # create and store the special form for invited users
        updated_fields = {
            'link_id':
            forms.CharField(widget=widgets.ReadOnlyInput(), required=False)
        }

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

        self._params['invited_create_form'] = invited_create_form