Ejemplo n.º 1
0
 def testCleanHtmlContent(self):
     """Tests that html content can be cleaned.
 """
     field_name = 'html'
     clean_field = cleaning.clean_html_content(field_name)
     # Test that normal html can be cleaned
     expected = html = '<div>f9-+@4</div>'
     self.form.cleaned_data = {field_name: html}
     self.assertEqual(clean_field(self.form), expected)
     # Test that normal html can be cleaned
     html = '<html>f9-+@4</html>'
     self.form.cleaned_data = {field_name: html}
     expected = html[6:-7]
     self.assertEqual(clean_field(self.form), expected)
     # Test that unicode is also supported
     expected = html = u'\ua000'
     self.form.cleaned_data = {field_name: html}
     self.assertEqual(clean_field(self.form), expected)
     # Test that input with scripts will raise forms.ValidationError
     html = '<script></script>'
     self.form.cleaned_data = {field_name: html}
     self.assertRaises(forms.ValidationError, clean_field, self.form)
     # Test that input can contain scripts when the current user is a developer
     self.user.is_developer = True
     self.user.put()
     expected = html = '<script></script>'
     self.form.cleaned_data = {field_name: html}
     self.assertEqual(clean_field(self.form), expected)
Ejemplo n.º 2
0
 def testCleanHtmlContent(self):
     """Tests that html content can be cleaned.
 """
     field_name = 'test_html'
     clean_field = cleaning.clean_html_content(field_name)
     # Test that normal html can be cleaned
     expected = html = '<div>f9-+@4</div>'
     self.form.cleaned_data = {field_name: html}
     self.assertEqual(clean_field(self.form), expected)
     # Test that normal html can be cleaned
     html = '<html>f9-+@4</html>'
     self.form.cleaned_data = {field_name: html}
     expected = html.replace('<', '&lt;').replace('>', '&gt;')
     actual = clean_field(self.form)
     self.assertEqual(actual, expected)
     expected = html = u'\ua000'
     self.form.cleaned_data = {field_name: html}
     self.assertEqual(clean_field(self.form), expected)
     # Test that input with scripts will be encoded as well
     html = '<script></script>'
     self.form.cleaned_data = {field_name: html}
     actual = clean_field(self.form)
     expected = html.replace('<', '&lt;').replace('>', '&gt;')
     self.assertEqual(actual, expected)
     # Test that input can contain scripts when the current user is a developer
     profile_utils.loginNDB(self.user, is_admin=True)
     expected = html = '<script></script>'
     self.form.cleaned_data = {field_name: html}
     self.assertEqual(clean_field(self.form), expected)
Ejemplo n.º 3
0
 def clean_content(self):
     content = cleaning.clean_html_content('content')(self)
     if content:
         return content
     else:
         raise django_forms.ValidationError(
             ugettext('Comment content cannot be empty.'), code='invalid')
Ejemplo n.º 4
0
 def testCleanHtmlContent(self):
   """Tests that html content can be cleaned.
   """
   field_name = 'test_html'
   clean_field = cleaning.clean_html_content(field_name)
   # Test that normal html can be cleaned
   expected = html = '<div>f9-+@4</div>'
   self.form.cleaned_data = {field_name: html}
   self.assertEqual(clean_field(self.form), expected)
   # Test that normal html can be cleaned
   html = '<html>f9-+@4</html>'
   self.form.cleaned_data = {field_name: html}
   expected = html.replace('<', '&lt;').replace('>', '&gt;')
   actual = clean_field(self.form)
   self.assertEqual(actual, expected)
   expected = html = u'\ua000'
   self.form.cleaned_data = {field_name: html}
   self.assertEqual(clean_field(self.form), expected)
   # Test that input with scripts will be encoded as well
   html = '<script></script>'
   self.form.cleaned_data = {field_name: html}
   actual = clean_field(self.form)
   expected = html.replace('<', '&lt;').replace('>', '&gt;')
   self.assertEqual(actual, expected)
   # Test that input can contain scripts when the current user is a developer
   profile_utils.loginNDB(self.user, is_admin=True)
   expected = html = '<script></script>'
   self.form.cleaned_data = {field_name: html}
   self.assertEqual(clean_field(self.form), expected)
