Example #1
0
def getCreateForm(params, model):
    """Constructs a new CreateForm using params.

  Params usage:
    dynabase: The dynabase value is used as the base argument to
      dynaform.newDynaForm.
    logic: The logic value is used to get the model argument to newDynaForm.
    create_dynainclude: same as dynabase, but as dynainclude argument
    create_dynaexclude: same as dynabase, but as dynaexclude argument
    create_dynaproperties: same as dynabase, but as dynaproperties argument
  """

    create_form = dynaform.newDynaForm(
        dynabase=params['dynabase'],
        dynamodel=model,
        dynainclude=params['create_dynainclude'],
        dynaexclude=params['create_dynaexclude'],
        dynaproperties=params['create_dynaproperties'],
    )

    if 'extra_key_order' in params:
        for field in params['extra_key_order']:
            if field in create_form.base_fields.keyOrder:
                create_form.base_fields.keyOrder.remove(field)
        create_form.base_fields.keyOrder.extend(params['extra_key_order'])

    return create_form
Example #2
0
def getCreateForm(params, model):
  """Constructs a new CreateForm using params.

  Params usage:
    dynabase: The dynabase value is used as the base argument to
      dynaform.newDynaForm.
    logic: The logic value is used to get the model argument to newDynaForm.
    create_dynainclude: same as dynabase, but as dynainclude argument
    create_dynaexclude: same as dynabase, but as dynaexclude argument
    create_dynaproperties: same as dynabase, but as dynaproperties argument
  """

  create_form = dynaform.newDynaForm(
    dynabase = params['dynabase'],
    dynamodel = model,
    dynainclude = params['create_dynainclude'],
    dynaexclude = params['create_dynaexclude'],
    dynaproperties = params['create_dynaproperties'],
    )

  if 'extra_key_order' in params:
    for field in params['extra_key_order']:
      if field in create_form.base_fields.keyOrder:
        create_form.base_fields.keyOrder.remove(field)
    create_form.base_fields.keyOrder.extend(params['extra_key_order'])

  return create_form
Example #3
0
        def getUploadForms(name, label, help_text):
            dynafields = [{
                'name': name,
                'base': forms.FileField,
                'label': label,
                'required': False,
                'help_text': help_text,
            }]

            dynaproperties = params_helper.getDynaFields(dynafields)

            add_form = dynaform.newDynaForm(dynabase=base_form,
                                            dynaproperties=dynaproperties)

            dynaproperties = {
                'name':
                django_fields.CharField(label='Name',
                                        required=False,
                                        widget=widgets.HTMLTextWidget),
                'uploaded':
                django_fields.CharField(label='Uploaded on',
                                        required=False,
                                        widget=widgets.PlainTextWidget),
                'size':
                django_fields.CharField(label='Size',
                                        required=False,
                                        widget=widgets.PlainTextWidget),
            }
            edit_form = dynaform.extendDynaForm(
                add_form,
                dynaproperties=dynaproperties,
                dynainclude=['name', 'size', 'uploaded', name])

            return add_form, edit_form
Example #4
0
        def getUploadForms(name, label, help_text):
            dynafields = [
                {"name": name, "base": forms.FileField, "label": label, "required": False, "help_text": help_text}
            ]

            dynaproperties = params_helper.getDynaFields(dynafields)

            add_form = dynaform.newDynaForm(dynabase=base_form, dynaproperties=dynaproperties)

            dynaproperties = {
                "name": django_fields.CharField(label="Name", required=False, widget=widgets.HTMLTextWidget),
                "uploaded": django_fields.CharField(
                    label="Uploaded on", required=False, widget=widgets.PlainTextWidget
                ),
                "size": django_fields.CharField(label="Size", required=False, widget=widgets.PlainTextWidget),
            }
            edit_form = dynaform.extendDynaForm(
                add_form, dynaproperties=dynaproperties, dynainclude=["name", "size", "uploaded", name]
            )

            return add_form, edit_form
