app/soc/views/models/student_proposal.py
author Lennard de Rijk <ljvderijk@gmail.com>
Wed, 04 Mar 2009 16:48:10 +0000
changeset 1620 45f4e9cd9100
parent 1613 59e5cc89e509
child 1639 170ac4ca078d
permissions -rw-r--r--
Added access check to student_proposal review. Hosts and Developers can comment but not score an proposal (unless of course they are an org_admin/mentor). Fixed the initial scoring being set to -4, which is annoying if you just want to comment. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Views for Student Proposal.
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
import datetime
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
import time
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
from django import forms
1498
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
    29
from django import http
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
from soc.logic import cleaning
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
from soc.logic import dicts
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
    33
from soc.logic.models import mentor as mentor_logic
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
from soc.logic.models import organization as org_logic
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
    35
from soc.logic.models import org_admin as org_admin_logic
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
from soc.logic.models import student as student_logic
1469
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
    37
from soc.logic.models import user as user_logic
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
    38
from soc.views import helper
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
    39
from soc.views import out_of_band
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
from soc.views.helper import access
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
from soc.views.helper import decorators
1569
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
    42
from soc.views.helper import dynaform
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
    43
from soc.views.helper import params as params_helper
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
from soc.views.helper import redirects
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
    45
from soc.views.helper import responses
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
from soc.views.helper import widgets
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
from soc.views.models import base
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
from soc.views.models import student as student_view
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
import soc.logic.models.student_proposal
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
class View(base.View):
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
  """View methods for the Student Proposal model.
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
  """
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
  def __init__(self, params=None):
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
    """Defines the fields and methods required for the base View class
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
    to provide the user with list, public, create, edit and delete views.
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
    Params:
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
      params: a dict with params for this View
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    63
    """
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
    rights = access.Checker(params)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
    rights['create'] = ['checkIsDeveloper']
1467
c5f99265a680 Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    67
    rights['edit'] = [('checkCanStudentPropose', 'scope_path'),
c5f99265a680 Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    68
        ('checkRoleAndStatusForStudentProposal',
c5f99265a680 Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    69
            [['proposer'], ['active'], ['new', 'pending']])]
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
    rights['delete'] = ['checkIsDeveloper']
1467
c5f99265a680 Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    71
    rights['show'] = [
c5f99265a680 Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    72
        ('checkRoleAndStatusForStudentProposal',
c5f99265a680 Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    73
            [['proposer', 'org_admin', 'mentor', 'host'], 
c5f99265a680 Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    74
            ['active', 'inactive'], ['new', 'pending', 'accepted', 'rejected']])]
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    75
    rights['list'] = ['checkIsDeveloper']
1482
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
    76
    rights['list_orgs'] = [
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
    77
        ('checkIsStudent', ['scope_path', ['active']]),
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
    78
        ('checkCanStudentPropose', 'scope_path')]
1469
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
    79
    rights['list_self'] = [
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
    80
        ('checkIsStudent', ['scope_path', ['active', 'inactive']])]
1467
c5f99265a680 Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    81
    rights['apply'] = [
c5f99265a680 Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    82
        ('checkIsStudent', ['scope_path', ['active']]),
c5f99265a680 Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1430
diff changeset
    83
        ('checkCanStudentPropose', 'scope_path')]