Ejemplo n.º 5
0
 def testCleanHtmlContent(self):
   """Tests that html content can be cleaned.
   """
   field_name = 'html'
   clean_field = cleaning.clean_html_content(field_name)
   # Test that normal html can be cleaned
   expected = html = '<div>f9-+@4</div>'
   self.form.cleaned_data = {field_name: html}
   self.assertEqual(clean_field(self.form), expected)
   # Test that normal html can be cleaned
   html = '<html>f9-+@4</html>'
   self.form.cleaned_data = {field_name: html}
   expected = html[6:-7]
   self.assertEqual(clean_field(self.form), expected)
   # Test that unicode is also supported
   expected = html = u'\ua000'
   self.form.cleaned_data = {field_name: html}
   self.assertEqual(clean_field(self.form), expected)
   # Test that input with scripts will raise forms.ValidationError
   html = '<script></script>'
   self.form.cleaned_data = {field_name: html}
   self.assertRaises(forms.ValidationError, clean_field, self.form)
   # Test that input can contain scripts when the current user is a developer
   self.user.is_developer = True
   self.user.put()
   expected = html = '<script></script>'
   self.form.cleaned_data = {field_name: html}
   self.assertEqual(clean_field(self.form), expected)
Ejemplo n.º 6
0
 def clean_content(self):
   content = cleaning.clean_html_content('content')(self)
   if content:
     return content
   else:
     raise django_forms.ValidationError(
         ugettext('Comment content cannot be empty.'), code='invalid')
Ejemplo n.º 7
0
 def clean_content(self):
     field_name = "content"
     wrapped_clean_html_content = cleaning.clean_html_content(field_name)
     content = wrapped_clean_html_content(self)
     if content:
         return content
     else:
         raise django_forms.ValidationError(ugettext("Comment content cannot be empty."), code="invalid")
Ejemplo n.º 8
0
 def clean_content(self):
     field_name = 'content'
     wrapped_clean_html_content = cleaning.clean_html_content(field_name)
     content = wrapped_clean_html_content(self)
     if content:
         return content
     else:
         raise django_forms.ValidationError(
             ugettext('Comment content cannot be empty.'), code='invalid')
Ejemplo n.º 9
0
class OrgProfileForm(forms.ModelForm):
    """Django form for the organization profile.
  """
    class Meta:
        model = GSoCOrganization
        css_prefix = 'gsoc_org_page'
        exclude = [
            'status', 'scope', 'scope_path', 'founder', 'founder', 'slots',
            'slots_calculated', 'nr_applications', 'nr_mentors',
            'scoring_disabled', 'link_id'
        ]
        widgets = forms.choiceWidgets(GSoCOrganization,
                                      ['contact_country', 'shipping_country'])

    clean_description = cleaning.clean_html_content('description')
    clean_contrib_template = cleaning.clean_html_content('contrib_template')
    clean_facebook = cleaning.clean_url('facebook')
    clean_twitter = cleaning.clean_url('twitter')
    clean_blog = cleaning.clean_url('blog')
    clean_pub_mailing_list = cleaning.clean_mailto('pub_mailing_list')
    clean_irc_channel = cleaning.clean_irc('irc_channel')
Ejemplo n.º 10
0
class GCIStudentInfoForm(gci_forms.GCIModelForm):
    """Django form for the student profile page.
  """

    school_name = forms.CharField(max_length=1024,
                                  help_text=SCHOOL_NAME_HELP_TEXT)

    class Meta:
        model = GCIStudentInfo
        css_prefix = 'student_info'
        exclude = [
            'number_of_completed_tasks', 'task_closed', 'parental_form_mail',
            'consent_form', 'consent_form_verified', 'consent_form_two',
            'student_id_form', 'major', 'student_id_form_verified', 'degree',
            'school', 'school_type', 'program', 'is_winner', 'winner_for'
        ]
        widgets = forms.choiceWidgets(
            model, ['school_country', 'school_type', 'degree'])

    clean_school_name = cleaning.clean_html_content('school_name')
    clean_major = cleaning.clean_html_content('major')