Example #5
0
    def __init__(self, params=None):
        """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

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

        rights = access.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
  def __init__(self, params=None):
    """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

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

    rights = access.GSoCChecker(params)
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = [('checkCanStudentPropose', ['scope_path', False]),
        ('checkRoleAndStatusForStudentProposal',
            [['proposer'], ['active'], ['new', 'pending', 'invalid']])]
    rights['delete'] = ['checkIsDeveloper']
    rights['private'] = [
        ('checkRoleAndStatusForStudentProposal',
            [['proposer', 'org_admin', 'mentor', 'host'], 
            ['active', 'inactive'], 
            ['new', 'pending', 'accepted', 'rejected', 'invalid']])]
    rights['show'] = ['checkIsStudentProposalPubliclyVisible']
    rights['comment'] = [
        ('checkRoleAndStatusForStudentProposal',
            [['org_admin', 'mentor', 'host'], 
            ['active', 'inactive'],
            ['new', 'pending', 'accepted', 'rejected', 'invalid']])]
    rights['list'] = ['checkIsDeveloper']
    rights['list_orgs'] = [
        ('checkIsStudent', ['scope_path', ['active']]),
        ('checkCanStudentPropose', ['scope_path', False])]
    rights['list_self'] = [
        ('checkIsStudent', ['scope_path', ['active', 'inactive']])]
    rights['apply'] = [
        ('checkIsStudent', ['scope_path', ['active']]),
        ('checkCanStudentPropose', ['scope_path', True])]
    rights['review'] = [
            ('checkIsBeforeEvent',
            ['accepted_students_announced_deadline', None,
             program_logic.logic]),
            ('checkRoleAndStatusForStudentProposal',
            [['org_admin', 'mentor', 'host'], 
            ['active'],
            ['new', 'pending', 'accepted', 'invalid']])]

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

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

    new_params['no_create_with_key_fields'] = True

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

    new_params['extra_django_patterns'] = patterns

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

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

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

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

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

    params = dicts.merge(params, new_params)

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

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

    dynaproperties = params_helper.getDynaFields(dynafields)

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

    self._params['student_create_form'] = student_create_form

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

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

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

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

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

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

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

    dynafields = [field.copy() for field in base_fields]
    dynaproperties = params_helper.getDynaFields(dynafields)
    dynaproperties['clean_comment'] = cleaning.clean_html_content('comment')
    mentor_review_form = dynaform.newDynaForm(dynamodel=None, 
        dynabase=helper.forms.BaseForm, dynainclude=None, 
        dynaexclude=None, dynaproperties=dynaproperties)
    self._params['mentor_review_form'] = mentor_review_form
    self._show_review_not_appeared_msg = False
Example #7
0
  def _enableMentorManagement(self, entity, params, context):
    """Sets the data required to manage mentors for a StudentProject.

    Args:
      entity: StudentProject entity to manage
      params: params dict for the manage view
      context: context for the manage view
    """

    context['can_manage_mentors'] = True

    # get all mentors for this organization
    fields = {'scope': entity.scope,
              'status': 'active'}
    mentors = mentor_logic.getForFields(fields)

    choices = [(mentor.link_id,'%s (%s)' %(mentor.name(), mentor.link_id))
                  for mentor in mentors]

    # create the form that org admins will use to reassign a mentor
    dynafields = [
        {'name': 'mentor_id',
         'base': forms.ChoiceField,
         'label': 'Primary Mentor',
         'required': True,
         'passthrough': ['required', 'choices', 'label'],
         'choices': choices,
        },]

    dynaproperties = params_helper.getDynaFields(dynafields)

    mentor_edit_form = dynaform.newDynaForm(
        dynabase = params['dynabase'],
        dynaproperties = dynaproperties,
    )

    params['mentor_edit_form'] = mentor_edit_form

    additional_mentors = entity.additional_mentors

    # we want to show the names of the additional mentors in the context
    # therefore they need to be resolved to entities first
    additional_mentors_context = []

    for mentor_key in additional_mentors:
      mentor_entity = mentor_logic.getFromKeyName(
          mentor_key.id_or_name())
      additional_mentors_context.append(mentor_entity)

    context['additional_mentors'] = additional_mentors_context

    # all mentors who are not already an additional mentor or
    # the primary mentor are allowed to become an additional mentor
    possible_additional_mentors = [m for m in mentors if 
        (m.key() not in additional_mentors) 
        and (m.key() != entity.mentor.key())]

    # create the information to be shown on the additional mentor form
    additional_mentor_choices = [
        (mentor.link_id,'%s (%s)' %(mentor.name(), mentor.link_id))
        for mentor in possible_additional_mentors]

    dynafields = [
        {'name': 'mentor_id',
         'base': forms.ChoiceField,
         'label': 'Co-Mentor',
         'required': True,
         'passthrough': ['required', 'choices', 'label'],
         'choices': additional_mentor_choices,
        },]

    dynaproperties = params_helper.getDynaFields(dynafields)

    additional_mentor_form = dynaform.newDynaForm(
        dynabase = params['dynabase'],
        dynaproperties = dynaproperties,
    )

    params['additional_mentor_form'] = additional_mentor_form
