Example #1
0
  def clean_link_id(self):
    """Accepts link_id of users which may be invited.
    """

    assert isSet(self.request_data.organization)

    invited_user = None

    link_id_cleaner = cleaning.clean_link_id('link_id')

    try:
      link_id = link_id_cleaner(self)
    except djangoforms.ValidationError, e:
      if e.code != 'invalid':
        raise

      email_cleaner = cleaning.clean_email('link_id')

      try:
        email_address = email_cleaner(self)
      except djangoforms.ValidationError, e:
        if e.code != 'invalid':
          raise
        msg = ugettext(u'Enter a valid link_id or email address.')
        raise djangoforms.ValidationError(msg, code='invalid')
Example #2
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['logic'] = group_app_logic

    new_params['name'] = "Group Application"
    new_params['name_short'] = "Group App"

    # use the twoline templates for these questionnaires
    new_params['create_template'] = 'soc/models/twoline_edit.html'
    new_params['edit_template'] = 'soc/models/twoline_edit.html'

    patterns = [(r'^%(url_name)s/(?P<access_type>list_self)/%(scope)s$',
        'soc.views.models.%(module_name)s.list_self',
        'List my %(name_plural)s'),
        (r'^%(url_name)s/(?P<access_type>review_overview)/%(scope)s$',
        'soc.views.models.%(module_name)s.review_overview',
        'List of %(name_plural)s for reviewing'),
        (r'^%(url_name)s/(?P<access_type>review)/%(key_fields)s$',
          'soc.views.models.%(module_name)s.review',
          'Review %(name_short)s')]

    new_params['extra_django_patterns'] = patterns

    new_params['extra_dynaexclude'] = ['applicant', 'backup_admin', 'status',
        'created_on', 'last_modified_on']

    new_params['create_dynafields'] = [
        {'name': 'backup_admin_link_id',
         'base': widgets.ReferenceField,
         'passthrough': ['reference_url', 'required', 'label'],
         'reference_url': 'user',
         'required': False,
         'label': params['logic'].getModel().backup_admin.verbose_name,
         'example_text': ugettext('The link_id of the backup admin'),
         },
         ]

    new_params['create_extra_dynaproperties'] = {
        'email': forms.fields.EmailField(required=True),
        'clean_backup_admin_link_id': 
            cleaning.clean_users_not_same('backup_admin_link_id'),
        }

    new_params['edit_extra_dynaproperties'] = {
        'clean_link_id' : cleaning.clean_link_id('link_id'),
        }

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

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

    Params:
      params: a dict with params for this View
    """

    rights = access.Checker(params)
    rights['home'] = ['allow']

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

    new_params['extra_dynaexclude'] = ['home']
    new_params['home_template'] = 'soc/presence/home.html'

    new_params['create_extra_dynaproperties'] = {
        # add cleaning of the link id and feed url
        'clean_link_id': cleaning.clean_link_id('link_id'),
        'clean_feed_url': cleaning.clean_feed_url('feed_url'),
        }

    new_params['edit_extra_dynaproperties'] = {
        'home_link_id': widgets.ReferenceField(
            reference_url='document', filter=['__scoped__'],
            filter_fields={'prefix': params['document_prefix']},
            required=False, label=ugettext('Home page Document link ID'),
            help_text=soc.models.work.Work.link_id.help_text,
            group=ugettext("1. Public Info")),
    }

    patterns = []

    page_name = "Home"
    patterns += [(r'^%(url_name)s/(?P<access_type>home)/%(key_fields)s$',
                  '%(module_package)s.%(module_name)s.home',
                  page_name)]

    new_params['extra_django_patterns'] = patterns

    new_params['public_field_prefetch'] = ['home']
    new_params['public_field_extra'] = lambda entity: {
        "path": entity.scope_path + '/' + entity.link_id if
            entity.scope_path else entity.link_id,
        "home": entity.home.title if entity.home else "",
    }
    new_params['public_field_keys'] = ["path", "home"]
    new_params['public_field_names'] = ["Path", "Home Document"]

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

    super(View, self).__init__(params=params)
Example #4
0
  def clean_org_id(self):
    org_id = cleaning.clean_link_id('org_id')(self)

    if not org_id:
      # manual required check, see Issue 1291
      raise django_forms.ValidationError('This field is required.')

    q = OrgAppRecord.all()
    q.filter('survey', self.survey)
    q.filter('org_id', org_id)

    org_app = q.get()

    if org_app:
      # If we are creating a new org app it is a duplicate, if we are editing
      # an org app we must check if the one we found has a different key.
      if (not self.instance) or (org_app.key() != self.instance.key()):
        raise django_forms.ValidationError('This ID has already been taken.')

    return org_id
Example #5
0
  def clean_org_id(self):
    org_id = cleaning.clean_link_id('org_id')(self)

    if not org_id:
      # manual required check, see Issue 1291
      raise django_forms.ValidationError('This field is required.')

    q = OrgAppRecord.all()
    q.filter('survey', self.survey)
    q.filter('org_id', org_id)

    org_app = q.get()

    if org_app:
      # If we are creating a new org app it is a duplicate, if we are editing
      # an org app we must check if the one we found has a different key.
      if (not self.instance) or (org_app.key() != self.instance.key()):
        raise django_forms.ValidationError('This ID has already been taken.')

    return org_id
Example #6
0
  def _clean_one_link_id(self):
    invited_user = None

    link_id_cleaner = cleaning.clean_link_id('link_id')

    try:
      link_id = link_id_cleaner(self)
    except djangoforms.ValidationError, e:
      if e.code != 'invalid':
        raise

      email_cleaner = cleaning.clean_email('link_id')

      try:
        email_address = email_cleaner(self)
      except djangoforms.ValidationError, e:
        if e.code != 'invalid':
          raise
        msg = ugettext(u'Enter a valid link_id or email address.')
        raise djangoforms.ValidationError(msg, code='invalid')
Example #7
0
    def clean_user_id(self):
        user_id_cleaner = cleaning.clean_link_id("user_id")

        try:
            user_id = user_id_cleaner(self)
        except djangoforms.ValidationError as e:
            if e.code != "invalid":
                raise
            msg = ugettext(u"Enter a valid username.")
            raise djangoforms.ValidationError(msg, code="invalid")

        user = user_model.User.get_by_id(user_id)
        if not user:
            raise djangoforms.ValidationError("There is no user with that email address")

        self.cleaned_data["user"] = user

        query = profile_model.Profile.query(
            profile_model.Profile.program == ndb.Key.from_old_key(self.request_data.program.key()), ancestor=user.key
        )
        self.cleaned_data["profile"] = query.get()
Example #8
0
 def testCleanLinkId(self):
     """Tests that link_id field can be cleaned."""
     field_name = 'test_link_id'
     clean_field = cleaning.clean_link_id(field_name)
     # Test that the value will be returned, the cleaned_data of form does not
     # change and there is no error message if the value of field has a valid
     # format
     field_value = 'valid_link_id'
     cleaned_data_before = {field_name: field_value}
     self.form.cleaned_data = cleaned_data_before.copy()
     self.assertEqual(clean_field(self.form), field_value)
     self.assertEqual(self.form.cleaned_data, cleaned_data_before)
     self.assertEqual(self.form._errors, {})
     # Test that forms.ValidationError will be raised, the cleaned_data of form
     # does not change and there is no error message if the value of field has
     # not a valid format
     field_value = 'v1_@?'
     cleaned_data_before = {field_name: field_value}
     self.form.cleaned_data = cleaned_data_before.copy()
     self.assertRaises(forms.ValidationError, clean_field, self.form)
     self.assertEqual(self.form.cleaned_data, cleaned_data_before)
     self.assertEqual(self.form._errors, {})
Example #9
0
 def testCleanLinkId(self):
   """Tests that link_id field can be cleaned."""
   field_name = 'test_link_id'
   clean_field = cleaning.clean_link_id(field_name)
   # Test that the value will be returned, the cleaned_data of form does not
   # change and there is no error message if the value of field has a valid
   # format
   field_value = 'valid_link_id'
   cleaned_data_before = {field_name: field_value}
   self.form.cleaned_data = cleaned_data_before.copy()
   self.assertEqual(clean_field(self.form), field_value)
   self.assertEqual(self.form.cleaned_data, cleaned_data_before)
   self.assertEqual(self.form._errors, {})
   # Test that forms.ValidationError will be raised, the cleaned_data of form
   # does not change and there is no error message if the value of field has
   # not a valid format
   field_value = 'v1_@?'
   cleaned_data_before = {field_name: field_value}
   self.form.cleaned_data = cleaned_data_before.copy()
   self.assertRaises(forms.ValidationError, clean_field, self.form)
   self.assertEqual(self.form.cleaned_data, cleaned_data_before)
   self.assertEqual(self.form._errors, {})
Example #10
0
    def clean_user_id(self):
        user_id_cleaner = cleaning.clean_link_id('user_id')

        try:
            user_id = user_id_cleaner(self)
        except djangoforms.ValidationError as e:
            if e.code != 'invalid':
                raise
            msg = ugettext(u'Enter a valid username.')
            raise djangoforms.ValidationError(msg, code='invalid')

        user = user_model.User.get_by_id(user_id)
        if not user:
            raise djangoforms.ValidationError(
                'There is no user with that email address')

        self.cleaned_data['user'] = user

        query = profile_model.Profile.query(
            profile_model.Profile.program == ndb.Key.from_old_key(
                self.request_data.program.key()),
            ancestor=user.key)
        self.cleaned_data['profile'] = query.get()
Example #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
    """

        rights = access.Checker(params)
        rights['create'] = ['checkIsDeveloper']
        rights['edit'] = [('checkHasRoleForLinkId', club_admin_logic.logic),
                          ('checkGroupIsActiveForLinkId', club_logic.logic)]
        rights['delete'] = ['checkIsDeveloper']
        rights['home'] = ['allow']
        rights['list'] = ['checkIsDeveloper']
        rights['apply_member'] = [
            'checkIsUser',
            ('checkGroupIsActiveForScopeAndLinkId', club_logic.logic)
        ]
        rights['list_requests'] = [('checkHasRoleForLinkId',
                                    club_admin_logic.logic)]
        rights['list_roles'] = [('checkHasRoleForLinkId',
                                 club_admin_logic.logic)]

        new_params = {}
        new_params['logic'] = soc.logic.models.club.logic
        new_params['rights'] = rights
        new_params['name'] = "Club"
        new_params['url_name'] = "club"
        new_params['document_prefix'] = "club"
        new_params['sidebar_grouping'] = 'Clubs'

        new_params['public_template'] = 'soc/group/public.html'

        patterns = []

        patterns += [
            (r'^%(url_name)s/(?P<access_type>apply_member)$',
             'soc.views.models.%(module_name)s.apply_member',
             "List of all %(name_plural)s you can apply to"),
        ]

        new_params['extra_django_patterns'] = patterns

        new_params['sidebar_additional'] = [
            ('/' + new_params['url_name'] + '/apply_member', 'Join a Club',
             'apply_member'),
        ]

        new_params['create_dynafields'] = [
            {
                'name': 'link_id',
                'base': forms.fields.CharField,
                'label': 'Club Link ID',
            },
        ]

        new_params['create_extra_dynaproperties'] = {
            'clean':
            cleaning.validate_new_group('link_id', 'scope_path', club_logic,
                                        None)
        }

        # get rid of the clean method
        new_params['edit_extra_dynaproperties'] = {
            'clean': (lambda x: x.cleaned_data)
        }

        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)

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

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

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

        self._params['applicant_create_form'] = applicant_create_form
