app/soc/views/models/student.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sun, 08 Mar 2009 13:14:28 +0000
changeset 1741 0da1285f5bc0
parent 1726 711c8dcab67e
child 1949 bcc52df68367
permissions -rw-r--r--
Public reviews are now shown on the public page for the student proposal. The assigned mentor name has been removed from the public page. The student proposal view now uses the new getReviewsForEntity method. Patch by: Lennard de Rijk Reviewed by:to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1379
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Views for Student.
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
    '"Lennard de Rijk" <ljvderijk@gmail.com>'
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
from django import forms
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
from django.utils.translation import ugettext
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
from soc.logic import cleaning
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
from soc.logic import dicts
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
from soc.logic.models import program as program_logic
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
from soc.logic.models import student as student_logic
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
from soc.logic.models import user as user_logic
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
from soc.views.helper import access
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
from soc.views.helper import decorators
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
from soc.views.helper import dynaform
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
from soc.views.helper import redirects
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
from soc.views.helper import widgets
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
from soc.views.models import program as program_view
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
from soc.views.models import role
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
import soc.logic.models.student
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
class View(role.View):
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
  """View methods for the Student model.
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
  """
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
  def __init__(self, params=None):
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
    """Defines the fields and methods required for the base View class
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
    to provide the user with list, public, create, edit and delete views.
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
    Params:
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
      params: a dict with params for this View
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
    """
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
    rights = access.Checker(params)
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
    rights['create'] = ['checkIsDeveloper']
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
    rights['edit'] = [('checkHasActiveRoleForScope', student_logic.logic)]
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
    rights['delete'] = ['checkIsDeveloper']
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
    rights['apply'] = [
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
        'checkIsUser',
1382
293a14668dc9 Students can now only get a student role during the student signup period.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1379
diff changeset
    63
        ('checkIsActivePeriod', ['student_signup', 'scope_path']),
1379
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
        'checkIsNotParticipatingInProgramInScope',
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
        ]
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
    rights['manage'] = [
1724
d8d04e17b574 Students can not be kicked from a program by a organization admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
    67
        ('checkIsAllowedToManageRole', [soc.logic.models.host.logic])]
1379
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    69
    new_params = {}
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
    new_params['logic'] = soc.logic.models.student.logic
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    71
    new_params['group_logic'] = program_logic.logic
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
    new_params['group_view'] = program_view.view
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
    new_params['rights'] = rights
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    74
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    75
    new_params['scope_view'] = program_view
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    76
    new_params['scope_redirect'] = redirects.getCreateRedirect
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    77
    new_params['manage_redirect'] = redirects.getUserRolesRedirect
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    78
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    79
    new_params['name'] = "Student"
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    80
    new_params['module_name'] = "student"
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    81
    new_params['sidebar_grouping'] = 'Students'
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    82
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    83
    # add apply pattern
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    84
    patterns = [(r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$',
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    85
        'soc.views.models.%(module_name)s.apply',
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    86
        'Become a %(name)s'),]
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    87
    new_params['extra_django_patterns'] = patterns
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    88
1383
18383d2e5a5b Students now have a reference to school again.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1382
diff changeset
    89
    new_params['extra_dynaexclude'] = ['agreed_to_tos', 'school']
1379
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    90
1461
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    91
    new_params['create_dynafields'] = [
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    92
        {'name': 'scope_path',
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    93
         'base': forms.fields.CharField,
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    94
         'widget': forms.HiddenInput,
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    95
         'required': True,
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    96
         },
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    97
        {'name': 'student_agreement',
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    98
         'base': forms.fields.CharField,
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    99
         'required': False,
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   100
         'widget': widgets.AgreementField,
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   101
         'group': ugettext("5. Terms of Service"),
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   102
         },
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   103
        {'name': 'agreed_to_student_agreement',
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   104
         'base': forms.fields.BooleanField,
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   105
         'initial': False,
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   106
         'required':True,
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   107
         'label': ugettext('I agree to the Student Agreement'),
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   108
         'group': ugettext("5. Terms of Service"),
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   109
         },
92c5a390739a Convert student and org_admin to dynafield
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
   110
        ]
1379
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   111
1384
bb22ea156567 Role overview membership is now determined by setting show_in_roles_overview param to true in the view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1383
diff changeset
   112
    new_params['show_in_roles_overview'] = True