Example #8
0
  def __init__(self, params=None):
    """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

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

    rights = access.GSoCChecker(params)
    rights['any_access'] = ['allow']
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = ['checkIsDeveloper']
    rights['delete'] = ['checkIsDeveloper']
    rights['show'] = ['allow']
    rights['list'] = ['checkIsDeveloper']
    rights['manage'] = [('checkHasRoleForScope',
                         [org_admin_logic, ['active', 'inactive']]),
        ('checkStudentProjectHasStatus', [['accepted', 'failed', 'completed',
                                           'withdrawn']])]
    rights['manage_overview'] = [('checkHasRoleForScope', [
        org_admin_logic, ['active', 'inactive']])]
    # TODO: lack of better name here!
    rights['st_edit'] = [
        'checkCanEditStudentProjectAsStudent',
        ('checkStudentProjectHasStatus',
            [['accepted', 'completed']])
        ]
    rights['withdraw'] = ['checkIsHostForProgram']
    rights['withdraw_project'] = ['checkIsHostForStudentProject',
        ('checkStudentProjectHasStatus',
            [['accepted', 'completed']])
        ]
    rights['accept_project'] = ['checkIsHostForStudentProject',
        ('checkStudentProjectHasStatus',
            [['withdrawn']])
        ]

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

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

    new_params['no_create_with_key_fields'] = True

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

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

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

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

    new_params['extra_django_patterns'] = patterns

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

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

    params = dicts.merge(params, new_params)

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

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

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

    self._params['student_edit_form'] = student_edit_form
Example #9
0
  def __init__(self, params=None):
    """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

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

    rights = access.Checker(params)
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = [('checkCanStudentPropose', ['scope_path', False]),
        ('checkRoleAndStatusForStudentProposal',
            [['proposer'], ['active'], ['new', 'pending', 'invalid']])]
    rights['delete'] = ['checkIsDeveloper']
    rights['show'] = [
        ('checkRoleAndStatusForStudentProposal',
            [['proposer', 'org_admin', 'mentor', 'host'], 
            ['active', 'inactive'], 
            ['new', 'pending', 'accepted', 'rejected', 'invalid']])]
    rights['list'] = ['checkIsDeveloper']
    rights['list_orgs'] = [
        ('checkIsStudent', ['scope_path', ['active']]),
        ('checkCanStudentPropose', ['scope_path', False])]
    rights['list_self'] = [
        ('checkIsStudent', ['scope_path', ['active', 'inactive']])]
    rights['apply'] = [
        ('checkIsStudent', ['scope_path', ['active']]),
        ('checkCanStudentPropose', ['scope_path', True])]
    rights['review'] = [('checkRoleAndStatusForStudentProposal',
            [['org_admin', 'mentor', 'host'], 
            ['active'],
            ['new', 'pending', 'accepted', 'rejected', 'invalid']])]

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

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

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

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

    new_params['extra_django_patterns'] = patterns

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

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

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

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

    params = dicts.merge(params, new_params)

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

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

    dynaproperties = params_helper.getDynaFields(dynafields)

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

    self._params['student_create_form'] = student_create_form

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

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

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

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

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

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

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

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

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

    self._params['admin_review_form'] = admin_review_form