Ejemplo n.º 11
0
class ProposalForm(forms.ModelForm):
    """Django form for the proposal page.
  """
    class Meta:
        model = GSoCProposal
        css_prefix = 'gsoc_proposal'
        exclude = [
            'status', 'mentor', 'possible_mentors', 'org', 'program',
            'created_on', 'last_modified_on', 'score'
        ]

    clean_content = cleaning.clean_html_content('content')
Ejemplo n.º 12
0
class ProposalForm(GSoCModelForm):
    """Django form for the proposal page.
  """
    class Meta:
        model = GSoCProposal
        css_prefix = 'gsoc_proposal'
        exclude = [
            'status', 'mentor', 'possible_mentors', 'org', 'program',
            'is_editable_post_deadline', 'created_on', 'last_modified_on',
            'score', 'nr_scores', 'accept_as_project', 'extra', 'has_mentor'
        ]

    clean_content = cleaning.clean_html_content('content')
Ejemplo n.º 13
0
class SlotTransferForm(forms.GSoCModelForm):
    """Django form for the slot transfer page.
  """
    def __init__(self, max_slots=None, **kwargs):
        super(SlotTransferForm, self).__init__(**kwargs)
        choices = [('None', self.fields['nr_slots'].label)
                   ] + [(i, i) for i in range(1, max_slots + 1)]
        self.fields['nr_slots'].widget = django_forms.widgets.Select(
            choices=choices)

    class Meta:
        model = GSoCSlotTransfer
        css_prefix = 'gsoc_slot_transfer'
        exclude = [
            'status', 'created_on', 'last_modified_on', 'program',
            'admin_remarks'
        ]

    clean_remarks = cleaning.clean_html_content('remarks')