bb22ea156567 Role overview membership is now determined by setting show_in_roles_overview param to true in the view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1383
diff changeset
   113
1379
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   114
    params = dicts.merge(params, new_params)
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   115
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   116
    super(View, self).__init__(params=params)
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   117
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   118
    # create and store the special form for users
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   119
    updated_fields = {
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   120
        'link_id': forms.CharField(widget=forms.HiddenInput,
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   121
            required=True),
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   122
        'clean_link_id': cleaning.clean_user_is_current('link_id')
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   123
        }
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   124
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   125
    user_create_form = dynaform.extendDynaForm(
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   126
        dynaform = self._params['create_form'],
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1394
diff changeset
   127
        dynaproperties = updated_fields)
1379
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   128
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   129
    self._params['user_create_form'] = user_create_form
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   130
1384
bb22ea156567 Role overview membership is now determined by setting show_in_roles_overview param to true in the view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1383
diff changeset
   131
1379
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   132
  @decorators.merge_params
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   133
  @decorators.check_access
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   134
  def apply(self, request, access_type,
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   135
           page_name=None, params=None, **kwargs):
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   136
    """Handles student role creation for the current user.
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   137
    """
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   138
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   139
    user_entity = user_logic.logic.getForCurrentAccount()
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   140
    params['create_form'] = params['user_create_form']
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   141
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   142
    return self.create(request, access_type='unspecified', page_name=page_name,
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   143
        params=params, link_id=user_entity.link_id, **kwargs)
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   144
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   145
  def _editPost(self, request, entity, fields):
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   146
    """See base.View._editPost().
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   147
    """
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   148
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   149
    if not entity:
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   150
      fields['user'] = fields['link_id']
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   151
      fields['link_id'] = fields['user'].link_id
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   152
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   153
    fields['agreed_to_tos'] = fields['agreed_to_student_agreement']
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   154
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   155
    super(View, self)._editPost(request, entity, fields)
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   156
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   157
  def _editGet(self, request, entity, form):
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   158
    """Sets the content of the agreed_to_tos_on field and replaces.
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   159
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   160
    Also replaces the agreed_to_tos field with a hidden field when the ToS has been signed.
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   161
    For params see base.View._editGet().
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   162
    """
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   163
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   164
    if entity.agreed_to_tos:
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   165
      form.fields['agreed_to_student_agreement'] = forms.fields.BooleanField(
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   166
          widget=forms.HiddenInput, initial=entity.agreed_to_tos,
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   167
          required=True)
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   168
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   169
    super(View, self)._editGet(request, entity, form)
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   170
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   171
  def _editContext(self, request, context):
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   172
    """See base.View._editContext().
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   173
    """
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   174
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   175
    entity = context['entity']
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   176
    form = context['form']
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   177
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   178
    if 'scope_path' in form.initial:
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   179
      scope_path = form.initial['scope_path']
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   180
    elif 'scope_path' in request.POST:
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   181
      scope_path = request.POST['scope_path']
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   182
    else:
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   183
      form.fields['student_agreement'] = None
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   184
      return
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   185
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   186
    program = program_logic.logic.getFromKeyName(scope_path)
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   187
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   188
    if not (program and program.student_agreement):
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   189
      return
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   190
1726
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1724
diff changeset
   191
    agreement = program.student_agreement
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1724
diff changeset
   192
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1724
diff changeset
   193
    content = agreement.content
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1724
diff changeset
   194
    params = {'url_name': 'document'}
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1724
diff changeset
   195
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1724
diff changeset
   196
    widget = form.fields['student_agreement'].widget
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1724
diff changeset
   197
    widget.text = content
711c8dcab67e Add a link to the full agreement text
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1724
diff changeset
   198
    widget.url = redirects.getPublicRedirect(agreement, params)
1379
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   199
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   200
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   201
view = View()
e6341549300c Added student view and accompanying templates.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   202
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1461
diff changeset
   203
apply = decorators.view(view.apply)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1461
diff changeset
   204
create = decorators.view(view.create)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1461
diff changeset
   205
delete = decorators.view(view.delete)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1461
diff changeset
   206
edit = decorators.view(view.edit)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1461
diff changeset
   207
list = decorators.view(view.list)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1461
diff changeset
   208
manage = decorators.view(view.manage)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1461
diff changeset
   209
public = decorators.view(view.public)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1461
diff changeset
   210
export = decorators.view(view.export)