Example #10
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
  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'] = [('checkIsHostForProgramInScope', program_logic)]
    rights['edit'] = [('checkIsHostForProgramInScope', program_logic)]
    rights['delete'] = ['checkIsDeveloper']
    rights['show'] = [('checkIsHostForProgramInScope', program_logic)]
    rights['list'] = [('checkIsHostForProgramInScope', program_logic)]
    rights['records'] = [('checkIsHostForProgramInScope', program_logic)]
    rights['edit_record'] = [('checkIsHostForProgramInScope', program_logic)]

    new_params = {}
    new_params['logic'] = survey_group_logic
    new_params['rights'] = rights
    new_params['name'] = "Grading Survey Group"
    new_params['url_name'] = 'gsoc/grading_survey_group'
    new_params['module_package'] = 'soc.modules.gsoc.views.models'
    new_params['sidebar_grouping'] = "Surveys"

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

    new_params['no_admin'] = True
    new_params['no_create_with_key_fields'] = True

    new_params['create_extra_dynaproperties'] = {
       'grading_survey': djangoforms.ModelChoiceField(
            GradingProjectSurvey, required=True),
       'student_survey': djangoforms.ModelChoiceField(ProjectSurvey,
                                                      required=False),
       }

    new_params['extra_dynaexclude'] = ['link_id', 'scope', 'scope_path',
                                       'last_update_started',
                                       'last_update_complete']

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

    # remove the raw list and add the one without the link_id
    new_params['no_list_raw'] = True
    new_params['sans_link_id_list'] = True

    # redefine the developer sidebar so that the list_raw is not shown
    new_params['sidebar_developer'] = [
        # TODO(SRabbelier): remove create once new list code is in
        ('/%s/create', 'New %(name)s', 'create')
    ]

    patterns = [
        (r'^%(url_name)s/(?P<access_type>records)/%(key_fields)s$',
        '%(module_package)s.%(module_name)s.view_records',
        'Overview of GradingRecords'),
        (r'^%(url_name)s/(?P<access_type>edit_record)/%(key_fields)s$',
        '%(module_package)s.%(module_name)s.edit_record',
        'Edit a GradingRecord'),
    ]

    new_params['extra_django_patterns'] = patterns

    new_params['edit_template'] = 'soc/grading_survey_group/edit.html'
    new_params['view_records_template'] = 'soc/grading_survey_group/records.html'
    new_params['record_edit_template'] = 'soc/grading_record/edit.html'

    # create the form that will be used to edit a GradingRecord
    record_logic = survey_group_logic.getRecordLogic()

    record_edit_form = dynaform.newDynaForm(
        dynabase=soc.views.helper.forms.BaseForm,
        dynamodel=record_logic.getModel(),
        dynaexclude=['grading_survey_group', 'mentor_record',
                     'student_record', 'project'],
    )

    new_params['record_edit_form'] = record_edit_form

    new_params['public_field_keys'] = ["name", "last_update_started",
                                       "last_update_completed"]
    new_params['public_field_names'] = ["Name", "Last update started",
                                        "Last update completed"]

    new_params['records_field_prefetch'] = [
        'project', 'mentor_record', 'student_record',
      # TODO(SRabbelier): Enable when we support multi-level prefetching
      # 'project.student', 'project.scope', 'project.mentor',
    ]
    new_params['records_field_extra'] = lambda entity: {
        "project_title": entity.project.title,
        "student_name": entity.project.student.link_id,
        "student_email": entity.project.student.email,
        "organization": entity.project.scope.name,
        "mentor_name": entity.project.mentor.link_id,
        "mentor_email": entity.project.mentor.email,
        "final_grade": entity.grade_decision.capitalize(),
        "mentor_grade": ("Pass" if entity.mentor_record.grade else "Fail") if
            entity.mentor_record else "Not Available",
        "student_eval": "Yes" if entity.student_record else "Not Available",
    }
    new_params['records_field_keys'] = [
        "project_title", "student_name", "student_email", "organization",
        "mentor_name", "mentor_email", "final_grade", "mentor_grade",
        "student_eval", "locked", "grade_decision",
    ]
    new_params['records_field_names'] = [
        "Project Name", "Student link_id", "Student email", "Organization",
        "Mentor link_id", "Mentor email", "Final Grade", "Mentor Grade",
        "Student Eval", "Locked", "Grade",
    ]
    new_params['records_row_extra'] = lambda entity: {
        "link": redirects.getEditRedirect(entity, params),
    }

    params = dicts.merge(params, new_params)

    super(View, self).__init__(params=params)