Ejemplo n.º 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['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
Ejemplo n.º 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
    """

    rights = access.GSoCChecker(params)
    rights['any_access'] = ['allow']
    rights['show'] = ['allow']
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = [('checkHasRoleForKeyFieldsAsScope',
                           org_admin_logic),
                      ('checkGroupIsActiveForLinkId', org_logic)]
    rights['delete'] = ['checkIsDeveloper']
    rights['home'] = ['allow']
    rights['public_list'] = ['allow']
    rights['applicant'] = [('checkIsOrgAppAccepted', org_app_logic)]
    rights['apply_mentor'] = ['checkIsUser']
    rights['list_requests'] = [('checkHasRoleForKeyFieldsAsScope',
                                org_admin_logic)]
    rights['list_roles'] = [('checkHasRoleForKeyFieldsAsScope',
                             org_admin_logic)]
    rights['list_proposals'] = [('checkHasAny', [
        [('checkHasRoleForKeyFieldsAsScope', 
          [org_admin_logic, ['active', 'inactive']]),
         ('checkHasRoleForKeyFieldsAsScope', 
          [mentor_logic, ['active', 'inactive']])]
        ])]

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

    new_params['scope_view'] = program_view

    new_params['name'] = "GSoC Organization"
    new_params['module_name'] = "organization"
    new_params['sidebar_grouping'] = 'Organizations'

    new_params['module_package'] = 'soc.modules.gsoc.views.models'
    new_params['url_name'] = 'gsoc/org'
    new_params['document_prefix'] = 'gsoc_org'

    new_params['mentor_role_name'] = 'gsoc_mentor'
    new_params['mentor_url_name'] = 'gsoc/mentor'
    new_params['org_admin_role_name'] = 'gsoc_org_admin'

    patterns = []

    patterns += [
        (r'^org_tags/(?P<access_type>pick)$',
        '%(module_package)s.%(module_name)s.pick_suggested_tags', 
        "Pick a list of suggested tags."),
        ]

    new_params['extra_django_patterns'] = patterns

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

    new_params['create_extra_dynaproperties']  = {
        'tags': widgets.ReferenceField(
              required=False,
              reference_url='org_tags',
              label=ugettext('Tags'),
              help_text=ugettext("A list of comma seperated tags"),
              example_text="e.g. python, django, appengine",
              filter=['scope_path'],
              group="1. Public Info"),
        'clean_tags': gsoc_cleaning.cleanTagsList(
            'tags', gsoc_cleaning.COMMA_SEPARATOR),
        'contrib_template': forms.fields.CharField(
            widget=helper.widgets.FullTinyMCE(
                attrs={'rows': 25, 'cols': 100})),
        'clean_contrib_template': cleaning.clean_html_content(
            'contrib_template'),
        'clean_facebook': cleaning.clean_url('facebook'),
        'clean_twitter': cleaning.clean_url('twitter'),
        'clean_blog': cleaning.clean_url('blog'),
        }

    new_params['org_app_logic'] = org_app_logic

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

    super(View, self).__init__(params)

    self._params['public_field_keys'].append('tags')
    self._params['public_field_names'].append("Tags")
    self._params['public_field_extra'] = lambda entity: {
        'ideas': lists.urlize(entity.ideas, 'Click Here'),
        'tags': entity.tags_string(entity.org_tag),
    }
    self._params['select_field_extra'] = self._params['public_field_extra']
Ejemplo n.º 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.Checker(params)
    rights['create'] = ['checkIsDeveloper']
    rights['delete'] = [('checkCanEditGroupApp',
                       [org_app_logic.logic]),
                       ('checkIsActivePeriod', ['org_signup', 'scope_path'])]
    rights['edit'] = [('checkCanEditGroupApp',
                       [org_app_logic.logic]),
                       ('checkIsActivePeriod', ['org_signup', 'scope_path'])]
    rights['list'] = ['checkIsDeveloper']
    rights['list_self'] = ['checkIsUser']
    rights['show'] = ['allow']
    rights['review'] = ['checkIsHostForProgramInScope',
                        ('checkCanReviewGroupApp', [org_app_logic.logic])]
    rights['review_overview'] = ['checkIsHostForProgramInScope']
    rights['bulk_accept'] = ['checkIsHostForProgramInScope']
    rights['bulk_reject'] = ['checkIsHostForProgramInScope']
    rights['apply'] = ['checkIsUser',
                             ('checkCanCreateOrgApp', ['org_signup']),
                       'checkIsNotStudentForProgramInScope']

    new_params = {}

    new_params['rights'] = rights
    new_params['logic'] = org_app_logic.logic

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

    new_params['sidebar_grouping'] = 'Organizations'

    new_params['list_key_order'] = [
        'link_id', 'scope_path', 'name', 'home_page', 'email',
        'description', 'why_applying','pub_mailing_list','irc_channel',
        'member_criteria', 'prior_participation', 'prior_application',
        'license_name', 'ideas', 'dev_mailing_list', 'contrib_template',
        'contrib_disappears', 'member_disappears', 'encourage_contribs',
        'continued_contribs']

    patterns = [(r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$',
        'soc.views.models.%(module_name)s.create',
        'Create an %(name_plural)s'),
        (r'^%(url_name)s/(?P<access_type>bulk_accept)/%(scope)s$',
        'soc.views.models.%(module_name)s.bulk_accept',
        'Bulk Acceptation of %(name_plural)s'),
        (r'^%(url_name)s/(?P<access_type>bulk_reject)/%(scope)s$',
        'soc.views.models.%(module_name)s.bulk_reject',
        'Bulk Rejection of %(name_plural)s'),]

    new_params['extra_django_patterns'] = patterns
    new_params['extra_key_order'] = ['admin_agreement',
                                     'agreed_to_admin_agreement']

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

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

    new_params['create_extra_dynaproperties'] = {
        'scope_path': forms.fields.CharField(widget=forms.HiddenInput,
                                             required=True),
        'contrib_template': forms.fields.CharField(
            widget=helper.widgets.FullTinyMCE(
                attrs={'rows': 25, 'cols': 100})),
        'description': forms.fields.CharField(
            widget=helper.widgets.FullTinyMCE(
                attrs={'rows': 25, 'cols': 100})),
        'admin_agreement': forms.fields.Field(required=False,
            widget=widgets.AgreementField),
        'agreed_to_admin_agreement': forms.fields.BooleanField(
            initial=False, required=True),

        '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',
            model_logic.organization, org_app_logic)}

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

    new_params['name'] = "Organization Application"
    new_params['name_plural'] = "Organization Applications"
    new_params['name_short'] = "Org App"
    new_params['url_name'] = "org_app"
    new_params['group_name'] = "Organization"
    new_params['group_url_name'] = 'org'

    new_params['review_template'] = 'soc/org_app/review.html'
    # TODO use a proper template that works for each program
    new_params['accepted_mail_template'] = \
        'soc/org_app/mail/accepted_gsoc2009.html'
    new_params['rejected_mail_template'] = 'soc/org_app/mail/rejected.html'

    params = dicts.merge(params, new_params)

    super(View, self).__init__(params=params)
Ejemplo n.º 17
0
class TaskCreateForm(TaskEditPostClaimForm):
  """Django form for the task creation page.
  """

  time_to_complete_days = django_forms.IntegerField(
      label=ugettext('Days to complete'), min_value=2,
      error_messages={
          'min_value': ugettext('Must be at least 2 days.')
      })

  def __init__(self, request_data=None, **kwargs):
    super(TaskCreateForm, self).__init__(request_data=request_data, **kwargs)

    types = []
    for t in request_data.program.task_types:
      types.append((t, t))

    self.fields['types'] = django_forms.MultipleChoiceField(
        label=ugettext('Type'), choices=types,
        widget=gci_forms.CheckboxSelectMultiple,
        help_text=DEF_TASK_TYPE_HELP_MSG)

    if self.instance:
      self.fields['types'].initial = [str(t) for t in self.instance.types]
      ttc = datetime.timedelta(hours=self.instance.time_to_complete)
      self.fields['time_to_complete_days'].initial = ttc.days

    # Bind all the fields here to boundclass since we do not iterate
    # over the fields using iterator for this form.
    for name, field in self.fields.items():
      self.bound_fields[name] = gci_forms.GCIBoundField(self, field, name)

  def create(self, commit=True, key_name=None, parent=None):
    # organization and status are in this create method and not in cleaner
    # because we want to store it in the entity only when it is created an
    # not while editing.
    organization = self.organization
    self.cleaned_data['org'] = organization

    profile = self.request_data.profile
    self.cleaned_data['created_by'] = profile
    self.cleaned_data['modified_by'] = profile

    # Difficulty is hardcoded to easy for GCI2012.
    self.cleaned_data['difficulty_level'] = DifficultyLevel.EASY

    entity = super(TaskCreateForm, self).create(
        commit=False, key_name=key_name, parent=parent)

    if commit:
      entity.put()

    if organization.key() in self.request_data.org_admin_for:
      entity.status = task_model.UNPUBLISHED
    elif organization.key() in self.request_data.mentor_for:
      entity.status = task_model.UNAPPROVED

    return entity

  clean_description = cleaning.clean_html_content('description')

  def clean(self):
    super(TaskCreateForm, self).clean()

    cleaned_data = self.cleaned_data
    ttc_days = cleaned_data.get("time_to_complete_days", 0)

    if ttc_days:
      # We check if the time to complete is under 30 days because Google
      # Appengine task queue API doesn't let us to add a Appengine task
      # the queue with an ETA longer than 30 days. We use this ETA feature
      # for GCI tasks to automatically trigger the reminders for the task
      # after the deadline.
      if ttc_days <= 30:
        cleaned_data['time_to_complete'] = ttc_days * 24
      else:
        errors = self._errors.setdefault('time_to_complete_days', ErrorList())
        errors.append(ugettext('Time to complete must be less than 30 days.'))
    else:
      errors = self._errors.setdefault('time_to_complete_days', ErrorList())
      errors.append(ugettext('Time to complete must be specified.'))

    return cleaned_data

  class Meta:
    model = task_model.GCITask
    css_prefix = 'gci-task'
    fields = ['title', 'description', 'mentors']
Ejemplo n.º 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:
      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)]

    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['home_template'] = 'soc/organization/home.html'

    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 "),
        (r'^%(url_name)s/(?P<access_type>applicant)/%(scope)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})),
        'clean_description': cleaning.clean_html_content('description'),
        'clean_ideas': cleaning.clean_url('ideas'),
        'clean': cleaning.validate_new_group('link_id', 'scope_path',
            soc.logic.models.organization),
        }

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

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

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

    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_field_extra'] = self._params['public_field_extra']
    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'])
    }
Ejemplo n.º 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.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
Ejemplo n.º 20
0
           'passthrough': ['min_value', 'required', 'help_text'],
        },
        {'name': 'mentor',
         'base': forms.ChoiceField,
         'passthrough': ['initial', 'required', 'choices'],
         'label': 'Assign Mentor',
         'choices': choices,
         'required': False,
         'help_text': 'Choose the mentor you would like to assign to this '
             'Proposal. Choose "No mentor" if you don\'t want any '
             'mentor assigned.'
         },
        ]

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

      form = dynaform.extendDynaForm(
          dynaform=params['mentor_review_form'], 
          dynaproperties=dynaproperties)

    else:
      # the current user is not an org admin
      if entity.org.scoring_disabled:
        # reviews are disabled, don't show score field
        form = params['locked_review_form']
      else:
        # reviews are enabled, show the score field
        form = params['mentor_review_form']

    if request.method == 'POST':
Ejemplo n.º 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.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)
Ejemplo n.º 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.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
Ejemplo n.º 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['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)
Ejemplo n.º 24
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)
Ejemplo n.º 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.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
Ejemplo n.º 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:
      params: a dict with params for this View
    """

        rights = access.GSoCChecker(params)
        rights['any_access'] = ['allow']
        rights['show'] = ['allow']
        rights['create'] = ['checkIsDeveloper']
        rights['edit'] = [('checkHasRoleForKeyFieldsAsScope', org_admin_logic),
                          ('checkGroupIsActiveForLinkId', org_logic)]
        rights['delete'] = ['checkIsDeveloper']
        rights['home'] = ['allow']
        rights['public_list'] = ['allow']
        rights['applicant'] = [('checkIsOrgAppAccepted', org_app_logic)]
        rights['apply_mentor'] = ['checkIsUser']
        rights['list_requests'] = [('checkHasRoleForKeyFieldsAsScope',
                                    org_admin_logic)]
        rights['list_roles'] = [('checkHasRoleForKeyFieldsAsScope',
                                 org_admin_logic)]
        rights['list_proposals'] = [
            ('checkHasAny', [[('checkHasRoleForKeyFieldsAsScope',
                               [org_admin_logic, ['active', 'inactive']]),
                              ('checkHasRoleForKeyFieldsAsScope',
                               [mentor_logic, ['active', 'inactive']])]])
        ]

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

        new_params['scope_view'] = program_view

        new_params['name'] = "GSoC Organization"
        new_params['module_name'] = "organization"
        new_params['sidebar_grouping'] = 'Organizations'

        new_params['module_package'] = 'soc.modules.gsoc.views.models'
        new_params['url_name'] = 'gsoc/org'
        new_params['document_prefix'] = 'gsoc_org'

        new_params['mentor_role_name'] = 'gsoc_mentor'
        new_params['mentor_url_name'] = 'gsoc/mentor'
        new_params['org_admin_role_name'] = 'gsoc_org_admin'

        patterns = []

        patterns += [
            (r'^org_tags/(?P<access_type>pick)$',
             '%(module_package)s.%(module_name)s.pick_suggested_tags',
             "Pick a list of suggested tags."),
        ]

        new_params['extra_django_patterns'] = patterns

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

        new_params['create_extra_dynaproperties'] = {
            'tags':
            widgets.ReferenceField(
                required=False,
                reference_url='org_tags',
                label=ugettext('Tags'),
                help_text=ugettext("A list of comma seperated tags"),
                example_text="e.g. python, django, appengine",
                filter=['scope_path'],
                group="1. Public Info"),
            'clean_tags':
            gsoc_cleaning.cleanTagsList('tags', gsoc_cleaning.COMMA_SEPARATOR),
            'contrib_template':
            forms.fields.CharField(widget=helper.widgets.FullTinyMCE(
                attrs={
                    'rows': 25,
                    'cols': 100
                })),
            'clean_contrib_template':
            cleaning.clean_html_content('contrib_template'),
            'clean_facebook':
            cleaning.clean_url('facebook'),
            'clean_twitter':
            cleaning.clean_url('twitter'),
            'clean_blog':
            cleaning.clean_url('blog'),
        }

        new_params['org_app_logic'] = org_app_logic

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

        super(View, self).__init__(params)

        self._params['public_field_keys'].append('tags')
        self._params['public_field_names'].append("Tags")
        self._params['public_field_extra'] = lambda entity: {
            'ideas': lists.urlize(entity.ideas, 'Click Here'),
            'tags': entity.tags_string(entity.org_tag),
        }
        self._params['select_field_extra'] = self._params['public_field_extra']
Ejemplo n.º 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:
      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
Ejemplo n.º 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
    """

        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)
Ejemplo n.º 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
    """

        # TODO(ljvderijk): phase out this module + access checks
        rights = access.Checker(params)
        rights['create'] = ['checkIsDeveloper']
        rights['delete'] = [('checkCanEditGroupApp', [org_app_logic.logic]),
                            ('checkIsActivePeriod',
                             ['org_signup', 'scope_path',
                              program_logic.logic])]
        rights['edit'] = [('checkCanEditGroupApp', [org_app_logic.logic]),
                          ('checkIsActivePeriod',
                           ['org_signup', 'scope_path', program_logic.logic])]
        rights['list'] = ['checkIsDeveloper']
        rights['list_self'] = ['checkIsUser']
        rights['show'] = ['allow']
        rights['review'] = [
            'checkIsHostForProgramInScope',
            ('checkCanReviewGroupApp', [org_app_logic.logic])
        ]
        rights['review_overview'] = ['checkIsHostForProgramInScope']
        rights['bulk_accept'] = ['checkIsHostForProgramInScope']
        rights['bulk_reject'] = ['checkIsHostForProgramInScope']
        rights['apply'] = [
            'checkIsUser',
            ('checkCanCreateOrgApp', ['org_signup', program_logic.logic]),
            ('checkIsNotStudentForProgramInScope',
             [program_logic.logic, student_logic.logic])
        ]

        new_params = {}

        new_params['rights'] = rights
        new_params['logic'] = org_app_logic.logic

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

        new_params['sidebar_grouping'] = 'Organizations'

        new_params['list_key_order'] = [
            'link_id', 'scope_path', 'name', 'home_page', 'email',
            'description', 'why_applying', 'pub_mailing_list', 'irc_channel',
            'member_criteria', 'prior_participation', 'prior_application',
            'license_name', 'ideas', 'dev_mailing_list', 'contrib_template',
            'contrib_disappears', 'member_disappears', 'encourage_contribs',
            'continued_contribs'
        ]

        patterns = [
            (r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$',
             'soc.views.models.%(module_name)s.create',
             'Create an %(name_plural)s'),
            (r'^%(url_name)s/(?P<access_type>bulk_accept)/%(scope)s$',
             'soc.views.models.%(module_name)s.bulk_accept',
             'Bulk Acceptation of %(name_plural)s'),
            (r'^%(url_name)s/(?P<access_type>bulk_reject)/%(scope)s$',
             'soc.views.models.%(module_name)s.bulk_reject',
             'Bulk Rejection of %(name_plural)s'),
        ]

        new_params['extra_django_patterns'] = patterns
        new_params['extra_key_order'] = [
            'admin_agreement', 'agreed_to_admin_agreement'
        ]

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

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

        new_params['create_extra_dynaproperties'] = {
            'scope_path':
            forms.fields.CharField(widget=forms.HiddenInput, required=True),
            'contrib_template':
            forms.fields.CharField(widget=helper.widgets.FullTinyMCE(
                attrs={
                    'rows': 25,
                    'cols': 100
                })),
            'description':
            forms.fields.CharField(widget=helper.widgets.FullTinyMCE(
                attrs={
                    'rows': 25,
                    'cols': 100
                })),
            'admin_agreement':
            forms.fields.Field(required=False, widget=widgets.AgreementField),
            'agreed_to_admin_agreement':
            forms.fields.BooleanField(initial=False, required=True),
            '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',
                                        model_logic.organization,
                                        org_app_logic)
        }

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

        new_params['name'] = "Organization Application"
        new_params['name_plural'] = "Organization Applications"
        new_params['name_short'] = "Org App"
        new_params['url_name'] = "org_app"
        new_params['group_name'] = "Organization"
        new_params['group_url_name'] = 'org'

        new_params['review_template'] = 'soc/org_app/review.html'
        # TODO use a proper template that works for each program
        new_params['accepted_mail_template'] = \
            'soc/org_app/mail/accepted_gsoc2009.html'
        new_params['rejected_mail_template'] = 'soc/org_app/mail/rejected.html'

        params = dicts.merge(params, new_params)

        super(View, self).__init__(params=params)