1620
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
    84
    rights['review'] = [('checkRoleAndStatusForStudentProposal',
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
    85
            [['org_admin', 'mentor', 'host'], 
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
    86
            ['active'], ['new', 'pending']])]
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    87
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    88
    new_params = {}
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    89
    new_params['logic'] = soc.logic.models.student_proposal.logic
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    90
    new_params['rights'] = rights
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    91
    new_params['name'] = "Student Proposal"
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
    new_params['url_name'] = "student_proposal"
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    93
    new_params['sidebar_grouping'] = 'Student Proposal'
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    94
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    95
    new_params['scope_view'] = student_view
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    96
    new_params['scope_redirect'] = redirects.getCreateRedirect
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    97
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    98
    new_params['no_create_with_key_fields'] = True
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    99
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   100
    patterns = [
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   101
        (r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$',
1569
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   102
        'soc.views.models.%(module_name)s.apply',
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   103
        'Create a new %(name)s'),
1469
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   104
        (r'^%(url_name)s/(?P<access_type>list_self)/%(scope)s$',
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   105
        'soc.views.models.%(module_name)s.list_self',
1482
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   106
        'List my %(name_plural)s'),
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   107
        (r'^%(url_name)s/(?P<access_type>list_orgs)/%(scope)s$',
1484
6b00a2a43eaf Changed the method and variable name in student_proposal to match the access type.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1482
diff changeset
   108
        'soc.views.models.%(module_name)s.list_orgs',
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   109
        'List my %(name_plural)s'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   110
        (r'^%(url_name)s/(?P<access_type>review)/%(key_fields)s$',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   111
        'soc.views.models.%(module_name)s.review',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   112
        'Review %(name)s'),
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   113
    ]
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   114
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   115
    new_params['extra_django_patterns'] = patterns
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   116
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   117
    new_params['extra_dynaexclude'] = ['org', 'program', 'score',
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   118
                                       'status', 'mentor', 'link_id',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   119
                                       'possible_mentors']
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   120
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1426
diff changeset
   121
    new_params['create_extra_dynaproperties'] = {
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   122
        'content': forms.fields.CharField(required=True,
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   123
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   124
        'scope_path': forms.CharField(widget=forms.HiddenInput,
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   125
            required=True),
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   126
        'organization': forms.CharField(label='Organization Link ID',
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   127
            required=True),
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   128
        'clean_organization': cleaning.clean_link_id('organization'),
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   129
        'clean_additional_info': cleaning.clean_url('additional_info'),
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   130
        'clean': cleaning.validate_student_proposal('organization',
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   131
            'scope_path', student_logic, org_logic),
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   132
        }
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   133
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1426
diff changeset
   134
    new_params['edit_extra_dynaproperties'] = {
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   135
        'organization': forms.CharField(label='Organization Link ID',
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   136
            widget=widgets.ReadOnlyInput),
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   137
        'link_id': forms.CharField(widget=forms.HiddenInput)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   138
        }
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   139
1498
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   140
    new_params['edit_template'] = 'soc/student_proposal/edit.html'
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   141
    new_params['review_template'] = 'soc/student_proposal/review.html'
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   142
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   143
    params = dicts.merge(params, new_params)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   144
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   145
    super(View, self).__init__(params=params)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   146
1569
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   147
    # create the special form for students
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   148
    dynafields = [
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   149
        {'name': 'organization',
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   150
         'base': forms.CharField,
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   151
         'label': 'Organization Link ID',
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   152
         'widget': widgets.ReadOnlyInput(),
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   153
         'required': False,
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   154
         },
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   155
        ]
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   156
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   157
    dynaproperties = params_helper.getDynaFields(dynafields)
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   158
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   159
    student_create_form = dynaform.extendDynaForm(
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   160
        dynaform=self._params['create_form'],
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   161
        dynaproperties=dynaproperties)
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   162
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   163
    params['student_create_form'] = student_create_form
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   164
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   165
    # create the special form for mentors
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   166
    dynafields = [
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   167
        {'name': 'score',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   168
         'base': forms.ChoiceField,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   169
         'label': 'Score',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   170
         'initial': 0,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   171
         'required': False,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   172
         'passthrough': ['initial', 'required', 'choices'],
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   173
         'choices': [(-4,'-4: Wow. This. Sucks.'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   174
                     (-3,'-3: Needs a lot of work'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   175
                     (-2,'-2: This is bad'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   176
                     (-1,'-1: I dont like this'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   177
                     (0,'0: No score'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   178
                     (1,'1: Might have potential'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   179
                     (2,'2: Good'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   180
                     (3,'3: Almost there'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   181
                     (4,'4: Made. Of. Awesome.')]
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   182
        },
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   183
        {'name': 'comment',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   184
         'base': forms.CharField,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   185
         'widget': forms.Textarea,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   186
         'label': 'Comment',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   187
         'required': False,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   188
         },
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   189
        {'name': 'public',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   190
         'base': forms.BooleanField,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   191
         'label': 'Public comment',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   192
         'initial': False,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   193
         'required': False,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   194
         },
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   195
         ]
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   196
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   197
    dynaproperties = params_helper.getDynaFields(dynafields)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   198
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   199
    mentor_review_form = dynaform.newDynaForm(dynamodel=None, dynabase=helper.forms.BaseForm,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   200
        dynainclude=None, dynaexclude=None, dynaproperties=dynaproperties)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   201
    params['mentor_review_form'] = mentor_review_form
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   202
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   203
    # TODO see if autocomplete can be used for this field
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   204
    dynafields = [
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   205
      {'name': 'mentor',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   206
       'base': forms.CharField,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   207
       'label': 'Assign Mentor (Link ID)',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   208
       'required': False
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   209
      },
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   210
      ]
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   211
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   212
    dynaproperties = params_helper.getDynaFields(dynafields)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   213
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   214
    admin_review_form = dynaform.extendDynaForm(dynaform=mentor_review_form, dynaproperties=dynaproperties)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   215
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   216
    params['admin_review_form'] = admin_review_form
1569
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   217
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   218
  def _editGet(self, request, entity, form):
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   219
    """See base.View._editGet().
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   220
    """
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   221
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   222
    form.fields['link_id'].initial = entity.link_id
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   223
    form.fields['organization'].initial = entity.org.link_id
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   224
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   225
    return super(View, self)._editGet(request, entity, form)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   226
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   227
  def _editPost(self, request, entity, fields):
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   228
    """See base.View._editPost().
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   229
    """
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   230
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   231
    if not entity:
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   232
      fields['link_id'] = 't%i' % (time.time())
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   233
    else:
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   234
      fields['link_id'] = entity.link_id
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   235
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   236
    # fill in the scope via call to super
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   237
    super(View, self)._editPost(request, entity, fields)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   238
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   239
    if not entity:
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   240
      # creating a new application so set the program and org field
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   241
      fields['program'] = fields['scope'].scope
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   242
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   243
      filter = {'scope': fields['program'],
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   244
                'link_id': fields['organization']}
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   245
      fields['org'] = org_logic.logic.getForFields(filter, unique=True)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   246
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   247
    # explicitly change the last_modified_on since the content has been edited
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   248
    fields['last_modified_on'] = datetime.datetime.now()
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   249
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   250
  def _public(self, request, entity, context):
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   251
    """See base.View._public().
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   252
    """
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   253
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   254
    context['student_name'] = entity.scope.name()
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   255
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   256
    if entity.mentor:
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   257
      context['mentor_name'] = entity.mentor.name()
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   258
    else:
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   259
      context['mentor_name'] = "No mentor assigned"
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   260
1469
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   261
  @decorators.merge_params
1482
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   262
  @decorators.check_access
1569
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   263
  def apply(self, request, access_type,
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   264
             page_name=None, params=None, **kwargs):
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   265
    """Special view used to prepopulate the form with the organization
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   266
       contributors template.
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   267
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   268
       For params see base.View.public()
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   269
    """
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   270
    get_dict = request.GET
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   271
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   272
    if get_dict.get('organization'):
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   273
      # organization chosen, prepopulate with template
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   274
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   275
      # get the organization
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   276
      student_entity = student_logic.logic.getFromKeyName(kwargs['scope_path'])
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   277
      program_entity = student_entity.scope
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   278
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   279
      filter = {'link_id': get_dict['organization'],
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   280
                'scope': program_entity}
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   281
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   282
      org_entity = org_logic.logic.getForFields(filter, unique=True)
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   283
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   284
      if org_entity:
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   285
        # organization found use special form
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   286
        params['create_form'] = params['student_create_form']
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   287
        kwargs['content'] = org_entity.contrib_template
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   288
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   289
    # Create page is an edit page with no key fields
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   290
    empty_kwargs = {}
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   291
    fields = self._logic.getKeyFieldNames()
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   292
    for field in fields:
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   293
      empty_kwargs[field] = None
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   294
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   295
    return super(View, self).edit(request, access_type, page_name=page_name,
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   296
                     params=params, seed=kwargs, **empty_kwargs)
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   297
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   298
  @decorators.merge_params
6347d0a4fa7b Students who follow the submit your student proposal link will now see their org's proposal template when creating their own proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1498
diff changeset
   299
  @decorators.check_access
1498
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   300
  def edit(self, request, access_type,
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   301
           page_name=None, params=None, seed=None, **kwargs):
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   302
    """If the POST contains (action, Withdraw) the proposal in kwargs
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   303
       will be marked as invalid.
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   304
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   305
    For params see base.View.edit()
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   306
    """
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   307
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   308
    # check if request.POST contains action
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   309
    post_dict = request.POST
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   310
    if 'action' in post_dict and post_dict['action'] == 'Withdraw':
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   311
      # withdraw this proposal
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   312
      filter = {'scope_path': kwargs['scope_path'],
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   313
                'link_id': kwargs['link_id']}
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   314
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   315
      proposal_logic = params['logic']
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   316
      student_proposal_entity = proposal_logic.getForFields(filter, unique=True)
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   317
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   318
      # update the entity mark it as invalid
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   319
      proposal_logic.updateEntityProperties(student_proposal_entity,
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   320
          {'status': 'invalid'})
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   321
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   322
      # redirect to the program's homepage
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   323
      redirect_url = redirects.getHomeRedirect(student_proposal_entity.program,
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   324
          {'url_name': 'program'})
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   325
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   326
      return http.HttpResponseRedirect(redirect_url)
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   327
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   328
    return super(View, self).edit(request=request, access_type=access_type,
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   329
           page_name=page_name, params=params, seed=seed, **kwargs)
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   330
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   331
  @decorators.merge_params
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   332
  @decorators.check_access
1484
6b00a2a43eaf Changed the method and variable name in student_proposal to match the access type.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1482
diff changeset
   333
  def listOrgs(self, request, access_type,
1491
acf7e32de8ca Style fixes in student_proposal and organization view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1484
diff changeset
   334
               page_name=None, params=None, **kwargs):
1482
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   335
    """Lists all organization which the given student can propose to.
1469
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   336
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   337
    For params see base.View.public().
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   338
    """
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   339
1482
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   340
    from soc.views.models import organization as org_view
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   341
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   342
    student_entity = student_logic.logic.getFromKeyName(kwargs['scope_path'])
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   343
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   344
    filter = {'scope' : student_entity.scope,
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   345
              'status': 'active'}
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   346
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   347
    list_params = org_view.view.getParams().copy()
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   348
    list_params['list_description'] = ('List of %(name_plural)s you can send '
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   349
        'your proposal to.') % list_params
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   350
    list_params['list_action'] = (redirects.getStudentProposalRedirect,
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   351
        {'student_key': student_entity.key().name(),
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   352
            'url_name': params['url_name']})
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   353
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   354
    return self.list(request, access_type=access_type, page_name=page_name,
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   355
                     params=list_params, filter=filter, **kwargs)
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   356
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   357
  @decorators.merge_params
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   358
  @decorators.check_access
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   359
  def listSelf(self, request, access_type,
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   360
             page_name=None, params=None, **kwargs):
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   361
    """Lists all proposals from the current logged-in user for the given student.
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   362
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   363
    For params see base.View.public().
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   364
    """
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   365
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   366
    student_entity = student_logic.logic.getFromKeyName(kwargs['scope_path'])
1469
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   367
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   368
    filter = {'scope' : student_entity,
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   369
              'status': ['new', 'pending', 'accepted', 'rejected']}
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   370
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   371
    list_params = params.copy()
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   372
    list_params['list_description'] = 'List of my %(name_plural)s' % list_params
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   373
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   374
    return self.list(request, access_type=access_type, page_name=page_name,
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   375
                     params=list_params, filter=filter, **kwargs)
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   376
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   377
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   378
  @decorators.merge_params
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   379
  @decorators.check_access
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   380
  def review(self, request, access_type,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   381
             page_name=None, params=None, **kwargs):
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   382
    """View that allows Organization Admins and Mentors to review the proposal.
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   383
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   384
       For Args see base.View.public().
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   385
    """
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   386
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   387
    try:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   388
        entity = self._logic.getFromKeyFieldsOr404(kwargs)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   389
    except out_of_band.Error, error:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   390
      return helper.responses.errorResponse(
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   391
          error, request, template=params['error_public'])
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   392
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   393
    # get the context for this webpage
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   394
    context = responses.getUniversalContext(request)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   395
    responses.useJavaScript(context, params['js_uses_all'])
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   396
    context['page_name'] = page_name
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   397
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   398
    context['student_name'] = entity.scope.name()
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   399
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   400
    if entity.mentor:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   401
      context['mentor_name'] = entity.mentor.name()
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   402
    else:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   403
      context['mentor_name'] = "No mentor assigned"
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   404
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   405
    context['entity'] = entity
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   406
    context['entity_type'] = params['name']
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   407
    context['entity_type_url'] = params['url_name']
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   408
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   409
    # get the roles important for reviewing an application
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   410
    filter = {'user': user_logic.logic.getForCurrentAccount(),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   411
        'scope': entity.org,
1620
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   412
        'status': 'active'}
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   413
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   414
    org_admin_entity = org_admin_logic.logic.getForFields(filter, unique=True)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   415
    mentor_entity = mentor_logic.logic.getForFields(filter, unique=True)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   416
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   417
    # check if the current user is a mentor and wants to change his role for this app
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   418
    choice = request.GET.get('mentor')
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   419
    if mentor_entity and choice:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   420
      self._adjustPossibleMentors(entity, mentor_entity, choice)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   421
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   422
    # set the possible mentors in the context
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   423
    possible_mentors = entity.possible_mentors
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   424
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   425
    if not possible_mentors:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   426
      context['possible_mentors'] = "None"
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   427
    else:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   428
      mentor_names = []
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   429
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   430
      for mentor_key in possible_mentors:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   431
        mentor = mentor_logic.logic.getFromKeyName(mentor_key.name())
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   432
        mentor_names.append(mentor.name())
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   433
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   434
      context['possible_mentors'] = ', '.join(mentor_names)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   435
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   436
    # decide which form to use
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   437
    if org_admin_entity:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   438
      form = params['admin_review_form']
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   439
    else:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   440
      form = params['mentor_review_form']
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   441
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   442
    if request.method == 'POST':
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   443
      return self.reviewPost(request, context, params, entity,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   444
                             form, org_admin_entity, mentor_entity, **kwargs)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   445
    else:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   446
      # request.method == 'GET'
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   447
      return self.reviewGet(request, context, params, entity,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   448
                            form, org_admin_entity, mentor_entity, **kwargs)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   449
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   450
  def reviewPost(self, request, context, params, entity, form,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   451
                 org_admin, mentor, **kwargs):
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   452
    """Handles the POST request for the proposal review view.
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   453
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   454
    Args:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   455
        entity: the student proposal entity
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   456
        form: the form to use in this view
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   457
        org_admin: org admin entity for the current user/proposal (iff available)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   458
        mentor: mentor entity for the current user/proposal (iff available)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   459
        rest: see base.View.public()
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   460
    """
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   461
    # populate the form using the POST data
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   462
    form = form(request.POST)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   463
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   464
    if not form.is_valid():
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   465
      # return the invalid form response
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   466
      return self._constructResponse(request, entity=entity, context=context,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   467
          form=form, params=params, template=params['review_template'])
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   468
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   469
    fields = form.cleaned_data
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   470
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   471
    if org_admin:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   472
      # org admin found, try to adjust the assigned mentor
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   473
      self._adjustMentor(entity, fields['mentor'])
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   474
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   475
    is_public = fields['public']
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   476
    comment = fields['comment']
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   477
    given_score = int(fields['score'])
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   478
1620
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   479
    if (org_admin or mentor) and (not is_public) and (given_score is not 0):
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   480
      # if it is not a public comment and it's made by a member of the
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   481
      # organization we score and display an additional message in the comment
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   482
      new_score = given_score + entity.score
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   483
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   484
      if org_admin:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   485
        name = org_admin.name()
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   486
      elif mentor:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   487
        name = mentor.name()
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   488
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   489
      # TODO(ljvderijk) hook up comments
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   490
      comment = '%s has given %i points \n %s' %(name, given_score, comment)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   491
1620
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   492
      properties = {'score': new_score}
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   493
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   494
      # if the proposal is new we change it status to pending
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   495
      if entity.status == 'new':
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   496
        properties['status'] = 'pending'
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   497
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   498
      # update the proposal with the new score
1620
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   499
      self._logic.updateEntityProperties(entity, properties)
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   500
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   501
    # redirect to the same page
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   502
    return http.HttpResponseRedirect('')
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   503
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   504
  def reviewGet(self, request, context, params, entity, form,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   505
                 org_admin, mentor, **kwargs):
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   506
    """Handles the GET request for the proposal review view.
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   507
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   508
    Args:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   509
        entity: the student proposal entity
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   510
        form: the form to use in this view
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   511
        org_admin: org admin entity for the current user/proposal (iff available)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   512
        mentor: mentor entity for the current user/proposal (iff available)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   513
        rest: see base.View.public()
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   514
    """
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   515
1620
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   516
    # set the initial score since the default is ignored
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   517
    initial = {'score': 0}
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   518
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   519
    if org_admin and entity.mentor:
1620
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   520
      # set the mentor field to the current mentor
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   521
      initial['mentor'] = entity.mentor.link_id
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   522
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   523
    context['form'] = form(initial)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   524
    template = params['review_template']
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   525
    context['mentor'] = mentor
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   526
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   527
    return responses.respond(request, template, context=context)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   528
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   529
  def _adjustPossibleMentors(self, entity, mentor, choice):
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   530
    """Adjusts the possible mentors list for a proposal.
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   531
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   532
    Args:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   533
      entity: Student Proposal entity
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   534
      mentor: Mentor entity
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   535
      choice: 1 means want to mentor, 0 do not want to mentor
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   536
    """
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   537
    possible_mentors = entity.possible_mentors
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   538
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   539
    if choice == '1':
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   540
      # add the mentor to possible mentors list if not already in
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   541
      if mentor.key() not in possible_mentors:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   542
        possible_mentors.append(mentor.key())
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   543
        fields = {'possible_mentors': possible_mentors}
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   544
        self._logic.updateEntityProperties(entity, fields)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   545
    elif choice == '0':
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   546
      # remove the mentor from the possible mentors list
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   547
      if mentor.key() in possible_mentors:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   548
        possible_mentors.remove(mentor.key())
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   549
        fields = {'possible_mentors': possible_mentors}
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   550
        self._logic.updateEntityProperties(entity, fields)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   551
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   552
  def _adjustMentor(self, entity, mentor_id):
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   553
    """Changes the mentor to the given link_id.
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   554
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   555
    Args:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   556
      entity: Student Proposal entity
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   557
      mentor_id: Link ID of the mentor that needs to be assigned
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   558
                 Iff not given then removes the assigned mentor
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   559
    """
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   560
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   561
    if entity.mentor and entity.mentor.link_id == mentor_id:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   562
      # no need to change
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   563
      return
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   564
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   565
    if mentor_id:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   566
      # try to locate the mentor
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   567
      fields = {'link_id': mentor_id,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   568
                'scope': entity.org,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   569
                'status': 'active'}
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   570
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   571
      mentor_entity = mentor_logic.logic.getForFields(fields, unique=True)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   572
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   573
      if not mentor_entity:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   574
        # no mentor found, do not update
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   575
        return
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   576
    else:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   577
      # reset to None
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   578
      mentor_entity = None
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   579
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   580
    # update the proposal
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   581
    properties = {'mentor': mentor_entity}
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   582
    self._logic.updateEntityProperties(entity, properties)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   583
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   584
view = View()
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   585
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
   586
admin = decorators.view(view.admin)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
   587
apply = decorators.view(view.apply)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
   588
create = decorators.view(view.create)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
   589
delete = decorators.view(view.delete)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
   590
edit = decorators.view(view.edit)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
   591
list = decorators.view(view.list)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
   592
list_orgs = decorators.view(view.listOrgs)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
   593
list_self = decorators.view(view.listSelf)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
   594
public = decorators.view(view.public)
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   595
review = decorators.view(view.review)
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
   596
export = decorators.view(view.export)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
   597
pick = decorators.view(view.pick)