Example #12
0
  def __init__(self, params=None):
    """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

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

    rights = access.Checker(params)
    rights['create'] = ['checkIsHostForProgramInScope']
    rights['edit'] = ['checkIsHostForProgramInScope']
    rights['delete'] = ['checkIsDeveloper']
    rights['show'] = ['checkIsHostForProgramInScope']
    rights['list'] = ['checkIsDeveloper']
    rights['records'] = ['checkIsHostForProgramInScope']
    rights['edit_record'] = ['checkIsHostForProgramInScope']

    new_params = {}
    new_params['logic'] = survey_group_logic
    new_params['rights'] = rights
    new_params['name'] = "Grading Survey Group"
    new_params['sidebar_grouping'] = "Surveys"

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

    new_params['no_admin'] = True
    new_params['no_create_with_key_fields'] = True

    new_params['create_extra_dynaproperties'] = {
       'grading_survey': djangoforms.ModelChoiceField(
            GradingProjectSurvey, required=True),
       'student_survey': djangoforms.ModelChoiceField(ProjectSurvey,
                                                      required=False),
       }

    new_params['extra_dynaexclude'] = ['link_id', 'scope', 'scope_path',
                                       'last_update_started',
                                       'last_update_complete']

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

    patterns = [
        (r'^%(url_name)s/(?P<access_type>records)/%(key_fields)s$',
        'soc.views.models.%(module_name)s.view_records',
        'Overview of GradingRecords'),
        (r'^%(url_name)s/(?P<access_type>edit_record)/%(key_fields)s$',
        'soc.views.models.%(module_name)s.edit_record',
        'Edit a GradingRecord'),
    ]

    new_params['extra_django_patterns'] = patterns

    new_params['view_records_template'] = 'soc/grading_survey_group/records.html'
    new_params['records_heading_template'] = 'soc/grading_record/list/heading.html'
    new_params['records_row_template'] = 'soc/grading_record/list/row.html'
    new_params['record_edit_template'] = 'soc/grading_record/edit.html'

    # create the form that will be used to edit a GradingRecord
    record_logic = survey_group_logic.getRecordLogic()

    record_edit_form = dynaform.newDynaForm(
        dynabase=soc.views.helper.forms.BaseForm,
        dynamodel=record_logic.getModel(),
        dynaexclude=['grading_survey_group', 'mentor_record',
                     'student_record', 'project'],
    )

    new_params['record_edit_form'] = record_edit_form

    params = dicts.merge(params, new_params)

    super(View, self).__init__(params=params)
Example #13
0
  def __init__(self, params=None):
    """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

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

    new_params = {}
    new_params['logic'] = org_app_logic

    new_params['name'] = "Org Application Survey"
    new_params['url_name'] = 'org_app'

    new_params['extra_dynaexclude'] = ['taking_access']

    new_params['survey_take_form'] = OrgAppSurveyForm
    new_params['survey_record_form'] = OrgAppRecordForm

    new_params['extra_django_patterns'] = [
         (r'^%(url_name)s/(?P<access_type>list_self)/%(key_fields)s$',
         '%(module_package)s.%(module_name)s.list_self',
         'Overview of %(name_plural)s Taken by You'),
         (r'^%(url_name)s/(?P<access_type>review)/%(key_fields)s$',
         '%(module_package)s.%(module_name)s.review',
         'Review %(name)s from '),
         (r'^%(url_name)s/(?P<access_type>review_overview)/%(key_fields)s$',
         '%(module_package)s.%(module_name)s.review_overview',
         'Overview of %(name_plural)s for Review')
         ]

    new_params['review_template'] = 'soc/org_app_survey/review.html'

    new_params['successful_take_message'] = ugettext(
        'Organization Application submitted.')

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

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

    # create the form to review an Organization Application
    dynaproperties = {
        'status': forms.fields.ChoiceField(required=True,
            label = 'New Status',
            choices = [('accepted', 'Accept'),
                       ('pre-accepted', 'Pre-Accept'),
                       ('rejected', 'Reject'),
                       ('pre-rejected', 'Pre-Reject'),
                       ('ignored', 'Ignore'),])
        }

    review_form = dynaform.newDynaForm(
        dynabase = self._params['dynabase'],
        dynaproperties = dynaproperties,
    )

    self._params['review_form'] = review_form

    # define the params for the OrgAppSurveyRecord listing
    record_list_params = {}
    record_list_params['logic'] = self._params['logic'].getRecordLogic()
    record_list_params['js_uses_all'] = self._params['js_uses_all']
    record_list_params['list_template'] = self._params['list_template']

    # define the fields for the public list
    record_list_params['public_field_keys'] = ['name', 'home_page']
    record_list_params['public_field_names'] = ['Name', 'Home Page']
    record_list_params['public_field_extra'] = lambda entity: {
        'home_page': lists.urlize(entity.home_page, 'Click Here'),
        }

    # define the fields for the self list
    record_list_params['self_field_keys'] = [
        'name', 'main_admin', 'backup_admin'
    ]
    record_list_params['self_field_names'] = [
        'Organization Name', 'Main Admin', 'Backup Admin'
    ]
    record_list_params['self_field_prefetch'] = ['main_admin', 'backup_admin']
    record_list_params['self_field_extra'] = lambda entity: {
        'main_admin': entity.main_admin.name,
        'backup_admin': entity.backup_admin.name}
    record_list_params['self_row_action'] = {
        "type": "redirect_custom",
        "parameters": dict(new_window=False),
    }

    self._params['record_list_params'] = record_list_params