Ejemplo n.º 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:
      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)
Ejemplo n.º 31
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)
Ejemplo n.º 32
0
class ProfileForm(forms.ModelForm):
    """Django form for profile page.
  """

    TWO_LETTER_STATE_REQ = ['United States', 'Canada']

    def __init__(self, bound_field_class, request_data=None, **kwargs):
        super(ProfileForm, self).__init__(bound_field_class, **kwargs)
        self.fields['given_name'].group = "2. Contact Info (Private)"
        self.fields['surname'].group = "2. Contact Info (Private)"
        self.request_data = request_data
        self.program = request_data.program if request_data else None

    public_name = fields.CharField(required=True)

    clean_public_name = cleaning.clean_html_content('public_name')
    clean_name_on_documents = cleaning.clean_html_content('name_on_documents')
    clean_im_network = cleaning.clean_html_content('im_network')
    clean_im_handle = cleaning.clean_html_content('im_handle')
    clean_program_knowledge = cleaning.clean_html_content('program_knowledge')
    clean_email = cleaning.clean_email('email')
    clean_phone = cleaning.clean_phone_number('phone')

    def clean_given_name(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['given_name'])

    def clean_surname(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['surname'])

    def clean_res_street(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['res_street'])

    def clean_res_city(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['res_city'])

    def clean_res_street_extra(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['res_street_extra'])

    def clean_res_state(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['res_state'])

    def clean_res_postalcode(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['res_postalcode'])

    def clean_ship_name(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['ship_name'])

    def clean_ship_street(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['ship_street'])

    def clean_ship_street_extra(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['ship_street_extra'])

    def clean_ship_city(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['ship_city'])

    def clean_ship_state(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['ship_state'])

    def clean_ship_postalcode(self):
        return cleaning.cleanValidAddressCharacters(
            self.cleaned_data['ship_postalcode'])

    clean_home_page = cleaning.clean_url('home_page')
    clean_blog = cleaning.clean_url('blog')
    clean_photo_url = cleaning.clean_url('photo_url')

    def clean(self):
        country = self.cleaned_data.get('res_country')
        state = self.cleaned_data.get('res_state')
        if country in self.TWO_LETTER_STATE_REQ and (not state
                                                     or len(state) != 2):
            self._errors['res_state'] = [
                "Please use a 2-letter state/province name"
            ]

        country = self.cleaned_data.get('ship_country')
        state = self.cleaned_data.get('ship_state')
        if country in self.TWO_LETTER_STATE_REQ and (not state
                                                     or len(state) != 2):
            self._errors['ship_state'] = [
                "Please use a 2-letter state/province name"
            ]
        return self.cleaned_data
Ejemplo n.º 33
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
Ejemplo n.º 34
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