Example #12
0
def constructParams(params):
    """Constructs a new params dictionary based on params.

  Params usage:
    The params dictionary is passed to getCreateForm and getEditForm,
    see their docstring on how they use it.

    rights: The rights value is merged with a default rights
      dictionary and then used as rights value.
    url_name: The url_name value is used in constructing several
      redirects as the first part of the url.
    module_name: The module_name value is used in constructing the
      location of several templates. It is expected that it matches
      the part after "/templates/soc/" for this View.
    name_plural: The name_plural argument is provided to the
      LIST_DESCRIPTION when constructing the list_description field.
    extra_dynainclude: The extra_dynainclude value is used when
      constructing the create_dynainclude value.
    extra_dynaexclude: The extra_dynaexclude value is used when
      constructing the create_dynaexclude value.
    logic: The logic value is used as argument to save the scope_logic
      and create a create form.
  """

    logic = params['logic']

    if params.get('rights'):
        rights = params['rights']
    else:
        rights = access.Checker(params)

    rights['unspecified'] = []
    rights['any_access'] = ['checkIsLoggedIn']
    rights['show'] = ['checkIsUser']
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = ['checkIsDeveloper']
    rights['delete'] = ['checkIsDeveloper']
    rights['list'] = ['checkIsDeveloper']
    rights['pick'] = ['checkIsUser']  # TODO(SRabbelier): proper check

    new_params = {}
    new_params['scope_logic'] = logic.getScopeLogic()

    if 'name_short' not in params:
        params['name_short'] = params['name']

    if 'name_plural' not in params:
        params['name_plural'] = params['name'] + 's'

    if 'module_name' not in params:
        params['module_name'] = params['name_short'].replace(' ', '_').lower()

    if 'url_name' not in params:
        params['url_name'] = params['module_name']

    if 'document_prefix' not in params:
        params['document_prefix'] = params['url_name']

    # Do not expand edit_redirect to allow it to be overwritten without suffix
    new_params['edit_redirect'] = '/%(url_name)s/edit/%(suffix)s'
    new_params['missing_redirect'] = '/%(url_name)s/create' % params
    new_params['delete_redirect'] = '/%(url_name)s/list' % params
    new_params['invite_redirect'] = '/request/list'
    # new_params['cancel_redirect'] = '/%(url_name)s/list' % params
    new_params['public_redirect'] = None

    new_params['sidebar'] = None
    new_params['sidebar_grouping'] = 'main'
    new_params['sidebar_defaults'] = []
    new_params['sidebar_developer'] = [
        # TODO(SRabbelier): remove create once new list code is in
        ('/%s/create', 'New %(name)s', 'create'),
        ('/%s/list', 'List %(name_plural)s', 'list'),
    ]
    new_params['sidebar_additional'] = []

    names_sans_link_id = [
        i for i in logic.getKeyFieldNames() if i != 'link_id'
    ]
    sans_link_id_pattern = getPattern(names_sans_link_id,
                                      linkable.SCOPE_PATH_ARG_PATTERN)

    new_params['link_id_arg_pattern'] = linkable.LINK_ID_ARG_PATTERN
    new_params['link_id_pattern_core'] = linkable.LINK_ID_PATTERN_CORE
    new_params['scope_path_pattern'] = getScopePattern(params)
    new_params['sans_link_id_pattern'] = sans_link_id_pattern

    new_params['django_patterns'] = None
    new_params['extra_django_patterns'] = []
    new_params['django_patterns_defaults'] = []

    # Defines the module package that the view is in. If it is not
    # already defined in the respective view, it defaults to
    # soc.views.models
    if not params.get('module_package'):
        new_params['module_package'] = 'soc.views.models'

    if not params.get('no_edit'):
        new_params['django_patterns_defaults'] += [
            (r'^%(url_name)s/(?P<access_type>edit)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.edit', 'Edit %(name_short)s')
        ]

    if not params.get('no_delete'):
        new_params['django_patterns_defaults'] += [
            (r'^%(url_name)s/(?P<access_type>delete)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.delete',
             'Delete %(name_short)s')
        ]

    if not params.get('no_show'):
        new_params['django_patterns_defaults'] += [
            (r'^%(url_name)s/(?P<access_type>show)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.public',
             'Show %(name_short)s')
        ]

    if not params.get('no_admin'):
        new_params['django_patterns_defaults'] += [
            (r'^%(url_name)s/(?P<access_type>admin)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.admin',
             'Show %(name_short)s (admin)')
        ]

    if not params.get('no_create_raw'):
        new_params['django_patterns_defaults'] += [
            (r'^%(url_name)s/(?P<access_type>create)$',
             '%(module_package)s.%(module_name)s.create',
             'Create %(name_short)s')
        ]

    if not params.get('no_create_with_scope'):
        new_params['django_patterns_defaults'] += [
            (r'^%(url_name)s/(?P<access_type>create)/%(scope)s$',
             '%(module_package)s.%(module_name)s.create',
             'Create %(name_short)s')
        ]

    if not params.get('no_create_with_key_fields'):
        new_params['django_patterns_defaults'] += [
            (r'^%(url_name)s/(?P<access_type>create)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.create',
             'Create %(name_short)s')
        ]

    if not params.get('no_list_raw'):
        new_params['django_patterns_defaults'] += [
            (r'^%(url_name)s/(?P<access_type>list)$',
             '%(module_package)s.%(module_name)s.list', 'List %(name_plural)s')
        ]

    if params.get('pickable'):
        new_params['django_patterns_defaults'] += [
            (r'^%(url_name)s/(?P<access_type>pick)$',
             '%(module_package)s.%(module_name)s.pick', 'Pick %(name_short)s')
        ]

    if params.get('export_content_type'):
        new_params['django_patterns_defaults'] += [
            (r'^%(url_name)s/(?P<access_type>export)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.export',
             'Export %(name_short)s')
        ]

    if params.get('sans_link_id_create'):
        new_params['django_patterns_defaults'] += [
            (r'^%(url_name)s/(?P<access_type>create)/%(sans_link_id)s$',
             '%(module_package)s.%(module_name)s.create',
             'Create %(name_short)s')
        ]

    if params.get('sans_link_id_list'):
        new_params['django_patterns_defaults'] += [
            (r'^%(url_name)s/(?P<access_type>list)/%(sans_link_id)s$',
             '%(module_package)s.%(module_name)s.list', 'List %(name_plural)s')
        ]

    if params.get('sans_link_id_public_list'):
        new_params['django_patterns_defaults'] += [
            (r'^%(url_name)s/(?P<access_type>list_public)/%(sans_link_id)s$',
             '%(module_package)s.%(module_name)s.list_public',
             'List %(name_plural)s')
        ]

    new_params['public_template'] = 'soc/%(module_name)s/public.html' % params
    new_params['export_template'] = 'soc/export.html'
    new_params['create_template'] = 'soc/models/edit.html'
    new_params['edit_template'] = 'soc/models/edit.html'
    new_params['admin_template'] = 'soc/models/admin.html'
    new_params['list_template'] = 'soc/models/list.html'
    new_params['invite_template'] = 'soc/models/invite.html'

    new_params['context'] = None

    new_params['cache_pick'] = False

    new_params['export_content_type'] = None
    new_params['export_extension'] = '.txt'
    new_params['csv_fieldnames'] = []

    # TODO: Use only the js modules needed instead of js_uses_all
    new_params['js_uses_all'] = DEF_JS_USES_LIST
    new_params['js_uses_list'] = ['jq', 'menu']
    new_params['js_uses_show'] = ['jq', 'menu']
    new_params['js_uses_edit'] = [
        'jq', 'menu', 'tinymce', 'jq_purr', 'jq_spin', 'jq_autocomplete'
    ]

    new_params['error_public'] = 'soc/%(module_name)s/error.html' % params
    new_params['error_export'] = new_params['error_public']
    new_params['error_edit'] = new_params['error_public']

    new_params['list_main'] = 'soc/list/main.html'
    new_params['list_pagination'] = 'soc/list/pagination.html'
    new_params['list_row'] = 'soc/%(module_name)s/list/row.html' % params
    new_params[
        'list_heading'] = 'soc/%(module_name)s/list/heading.html' % params

    new_params['public_row_action'] = {
        "type": "redirect_custom",
        "parameters": dict(new_window=True),
    }
    new_params['public_row_extra'] = lambda entity, *args: {
        "link": redirects.getEditRedirect(entity, params),
    }

    new_params['list_params'] = {
        'list_description': 'description',
        'list_info': 'info',
        'list_key_order': 'key_order',
        'list_main': 'main',
        'list_pagination': 'pagination',
        'list_row': 'row',
        'list_heading': 'heading',
    }

    new_params['list_description'] = DEF_LIST_DESCRIPTION_FMT % params
    new_params['no_lists_msg'] = ""
    new_params['save_message'] = [
        ugettext('%(name)s saved.' % params),
        ugettext('Cannot delete %(name)s.' % params)
    ]
    new_params['submit_msg_param_name'] = DEF_SUBMIT_MSG_PARAM_NAME
    new_params['edit_params'] = {
        DEF_SUBMIT_MSG_PARAM_NAME: DEF_SUBMIT_MSG_PROFILE_SAVED,
    }

    new_params['cannot_delete_params'] = {
        DEF_SUBMIT_MSG_PARAM_NAME: DEF_SUBMIT_MSG_CANNOT_DELETE_ENTITY,
    }

    new_params['dynabase'] = helper.forms.BaseForm

    create_dynaproperties = {
        'clean_link_id': cleaning.clean_link_id('link_id'),
        'clean_feed_url': cleaning.clean_feed_url,
    }
    create_dynaproperties.update(params.get('create_extra_dynaproperties', {}))

    # dynafields override any dynaproperties
    create_dynafields = getDynaFields(params.get('create_dynafields', {}))
    create_dynaproperties = dicts.merge(create_dynafields,
                                        create_dynaproperties)

    new_params['references'] = []
    new_params['create_dynainclude'] = [] + params.get('extra_dynainclude', [])
    new_params['create_dynaexclude'] = ['scope', 'scope_path'] + \
        params.get('extra_dynaexclude', [])
    new_params['create_dynaproperties'] = create_dynaproperties

    edit_dynaproperties = {
        'clean_link_id': cleaning.clean_link_id('link_id'),
        'link_id': forms.CharField(widget=helper.widgets.ReadOnlyInput()),
    }
    edit_dynaproperties.update(params.get('edit_extra_dynaproperties', {}))

    # dynafields override any dynaproperties
    edit_dynafields = getDynaFields(params.get('edit_dynafields', {}))
    edit_dynaproperties = dicts.merge(edit_dynafields, edit_dynaproperties)

    new_params['edit_dynainclude'] = None
    new_params['edit_dynaexclude'] = None
    new_params['edit_dynaproperties'] = edit_dynaproperties
    new_params['list_msg'] = None

    params = dicts.merge(params, new_params)

    # These need to be constructed separately, because they require
    # parameters that can be defined either in params, or new_params.
    if not 'create_form' in params:
        params['create_form'] = getCreateForm(params, logic.getModel())

    if not 'edit_form' in params:
        params['edit_form'] = getEditForm(params, params['create_form'])

    if not 'admin_form' in params:
        params['admin_form'] = getAdminForm(params['edit_form'])

    if not 'key_fields_pattern' in params:
        params['key_fields_pattern'] = getKeyFieldsPattern(params)

    # merge already done by access.Checker
    params['rights'] = rights

    return params