Example #14
0
  def __init__(self, params=None):
    """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

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

    rights = access.GSoCChecker(params)
    rights['any_access'] = ['allow']
    rights['create'] = ['checkIsDeveloper']
    rights['edit'] = ['checkIsDeveloper']
    rights['delete'] = ['checkIsDeveloper']
    rights['show'] = ['allow']
    rights['list'] = ['checkIsDeveloper']
    rights['manage'] = [('checkHasRoleForScope',
                         [org_admin_logic, ['active', 'inactive']]),
        ('checkStudentProjectHasStatus', [['accepted', 'failed', 'completed',
                                           'withdrawn']])]
    rights['manage_overview'] = [
        ('checkHasAny', [
            [('checkHasRoleForScope', [org_admin_logic,
                                       ['active', 'inactive']]),
             ('checkHasRoleForScope', [mentor_logic,
                                       ['active', 'inactive']])
        ]])]
    # TODO: lack of better name here!
    rights['st_edit'] = [
        'checkCanEditStudentProjectAsStudent',
        ('checkStudentProjectHasStatus',
            [['accepted', 'completed']])
        ]
    rights['overview'] = [('checkIsHostForProgram', [program_logic])]

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

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

    new_params['no_create_with_key_fields'] = True

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

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

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

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

    new_params['extra_django_patterns'] = patterns

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

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

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

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

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

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

    params = dicts.merge(params, new_params)

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

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

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

    self._params['student_edit_form'] = student_edit_form
Example #15
0
  def _enableMentorManagement(self, entity, params, context):
    """Sets the data required to manage mentors for a StudentProject.

    Args:
      entity: StudentProject entity to manage
      params: params dict for the manage view
      context: context for the manage view
    """

    context['can_manage_mentors'] = True

    # get all mentors for this organization
    fields = {'scope': entity.scope,
              'status': 'active'}
    mentors = mentor_logic.getForFields(fields)

    choices = [(mentor.link_id,'%s (%s)' %(mentor.name(), mentor.link_id))
                  for mentor in mentors]

    # create the form that org admins will use to reassign a mentor
    dynafields = [
        {'name': 'mentor_id',
         'base': forms.ChoiceField,
         'label': 'Primary Mentor',
         'required': True,
         'passthrough': ['required', 'choices', 'label'],
         'choices': choices,
        },]

    dynaproperties = params_helper.getDynaFields(dynafields)

    mentor_edit_form = dynaform.newDynaForm(
        dynabase = params['dynabase'],
        dynaproperties = dynaproperties,
    )

    params['mentor_edit_form'] = mentor_edit_form

    additional_mentors = entity.additional_mentors

    # we want to show the names of the additional mentors in the context
    # therefore they need to be resolved to entities first
    additional_mentors_context = []

    for mentor_key in additional_mentors:
      mentor_entity = mentor_logic.getFromKeyName(
          mentor_key.id_or_name())
      additional_mentors_context.append(mentor_entity)

    context['additional_mentors'] = additional_mentors_context

    # all mentors who are not already an additional mentor or
    # the primary mentor are allowed to become an additional mentor
    possible_additional_mentors = [m for m in mentors if 
        (m.key() not in additional_mentors) 
        and (m.key() != entity.mentor.key())]

    # create the information to be shown on the additional mentor form
    additional_mentor_choices = [
        (mentor.link_id,'%s (%s)' %(mentor.name(), mentor.link_id))
        for mentor in possible_additional_mentors]

    dynafields = [
        {'name': 'mentor_id',
         'base': forms.ChoiceField,
         'label': 'Co-Mentor',
         'required': True,
         'passthrough': ['required', 'choices', 'label'],
         'choices': additional_mentor_choices,
        },]

    dynaproperties = params_helper.getDynaFields(dynafields)

    additional_mentor_form = dynaform.newDynaForm(
        dynabase = params['dynabase'],
        dynaproperties = dynaproperties,
    )

    params['additional_mentor_form'] = additional_mentor_form
Example #16
0
    def __init__(self, params=None):
        """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

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

        new_params = {}
        new_params['logic'] = org_app_logic

        new_params['name'] = "Org Application Survey"
        new_params['url_name'] = 'org_app'

        new_params['extra_dynaexclude'] = ['taking_access']

        new_params['survey_take_form'] = OrgAppSurveyForm
        new_params['survey_record_form'] = OrgAppRecordForm

        new_params['extra_django_patterns'] = [
            (r'^%(url_name)s/(?P<access_type>list_self)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.list_self',
             'Overview of %(name_plural)s Taken by You'),
            (r'^%(url_name)s/(?P<access_type>review)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.review',
             'Review %(name)s from '),
            (r'^%(url_name)s/(?P<access_type>review_overview)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.review_overview',
             'Overview of %(name_plural)s for Review')
        ]

        new_params['review_template'] = 'soc/org_app_survey/review.html'

        new_params['successful_take_message'] = ugettext(
            'Organization Application submitted.')

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

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

        # create the form to review an Organization Application
        dynaproperties = {
            'status':
            forms.fields.ChoiceField(required=True,
                                     label='New Status',
                                     choices=[
                                         ('accepted', 'Accept'),
                                         ('pre-accepted', 'Pre-Accept'),
                                         ('rejected', 'Reject'),
                                         ('pre-rejected', 'Pre-Reject'),
                                         ('ignored', 'Ignore'),
                                     ])
        }

        review_form = dynaform.newDynaForm(
            dynabase=self._params['dynabase'],
            dynaproperties=dynaproperties,
        )

        self._params['review_form'] = review_form

        # define the params for the OrgAppSurveyRecord listing
        record_list_params = {}
        record_list_params['logic'] = self._params['logic'].getRecordLogic()
        record_list_params['js_uses_all'] = self._params['js_uses_all']
        record_list_params['list_template'] = self._params['list_template']

        # define the fields for the public list
        record_list_params['public_field_keys'] = ['name', 'home_page']
        record_list_params['public_field_names'] = ['Name', 'Home Page']
        record_list_params['public_field_extra'] = lambda entity: {
            'home_page': lists.urlize(entity.home_page, 'Click Here'),
        }

        # define the fields for the self list
        record_list_params['self_field_keys'] = [
            'name', 'main_admin', 'backup_admin'
        ]
        record_list_params['self_field_names'] = [
            'Organization Name', 'Main Admin', 'Backup Admin'
        ]
        record_list_params['self_field_prefetch'] = [
            'main_admin', 'backup_admin'
        ]
        record_list_params['self_field_extra'] = lambda entity: {
            'main_admin': entity.main_admin.name,
            'backup_admin': entity.backup_admin.name
        }
        record_list_params['self_row_action'] = {
            "type": "redirect_custom",
            "parameters": dict(new_window=False),
        }

        self._params['record_list_params'] = record_list_params
Example #17
0
    def __init__(self, params=None):
        """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

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

        rights = access.GSoCChecker(params)
        rights['create'] = [('checkIsHostForProgramInScope', program_logic)]
        rights['edit'] = [('checkIsHostForProgramInScope', program_logic)]
        rights['delete'] = ['checkIsDeveloper']
        rights['show'] = [('checkIsHostForProgramInScope', program_logic)]
        rights['list'] = ['checkIsDeveloper']
        rights['records'] = [('checkIsHostForProgramInScope', program_logic)]
        rights['edit_record'] = [('checkIsHostForProgramInScope',
                                  program_logic)]

        new_params = {}
        new_params['logic'] = survey_group_logic
        new_params['rights'] = rights
        new_params['name'] = "Grading Survey Group"
        new_params['url_name'] = 'gsoc/grading_survey_group'
        new_params['module_package'] = 'soc.modules.gsoc.views.models'
        new_params['sidebar_grouping'] = "Surveys"

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

        new_params['no_admin'] = True
        new_params['no_create_with_key_fields'] = True

        new_params['create_extra_dynaproperties'] = {
            'grading_survey':
            djangoforms.ModelChoiceField(GradingProjectSurvey, required=True),
            'student_survey':
            djangoforms.ModelChoiceField(ProjectSurvey, required=False),
        }

        new_params['extra_dynaexclude'] = [
            'link_id', 'scope', 'scope_path', 'last_update_started',
            'last_update_complete'
        ]

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

        patterns = [
            (r'^%(url_name)s/(?P<access_type>records)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.view_records',
             'Overview of GradingRecords'),
            (r'^%(url_name)s/(?P<access_type>edit_record)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.edit_record',
             'Edit a GradingRecord'),
        ]

        new_params['extra_django_patterns'] = patterns

        new_params[
            'view_records_template'] = 'soc/grading_survey_group/records.html'
        new_params[
            'records_heading_template'] = 'soc/grading_record/list/heading.html'
        new_params['records_row_template'] = 'soc/grading_record/list/row.html'
        new_params['record_edit_template'] = 'soc/grading_record/edit.html'

        # create the form that will be used to edit a GradingRecord
        record_logic = survey_group_logic.getRecordLogic()

        record_edit_form = dynaform.newDynaForm(
            dynabase=soc.views.helper.forms.BaseForm,
            dynamodel=record_logic.getModel(),
            dynaexclude=[
                'grading_survey_group', 'mentor_record', 'student_record',
                'project'
            ],
        )

        new_params['record_edit_form'] = record_edit_form

        new_params['public_field_keys'] = [
            "name", "last_update_started", "last_update_completed"
        ]
        new_params['public_field_names'] = [
            "Name", "Last update started", "Last update completed"
        ]

        new_params['records_field_extra'] = lambda entity: {
            "project_title":
            entity.project.title,
            "student_name":
            "%s (%s)" %
            (entity.project.student.name, entity.project.student.link_id),
            "organization":
            entity.project.name,
            "mentor_name":
            "%s (%s)" %
            (entity.project.mentor.name, entity.project.mentor.link_id),
            "final_grade":
            entity.grade_decision.capitalize(),
            "mentor_grade": ("Pass" if entity.mentor_record.grade else "Fail")
            if entity.mentor_record else "Not Available",
            "student_eval":
            "Yes" if entity.student_record else "Not Available",
        }
        new_params['records_field_keys'] = [
            "project_title", "student_name", "organization", "mentor_name",
            "final_grade", "mentor_grade", "student_eval", "locked"
        ]
        new_params['records_field_names'] = [
            "Project Name", "Student (link id)", "Organization",
            "Mentor (link id)", "Final Grade", "Mentor Grade", "Student Eval",
            "Locked"
        ]

        params = dicts.merge(params, new_params)

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