Example #13
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['any_access'] = ['allow']
    rights['show'] = [('checkIsSurveyWritable', survey_logic)]
    rights['create'] = ['checkIsUser']
    rights['edit'] = [('checkIsSurveyWritable', survey_logic)]
    rights['delete'] = ['checkIsDeveloper'] # TODO: fix deletion of Surveys
    rights['list'] = ['checkDocumentList']
    rights['pick'] = ['checkDocumentPick']
    rights['record'] = [('checkHasAny', [
        [('checkIsSurveyReadable', [survey_logic]),
         ('checkIsMySurveyRecord', [survey_logic, 'id'])]
        ])]
    rights['results'] = ['checkIsUser']
    rights['take'] = [('checkIsSurveyTakeable', survey_logic)]

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

    new_params['name'] = 'Survey'
    new_params['sidebar_grouping'] = "Surveys"

    new_params['extra_django_patterns'] = [
         (r'^%(url_name)s/(?P<access_type>take)/%(key_fields)s$',
         '%(module_package)s.%(module_name)s.take',
         'Take %(name)s'),
         (r'^%(url_name)s/(?P<access_type>json)/%(scope)s$',
         '%(module_package)s.%(module_name)s.json',
         'Export %(name)s as JSON'),
        (r'^%(url_name)s/(?P<access_type>record)/%(key_fields)s$',
         '%(module_package)s.%(module_name)s.record',
         'View survey record for %(name)s'),
        (r'^%(url_name)s/(?P<access_type>results)/%(key_fields)s$',
         '%(module_package)s.%(module_name)s.results',
         'View survey results for %(name)s'),
        (r'^%(url_name)s/(?P<access_type>show)/user/(?P<link_id>)\w+$',
         '%(module_package)s.%(module_name)s.results',
         'View survey results for user'),
        ]

    new_params['export_content_type'] = 'text/text'
    new_params['export_extension'] = '.csv'
    new_params['export_function'] = surveys.toCSV(self)
    new_params['delete_redirect'] = '/'

    new_params['edit_template'] = 'soc/survey/edit.html'
    new_params['create_template'] = 'soc/survey/edit.html'
    new_params['public_template'] = 'soc/survey/public.html'
    new_params['record_template'] = 'soc/survey/view_record.html'
    new_params['take_template'] = 'soc/survey/take.html'

    new_params['no_create_raw'] = True
    new_params['no_create_with_scope'] = True
    new_params['no_create_with_key_fields'] = True
    new_params['no_list_raw'] = True
    new_params['sans_link_id_create'] = True
    new_params['sans_link_id_list'] = True

    new_params['create_dynafields'] = [
        {'name': 'link_id',
         'base': forms.fields.CharField,
         'label': 'Survey Link ID',
         },
        ]

    new_params['create_extra_dynaproperties'] = {
        'content': forms.fields.CharField(required=False, label='Description',
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
        'survey_html': forms.fields.CharField(widget=forms.HiddenInput,
                                              required=False),
        'scope_path': forms.fields.CharField(widget=forms.HiddenInput,
                                             required=True),
        'prefix': forms.fields.CharField(widget=widgets.ReadOnlyInput(),
                                        required=True),
        'clean_content': cleaning.clean_html_content('content'),
        'clean_link_id': cleaning.clean_link_id('link_id'),
        'clean_scope_path': cleaning.clean_scope_path('scope_path'),
        'clean': cleaning.validate_document_acl(self, True),
        }

    new_params['extra_dynaexclude'] = ['author', 'created',
                                       'home_for', 'modified_by', 'modified',
                                       'take_survey', 'survey_content']

    new_params['edit_extra_dynaproperties'] = {
        'doc_key_name': forms.fields.CharField(widget=forms.HiddenInput),
        'created_by': forms.fields.CharField(widget=widgets.ReadOnlyInput(),
                                             required=False),
        'last_modified_by': forms.fields.CharField(
                                widget=widgets.ReadOnlyInput(), required=False),
        'clean': cleaning.validate_document_acl(self),
        }

    new_params['survey_take_form'] = surveys.SurveyTakeForm
    new_params['survey_record_form'] = surveys.SurveyRecordForm

    new_params['public_field_prefetch'] = ['author']
    new_params['public_field_extra'] = lambda entity: {
        "path": entity.scope_path + '/' + entity.link_id,
        "created_by": entity.author.link_id,
    }
    new_params['public_field_keys'] = [
        "path", "title", "link_id","is_featured",
        "created_by", "created", "modified"
    ]
    new_params['public_field_names'] = [
        "Path", "Title", "Link ID", "Featured",
        "Created By", "Created On", "Modified",
    ]

    new_params['records_field_keys'] = [
        'taken_by', 'modified'
    ]
    new_params['records_field_names'] = [
        'Taken By', 'Taken On',
    ]
    new_params['records_field_prefetch'] = ['user']
    new_params['records_field_extra'] = lambda entity: {
        'taken_by': '%s (%s)' %(entity.user.name, entity.user.link_id),
    }

    new_params['take_params'] = {'s': '0'}

    new_params['successful_take_message'] = ugettext(
        'Survey record submitted.')

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

    super(View, self).__init__(params=params)
Example #14
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['any_access'] = ['allow']
    rights['show'] = ['checkIsDocumentReadable']
    rights['create'] = ['checkIsDocumentCreatable']
    rights['edit'] = ['checkIsDocumentWritable']
    rights['delete'] = ['checkIsDocumentWritable']
    rights['list'] = ['checkDocumentList']
    rights['pick'] = ['checkDocumentPick']

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

    new_params['name'] = "Document"
    new_params['pickable'] = True

    new_params['export_content_type'] = 'text/text'
    new_params['export_extension'] = '.html'
    new_params['export_function'] = lambda x: (x.content, x.link_id)
    new_params['delete_redirect'] = '/'

    new_params['no_create_raw'] = True
    new_params['no_create_with_scope'] = True
    new_params['no_create_with_key_fields'] = True
    new_params['no_list_raw'] = True
    new_params['sans_link_id_create'] = True
    new_params['sans_link_id_list'] = True

    new_params['create_dynafields'] = [
        {'name': 'link_id',
         'base': forms.fields.CharField,
         'label': 'Document Link ID',
         },
        ]

    new_params['create_extra_dynaproperties'] = {
        'content': forms.fields.CharField(
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
        'scope_path': forms.fields.CharField(widget=forms.HiddenInput,
                                             required=True),
        'prefix': forms.fields.CharField(widget=widgets.ReadOnlyInput(),
                                        required=True),
        'clean_content': cleaning.clean_html_content('content'),
        'clean_link_id': cleaning.clean_link_id('link_id'),
        'clean_scope_path': cleaning.clean_scope_path('scope_path'),
        'clean': cleaning.validate_document_acl(self, True),
        }
    new_params['extra_dynaexclude'] = ['author', 'created', 'home_for',
                                       'modified_by', 'modified']

    new_params['edit_extra_dynaproperties'] = {
        'doc_key_name': forms.fields.CharField(widget=forms.HiddenInput),
        'created_by': forms.fields.CharField(
            widget=widgets.ReadOnlyInput(), required=False),
        'last_modified_by': forms.fields.CharField(
            widget=widgets.ReadOnlyInput(), required=False),
        'clean': cleaning.validate_document_acl(self),
        }

    new_params['public_field_prefetch'] = ['author']
    new_params['public_field_extra'] = lambda entity: {
        'path': entity.scope_path + '/' + entity.link_id,
        'author_id': entity.author.link_id,
    }
    new_params['public_field_keys'] = ["path", "title", "link_id",
                                       "is_featured", "author_id", "created",
                                       "modified"]
    new_params['public_field_names'] = ["Path", "Title", "Link ID", "Featured",
                                        "Created By", "Created On", "Modified"]

    params = dicts.merge(params, new_params)

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

    # TODO: read/write access needs to match survey
    # TODO: usage requirements

    rights = access.Checker(params)
    rights['any_access'] = ['allow']
    rights['show'] = [('checkIsSurveyReadable', survey_logic)]
    rights['create'] = ['checkIsUser']
    rights['edit'] = ['checkIsSurveyWritable']
    rights['delete'] = ['checkIsSurveyWritable']
    rights['list'] = ['checkDocumentList']
    rights['pick'] = ['checkDocumentPick']
    rights['grade'] = ['checkIsSurveyGradable']

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

    new_params['name'] = "Survey"
    new_params['pickable'] = True

    new_params['extra_django_patterns'] = [
         (r'^%(url_name)s/(?P<access_type>json)/%(scope)s$',
         'soc.views.models.%(module_name)s.json',
         'Export %(name)s as JSON'),
        (r'^%(url_name)s/(?P<access_type>results)/%(scope)s$',
         'soc.views.models.%(module_name)s.results',
         'View survey results for %(name)s'),
        (r'^%(url_name)s/(?P<access_type>show)/user/(?P<link_id>)\w+$',
         'soc.views.models.%(module_name)s.results',
         'View survey results for user'),
        ]

    new_params['export_content_type'] = 'text/text'
    new_params['export_extension'] = '.csv'
    new_params['export_function'] = surveys.to_csv
    new_params['delete_redirect'] = '/'
    new_params['list_key_order'] = [
        'link_id', 'scope_path', 'name', 'short_name', 'title',
        'content', 'prefix','read_access','write_access']

    new_params['edit_template'] = 'soc/survey/edit.html'
    new_params['create_template'] = 'soc/survey/edit.html'
    new_params['public_template'] = 'soc/survey/public.html'

    # TODO: which one of these are leftovers from Document?
    new_params['no_create_raw'] = True
    new_params['no_create_with_scope'] = True
    new_params['no_create_with_key_fields'] = True
    new_params['no_list_raw'] = True
    new_params['sans_link_id_create'] = True
    new_params['sans_link_id_list'] = True

    new_params['create_dynafields'] = [
        {'name': 'link_id',
         'base': forms.fields.CharField,
         'label': 'Survey Link ID',
         },
        ]

    # survey_html: save form content if POST fails, so fields remain in UI
    new_params['create_extra_dynaproperties'] = {
        #'survey_content': forms.fields.CharField(widget=surveys.EditSurvey(),
                                                 #required=False),
        'survey_html': forms.fields.CharField(widget=forms.HiddenInput,
                                              required=False),
        'scope_path': forms.fields.CharField(widget=forms.HiddenInput,
                                             required=True),
        'prefix': forms.fields.CharField(widget=widgets.ReadOnlyInput(),
                                        required=True),
        'clean_content': cleaning.clean_html_content('content'),
        'clean_link_id': cleaning.clean_link_id('link_id'),
        'clean_scope_path': cleaning.clean_scope_path('scope_path'),
        'clean': cleaning.validate_document_acl(self, True),
        }

    new_params['extra_dynaexclude'] = ['author', 'created', 'content',
                                       'home_for', 'modified_by', 'modified',
                                       'take_survey', 'survey_content']

    new_params['edit_extra_dynaproperties'] = {
        'doc_key_name': forms.fields.CharField(widget=forms.HiddenInput),
        'created_by': forms.fields.CharField(widget=widgets.ReadOnlyInput(),
                                             required=False),
        'last_modified_by': forms.fields.CharField(
                                widget=widgets.ReadOnlyInput(), required=False),
        'clean': cleaning.validate_document_acl(self),
        }

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

    super(View, self).__init__(params=params)
Example #16
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.GSoCChecker(params)
    rights['any_access'] = ['allow']
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = ['checkIsDeveloper']
    rights['delete'] = ['checkIsDeveloper']
    rights['show'] = ['allow']
    rights['list'] = ['checkIsDeveloper']
    rights['manage'] = [('checkHasRoleForScope',
                         [org_admin_logic, ['active', 'inactive']]),
        ('checkStudentProjectHasStatus', [['accepted', 'failed', 'completed',
                                           'withdrawn']])]
    rights['manage_overview'] = [('checkHasRoleForScope', [
        org_admin_logic, ['active', 'inactive']])]
    # TODO: lack of better name here!
    rights['st_edit'] = [
        'checkCanEditStudentProjectAsStudent',
        ('checkStudentProjectHasStatus',
            [['accepted', 'completed']])
        ]
    rights['withdraw'] = ['checkIsHostForProgram']
    rights['withdraw_project'] = ['checkIsHostForStudentProject',
        ('checkStudentProjectHasStatus',
            [['accepted', 'completed']])
        ]
    rights['accept_project'] = ['checkIsHostForStudentProject',
        ('checkStudentProjectHasStatus',
            [['withdrawn']])
        ]

    new_params = {}
    new_params['logic'] = project_logic
    new_params['rights'] = rights
    new_params['name'] = "Student Project"
    new_params['url_name'] = "gsoc/student_project"
    new_params['module_package'] = 'soc.modules.gsoc.views.models'
    new_params['sidebar_grouping'] = 'Students'

    new_params['scope_view'] = org_view
    new_params['scope_redirect'] = redirects.getCreateRedirect

    new_params['no_create_with_key_fields'] = True

    new_params['extra_dynaexclude'] = ['program', 'status', 'link_id',
                                       'mentor', 'additional_mentors',
                                       'student', 'passed_evaluations',
                                       'failed_evaluations']

    new_params['create_extra_dynaproperties'] = {
        'scope_path': forms.CharField(widget=forms.HiddenInput,
            required=True),
        'public_info': forms.fields.CharField(required=True,
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
        'student_id': forms.CharField(label='Student Link ID',
            required=True),
        'mentor_id': forms.CharField(label='Mentor Link ID',
            required=True),
        'clean_abstract': cleaning.clean_content_length('abstract'),
        'clean_public_info': cleaning.clean_html_content('public_info'),
        'clean_student': cleaning.clean_link_id('student'),
        'clean_mentor': cleaning.clean_link_id('mentor'),
        'clean_additional_info': cleaning.clean_url('additional_info'),
        'clean_feed_url': cleaning.clean_feed_url,
        'clean': cleaning.validate_student_project('scope_path',
            'mentor_id', 'student_id')
        }

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

    patterns = [
        (r'^%(url_name)s/(?P<access_type>manage_overview)/%(scope)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.manage_overview',
        'Overview of %(name_plural)s to Manage for'),
        (r'^%(url_name)s/(?P<access_type>manage)/%(key_fields)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.manage',
        'Manage %(name)s'),
        (r'^%(url_name)s/(?P<access_type>st_edit)/%(key_fields)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.st_edit',
        'Edit my %(name)s'),
        (r'^%(url_name)s/(?P<access_type>withdraw)/(?P<scope_path>%(ulnp)s)/%(lnp)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.withdraw',
        'Withdraw %(name_plural)s'),
        (r'^%(url_name)s/(?P<access_type>withdraw_project)/%(key_fields)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.withdraw_project',
        'Withdraw a %(name)s'),
        (r'^%(url_name)s/(?P<access_type>accept_project)/%(key_fields)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.accept_project',
        'Accept a %(name)s'),
    ]

    new_params['extra_django_patterns'] = patterns

    new_params['edit_template'] = 'soc/student_project/edit.html'
    new_params['manage_template'] = 'soc/student_project/manage.html'
    new_params['manage_overview_heading'] = \
        'soc/student_project/list/heading_manage.html'
    new_params['manage_overview_row'] = \
        'soc/student_project/list/row_manage.html'

    new_params['public_field_extra'] = lambda entity: {
        "student": entity.student.name(),
        "mentor": entity.mentor.name(),
    }
    new_params['public_field_keys'] = ["student", "title", "mentor", "status"]
    new_params['public_field_names'] = ["Student", "Title", "Mentor", "Status"]

    params = dicts.merge(params, new_params)

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

    # create the form that students will use to edit their projects
    dynaproperties = {
        'public_info': forms.fields.CharField(required=True,
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
        'clean_abstract': cleaning.clean_content_length('abstract'),
        'clean_public_info': cleaning.clean_html_content('public_info'),
        'clean_additional_info': cleaning.clean_url('additional_info'),
        'clean_feed_url': cleaning.clean_feed_url,
        }

    student_edit_form = dynaform.newDynaForm(
        dynabase = self._params['dynabase'],
        dynamodel = self._params['logic'].getModel(),
        dynaexclude = self._params['create_dynaexclude'],
        dynaproperties = dynaproperties,
    )

    self._params['student_edit_form'] = student_edit_form
Example #17
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['any_access'] = ['allow']
    rights['show'] = [('checkIsSurveyWritable', survey_logic)]
    rights['create'] = ['checkIsUser']
    rights['edit'] = [('checkIsSurveyWritable', survey_logic)]
    rights['delete'] = ['checkIsDeveloper'] # TODO: fix deletion of Surveys
    rights['list'] = ['checkDocumentList']
    rights['pick'] = ['checkDocumentPick']
    rights['record'] = [('checkIsSurveyReadable', survey_logic)]
    rights['results'] = [('checkIsSurveyWritable', survey_logic)]
    rights['take'] = [('checkIsSurveyTakeable', survey_logic)]

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

    new_params['name'] = 'Survey'
    new_params['sidebar_grouping'] = "Surveys"

    new_params['extra_django_patterns'] = [
         (r'^%(url_name)s/(?P<access_type>take)/%(key_fields)s$',
         'soc.views.models.%(module_name)s.take',
         'Take %(name)s'),
         (r'^%(url_name)s/(?P<access_type>json)/%(scope)s$',
         'soc.views.models.%(module_name)s.json',
         'Export %(name)s as JSON'),
        (r'^%(url_name)s/(?P<access_type>record)/%(key_fields)s$',
         'soc.views.models.%(module_name)s.record',
         'View survey records for %(name)s'),
        (r'^%(url_name)s/(?P<access_type>results)/%(key_fields)s$',
         'soc.views.models.%(module_name)s.results',
         'View survey results for %(name)s'),
        (r'^%(url_name)s/(?P<access_type>show)/user/(?P<link_id>)\w+$',
         'soc.views.models.%(module_name)s.results',
         'View survey results for user'),
        ]

    new_params['export_content_type'] = 'text/text'
    new_params['export_extension'] = '.csv'
    new_params['export_function'] = surveys.toCSV(self)
    new_params['delete_redirect'] = '/'
    new_params['list_key_order'] = [
        'link_id', 'scope_path', 'name', 'short_name', 'title',
        'content', 'prefix','read_access','write_access']

    new_params['edit_template'] = 'soc/survey/edit.html'
    new_params['create_template'] = 'soc/survey/edit.html'
    new_params['public_template'] = 'soc/survey/public.html'
    new_params['record_template'] = 'soc/survey/record.html'
    new_params['take_template'] = 'soc/survey/take.html'

    new_params['no_create_raw'] = True
    new_params['no_create_with_scope'] = True
    new_params['no_create_with_key_fields'] = True
    new_params['no_list_raw'] = True
    new_params['sans_link_id_create'] = True
    new_params['sans_link_id_list'] = True

    new_params['create_dynafields'] = [
        {'name': 'link_id',
         'base': forms.fields.CharField,
         'label': 'Survey Link ID',
         },
        ]

    new_params['create_extra_dynaproperties'] = {
        'content': forms.fields.CharField(required=False, label='Description',
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
        'survey_html': forms.fields.CharField(widget=forms.HiddenInput,
                                              required=False),
        'scope_path': forms.fields.CharField(widget=forms.HiddenInput,
                                             required=True),
        'prefix': forms.fields.CharField(widget=widgets.ReadOnlyInput(),
                                        required=True),
        'clean_content': cleaning.clean_html_content('content'),
        'clean_link_id': cleaning.clean_link_id('link_id'),
        'clean_scope_path': cleaning.clean_scope_path('scope_path'),
        'clean': cleaning.validate_document_acl(self, True),
        }

    new_params['extra_dynaexclude'] = ['author', 'created',
                                       'home_for', 'modified_by', 'modified',
                                       'take_survey', 'survey_content']

    new_params['edit_extra_dynaproperties'] = {
        'doc_key_name': forms.fields.CharField(widget=forms.HiddenInput),
        'created_by': forms.fields.CharField(widget=widgets.ReadOnlyInput(),
                                             required=False),
        'last_modified_by': forms.fields.CharField(
                                widget=widgets.ReadOnlyInput(), required=False),
        'clean': cleaning.validate_document_acl(self),
        }

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

    super(View, self).__init__(params=params)
Example #18
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['any_access'] = ['allow']
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = ['checkIsDeveloper']
    rights['delete'] = ['checkIsDeveloper']
    rights['show'] = ['allow']
    rights['list'] = ['checkIsDeveloper']
    rights['manage'] = [('checkHasActiveRoleForScope',
                         org_admin_logic),
        ('checkStudentProjectHasStatus', [['accepted', 'mid_term_passed']])]
    rights['manage_overview'] = [('checkHasActiveRoleForScope',
                         org_admin_logic)]
    # TODO lack of better name here!
    rights['st_edit'] = ['checkIsMyStudentProject',
        ('checkStudentProjectHasStatus',
            [['accepted', 'mid_term_passed', 'passed']])
        ]

    new_params = {}
    new_params['logic'] = soc.logic.models.student_project.logic
    new_params['rights'] = rights
    new_params['name'] = "Student Project"
    new_params['url_name'] = "student_project"
    new_params['sidebar_grouping'] = 'Students'

    new_params['scope_view'] = org_view
    new_params['scope_redirect'] = redirects.getCreateRedirect

    new_params['no_create_with_key_fields'] = True

    new_params['extra_dynaexclude'] = ['program', 'status', 'link_id',
                                       'mentor', 'additional_mentors',
                                       'student']

    new_params['create_extra_dynaproperties'] = {
        'scope_path': forms.CharField(widget=forms.HiddenInput,
            required=True),
        'public_info': forms.fields.CharField(required=True,
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
        'student_id': forms.CharField(label='Student Link ID',
            required=True),
        'mentor_id': forms.CharField(label='Mentor Link ID',
            required=True),
        'clean_abstract': cleaning.clean_content_length('abstract'),
        'clean_public_info': cleaning.clean_html_content('public_info'),
        'clean_student': cleaning.clean_link_id('student'),
        'clean_mentor': cleaning.clean_link_id('mentor'),
        'clean_additional_info': cleaning.clean_url('additional_info'),
        'clean_feed_url': cleaning.clean_feed_url,
        'clean': cleaning.validate_student_project('scope_path',
            'mentor_id', 'student_id')
        }

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

    patterns = [
        (r'^%(url_name)s/(?P<access_type>manage_overview)/%(scope)s$',
        'soc.views.models.%(module_name)s.manage_overview',
        'Overview of %(name_plural)s to Manage for'),
        (r'^%(url_name)s/(?P<access_type>manage)/%(key_fields)s$',
        'soc.views.models.%(module_name)s.manage',
        'Manage %(name)s'),
        (r'^%(url_name)s/(?P<access_type>st_edit)/%(key_fields)s$',
        'soc.views.models.%(module_name)s.st_edit',
        'Edit my %(name)s'),
    ]

    new_params['extra_django_patterns'] = patterns

    new_params['edit_template'] = 'soc/student_project/edit.html'
    new_params['manage_template'] = 'soc/student_project/manage.html'

    params = dicts.merge(params, new_params)

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

    # create the form that students will use to edit their projects
    dynaproperties = {
        'public_info': forms.fields.CharField(required=True,
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
        'clean_abstract': cleaning.clean_content_length('abstract'),
        'clean_public_info': cleaning.clean_html_content('public_info'),
        'clean_additional_info': cleaning.clean_url('additional_info'),
        'clean_feed_url': cleaning.clean_feed_url,
        }

    student_edit_form = dynaform.newDynaForm(
        dynabase = self._params['dynabase'],
        dynamodel = self._params['logic'].getModel(),
        dynaexclude = self._params['create_dynaexclude'],
        dynaproperties = dynaproperties,
    )

    self._params['student_edit_form'] = student_edit_form
Example #19
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 #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['any_access'] = ['allow']
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = [('checkHasRoleForLinkId', club_admin_logic.logic),
                      ('checkGroupIsActiveForLinkId', club_logic.logic)]
    rights['delete'] = ['checkIsDeveloper']
    rights['home'] = ['allow']
    rights['list'] = ['checkIsDeveloper']
    rights['apply_member'] = ['checkIsUser',
                              ('checkGroupIsActiveForScopeAndLinkId', 
                               club_logic.logic)]
    rights['list_requests'] = [('checkHasRoleForLinkId', 
                                club_admin_logic.logic)]
    rights['list_roles'] = [('checkHasRoleForLinkId', 
                             club_admin_logic.logic)]

    new_params = {}
    new_params['logic'] = soc.logic.models.club.logic
    new_params['rights'] = rights
    new_params['name'] = "Club"
    new_params['url_name'] = "club"
    new_params['document_prefix'] = "club"
    new_params['sidebar_grouping'] = 'Clubs'

    new_params['public_template'] = 'soc/group/public.html'

    patterns = []

    patterns += [(r'^%(url_name)s/(?P<access_type>apply_member)$',
        'soc.views.models.%(module_name)s.apply_member', 
        "List of all %(name_plural)s you can apply to"),]

    new_params['extra_django_patterns'] = patterns

    new_params['sidebar_additional'] = [
        ('/' + new_params['url_name'] + '/apply_member', 
         'Join a Club', 'apply_member'),]

    new_params['create_dynafields'] = [
        {'name': 'link_id',
         'base': forms.fields.CharField,
         'label': 'Club Link ID',
         },
        ]

    new_params['create_extra_dynaproperties'] = {
        'clean' : cleaning.validate_new_group('link_id', 'scope_path',
            club_logic)}

    # get rid of the clean method
    new_params['edit_extra_dynaproperties'] = {
        'clean' : (lambda x: x.cleaned_data)}

    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)

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

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

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

    self._params['applicant_create_form'] = applicant_create_form
Example #21
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.GSoCChecker(params)
    rights['any_access'] = ['allow']
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = ['checkIsDeveloper']
    rights['delete'] = ['checkIsDeveloper']
    rights['show'] = ['allow']
    rights['list'] = ['checkIsDeveloper']
    rights['manage'] = [('checkHasRoleForScope',
                         [org_admin_logic, ['active', 'inactive']]),
        ('checkStudentProjectHasStatus', [['accepted', 'failed', 'completed',
                                           'withdrawn']])]
    rights['manage_overview'] = [
        ('checkHasAny', [
            [('checkHasRoleForScope', [org_admin_logic,
                                       ['active', 'inactive']]),
             ('checkHasRoleForScope', [mentor_logic,
                                       ['active', 'inactive']])
        ]])]
    # TODO: lack of better name here!
    rights['st_edit'] = [
        'checkCanEditStudentProjectAsStudent',
        ('checkStudentProjectHasStatus',
            [['accepted', 'completed']])
        ]
    rights['overview'] = [('checkIsHostForProgram', [program_logic])]

    new_params = {}
    new_params['logic'] = project_logic
    new_params['rights'] = rights
    new_params['name'] = 'Student Project'
    new_params['url_name'] = 'gsoc/student_project'
    new_params['module_package'] = 'soc.modules.gsoc.views.models'
    new_params['sidebar_grouping'] = 'Students'

    new_params['scope_view'] = org_view
    new_params['scope_redirect'] = redirects.getCreateRedirect

    new_params['no_create_with_key_fields'] = True

    new_params['extra_dynaexclude'] = ['program', 'status', 'link_id',
                                       'mentor', 'additional_mentors',
                                       'student', 'passed_evaluations',
                                       'failed_evaluations']

    new_params['create_extra_dynaproperties'] = {
        'scope_path': forms.CharField(widget=forms.HiddenInput,
            required=True),
        'public_info': forms.fields.CharField(required=True,
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
        'student_id': forms.CharField(label='Student Link ID',
            required=True),
        'mentor_id': forms.CharField(label='Mentor Link ID',
            required=True),
        'clean_abstract': cleaning.clean_content_length('abstract'),
        'clean_public_info': cleaning.clean_html_content('public_info'),
        'clean_student': cleaning.clean_link_id('student'),
        'clean_mentor': cleaning.clean_link_id('mentor'),
        'clean_additional_info': cleaning.clean_url('additional_info'),
        'clean_feed_url': cleaning.clean_feed_url('feed_url'),
        'clean': cleaning.validate_student_project('scope_path',
            'mentor_id', 'student_id')
        }

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

    patterns = [
        (r'^%(url_name)s/(?P<access_type>manage_overview)/%(scope)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.manage_overview',
        'Overview of %(name_plural)s to Manage for'),
        (r'^%(url_name)s/(?P<access_type>manage)/%(key_fields)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.manage',
        'Manage %(name)s'),
        (r'^%(url_name)s/(?P<access_type>st_edit)/%(key_fields)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.st_edit',
        'Edit my %(name)s'),
        (r'^%(url_name)s/(?P<access_type>overview)/(?P<scope_path>%(ulnp)s)/%(lnp)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.overview',
        'Overview of all %(name_plural)s for'),
    ]

    new_params['extra_django_patterns'] = patterns

    new_params['edit_template'] = 'soc/student_project/edit.html'
    new_params['manage_template'] = 'soc/student_project/manage.html'

    new_params['public_field_prefetch'] = ['mentor', 'student', 'scope']
    new_params['public_field_extra'] = lambda entity: {
        'student': entity.student.name(),
        'mentor': entity.mentor.name(),
        'org': entity.scope.name,
    }
    new_params['public_field_keys'] = ['student', 'title', 'mentor',
                                       'org', 'status']
    new_params['public_field_names'] = ['Student', 'Title', 'Mentor',
                                        'Organization', 'Status']

    new_params['org_home_field_prefetch'] = ['mentor', 'student']
    new_params['org_home_field_extra'] = lambda entity: {
        'student': entity.student.name(),
        'mentor': ', '.join(
            mentor.name() for mentor in
            [entity.mentor] + db.get(entity.additional_mentors))
    }
    new_params['org_home_field_keys'] = ['student', 'title', 'mentor',
                                         'status']
    new_params['org_home_field_names'] = ['Student', 'Title',
                                          'Mentor', 'Status']

    # define the list redirect action to show the notification
    new_params['public_row_extra'] = new_params[
        'org_home_row_extra'] = lambda entity: {
            'link': redirects.getPublicRedirect(entity, new_params)
        }
    new_params['org_home_row_action'] = {
        'type': 'redirect_custom',
        'parameters': dict(new_window=False),
    }

    new_params['admin_field_prefetch'] = ['mentor', 'student', 'scope']
    new_params['admin_field_extra'] = lambda entity: {
        'student': entity.student.name(),
        'mentor': entity.mentor.name(),
        'student_id': entity.student.link_id
    }
    new_params['admin_field_keys'] = ['student', 'title', 'mentor', 'status',
                                      'student_id']
    new_params['admin_field_names'] = ['Student', 'Title', 'Mentor', 'Status',
                                       'Student Link ID']
    new_params['admin_field_hidden'] = ['student_id']

    new_params['admin_conf_extra'] = {
        'multiselect': True,
    }
    new_params['admin_button_global'] = [
        {
          'bounds': [1,'all'],
          'id': 'withdraw',
          'caption': 'Withdraw Project',
          'type': 'post',
          'parameters': {
              'url': '',
              'keys': ['key'],
              'refresh': 'current',
              }
        },
        {
          'bounds': [1,'all'],
          'id': 'accept',
          'caption': 'Accept Project',
          'type': 'post',
          'parameters': {
              'url': '',
              'keys': ['key'],
              'refresh': 'current',
              }
        }]

    params = dicts.merge(params, new_params)

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

    # create the form that students will use to edit their projects
    dynaproperties = {
        'public_info': forms.fields.CharField(required=True,
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
        'clean_abstract': cleaning.clean_content_length('abstract'),
        'clean_public_info': cleaning.clean_html_content('public_info'),
        'clean_additional_info': cleaning.clean_url('additional_info'),
        'clean_feed_url': cleaning.clean_feed_url('feed_url'),
        }

    student_edit_form = dynaform.newDynaForm(
        dynabase = self._params['dynabase'],
        dynamodel = self._params['logic'].getModel(),
        dynaexclude = self._params['create_dynaexclude'],
        dynaproperties = dynaproperties,
    )

    self._params['student_edit_form'] = student_edit_form
Example #22
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['any_access'] = ['allow']
        rights['show'] = ['checkIsDocumentReadable']
        rights['create'] = ['checkIsDocumentCreatable']
        rights['edit'] = ['checkIsDocumentWritable']
        rights['delete'] = ['checkIsDocumentWritable']
        rights['list'] = ['checkDocumentList']
        rights['pick'] = ['checkDocumentPick']

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

        new_params['name'] = "Document"
        new_params['pickable'] = True

        new_params['export_content_type'] = 'text/text'
        new_params['export_extension'] = '.html'
        new_params['export_function'] = lambda x: (x.content, x.link_id)
        new_params['delete_redirect'] = '/'

        new_params['no_create_raw'] = True
        new_params['no_create_with_scope'] = True
        new_params['no_create_with_key_fields'] = True
        new_params['no_list_raw'] = True
        new_params['sans_link_id_create'] = True
        new_params['sans_link_id_list'] = True

        new_params['create_dynafields'] = [
            {
                'name': 'link_id',
                'base': forms.fields.CharField,
                'label': 'Document Link ID',
            },
        ]

        new_params['create_extra_dynaproperties'] = {
            'content':
            forms.fields.CharField(widget=widgets.FullTinyMCE(attrs={
                'rows': 25,
                'cols': 100
            })),
            'scope_path':
            forms.fields.CharField(widget=forms.HiddenInput, required=True),
            'prefix':
            forms.fields.CharField(widget=widgets.ReadOnlyInput(),
                                   required=True),
            'clean_content':
            cleaning.clean_html_content('content'),
            'clean_link_id':
            cleaning.clean_link_id('link_id'),
            'clean_scope_path':
            cleaning.clean_scope_path('scope_path'),
            'clean':
            cleaning.validate_document_acl(self, True),
        }
        new_params['extra_dynaexclude'] = [
            'author', 'created', 'home_for', 'modified_by', 'modified'
        ]

        new_params['edit_extra_dynaproperties'] = {
            'doc_key_name':
            forms.fields.CharField(widget=forms.HiddenInput),
            'created_by':
            forms.fields.CharField(widget=widgets.ReadOnlyInput(),
                                   required=False),
            'last_modified_by':
            forms.fields.CharField(widget=widgets.ReadOnlyInput(),
                                   required=False),
            'clean':
            cleaning.validate_document_acl(self),
        }

        new_params['public_field_prefetch'] = ['author']
        new_params['public_field_extra'] = lambda entity: {
            'path': entity.scope_path + '/' + entity.link_id,
            'author_id': entity.author.link_id,
        }
        new_params['public_field_keys'] = [
            "path", "title", "link_id", "is_featured", "author_id", "created",
            "modified"
        ]
        new_params['public_field_names'] = [
            "Path", "Title", "Link ID", "Featured", "Created By", "Created On",
            "Modified"
        ]

        params = dicts.merge(params, new_params)

        super(View, self).__init__(params=params)
Example #23
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'] = [('checkCanStudentPropose', ['scope_path', False]),
        ('checkRoleAndStatusForStudentProposal',
            [['proposer'], ['active'], ['new', 'pending', 'invalid']])]
    rights['delete'] = ['checkIsDeveloper']
    rights['show'] = [
        ('checkRoleAndStatusForStudentProposal',
            [['proposer', 'org_admin', 'mentor', 'host'], 
            ['active', 'inactive'], 
            ['new', 'pending', 'accepted', 'rejected', 'invalid']])]
    rights['list'] = ['checkIsDeveloper']
    rights['list_orgs'] = [
        ('checkIsStudent', ['scope_path', ['active']]),
        ('checkCanStudentPropose', ['scope_path', False])]
    rights['list_self'] = [
        ('checkIsStudent', ['scope_path', ['active', 'inactive']])]
    rights['apply'] = [
        ('checkIsStudent', ['scope_path', ['active']]),
        ('checkCanStudentPropose', ['scope_path', True])]
    rights['review'] = [('checkRoleAndStatusForStudentProposal',
            [['org_admin', 'mentor', 'host'], 
            ['active'],
            ['new', 'pending', 'accepted', 'rejected', 'invalid']])]

    new_params = {}
    new_params['logic'] = soc.logic.models.student_proposal.logic
    new_params['rights'] = rights
    new_params['name'] = "Student Proposal"
    new_params['url_name'] = "student_proposal"
    new_params['sidebar_grouping'] = 'Students'

    new_params['scope_view'] = student_view
    new_params['scope_redirect'] = redirects.getCreateRedirect

    new_params['no_create_with_key_fields'] = True
    new_params['list_key_order'] = ['title', 'abstract', 'content',
        'additional_info', 'created_on', 'last_modified_on']

    patterns = [
        (r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$',
        'soc.views.models.%(module_name)s.apply',
        'Create a new %(name)s'),
        (r'^%(url_name)s/(?P<access_type>list_self)/%(scope)s$',
        'soc.views.models.%(module_name)s.list_self',
        'List my %(name_plural)s'),
        (r'^%(url_name)s/(?P<access_type>list_orgs)/%(scope)s$',
        'soc.views.models.%(module_name)s.list_orgs',
        'List my %(name_plural)s'),
        (r'^%(url_name)s/(?P<access_type>review)/%(key_fields)s$',
        'soc.views.models.%(module_name)s.review',
        'Review %(name)s'),
    ]

    new_params['extra_django_patterns'] = patterns

    new_params['extra_dynaexclude'] = ['org', 'program', 'score',
                                       'status', 'mentor', 'link_id',
                                       'possible_mentors']

    new_params['create_extra_dynaproperties'] = {
        'content': forms.fields.CharField(required=True,
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
        'scope_path': forms.CharField(widget=forms.HiddenInput,
            required=True),
        'organization': forms.CharField(label='Organization Link ID',
            required=True),
        'clean_abstract': cleaning.clean_content_length('abstract'),
        'clean_content': cleaning.clean_html_content('content'),
        'clean_organization': cleaning.clean_link_id('organization'),
        'clean_additional_info': cleaning.clean_url('additional_info'),
        'clean': cleaning.validate_student_proposal('organization',
            'scope_path', student_logic, org_logic),
        }

    new_params['edit_extra_dynaproperties'] = {
        'organization': forms.CharField(label='Organization Link ID',
            widget=widgets.ReadOnlyInput),
        'link_id': forms.CharField(widget=forms.HiddenInput)
        }

    new_params['edit_template'] = 'soc/student_proposal/edit.html'
    new_params['review_template'] = 'soc/student_proposal/review.html'
    new_params['review_after_deadline_template'] = 'soc/student_proposal/review_after_deadline.html'

    params = dicts.merge(params, new_params)

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

    # create the special form for students
    dynafields = [
        {'name': 'organization',
         'base': forms.CharField,
         'label': 'Organization Link ID',
         'widget': widgets.ReadOnlyInput(),
         'required': False,
         },
        ]

    dynaproperties = params_helper.getDynaFields(dynafields)

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

    self._params['student_create_form'] = student_create_form

    # create the special form for public review
    dynafields = [
        {'name': 'comment',
         'base': forms.CharField,
         'widget': widgets.FullTinyMCE(attrs={'rows': 10, 'cols': 40}),
         'label': 'Comment',
         'required': False,
         'example_text': 'Caution, you will not be able to edit your comment!',
         },
         ]

    dynaproperties = params_helper.getDynaFields(dynafields)
    dynaproperties['clean_comment'] = cleaning.clean_html_content('comment')

    public_review_form = dynaform.newDynaForm(dynamodel=None, 
        dynabase=helper.forms.BaseForm, dynainclude=None, 
        dynaexclude=None, dynaproperties=dynaproperties)
    self._params['public_review_form'] = public_review_form

    # create the special form for mentors
    dynafields = [
        {'name': 'score',
         'base': forms.ChoiceField,
         'label': 'Score',
         'initial': 0,
         'required': False,
         'passthrough': ['initial', 'required', 'choices'],
         'example_text':
             'A score will only be assigned if the review is private!',
         'choices': [(-4,'-4: Wow. This. Sucks.'),
                     (-3,'-3: Needs a lot of work'),
                     (-2,'-2: This is bad'),
                     (-1,'-1: I dont like this'),
                     (0,'0: No score'),
                     (1,'1: Might have potential'),
                     (2,'2: Good'),
                     (3,'3: Almost there'),
                     (4,'4: Made. Of. Awesome.')]
        },
        {'name': 'comment',
         'base': forms.CharField,
         'widget': widgets.FullTinyMCE(attrs={'rows': 10, 'cols': 40}),
         'label': 'Comment',
         'required': False,
         'example_text': 'Caution, you will not be able to edit your review!',
         },
        {'name': 'public',
         'base': forms.BooleanField,
         'label': 'Review visible to Student',
         'initial': False,
         'required': False,
         'help_text': 'By ticking this box the score will not be assigned, '
             'and the review will be visible to the student.',
         },
         ]

    dynaproperties = params_helper.getDynaFields(dynafields)
    dynaproperties['clean_comment'] = cleaning.clean_html_content('comment')

    mentor_review_form = dynaform.newDynaForm(dynamodel=None, 
        dynabase=helper.forms.BaseForm, dynainclude=None, 
        dynaexclude=None, dynaproperties=dynaproperties)
    self._params['mentor_review_form'] = mentor_review_form

    dynafields = [
      {'name': 'rank',
         'base': forms.IntegerField,
         'label': 'Set to rank',
         'help_text':
             'Set this proposal to the given rank (ignores the given score)',
         'example_text': 'A rank will only be assigned if the '
            'review is private!',
         'min_value': 1,
         'required': False,
         'passthrough': ['min_value', 'required', 'help_text'],
      },
      {'name': 'mentor',
       'base': widgets.ReferenceField,
       'passthrough': ['reference_url', 'required', 'label', 'filter'],
       'reference_url': 'mentor',
       'filter': ['__org__'],
       'label': 'Assign Mentor (Link ID)',
       'required': False,
       'help_text': 'Fill in the Link ID of the Mentor '
           'you would like to assign to this Proposal. '
           'Leave this box empty if you don\'t want any mentor assigned.',
      },
      ]

    dynaproperties = params_helper.getDynaFields(dynafields)
    dynaproperties['clean_comment'] = cleaning.clean_html_content('comment')

    admin_review_form = dynaform.extendDynaForm(dynaform=mentor_review_form, 
        dynaproperties=dynaproperties)

    self._params['admin_review_form'] = admin_review_form
Example #24
0
def constructParams(params):
  """Constructs a new params dictionary based on params.

  Params usage:
    The params dictionary is passed to getCreateForm and getEditForm,
    see their docstring on how they use it.

    rights: The rights value is merged with a default rights
      dictionary and then used as rights value.
    url_name: The url_name value is used in constructing several
      redirects as the first part of the url.
    module_name: The module_name value is used in constructing the
      location of several templates. It is expected that it matches
      the part after "/templates/soc/" for this View.
    name_plural: The name_plural argument is provided to the
      LIST_DESCRIPTION when constructing the list_description field.
    extra_dynainclude: The extra_dynainclude value is used when
      constructing the create_dynainclude value.
    extra_dynaexclude: The extra_dynaexclude value is used when
      constructing the create_dynaexclude value.
    logic: The logic value is used as argument to save the scope_logic
      and create a create form.
  """

  logic = params['logic']

  rights = access.Checker(params)
  rights['unspecified'] = []
  rights['any_access'] = ['checkIsLoggedIn']
  rights['show'] = ['checkIsUser']
  rights['create'] = ['checkIsDeveloper']
  rights['edit'] = ['checkIsDeveloper']
  rights['delete'] = ['checkIsDeveloper']
  rights['list'] = ['checkIsDeveloper']
  rights['pick'] = ['checkIsUser'] # TODO(SRabbelier): proper check

  new_params = {}
  new_params['scope_logic'] = logic.getScopeLogic()

  if 'name_short' not in params:
    params['name_short'] = params['name']

  if 'name_plural' not in params:
    params['name_plural'] = params['name'] + 's'

  if 'module_name' not in params:
    params['module_name'] = params['name_short'].replace(' ', '_').lower()

  if 'url_name' not in params:
    params['url_name'] = params['module_name']

  if 'document_prefix' not in params:
    params['document_prefix'] = params['url_name']

  # Do not expand edit_redirect to allow it to be overwritten without suffix
  new_params['edit_redirect'] = '/%(url_name)s/edit/%(suffix)s'
  new_params['missing_redirect'] = '/%(url_name)s/create' % params
  new_params['delete_redirect'] = '/%(url_name)s/list' % params
  new_params['invite_redirect'] = '/request/list'
  # new_params['cancel_redirect'] = '/%(url_name)s/list' % params
  new_params['public_redirect'] = None

  new_params['sidebar'] = None
  new_params['sidebar_grouping'] = 'main'
  new_params['sidebar_defaults'] = [
      ('/%s/create', 'New %(name)s', 'create'),
      ('/%s/list', 'List %(name_plural)s', 'list'),
      ]
  new_params['sidebar_additional'] = []

  names_sans_link_id = [i for i in logic.getKeyFieldNames() if i != 'link_id']
  sans_link_id_pattern = getPattern(names_sans_link_id,
                              linkable.SCOPE_PATH_ARG_PATTERN)

  new_params['link_id_arg_pattern'] = linkable.LINK_ID_ARG_PATTERN
  new_params['link_id_pattern_core'] = linkable.LINK_ID_PATTERN_CORE
  new_params['scope_path_pattern'] = getScopePattern(params)
  new_params['sans_link_id_pattern'] = sans_link_id_pattern

  new_params['django_patterns'] = None
  new_params['extra_django_patterns'] = []
  new_params['django_patterns_defaults'] = []

  # Defines the module package that the view is in. If it is not
  # already defined in the respective view, it defaults to 
  # soc.views.models
  if not params.get('module_package'):
    new_params['module_package'] = 'soc.views.models'

  if not params.get('no_edit'):
    new_params['django_patterns_defaults'] += [
        (r'^%(url_name)s/(?P<access_type>edit)/%(key_fields)s$',
          '%(module_package)s.%(module_name)s.edit', 'Edit %(name_short)s')]

  if not params.get('no_delete'):
    new_params['django_patterns_defaults'] += [
        (r'^%(url_name)s/(?P<access_type>delete)/%(key_fields)s$',
          '%(module_package)s.%(module_name)s.delete', 'Delete %(name_short)s')]

  if not params.get('no_show'):
    new_params['django_patterns_defaults'] += [
        (r'^%(url_name)s/(?P<access_type>show)/%(key_fields)s$',
          '%(module_package)s.%(module_name)s.public', 'Show %(name_short)s')]

  if not params.get('no_admin'):
    new_params['django_patterns_defaults'] += [
        (r'^%(url_name)s/(?P<access_type>admin)/%(key_fields)s$',
          '%(module_package)s.%(module_name)s.admin', 
          'Show %(name_short)s (admin)')]

  if not params.get('no_create_raw'):
    new_params['django_patterns_defaults'] += [
        (r'^%(url_name)s/(?P<access_type>create)$',
          '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s')]

  if not params.get('no_create_with_scope'):
    new_params['django_patterns_defaults'] += [
        (r'^%(url_name)s/(?P<access_type>create)/%(scope)s$',
        '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s')]

  if not params.get('no_create_with_key_fields'):
    new_params['django_patterns_defaults'] += [
        (r'^%(url_name)s/(?P<access_type>create)/%(key_fields)s$',
        '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s')]

  if not params.get('no_list_raw'):
    new_params['django_patterns_defaults'] += [
        (r'^%(url_name)s/(?P<access_type>list)$',
          '%(module_package)s.%(module_name)s.list', 'List %(name_plural)s')]

  if params.get('pickable'):
    new_params['django_patterns_defaults'] += [
        (r'^%(url_name)s/(?P<access_type>pick)$',
          '%(module_package)s.%(module_name)s.pick', 'Pick %(name_short)s')]

  if params.get('export_content_type'):
    new_params['django_patterns_defaults'] += [
        (r'^%(url_name)s/(?P<access_type>export)/%(key_fields)s$',
          '%(module_package)s.%(module_name)s.export', 'Export %(name_short)s')]

  if params.get('sans_link_id_create'):
    new_params['django_patterns_defaults'] += [
        (r'^%(url_name)s/(?P<access_type>create)/%(sans_link_id)s$',
         '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s')]

  if params.get('sans_link_id_list'):
    new_params['django_patterns_defaults'] += [
        (r'^%(url_name)s/(?P<access_type>list)/%(sans_link_id)s$',
         '%(module_package)s.%(module_name)s.list', 'List %(name_plural)s')]

  if params.get('sans_link_id_public_list'):
    new_params['django_patterns_defaults'] += [
        (r'^%(url_name)s/(?P<access_type>list_public)/%(sans_link_id)s$',
         '%(module_package)s.%(module_name)s.list_public', 
         'List %(name_plural)s')]

  new_params['public_template'] = 'soc/%(module_name)s/public.html' % params
  new_params['export_template'] = 'soc/export.html'
  new_params['create_template'] = 'soc/models/edit.html'
  new_params['edit_template'] = 'soc/models/edit.html'
  new_params['admin_template'] = 'soc/models/admin.html'
  new_params['list_template'] = 'soc/models/list.html'
  new_params['invite_template'] = 'soc/models/invite.html'

  new_params['context'] = None

  new_params['cache_pick'] = False

  new_params['export_content_type'] = None
  new_params['export_extension'] = '.txt'
  new_params['csv_fieldnames'] = []

  # TODO: Use only the js modules needed instead of js_uses_all
  new_params['js_uses_all'] = DEF_JS_USES_LIST
  new_params['js_uses_list'] = ['jq', 'menu']
  new_params['js_uses_show'] = ['jq', 'menu']
  new_params['js_uses_edit'] = ['jq', 'menu', 'tinymce', 'jq_purr',
                                'jq_spin', 'jq_autocomplete']

  new_params['error_public'] = 'soc/%(module_name)s/error.html' % params
  new_params['error_export'] = new_params['error_public']
  new_params['error_edit'] = new_params['error_public']

  new_params['list_main'] = 'soc/list/main.html'
  new_params['list_pagination'] = 'soc/list/pagination.html'
  new_params['list_row'] = 'soc/%(module_name)s/list/row.html' % params
  new_params['list_heading'] = 'soc/%(module_name)s/list/heading.html' % params

  new_params['list_action'] = (redirects.getEditRedirect, params)
  new_params['list_params'] = {
      'list_action': 'action',
      'list_description': 'description',
      'list_info': 'info',
      'list_key_order': 'key_order',
      'list_main': 'main',
      'list_pagination': 'pagination',
      'list_row': 'row',
      'list_heading': 'heading',
      }

  new_params['list_description'] = DEF_LIST_DESCRIPTION_FMT % params
  new_params['no_lists_msg'] = ""
  new_params['save_message'] = [ugettext('%(name)s saved.' % params),
                                ugettext('Cannot delete %(name)s.' % params)]
  new_params['submit_msg_param_name'] = DEF_SUBMIT_MSG_PARAM_NAME
  new_params['edit_params'] = {
      DEF_SUBMIT_MSG_PARAM_NAME: DEF_SUBMIT_MSG_PROFILE_SAVED,
      }

  new_params['cannot_delete_params'] = {
      DEF_SUBMIT_MSG_PARAM_NAME: DEF_SUBMIT_MSG_CANNOT_DELETE_ENTITY,
      }

  new_params['dynabase'] = helper.forms.BaseForm

  create_dynaproperties = {
      'clean_link_id': cleaning.clean_link_id('link_id'),
      'clean_feed_url': cleaning.clean_feed_url,
      }
  create_dynaproperties.update(params.get('create_extra_dynaproperties', {}))

  # dynafields override any dynaproperties
  create_dynafields = getDynaFields(params.get('create_dynafields', {}))
  create_dynaproperties = dicts.merge(create_dynafields, create_dynaproperties)

  new_params['references'] = []
  new_params['create_dynainclude'] = [] + params.get('extra_dynainclude', [])
  new_params['create_dynaexclude'] = ['scope', 'scope_path'] + \
      params.get('extra_dynaexclude', [])
  new_params['create_dynaproperties'] = create_dynaproperties

  edit_dynaproperties = {
      'clean_link_id': cleaning.clean_link_id('link_id'),
      'link_id': forms.CharField(widget=helper.widgets.ReadOnlyInput()),
      }
  edit_dynaproperties.update(params.get('edit_extra_dynaproperties', {}))

  # dynafields override any dynaproperties
  edit_dynafields = getDynaFields(params.get('edit_dynafields', {}))
  edit_dynaproperties = dicts.merge(edit_dynafields, edit_dynaproperties)

  new_params['edit_dynainclude'] = None
  new_params['edit_dynaexclude'] = None
  new_params['edit_dynaproperties'] = edit_dynaproperties
  new_params['list_msg'] = None

  params = dicts.merge(params, new_params)

  # These need to be constructed separately, because they require
  # parameters that can be defined either in params, or new_params.
  if not 'create_form' in params:
    params['create_form'] = getCreateForm(params, logic.getModel())

  if not 'edit_form' in params:
    params['edit_form'] = getEditForm(params, params['create_form'])

  if not 'admin_form' in params:
    params['admin_form'] = getAdminForm(params['edit_form'])

  if not 'key_fields_pattern' in params:
    params['key_fields_pattern'] = getKeyFieldsPattern(params)

  # merge already done by access.Checker
  params['rights'] = rights

  return params
Example #25
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.GSoCChecker(params)
        rights['any_access'] = ['allow']
        rights['create'] = ['checkIsDeveloper']
        rights['edit'] = ['checkIsDeveloper']
        rights['delete'] = ['checkIsDeveloper']
        rights['show'] = ['allow']
        rights['list'] = ['checkIsDeveloper']
        rights['manage'] = [('checkHasRoleForScope',
                             [org_admin_logic, ['active', 'inactive']]),
                            ('checkStudentProjectHasStatus',
                             [['accepted', 'failed', 'completed',
                               'withdrawn']])]
        rights['manage_overview'] = [('checkHasAny', [[
            ('checkHasRoleForScope', [org_admin_logic, ['active',
                                                        'inactive']]),
            ('checkHasRoleForScope', [mentor_logic, ['active', 'inactive']])
        ]])]
        # TODO: lack of better name here!
        rights['st_edit'] = [
            'checkCanEditStudentProjectAsStudent',
            ('checkStudentProjectHasStatus', [['accepted', 'completed']])
        ]
        rights['overview'] = [('checkIsHostForProgram', [program_logic])]

        new_params = {}
        new_params['logic'] = project_logic
        new_params['rights'] = rights
        new_params['name'] = 'Student Project'
        new_params['url_name'] = 'gsoc/student_project'
        new_params['module_package'] = 'soc.modules.gsoc.views.models'
        new_params['sidebar_grouping'] = 'Students'

        new_params['scope_view'] = org_view
        new_params['scope_redirect'] = redirects.getCreateRedirect

        new_params['no_create_with_key_fields'] = True

        new_params['extra_dynaexclude'] = [
            'program', 'status', 'link_id', 'mentor', 'additional_mentors',
            'student', 'passed_evaluations', 'failed_evaluations'
        ]

        new_params['create_extra_dynaproperties'] = {
            'scope_path':
            forms.CharField(widget=forms.HiddenInput, required=True),
            'public_info':
            forms.fields.CharField(required=True,
                                   widget=widgets.FullTinyMCE(attrs={
                                       'rows': 25,
                                       'cols': 100
                                   })),
            'student_id':
            forms.CharField(label='Student Link ID', required=True),
            'mentor_id':
            forms.CharField(label='Mentor Link ID', required=True),
            'clean_abstract':
            cleaning.clean_content_length('abstract'),
            'clean_public_info':
            cleaning.clean_html_content('public_info'),
            'clean_student':
            cleaning.clean_link_id('student'),
            'clean_mentor':
            cleaning.clean_link_id('mentor'),
            'clean_additional_info':
            cleaning.clean_url('additional_info'),
            'clean_feed_url':
            cleaning.clean_feed_url('feed_url'),
            'clean':
            cleaning.validate_student_project('scope_path', 'mentor_id',
                                              'student_id')
        }

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

        patterns = [
            (r'^%(url_name)s/(?P<access_type>manage_overview)/%(scope)s$',
             'soc.modules.gsoc.views.models.%(module_name)s.manage_overview',
             'Overview of %(name_plural)s to Manage for'),
            (r'^%(url_name)s/(?P<access_type>manage)/%(key_fields)s$',
             'soc.modules.gsoc.views.models.%(module_name)s.manage',
             'Manage %(name)s'),
            (r'^%(url_name)s/(?P<access_type>st_edit)/%(key_fields)s$',
             'soc.modules.gsoc.views.models.%(module_name)s.st_edit',
             'Edit my %(name)s'),
            (r'^%(url_name)s/(?P<access_type>overview)/(?P<scope_path>%(ulnp)s)/%(lnp)s$',
             'soc.modules.gsoc.views.models.%(module_name)s.overview',
             'Overview of all %(name_plural)s for'),
        ]

        new_params['extra_django_patterns'] = patterns

        new_params['edit_template'] = 'soc/student_project/edit.html'
        new_params['manage_template'] = 'soc/student_project/manage.html'

        new_params['public_field_prefetch'] = ['mentor', 'student', 'scope']
        new_params['public_field_extra'] = lambda entity: {
            'student': entity.student.name(),
            'mentor': entity.mentor.name(),
            'org': entity.scope.name,
        }
        new_params['public_field_keys'] = [
            'student', 'title', 'mentor', 'org', 'status'
        ]
        new_params['public_field_names'] = [
            'Student', 'Title', 'Mentor', 'Organization', 'Status'
        ]

        new_params['org_home_field_prefetch'] = ['mentor', 'student']
        new_params['org_home_field_extra'] = lambda entity: {
            'student':
            entity.student.name(),
            'mentor':
            ', '.join(mentor.name() for mentor in [entity.mentor] + db.get(
                entity.additional_mentors))
        }
        new_params['org_home_field_keys'] = [
            'student', 'title', 'mentor', 'status'
        ]
        new_params['org_home_field_names'] = [
            'Student', 'Title', 'Mentor', 'Status'
        ]

        # define the list redirect action to show the notification
        new_params['public_row_extra'] = new_params[
            'org_home_row_extra'] = lambda entity: {
                'link': redirects.getPublicRedirect(entity, new_params)
            }
        new_params['org_home_row_action'] = {
            'type': 'redirect_custom',
            'parameters': dict(new_window=False),
        }

        new_params['admin_field_prefetch'] = ['mentor', 'student', 'scope']
        new_params['admin_field_extra'] = lambda entity: {
            'student': entity.student.name(),
            'mentor': entity.mentor.name(),
            'student_id': entity.student.link_id
        }
        new_params['admin_field_keys'] = [
            'student', 'title', 'mentor', 'status', 'student_id'
        ]
        new_params['admin_field_names'] = [
            'Student', 'Title', 'Mentor', 'Status', 'Student Link ID'
        ]
        new_params['admin_field_hidden'] = ['student_id']

        new_params['admin_conf_extra'] = {
            'multiselect': True,
        }
        new_params['admin_button_global'] = [{
            'bounds': [1, 'all'],
            'id': 'withdraw',
            'caption': 'Withdraw Project',
            'type': 'post',
            'parameters': {
                'url': '',
                'keys': ['key'],
                'refresh': 'current',
            }
        }, {
            'bounds': [1, 'all'],
            'id': 'accept',
            'caption': 'Accept Project',
            'type': 'post',
            'parameters': {
                'url': '',
                'keys': ['key'],
                'refresh': 'current',
            }
        }]

        params = dicts.merge(params, new_params)

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

        # create the form that students will use to edit their projects
        dynaproperties = {
            'public_info':
            forms.fields.CharField(required=True,
                                   widget=widgets.FullTinyMCE(attrs={
                                       'rows': 25,
                                       'cols': 100
                                   })),
            'clean_abstract':
            cleaning.clean_content_length('abstract'),
            'clean_public_info':
            cleaning.clean_html_content('public_info'),
            'clean_additional_info':
            cleaning.clean_url('additional_info'),
            'clean_feed_url':
            cleaning.clean_feed_url('feed_url'),
        }

        student_edit_form = dynaform.newDynaForm(
            dynabase=self._params['dynabase'],
            dynamodel=self._params['logic'].getModel(),
            dynaexclude=self._params['create_dynaexclude'],
            dynaproperties=dynaproperties,
        )

        self._params['student_edit_form'] = student_edit_form
Example #26
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:
      original_params: a dict with params for this View
    """

    from soc.views.models import program as program_view

    rights = access.Checker(params)
    rights['any_access'] = ['allow']
    rights['show'] = ['allow']
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = [('checkHasActiveRoleForKeyFieldsAsScope',
                           org_admin_logic.logic,),
                      ('checkGroupIsActiveForLinkId', org_logic.logic)]
    rights['delete'] = ['checkIsDeveloper']
    rights['home'] = ['allow']
    rights['public_list'] = ['allow']
    rights['apply_mentor'] = ['checkIsUser']
    rights['list_requests'] = [('checkHasActiveRoleForKeyFieldsAsScope',
                                org_admin_logic.logic)]
    rights['list_roles'] = [('checkHasActiveRoleForKeyFieldsAsScope',
                             org_admin_logic.logic)]
    rights['applicant'] = [('checkIsApplicationAccepted',
                            org_app_logic.logic)]
    rights['list_proposals'] = [('checkHasAny', [
        [('checkHasActiveRoleForKeyFieldsAsScope', [org_admin_logic.logic]),
         ('checkHasActiveRoleForKeyFieldsAsScope', [mentor_logic.logic])]
        ])]

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

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

    new_params['name'] = "Organization"
    new_params['url_name'] = "org"
    new_params['document_prefix'] = "org"
    new_params['sidebar_grouping'] = 'Organizations'

    new_params['public_template'] = 'soc/organization/public.html'
    new_params['list_row'] = 'soc/organization/list/row.html'
    new_params['list_heading'] = 'soc/organization/list/heading.html'
    new_params['home_template'] = 'soc/organization/home.html'

    new_params['application_logic'] = org_app_logic
    new_params['group_applicant_url'] = True
    new_params['sans_link_id_public_list'] = True

    new_params['extra_dynaexclude'] = ['slots', 'slots_calculated',
                                       'nr_applications', 'nr_mentors']

    patterns = []

    patterns += [
        (r'^%(url_name)s/(?P<access_type>apply_mentor)/%(scope)s$',
        'soc.views.models.%(module_name)s.apply_mentor',
        "List of all %(name_plural)s you can apply to"),
        (r'^%(url_name)s/(?P<access_type>list_proposals)/%(key_fields)s$',
        'soc.views.models.%(module_name)s.list_proposals',
        "List of all Student Proposals for this %(name)s"),
        ]

    new_params['extra_django_patterns'] = patterns

    new_params['create_dynafields'] = [
        {'name': 'link_id',
         'base': forms.fields.CharField,
         'label': 'Organization Link ID',
         },
        ]

    new_params['create_extra_dynaproperties'] = {
        'scope_path': forms.CharField(widget=forms.HiddenInput,
                                   required=True),
        'description': forms.fields.CharField(
            widget=helper.widgets.FullTinyMCE(
                attrs={'rows': 25, 'cols': 100})),
        'contrib_template': forms.fields.CharField(
            widget=helper.widgets.FullTinyMCE(
                attrs={'rows': 25, 'cols': 100})),
        'clean_description': cleaning.clean_html_content('description'),
        'clean_contrib_template': cleaning.clean_html_content(
            'contrib_template'),
        'clean_ideas': cleaning.clean_url('ideas'),
        'clean': cleaning.validate_new_group('link_id', 'scope_path',
            soc.logic.models.organization, org_app_logic)
        }

    new_params['edit_extra_dynaproperties'] = {
        'clean': cleaning.clean_refs(new_params, ['home_link_id'])
        }

    params = dicts.merge(params, new_params)

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

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

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

    self._params['applicant_create_form'] = applicant_create_form
Example #27
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['any_access'] = ['allow']
        rights['show'] = [('checkIsSurveyWritable', survey_logic)]
        rights['create'] = ['checkIsUser']
        rights['edit'] = [('checkIsSurveyWritable', survey_logic)]
        rights['delete'] = ['checkIsDeveloper'
                            ]  # TODO: fix deletion of Surveys
        rights['list'] = ['checkDocumentList']
        rights['pick'] = ['checkDocumentPick']
        rights['record'] = [('checkHasAny', [[
            ('checkIsSurveyReadable', [survey_logic]),
            ('checkIsMySurveyRecord', [survey_logic, 'id'])
        ]])]
        rights['results'] = ['checkIsUser']
        rights['take'] = [('checkIsSurveyTakeable', survey_logic)]

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

        new_params['name'] = 'Survey'
        new_params['sidebar_grouping'] = "Surveys"

        new_params['extra_django_patterns'] = [
            (r'^%(url_name)s/(?P<access_type>take)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.take', 'Take %(name)s'),
            (r'^%(url_name)s/(?P<access_type>json)/%(scope)s$',
             '%(module_package)s.%(module_name)s.json',
             'Export %(name)s as JSON'),
            (r'^%(url_name)s/(?P<access_type>record)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.record',
             'View survey record for %(name)s'),
            (r'^%(url_name)s/(?P<access_type>results)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.results',
             'View survey results for %(name)s'),
            (r'^%(url_name)s/(?P<access_type>show)/user/(?P<link_id>)\w+$',
             '%(module_package)s.%(module_name)s.results',
             'View survey results for user'),
        ]

        new_params['export_content_type'] = 'text/text'
        new_params['export_extension'] = '.csv'
        new_params['export_function'] = surveys.toCSV(self)
        new_params['delete_redirect'] = '/'

        new_params['edit_template'] = 'soc/survey/edit.html'
        new_params['create_template'] = 'soc/survey/edit.html'
        new_params['public_template'] = 'soc/survey/public.html'
        new_params['record_template'] = 'soc/survey/view_record.html'
        new_params['take_template'] = 'soc/survey/take.html'

        new_params['no_create_raw'] = True
        new_params['no_create_with_scope'] = True
        new_params['no_create_with_key_fields'] = True
        new_params['no_list_raw'] = True
        new_params['sans_link_id_create'] = True
        new_params['sans_link_id_list'] = True

        new_params['create_dynafields'] = [
            {
                'name': 'link_id',
                'base': forms.fields.CharField,
                'label': 'Survey Link ID',
            },
        ]

        new_params['create_extra_dynaproperties'] = {
            'content':
            forms.fields.CharField(required=False,
                                   label='Description',
                                   widget=widgets.FullTinyMCE(attrs={
                                       'rows': 25,
                                       'cols': 100
                                   })),
            'survey_html':
            forms.fields.CharField(widget=forms.HiddenInput, required=False),
            'scope_path':
            forms.fields.CharField(widget=forms.HiddenInput, required=True),
            'prefix':
            forms.fields.CharField(widget=widgets.ReadOnlyInput(),
                                   required=True),
            'clean_content':
            cleaning.clean_html_content('content'),
            'clean_link_id':
            cleaning.clean_link_id('link_id'),
            'clean_scope_path':
            cleaning.clean_scope_path('scope_path'),
            'clean':
            cleaning.validate_document_acl(self, True),
        }

        new_params['extra_dynaexclude'] = [
            'author', 'created', 'home_for', 'modified_by', 'modified',
            'take_survey', 'survey_content'
        ]

        new_params['edit_extra_dynaproperties'] = {
            'doc_key_name':
            forms.fields.CharField(widget=forms.HiddenInput),
            'created_by':
            forms.fields.CharField(widget=widgets.ReadOnlyInput(),
                                   required=False),
            'last_modified_by':
            forms.fields.CharField(widget=widgets.ReadOnlyInput(),
                                   required=False),
            'clean':
            cleaning.validate_document_acl(self),
        }

        new_params['survey_take_form'] = surveys.SurveyTakeForm
        new_params['survey_record_form'] = surveys.SurveyRecordForm

        new_params['public_field_prefetch'] = ['author']
        new_params['public_field_extra'] = lambda entity: {
            "path": entity.scope_path + '/' + entity.link_id,
            "created_by": entity.author.link_id,
        }
        new_params['public_field_keys'] = [
            "path", "title", "link_id", "is_featured", "created_by", "created",
            "modified"
        ]
        new_params['public_field_names'] = [
            "Path",
            "Title",
            "Link ID",
            "Featured",
            "Created By",
            "Created On",
            "Modified",
        ]

        new_params['records_field_keys'] = ['taken_by', 'modified']
        new_params['records_field_names'] = [
            'Taken By',
            'Taken On',
        ]
        new_params['records_field_prefetch'] = ['user']
        new_params['records_field_extra'] = lambda entity: {
            'taken_by': '%s (%s)' % (entity.user.name, entity.user.link_id),
        }

        new_params['take_params'] = {'s': '0'}

        new_params['successful_take_message'] = ugettext(
            'Survey record submitted.')

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

        super(View, self).__init__(params=params)
Example #28
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['logic'] = group_app_logic

    new_params['name'] = "Group Application"
    new_params['name_short'] = "Group App"

    # use the twoline templates for these questionnaires
    new_params['create_template'] = 'soc/models/twoline_edit.html'
    new_params['edit_template'] = 'soc/models/twoline_edit.html'

    patterns = [(r'^%(url_name)s/(?P<access_type>list_self)/%(scope)s$',
        'soc.views.models.%(module_name)s.list_self',
        'List my %(name_plural)s'),
        (r'^%(url_name)s/(?P<access_type>review_overview)/%(scope)s$',
        'soc.views.models.%(module_name)s.review_overview',
        'List of %(name_plural)s for reviewing'),
        (r'^%(url_name)s/(?P<access_type>review)/%(key_fields)s$',
          'soc.views.models.%(module_name)s.review',
          'Review %(name_short)s')]

    new_params['extra_django_patterns'] = patterns

    new_params['extra_dynaexclude'] = ['applicant', 'backup_admin', 'status',
        'created_on', 'last_modified_on']

    new_params['create_dynafields'] = [
        {'name': 'backup_admin_link_id',
         'base': widgets.ReferenceField,
         'passthrough': ['reference_url', 'required', 'label'],
         'reference_url': 'user',
         'required': False,
         'label': params['logic'].getModel().backup_admin.verbose_name,
         'example_text': ugettext('The link_id of the backup admin'),
         },
         ]

    new_params['create_extra_dynaproperties'] = {
        'email': forms.fields.EmailField(required=True),
        'clean_backup_admin_link_id': 
            cleaning.clean_users_not_same('backup_admin_link_id'),
        }

    new_params['edit_extra_dynaproperties'] = {
        'clean_link_id' : cleaning.clean_link_id('link_id'),
        }

    new_params['public_field_extra'] = lambda entity: {
        'ideas': list_helper.urlize(entity.ideas),
    }
    new_params['public_field_keys'] = new_params['self_field_keys'] = [
        "name", "link_id", "ideas", "status",
    ]
    new_params['public_field_names'] = new_params['self_field_names'] = [
        "Name", "Link ID", "Ideas Page", "Status",
    ]
    new_params['self_field_extra'] = lambda entity: {
        'ideas': list_helper.urlize(entity.ideas),
        'status': "accepted" if entity.status == "accepted" else
                  "rejected" if entity.status == "rejected" else
                  "under review",
    }

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

    super(View, self).__init__(params=params)
Example #29
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.GSoCChecker(params)
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = [('checkCanStudentPropose', ['scope_path', False]),
        ('checkRoleAndStatusForStudentProposal',
            [['proposer'], ['active'], ['new', 'pending', 'invalid']])]
    rights['delete'] = ['checkIsDeveloper']
    rights['private'] = [
        ('checkRoleAndStatusForStudentProposal',
            [['proposer', 'org_admin', 'mentor', 'host'], 
            ['active', 'inactive'], 
            ['new', 'pending', 'accepted', 'rejected', 'invalid']])]
    rights['show'] = ['checkIsStudentProposalPubliclyVisible']
    rights['comment'] = [
        ('checkRoleAndStatusForStudentProposal',
            [['org_admin', 'mentor', 'host'], 
            ['active', 'inactive'],
            ['new', 'pending', 'accepted', 'rejected', 'invalid']])]
    rights['list'] = ['checkIsDeveloper']
    rights['list_orgs'] = [
        ('checkIsStudent', ['scope_path', ['active']]),
        ('checkCanStudentPropose', ['scope_path', False])]
    rights['list_self'] = [
        ('checkIsStudent', ['scope_path', ['active', 'inactive']])]
    rights['apply'] = [
        ('checkIsStudent', ['scope_path', ['active']]),
        ('checkCanStudentPropose', ['scope_path', True])]
    rights['review'] = [
            ('checkIsBeforeEvent',
            ['accepted_students_announced_deadline', None,
             program_logic.logic]),
            ('checkRoleAndStatusForStudentProposal',
            [['org_admin', 'mentor', 'host'], 
            ['active'],
            ['new', 'pending', 'accepted', 'invalid']])]

    new_params = {}
    new_params['logic'] = student_proposal_logic.logic
    new_params['rights'] = rights
    new_params['name'] = "Student Proposal"
    new_params['url_name'] = "gsoc/student_proposal"
    new_params['module_package'] = 'soc.modules.gsoc.views.models'
    new_params['sidebar_grouping'] = 'Students'

    new_params['scope_view'] = student_view
    new_params['scope_redirect'] = redirects.getCreateRedirect

    new_params['no_create_with_key_fields'] = True

    patterns = [
        (r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.apply',
        'Create a new %(name)s'),
        (r'^%(url_name)s/(?P<access_type>list_self)/%(scope)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.list_self',
        'List my %(name_plural)s'),
        (r'^%(url_name)s/(?P<access_type>list_orgs)/%(scope)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.list_orgs',
        'List my %(name_plural)s'),
        (r'^%(url_name)s/(?P<access_type>review)/%(key_fields)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.review',
        'Review %(name)s'),
        (r'^%(url_name)s/(?P<access_type>public)/%(key_fields)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.public',
        'Public view for %(name)s'),
        (r'^%(url_name)s/(?P<access_type>private)/%(key_fields)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.private',
        'Private view of %(name)s'),
        (r'^%(url_name)s/(?P<access_type>comment)/%(key_fields)s$',
        'soc.modules.gsoc.views.models.%(module_name)s.comment',
        'Comment view of %(name)s'),
    ]

    new_params['extra_django_patterns'] = patterns

    new_params['extra_dynaexclude'] = ['org', 'program', 'score',
                                       'status', 'mentor', 'link_id',
                                       'possible_mentors']

    new_params['create_extra_dynaproperties'] = {
        'content': forms.fields.CharField(required=True,
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
        'scope_path': forms.CharField(widget=forms.HiddenInput,
            required=True),
        'organization': forms.CharField(label='Organization Link ID',
            required=True),
        'clean_abstract': cleaning.clean_content_length('abstract'),
        'clean_content': cleaning.clean_html_content('content'),
        'clean_organization': cleaning.clean_link_id('organization'),
        'clean_additional_info': cleaning.clean_url('additional_info'),
        'clean': cleaning.validate_student_proposal('organization',
            'scope_path', student_logic, org_logic),
        }

    new_params['edit_extra_dynaproperties'] = {
        'organization': forms.CharField(label='Organization Link ID',
            widget=widgets.ReadOnlyInput),
        'link_id': forms.CharField(widget=forms.HiddenInput)
        }

    new_params['comment_template'] = 'soc/student_proposal/comment.html'
    new_params['edit_template'] = 'soc/student_proposal/edit.html'
    new_params['private_template'] = 'soc/student_proposal/private.html'
    new_params['review_template'] = 'soc/student_proposal/review.html'
    new_params['public_template'] = 'soc/student_proposal/public.html'
    new_params['review_after_deadline_template'] = \
        'soc/student_proposal/review_after_deadline.html'

    new_params['public_field_extra'] = lambda entity: {
        "student": entity.scope.name(),
        "organization_name": entity.org.name,
    }
    new_params['public_field_keys'] = [
        "title", "student", "organization_name", "last_modified_on",
    ]
    new_params['public_field_names'] = [
        "Title", "Student", "Organization Name", "Last Modified On",
    ]

    params = dicts.merge(params, new_params)

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

    # create the special form for students
    dynafields = [
        {'name': 'organization',
         'base': forms.CharField,
         'label': 'Organization Link ID',
         'widget': widgets.ReadOnlyInput(),
         'required': False,
         },
        ]

    dynaproperties = params_helper.getDynaFields(dynafields)

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

    self._params['student_create_form'] = student_create_form

    # create the special form for public review
    base_fields = [
        {'name': 'comment',
         'base': forms.CharField,
         'widget': widgets.FullTinyMCE(attrs={'rows': 10, 'cols': 40}),
         'label': 'Comment',
         'required': False,
         'example_text': 'Caution, you will not be able to edit your comment!',
         },
         ]

    dynafields = [field.copy() for field in base_fields]
    dynaproperties = params_helper.getDynaFields(dynafields)
    dynaproperties['clean_comment'] = cleaning.clean_html_content('comment')

    public_review_form = dynaform.newDynaForm(dynamodel=None, 
        dynabase=helper.forms.BaseForm, dynainclude=None, 
        dynaexclude=None, dynaproperties=dynaproperties)
    self._params['public_review_form'] = public_review_form

    # create the special form for mentors when the scoring is locked

    # this fields is used by the on-page JS
    base_fields.append(
        {'name': 'public',
         'base': forms.BooleanField,
         'label': 'Review visible to Student',
         'initial': False,
         'required': False,
         'help_text': 'By ticking this box the score will not be assigned, '
             'and the review will be visible to the student.',
         })

    dynafields = [field.copy() for field in base_fields]
    dynaproperties = params_helper.getDynaFields(dynafields)
    dynaproperties['clean_comment'] = cleaning.clean_html_content('comment')
    locked_review_form = dynaform.newDynaForm(dynamodel=None, 
        dynabase=helper.forms.BaseForm, dynainclude=None, 
        dynaexclude=None, dynaproperties=dynaproperties)
    self._params['locked_review_form'] = locked_review_form

    # create the form for mentors when the scoring is unlocked
    base_fields.append(
        {'name': 'score',
         'base': forms.ChoiceField,
         'label': 'Score',
         'initial': 0,
         'required': False,
         'passthrough': ['initial', 'required', 'choices'],
         'choices': [(-4,'-4'),
                     (-3,'-3'),
                     (-2,'-2'),
                     (-1,'-1'),
                     (0,'No score'),
                     (1,'1'),
                     (2,'2'),
                     (3,'3'),
                     (4,'4')]
        })

    dynafields = [field.copy() for field in base_fields]
    dynaproperties = params_helper.getDynaFields(dynafields)
    dynaproperties['clean_comment'] = cleaning.clean_html_content('comment')
    mentor_review_form = dynaform.newDynaForm(dynamodel=None, 
        dynabase=helper.forms.BaseForm, dynainclude=None, 
        dynaexclude=None, dynaproperties=dynaproperties)
    self._params['mentor_review_form'] = mentor_review_form
    self._show_review_not_appeared_msg = False
Example #30
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:
      original_params: a dict with params for this View
    """

        from soc.views.models import program as program_view

        rights = access.Checker(params)
        rights['any_access'] = ['allow']
        rights['show'] = ['allow']
        rights['create'] = ['checkIsDeveloper']
        rights['edit'] = [(
            'checkHasRoleForKeyFieldsAsScope',
            org_admin_logic.logic,
        ), ('checkGroupIsActiveForLinkId', org_logic.logic)]
        rights['delete'] = ['checkIsDeveloper']
        rights['home'] = ['allow']
        rights['public_list'] = ['allow']
        rights['apply_mentor'] = ['checkIsUser']
        rights['list_requests'] = [('checkHasRoleForKeyFieldsAsScope',
                                    org_admin_logic.logic)]
        rights['list_roles'] = [('checkHasRoleForKeyFieldsAsScope',
                                 org_admin_logic.logic)]
        rights['applicant'] = [('checkIsApplicationAccepted',
                                org_app_logic.logic)]

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

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

        new_params['name'] = "Organization"
        new_params['url_name'] = "org"
        new_params['document_prefix'] = "org"
        new_params['sidebar_grouping'] = 'Organizations'

        new_params['public_template'] = 'soc/organization/public.html'
        new_params['list_row'] = 'soc/organization/list/row.html'
        new_params['list_heading'] = 'soc/organization/list/heading.html'
        new_params['home_template'] = 'soc/organization/home.html'

        new_params['application_logic'] = org_app_logic
        new_params['sans_link_id_public_list'] = True

        patterns = []

        patterns += [
            (r'^%(url_name)s/(?P<access_type>apply_mentor)/%(scope)s$',
             '%(module_package)s.%(module_name)s.apply_mentor',
             "List of all %(name_plural)s you can apply to"),
            (r'^%(url_name)s/(?P<access_type>list_proposals)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.list_proposals',
             "List of all Student Proposals for this %(name)s"),
            (r'^%(url_name)s/(?P<access_type>applicant)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.applicant',
             "%(name)s Creation via Accepted Application"),
        ]

        new_params['extra_django_patterns'] = patterns

        new_params['create_dynafields'] = [
            {
                'name': 'link_id',
                'base': forms.fields.CharField,
                'label': 'Organization Link ID',
            },
        ]

        new_params['create_extra_dynaproperties'] = {
            'scope_path':
            forms.CharField(widget=forms.HiddenInput, required=True),
            'description':
            forms.fields.CharField(widget=helper.widgets.FullTinyMCE(
                attrs={
                    'rows': 25,
                    'cols': 100
                })),
            'contrib_template':
            forms.fields.CharField(widget=helper.widgets.FullTinyMCE(
                attrs={
                    'rows': 25,
                    'cols': 100
                })),
            'clean_description':
            cleaning.clean_html_content('description'),
            'clean_contrib_template':
            cleaning.clean_html_content('contrib_template'),
            'clean_ideas':
            cleaning.clean_url('ideas'),
            'clean':
            cleaning.validate_new_group('link_id', 'scope_path',
                                        soc.logic.models.organization,
                                        org_app_logic)
        }

        new_params['edit_extra_dynaproperties'] = {
            'clean': cleaning.clean_refs(new_params, ['home_link_id'])
        }

        new_params['mentor_role_name'] = 'mentor'

        new_params['public_field_extra'] = lambda entity: {
            'ideas': lists.urlize(entity.ideas),
        }

        params = dicts.merge(params, new_params)

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

        self._params['public_field_keys'] = self._params[
            'select_field_keys'] = ["name", "link_id", "short_name", "ideas"]
        self._params['public_field_names'] = self._params[
            'select_field_names'] = [
                "Name", "Link ID", "Short Name", "Ideas Page"
            ]
        self._params['select_row_action'] = {
            "type": "redirect_custom",
            "parameters": dict(new_window=True),
        }
        self._params['select_row_extra'] = lambda entity: {
            "link":
            redirects.getRequestRedirectForRole(entity, params[
                'mentor_url_name'])
        }

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

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

        self._params['applicant_create_form'] = applicant_create_form