app/soc/views/models/student_proposal.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Fri, 17 Apr 2009 16:23:01 +0000
changeset 2191 d20557e217dc
parent 2185 09ca8e661728
child 2258 280d2cf745f2
permissions -rw-r--r--
Proposal CSV export for students. Patch by: Matthew Wilkes Reviewed by: Pawel Solyga
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
2094
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
    30
from django.utils.translation import ugettext
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
from soc.logic import cleaning
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
from soc.logic import dicts
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
    34
from soc.logic.models import mentor as mentor_logic
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
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
    36
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
    37
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
    38
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
    39
from soc.views import helper
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
    40
from soc.views import out_of_band
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
from soc.views.helper import access
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
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
    43
from soc.views.helper import dynaform
2094
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
    44
from soc.views.helper import lists
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
    45
from soc.views.helper import params as params_helper
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
from soc.views.helper import redirects
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
    47
from soc.views.helper import responses
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
from soc.views.helper import widgets
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
from soc.views.models import base
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
from soc.views.models import student as student_view
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
import soc.logic.models.student_proposal
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
class View(base.View):
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
  """View methods for the Student Proposal model.
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
  """
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
  def __init__(self, params=None):
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
    """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
    61
    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
    62
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    63
    Params:
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
      params: a dict with params for this View
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
    """
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
    rights = access.Checker(params)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    rights['create'] = ['checkIsDeveloper']
1995
768f533d91e3 Added check to prevent students from submitting more proposals then allowed by the program settings.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1898
diff changeset
    69
    rights['edit'] = [('checkCanStudentPropose', ['scope_path', False]),
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
    70
        ('checkRoleAndStatusForStudentProposal',
2094
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
    71
            [['proposer'], ['active'], ['new', 'pending', 'invalid']])]
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
    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
    73
    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
    74
        ('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
    75
            [['proposer', 'org_admin', 'mentor', 'host'], 
1639
170ac4ca078d Fix too long lines in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1620
diff changeset
    76
            ['active', 'inactive'], 
2094
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
    77
            ['new', 'pending', 'accepted', 'rejected', 'invalid']])]
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    78
    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
    79
    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
    80
        ('checkIsStudent', ['scope_path', ['active']]),
1995
768f533d91e3 Added check to prevent students from submitting more proposals then allowed by the program settings.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1898
diff changeset
    81
        ('checkCanStudentPropose', ['scope_path', False])]
1469
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
    82
    rights['list_self'] = [
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
    83
        ('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
    84
    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
    85
        ('checkIsStudent', ['scope_path', ['active']]),
1995
768f533d91e3 Added check to prevent students from submitting more proposals then allowed by the program settings.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1898
diff changeset
    86
        ('checkCanStudentPropose', ['scope_path', True])]
1620
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
    87
    rights['review'] = [('checkRoleAndStatusForStudentProposal',
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
    88
            [['org_admin', 'mentor', 'host'], 
2041
9a9307b22312 Make invalid Student Proposals also accessible for Hosts, Mentors and Org admins. Previously only new and pending Student Proposals could be viewed.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2031
diff changeset
    89
            ['active'], ['new', 'pending', 'invalid']])]
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    90
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    91
    new_params = {}
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
    new_params['logic'] = soc.logic.models.student_proposal.logic
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    93
    new_params['rights'] = rights
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    94
    new_params['name'] = "Student Proposal"
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    95
    new_params['url_name'] = "student_proposal"
1853
6cd70644892d Group StudentProposals under Students in the sidebar.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1840
diff changeset
    96
    new_params['sidebar_grouping'] = 'Students'
1426
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['scope_view'] = student_view
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    99
    new_params['scope_redirect'] = redirects.getCreateRedirect
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   100
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   101
    new_params['no_create_with_key_fields'] = True
2191
d20557e217dc Proposal CSV export for students.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2185
diff changeset
   102
    new_params['list_key_order'] = ['title', 'abstract', 'content',
d20557e217dc Proposal CSV export for students.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2185
diff changeset
   103
        'additional_info', 'created_on', 'last_modified_on']
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   104
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   105
    patterns = [
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   106
        (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
   107
        'soc.views.models.%(module_name)s.apply',
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   108
        'Create a new %(name)s'),
1469
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   109
        (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
   110
        '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
   111
        '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
   112
        (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
   113
        '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
   114
        'List my %(name_plural)s'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   115
        (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
   116
        'soc.views.models.%(module_name)s.review',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   117
        'Review %(name)s'),
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   118
    ]
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   119
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   120
    new_params['extra_django_patterns'] = patterns
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   121
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   122
    new_params['extra_dynaexclude'] = ['org', 'program', 'score',
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   123
                                       'status', 'mentor', 'link_id',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   124
                                       'possible_mentors']
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   125
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1426
diff changeset
   126
    new_params['create_extra_dynaproperties'] = {
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   127
        'content': forms.fields.CharField(required=True,
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   128
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   129
        'scope_path': forms.CharField(widget=forms.HiddenInput,
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   130
            required=True),
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   131
        'organization': forms.CharField(label='Organization Link ID',
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   132
            required=True),
2031
f018461e0f8a Enforce the 500 character limit for abstracts.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2011
diff changeset
   133
        'clean_abstract': cleaning.clean_content_length('abstract'),
2006
8b7b5bc9abe2 Added cleaning to student proposal content and the contents of the reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2003
diff changeset
   134
        'clean_content': cleaning.clean_html_content('content'),
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   135
        'clean_organization': cleaning.clean_link_id('organization'),
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   136
        'clean_additional_info': cleaning.clean_url('additional_info'),
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   137
        'clean': cleaning.validate_student_proposal('organization',
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   138
            'scope_path', student_logic, org_logic),
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   139
        }
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   140
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1426
diff changeset
   141
    new_params['edit_extra_dynaproperties'] = {
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   142
        'organization': forms.CharField(label='Organization Link ID',
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   143
            widget=widgets.ReadOnlyInput),
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   144
        'link_id': forms.CharField(widget=forms.HiddenInput)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   145
        }
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   146
1498
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   147
    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
   148
    new_params['review_template'] = 'soc/student_proposal/review.html'
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   149
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   150
    params = dicts.merge(params, new_params)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   151
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   152
    super(View, self).__init__(params=params)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   153
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
   154
    # 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
   155
    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
   156
        {'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
   157
         '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
   158
         '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
   159
         '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
   160
         '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
   161
         },
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
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
    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
   165
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
   166
    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
   167
        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
   168
        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
   169
2177
e2c193e1f631 Do not rely on dicts.merge to change target
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2174
diff changeset
   170
    self._params['student_create_form'] = student_create_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
   171
1752
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   172
    # create the special form for public review
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   173
    dynafields = [
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   174
        {'name': 'comment',
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   175
         'base': forms.CharField,
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   176
         'widget': widgets.FullTinyMCE(attrs={'rows': 10, 'cols': 40}),
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   177
         'label': 'Comment',
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   178
         'required': False,
2174
19ed1c42e836 Added a warning message to alert the user that reviews are not editable.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2173
diff changeset
   179
         'example_text': 'Caution, you will not be able to edit your comment!',
1752
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   180
         },
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   181
         ]
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   182
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   183
    dynaproperties = params_helper.getDynaFields(dynafields)
2006
8b7b5bc9abe2 Added cleaning to student proposal content and the contents of the reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2003
diff changeset
   184
    dynaproperties['clean_comment'] = cleaning.clean_html_content('comment')
1752
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   185
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   186
    public_review_form = dynaform.newDynaForm(dynamodel=None, 
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   187
        dynabase=helper.forms.BaseForm, dynainclude=None, 
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   188
        dynaexclude=None, dynaproperties=dynaproperties)
2177
e2c193e1f631 Do not rely on dicts.merge to change target
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2174
diff changeset
   189
    self._params['public_review_form'] = public_review_form
1752
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   190
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   191
    # create the special form for mentors
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   192
    dynafields = [
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   193
        {'name': 'score',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   194
         'base': forms.ChoiceField,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   195
         'label': 'Score',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   196
         'initial': 0,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   197
         'required': False,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   198
         'passthrough': ['initial', 'required', 'choices'],
1839
92b28d1bf2f5 Added example and help text to clarify the use of some fields on the proposal ranking.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1838
diff changeset
   199
         'example_text':
92b28d1bf2f5 Added example and help text to clarify the use of some fields on the proposal ranking.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1838
diff changeset
   200
             'A score will only be assigned if the review is private!',
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   201
         'choices': [(-4,'-4: Wow. This. Sucks.'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   202
                     (-3,'-3: Needs a lot of work'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   203
                     (-2,'-2: This is bad'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   204
                     (-1,'-1: I dont like this'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   205
                     (0,'0: No score'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   206
                     (1,'1: Might have potential'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   207
                     (2,'2: Good'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   208
                     (3,'3: Almost there'),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   209
                     (4,'4: Made. Of. Awesome.')]
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
        {'name': 'comment',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   212
         'base': forms.CharField,
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   213
         'widget': widgets.FullTinyMCE(attrs={'rows': 10, 'cols': 40}),
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   214
         'label': 'Comment',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   215
         'required': False,
2174
19ed1c42e836 Added a warning message to alert the user that reviews are not editable.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2173
diff changeset
   216
         'example_text': 'Caution, you will not be able to edit your review!',
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   217
         },
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   218
        {'name': 'public',
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   219
         'base': forms.BooleanField,
2096
eed59b94aae2 Changed label and help_text for public review button on studentproposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2094
diff changeset
   220
         'label': 'Review visible to Student',
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   221
         'initial': False,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   222
         'required': False,
1838
5a8a254af95b Some textual changes for proposal reviewing.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1787
diff changeset
   223
         'help_text': 'By ticking this box the score will not be assigned, '
2096
eed59b94aae2 Changed label and help_text for public review button on studentproposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2094
diff changeset
   224
             'and the review will be visible to the student.',
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   225
         },
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   226
         ]
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   227
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   228
    dynaproperties = params_helper.getDynaFields(dynafields)
2006
8b7b5bc9abe2 Added cleaning to student proposal content and the contents of the reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2003
diff changeset
   229
    dynaproperties['clean_comment'] = cleaning.clean_html_content('comment')
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   230
1639
170ac4ca078d Fix too long lines in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1620
diff changeset
   231
    mentor_review_form = dynaform.newDynaForm(dynamodel=None, 
170ac4ca078d Fix too long lines in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1620
diff changeset
   232
        dynabase=helper.forms.BaseForm, dynainclude=None, 
170ac4ca078d Fix too long lines in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1620
diff changeset
   233
        dynaexclude=None, dynaproperties=dynaproperties)
2177
e2c193e1f631 Do not rely on dicts.merge to change target
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2174
diff changeset
   234
    self._params['mentor_review_form'] = mentor_review_form
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   235
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   236
    dynafields = [
1787
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   237
      {'name': 'rank',
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   238
         'base': forms.IntegerField,
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   239
         'label': 'Set to rank',
1839
92b28d1bf2f5 Added example and help text to clarify the use of some fields on the proposal ranking.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1838
diff changeset
   240
         'help_text':
92b28d1bf2f5 Added example and help text to clarify the use of some fields on the proposal ranking.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1838
diff changeset
   241
             'Set this proposal to the given rank (ignores the given score)',
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   242
         'example_text': 'A rank will only be assigned if the '
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   243
            'review is private!',
1787
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   244
         'min_value': 1,
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   245
         'required': False,
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   246
         'passthrough': ['min_value', 'required', 'help_text'],
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   247
      },
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   248
      {'name': 'mentor',
2134
bd93e34108b8 Add auto-completion for mentor field
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2098
diff changeset
   249
       'base': widgets.ReferenceField,
bd93e34108b8 Add auto-completion for mentor field
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2098
diff changeset
   250
       'passthrough': ['reference_url', 'required', 'label', 'filter'],
bd93e34108b8 Add auto-completion for mentor field
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2098
diff changeset
   251
       'reference_url': 'mentor',
bd93e34108b8 Add auto-completion for mentor field
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2098
diff changeset
   252
       'filter': ['__org__'],
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   253
       'label': 'Assign Mentor (Link ID)',
1839
92b28d1bf2f5 Added example and help text to clarify the use of some fields on the proposal ranking.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1838
diff changeset
   254
       'required': False,
92b28d1bf2f5 Added example and help text to clarify the use of some fields on the proposal ranking.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1838
diff changeset
   255
       'help_text': 'Fill in the Link ID of the Mentor '
92b28d1bf2f5 Added example and help text to clarify the use of some fields on the proposal ranking.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1838
diff changeset
   256
           'you would like to assign to this Proposal. '
92b28d1bf2f5 Added example and help text to clarify the use of some fields on the proposal ranking.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1838
diff changeset
   257
           'Leave this box empty if you don\'t want any mentor assigned.',
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   258
      },
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   259
      ]
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   260
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   261
    dynaproperties = params_helper.getDynaFields(dynafields)
2006
8b7b5bc9abe2 Added cleaning to student proposal content and the contents of the reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2003
diff changeset
   262
    dynaproperties['clean_comment'] = cleaning.clean_html_content('comment')
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   263
1639
170ac4ca078d Fix too long lines in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1620
diff changeset
   264
    admin_review_form = dynaform.extendDynaForm(dynaform=mentor_review_form, 
170ac4ca078d Fix too long lines in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1620
diff changeset
   265
        dynaproperties=dynaproperties)
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   266
2177
e2c193e1f631 Do not rely on dicts.merge to change target
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2174
diff changeset
   267
    self._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
   268
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   269
  def _editGet(self, request, entity, form):
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   270
    """See base.View._editGet().
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   271
    """
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   272
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   273
    form.fields['link_id'].initial = entity.link_id
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   274
    form.fields['organization'].initial = entity.org.link_id
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   275
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   276
    return super(View, self)._editGet(request, entity, form)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   277
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   278
  def _editPost(self, request, entity, fields):
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   279
    """See base.View._editPost().
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   280
    """
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   281
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   282
    if not entity:
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   283
      fields['link_id'] = 't%i' % (int(time.time()*100))
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   284
    else:
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   285
      fields['link_id'] = entity.link_id
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   286
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   287
    # fill in the scope via call to super
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   288
    super(View, self)._editPost(request, entity, fields)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   289
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   290
    if not entity:
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   291
      # 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
   292
      fields['program'] = fields['scope'].scope
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   293
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   294
      filter = {'scope': fields['program'],
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   295
                'link_id': fields['organization']}
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   296
      fields['org'] = org_logic.logic.getForFields(filter, unique=True)
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   297
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   298
    # 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
   299
    fields['last_modified_on'] = datetime.datetime.now()
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   300
1752
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   301
  @decorators.merge_params
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   302
  @decorators.check_access
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   303
  def public(self, request, access_type,
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   304
             page_name=None, params=None, **kwargs):
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   305
    """View in which the student can see and reply to the comments on the
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   306
       Student Proposal.
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   307
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   308
    For params see base.view.Public().
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   309
    """
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   310
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   311
    context = helper.responses.getUniversalContext(request)
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   312
    helper.responses.useJavaScript(context, params['js_uses_all'])
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   313
    context['page_name'] = page_name
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   314
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   315
    try:
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   316
      entity = self._logic.getFromKeyFieldsOr404(kwargs)
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   317
    except out_of_band.Error, error:
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   318
      return helper.responses.errorResponse(
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   319
          error, request, template=params['error_public'], context=context)
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   320
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   321
    context['entity'] = entity
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   322
    context['entity_type'] = params['name']
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   323
    context['entity_type_url'] = params['url_name']
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   324
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   325
    if request.method == 'POST':
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   326
      return self.publicPost(request, context, params, entity, **kwargs)
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   327
    else: # request.method == 'GET'
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   328
      return self.publicGet(request, context, params, entity, **kwargs)
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   329
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   330
  def publicPost(self, request, context, params, entity, **kwargs):
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   331
    """Handles the POST request for the entity's public page.
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   332
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   333
    Args:
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   334
        entity: the student proposal entity
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   335
        rest: see base.View.public()
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   336
    """
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   337
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   338
    # populate the form using the POST data
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   339
    form = params['public_review_form'](request.POST)
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   340
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   341
    if not form.is_valid():
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   342
      # get some entity specific context
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   343
      self.updatePublicContext(context, entity, params)
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   344
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   345
      # return the invalid form response
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   346
      return self._constructResponse(request, entity=entity, context=context,
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   347
          form=form, params=params, template=params['public_template'])
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   348
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   349
    # get the commentary
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   350
    fields = form.cleaned_data
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   351
    comment = fields['comment']
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   352
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   353
    if comment:
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   354
      # create a new public review containing the comment
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   355
      user_entity = user_logic.logic.getForCurrentAccount()
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   356
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   357
      if user_entity.key() == entity.scope.user.key():
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   358
        # student is posting
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   359
        reviewer = entity.scope
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   360
      else:
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   361
        # check if the person commenting is an org_admin
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   362
        # or a mentor for the given proposal
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   363
        fields = {'user': user_entity,
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   364
                  'scope': entity.org,
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   365
                  'status': 'active',
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   366
                  }
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   367
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   368
        reviewer = org_admin_logic.logic.getForFields(fields, unique=True)
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   369
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   370
        if not reviewer:
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   371
          # no org_admin found, maybe it's a mentor?
2003
ed24a0bd19d9 Fixed error occurring when mentor or student posts a comment because a built-in function was passed rather then a real argument.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1995
diff changeset
   372
          reviewer = mentor_logic.logic.getForFields(fields, unique=True)
1752
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   373
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   374
      # create the review (reviewer might be None 
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   375
      # if a Host or Developer is posting)
1752
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   376
      self._createReviewFor(entity, reviewer, comment, is_public=True)
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   377
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   378
    # redirect to the same page
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   379
    return http.HttpResponseRedirect('')
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   380
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   381
  def publicGet(self, request, context, params, entity, **kwargs):
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   382
    """Handles the GET request for the entity's public page.
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   383
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   384
    Args:
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   385
        entity: the student proposal entity
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   386
        rest see base.View.public()
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   387
    """
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   388
1882
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   389
    from soc.logic.models.review_follower import logic as review_follower_logic
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   390
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   391
    get_dict = request.GET
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   392
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   393
    if get_dict.get('subscription') and (
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   394
      get_dict['subscription'] in ['on', 'off']):
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   395
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   396
      subscription = get_dict['subscription']
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   397
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   398
      # get the current user
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   399
      user_entity = user_logic.logic.getForCurrentAccount()
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   400
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   401
      # create the fields that should be in the ReviewFollower entity
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   402
      fields = {'link_id': user_entity.link_id,
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   403
                'scope': entity,
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2150
diff changeset
   404
                'scope_path': entity.key().id_or_name(),
1882
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   405
                'user': user_entity
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   406
               }
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   407
      # get the keyname for the ReviewFollower entity
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   408
      key_name = review_follower_logic.getKeyNameFromFields(fields)
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   409
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   410
      # determine if we should set subscribed_public to True or False
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   411
      if subscription == 'on':
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   412
        fields['subscribed_public'] = True
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   413
      elif subscription == 'off':
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   414
        fields['subscribed_public'] = False
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   415
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   416
      # update the ReviewFollower
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   417
      review_follower_logic.updateOrCreateFromKeyName(fields, key_name)
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   418
1752
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   419
    # get some entity specific context
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   420
    self.updatePublicContext(context, entity, params)
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   421
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   422
    context['form'] = params['public_review_form']()
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   423
    template = params['public_template']
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   424
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   425
    return responses.respond(request, template, context=context)
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   426
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   427
  def updatePublicContext(self, context, entity, params):
1758
e035f81d367b Some minor style fixes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1752
diff changeset
   428
    """Updates the context for the public page with information from the entity.
1752
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   429
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   430
    Args:
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   431
      context: the context that should be updated
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   432
      entity: a student proposal_entity used to set context
255117ccd6a0 The student proposal public page can now be used to place a public comment.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1741
diff changeset
   433
      params: dict with params for the view using this context
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   434
    """
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   435
1741
0da1285f5bc0 Public reviews are now shown on the public page for the student proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1715
diff changeset
   436
    from soc.logic.models.review import logic as review_logic
1882
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   437
    from soc.logic.models.review_follower import logic as review_follower_logic
1741
0da1285f5bc0 Public reviews are now shown on the public page for the student proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1715
diff changeset
   438
1840
bf2c705ead19 Changed the workflow for students regarding their proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1839
diff changeset
   439
    student_entity = entity.scope
bf2c705ead19 Changed the workflow for students regarding their proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1839
diff changeset
   440
1898
7f18e83a129f Hook up the new template tag for StudentProposal reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1895
diff changeset
   441
    context['student'] = student_entity
1840
bf2c705ead19 Changed the workflow for students regarding their proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1839
diff changeset
   442
    context['student_name'] = student_entity.name()
bf2c705ead19 Changed the workflow for students regarding their proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1839
diff changeset
   443
bf2c705ead19 Changed the workflow for students regarding their proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1839
diff changeset
   444
    user_entity = user_logic.logic.getForCurrentAccount()
bf2c705ead19 Changed the workflow for students regarding their proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1839
diff changeset
   445
bf2c705ead19 Changed the workflow for students regarding their proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1839
diff changeset
   446
    # check if the current user is the student
bf2c705ead19 Changed the workflow for students regarding their proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1839
diff changeset
   447
    if user_entity.key() == student_entity.user.key():
bf2c705ead19 Changed the workflow for students regarding their proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1839
diff changeset
   448
      # show the proposal edit link
bf2c705ead19 Changed the workflow for students regarding their proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1839
diff changeset
   449
      context['edit_link'] = redirects.getEditRedirect(entity, params)
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   450
1882
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   451
    # check if the current user is subscribed to this proposal's public reviews
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   452
    fields = {'user': user_entity,
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   453
        'scope': entity,
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   454
        'subscribed_public': True}
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   455
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   456
    context['is_subscribed'] = review_follower_logic.getForFields(fields,
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   457
                                                                  unique=True)
72b42ffee2a1 Everyone that is able to see the StudentProposals public page can subscribe to public review updates.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1853
diff changeset
   458
1741
0da1285f5bc0 Public reviews are now shown on the public page for the student proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1715
diff changeset
   459
    context['public_reviews'] = review_logic.getReviewsForEntity(entity,
0da1285f5bc0 Public reviews are now shown on the public page for the student proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1715
diff changeset
   460
        is_public=True, order=['created'])
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   461
1469
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   462
  @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
   463
  @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
   464
  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
   465
             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
   466
    """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
   467
       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
   468
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
   469
       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
   470
    """
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
   471
    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
   472
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
   473
    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
   474
      # 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
   475
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
   476
      # 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
   477
      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
   478
      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
   479
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
   480
      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
   481
                '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
   482
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
   483
      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
   484
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
   485
      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
   486
        # 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
   487
        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
   488
        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
   489
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
   490
    # 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
   491
    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
   492
    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
   493
    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
   494
      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
   495
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
   496
    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
   497
                     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
   498
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
   499
  @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
   500
  @decorators.check_access
1498
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   501
  def edit(self, request, access_type,
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   502
           page_name=None, params=None, seed=None, **kwargs):
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   503
    """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
   504
       will be marked as invalid.
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   505
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   506
    For params see base.View.edit()
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   507
    """
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   508
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   509
    # check if request.POST contains action
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   510
    post_dict = request.POST
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   511
    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
   512
      # withdraw this proposal
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   513
      filter = {'scope_path': kwargs['scope_path'],
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   514
                'link_id': kwargs['link_id']}
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   515
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   516
      proposal_logic = params['logic']
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   517
      student_proposal_entity = proposal_logic.getForFields(filter, unique=True)
2092
6de3693ba9d4 When Student withdrew a proposal a public comment "Student withdrew proposal." is posted.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2091
diff changeset
   518
      reviewer = student_proposal_entity.scope
6de3693ba9d4 When Student withdrew a proposal a public comment "Student withdrew proposal." is posted.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2091
diff changeset
   519
      
1498
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   520
      # update the entity mark it as invalid
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   521
      proposal_logic.updateEntityProperties(student_proposal_entity,
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   522
          {'status': 'invalid'})
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   523
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   524
      # redirect to the program's homepage
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   525
      redirect_url = redirects.getHomeRedirect(student_proposal_entity.program,
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   526
          {'url_name': 'program'})
2092
6de3693ba9d4 When Student withdrew a proposal a public comment "Student withdrew proposal." is posted.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2091
diff changeset
   527
      
6de3693ba9d4 When Student withdrew a proposal a public comment "Student withdrew proposal." is posted.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2091
diff changeset
   528
      comment = "Student withdrew proposal."
6de3693ba9d4 When Student withdrew a proposal a public comment "Student withdrew proposal." is posted.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2091
diff changeset
   529
      self._createReviewFor(student_proposal_entity, reviewer, comment)
1498
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   530
      return http.HttpResponseRedirect(redirect_url)
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   531
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   532
    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
   533
           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
   534
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   535
  @decorators.merge_params
00293057b009 Added proposal withdrawal for students.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1491
diff changeset
   536
  @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
   537
  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
   538
               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
   539
    """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
   540
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   541
    For params see base.View.public().
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   542
    """
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   543
1482
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   544
    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
   545
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   546
    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
   547
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   548
    filter = {'scope': student_entity.scope,
1482
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   549
              'status': 'active'}
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   550
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   551
    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
   552
    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
   553
        '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
   554
    list_params['list_action'] = (redirects.getStudentProposalRedirect,
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2150
diff changeset
   555
        {'student_key': student_entity.key().id_or_name(),
1482
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   556
            '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
   557
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   558
    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
   559
                     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
   560
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   561
  @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
   562
  @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
   563
  def listSelf(self, request, access_type,
2094
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   564
               page_name=None, params=None, **kwargs):
1639
170ac4ca078d Fix too long lines in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1620
diff changeset
   565
    """Lists all proposals from the current logged-in user 
170ac4ca078d Fix too long lines in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1620
diff changeset
   566
       for the given student.
1482
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   567
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   568
    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
   569
    """
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   570
2094
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   571
    context = {}
1482
5229a40d4792 Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1469
diff changeset
   572
    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
   573
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   574
    filter = {'scope' : student_entity,
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   575
              'status': ['new', 'pending', 'accepted', 'rejected']}
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   576
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   577
    list_params = params.copy()
2098
6557b0b1305f Fix too long line in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2096
diff changeset
   578
    list_params['list_description'] = \
6557b0b1305f Fix too long line in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2096
diff changeset
   579
        'List of my %(name_plural)s.' % list_params
1839
92b28d1bf2f5 Added example and help text to clarify the use of some fields on the proposal ranking.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1838
diff changeset
   580
    list_params['list_action'] = (redirects.getPublicRedirect, list_params)
1469
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   581
2094
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   582
    valid_list = lists.getListContent(
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   583
        request, list_params, filter, idx=0)
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   584
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   585
    ip_params = list_params.copy() # ineligible proposals
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   586
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   587
    description = ugettext('List of my ineligible/withdrawn %s.') % (
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   588
        ip_params['name_plural'])
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   589
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   590
    ip_params['list_description'] = description
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   591
    ip_params['list_action'] = (redirects.getPublicRedirect, ip_params)
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   592
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   593
    filter = {'scope' : student_entity,
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   594
              'status': 'invalid'}
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   595
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   596
    ip_list = lists.getListContent(
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   597
        request, ip_params, filter, idx=1, need_content=True)
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   598
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   599
    contents = []
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   600
    # fill contents with all the needed lists
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   601
    contents.append(valid_list)
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   602
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   603
    if ip_list != None:
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   604
      contents.append(ip_list)
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   605
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   606
    # call the _list method from base to display the list
8c0531c9870d Allow students to see and comment on withdrawn and ineligible proposals, hide withdraw button for those proposals.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2092
diff changeset
   607
    return self._list(request, list_params, contents, page_name, context)
1469
d69b00439d59 Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1467
diff changeset
   608
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   609
  @decorators.merge_params
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   610
  @decorators.check_access
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   611
  def review(self, request, access_type,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   612
             page_name=None, params=None, **kwargs):
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   613
    """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
   614
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   615
       For Args see base.View.public().
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   616
    """
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   617
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   618
    try:
1639
170ac4ca078d Fix too long lines in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1620
diff changeset
   619
      entity = self._logic.getFromKeyFieldsOr404(kwargs)
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   620
    except out_of_band.Error, error:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   621
      return helper.responses.errorResponse(
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   622
          error, request, template=params['error_public'])
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   623
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   624
    # get the context for this webpage
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   625
    context = responses.getUniversalContext(request)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   626
    responses.useJavaScript(context, params['js_uses_all'])
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   627
    context['page_name'] = '%s "%s" from %s' % (page_name, entity.title,
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   628
                                                entity.scope.name())
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   629
    context['entity'] = entity
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   630
    context['entity_type'] = params['name']
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   631
    context['entity_type_url'] = params['url_name']
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   632
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   633
    # get the roles important for reviewing an application
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   634
    filter = {'user': user_logic.logic.getForCurrentAccount(),
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   635
        'scope': entity.org,
1620
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   636
        'status': 'active'}
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   637
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   638
    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
   639
    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
   640
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   641
    # decide which form to use
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   642
    if org_admin_entity:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   643
      form = params['admin_review_form']
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   644
    else:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   645
      form = params['mentor_review_form']
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   646
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   647
    if request.method == 'POST':
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   648
      return self.reviewPost(request, context, params, entity,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   649
                             form, org_admin_entity, mentor_entity, **kwargs)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   650
    else:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   651
      # request.method == 'GET'
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   652
      return self.reviewGet(request, context, params, entity,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   653
                            form, org_admin_entity, mentor_entity, **kwargs)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   654
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   655
  def reviewPost(self, request, context, params, entity, form,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   656
                 org_admin, mentor, **kwargs):
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   657
    """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
   658
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   659
    Args:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   660
        entity: the student proposal entity
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   661
        form: the form to use in this view
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   662
        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
   663
        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
   664
        rest: see base.View.public()
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   665
    """
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   666
    # populate the form using the POST data
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   667
    form = form(request.POST)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   668
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   669
    if not form.is_valid():
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   670
      # return the invalid form response
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   671
      # get all the extra information that should be in the context
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   672
      review_context = self._getDefaultReviewContext(entity, org_admin, mentor)
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   673
      context = dicts.merge(context, review_context)
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   674
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   675
      return self._constructResponse(request, entity=entity, context=context,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   676
          form=form, params=params, template=params['review_template'])
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   677
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   678
    fields = form.cleaned_data
1787
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   679
    is_public = fields['public']
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   680
    comment = fields['comment']
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   681
    given_score = int(fields['score'])
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   682
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   683
    if org_admin:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   684
      # 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
   685
      self._adjustMentor(entity, fields['mentor'])
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   686
      reviewer = org_admin
1787
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   687
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   688
      # try to see if the rank is given and adjust the given_score if needed
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   689
      rank = fields['rank']
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   690
      if rank:
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   691
        ranker = self._logic.getRankerFor(entity)
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   692
        # if a very high rank is filled in use the highest 
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   693
        # one that returns a score
1787
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   694
        rank = min(ranker.TotalRankedScores(), rank)
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   695
        # ranker uses zero-based ranking
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   696
        score_and_rank = ranker.FindScore(rank-1)
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   697
        # get the score at the requested rank
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   698
        score_at_rank = score_and_rank[0][0]
b623d96bc830 Organization admins can now put a Student Proposal at a specific rank.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1779
diff changeset
   699
        # calculate the score that should be given to end up at the given rank
2150
5c125051252e When ranking, put them at or above the given rank
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2144
diff changeset
   700
        # give +1 to make sure that in the case of a tie they end up top
5c125051252e When ranking, put them at or above the given rank
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2144
diff changeset
   701
        given_score = score_at_rank - entity.score + 1
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   702
    else:
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   703
      # might be None (if Host or Developer is commenting)
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   704
      reviewer = mentor
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   705
2008
33c7bd727f16 Placing a public review via the review interface now also triggers the status change to pending.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2006
diff changeset
   706
    # store the properties to update the proposal with
33c7bd727f16 Placing a public review via the review interface now also triggers the status change to pending.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2006
diff changeset
   707
    properties = {}
33c7bd727f16 Placing a public review via the review interface now also triggers the status change to pending.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2006
diff changeset
   708
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   709
    if reviewer and (not is_public) and (given_score is not 0):
1620
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   710
      # if it is not a public comment and it's made by a member of the
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   711
      # organization we update the score of the proposal
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   712
      new_score = given_score + entity.score
1620
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   713
      properties = {'score': new_score}
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   714
2008
33c7bd727f16 Placing a public review via the review interface now also triggers the status change to pending.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2006
diff changeset
   715
    if comment or (given_score is not 0):
1620
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   716
      # 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
   717
      if entity.status == 'new':
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   718
        properties['status'] = 'pending'
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   719
2008
33c7bd727f16 Placing a public review via the review interface now also triggers the status change to pending.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2006
diff changeset
   720
      # create the review entity
33c7bd727f16 Placing a public review via the review interface now also triggers the status change to pending.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2006
diff changeset
   721
      self._createReviewFor(entity, reviewer, comment, given_score, is_public)
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   722
2008
33c7bd727f16 Placing a public review via the review interface now also triggers the status change to pending.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2006
diff changeset
   723
    if properties.values():
33c7bd727f16 Placing a public review via the review interface now also triggers the status change to pending.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2006
diff changeset
   724
      # there is something to update
33c7bd727f16 Placing a public review via the review interface now also triggers the status change to pending.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2006
diff changeset
   725
      self._logic.updateEntityProperties(entity, properties)
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   726
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   727
    # redirect to the same page
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   728
    return http.HttpResponseRedirect('')
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   729
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   730
  def reviewGet(self, request, context, params, entity, form,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   731
                 org_admin, mentor, **kwargs):
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   732
    """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
   733
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   734
    Args:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   735
        entity: the student proposal entity
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   736
        form: the form to use in this view
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   737
        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
   738
        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
   739
        rest: see base.View.public()
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   740
    """
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   741
1883
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   742
    from soc.logic.models.review_follower import logic as review_follower_logic
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   743
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   744
    get_dict = request.GET
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   745
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   746
    # check if the current user is a mentor and wants 
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   747
    # to change his role for this app
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   748
    choice = get_dict.get('mentor')
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   749
    if mentor and choice:
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   750
      self._adjustPossibleMentors(entity, mentor, choice)
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   751
2091
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   752
    ineligible = get_dict.get('ineligible')
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   753
    
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   754
    if org_admin:
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   755
      reviewer = org_admin
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   756
    elif mentor:
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   757
      reviewer = mentor
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   758
    
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   759
    if (org_admin or mentor) and ineligible != None:
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   760
      ineligible = int(ineligible)
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   761
      if ineligible == 1:
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   762
        # mark the proposal invalid and return to the list
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   763
        properties = {'status': 'invalid'}
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   764
        self._logic.updateEntityProperties(entity, properties)
1883
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   765
2091
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   766
        redirect = redirects.getListProposalsRedirect(entity.org,
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   767
                                                      {'url_name': 'org'})
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   768
        comment = "Marked Student Proposal as Ineligible."
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   769
        self._createReviewFor(entity, reviewer, comment, is_public=False)
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   770
        return http.HttpResponseRedirect(redirect)
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   771
      elif ineligible == 0:
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   772
        # mark the proposal as new and return to the list
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   773
        properties = {'status': 'new'}
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   774
        self._logic.updateEntityProperties(entity, properties)
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   775
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   776
        redirect = redirects.getListProposalsRedirect(entity.org,
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   777
                                                      {'url_name': 'org'})
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   778
        comment = "Marked Student Proposal as Eligible."
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   779
        self._createReviewFor(entity, reviewer, comment, is_public=False)
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   780
        return http.HttpResponseRedirect(redirect)
1883
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   781
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   782
    # check if we should change the subscription state for the current user
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   783
    public_subscription = None
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   784
    private_subscription = None
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   785
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   786
    if get_dict.get('public_subscription') and (
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   787
      get_dict['public_subscription'] in ['on', 'off']):
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   788
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   789
      public_subscription = get_dict['public_subscription'] == 'on'
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   790
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   791
    if get_dict.get('private_subscription') and (
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   792
      get_dict['private_subscription'] in ['on', 'off']):
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   793
      private_subscription = get_dict['private_subscription'] == 'on'
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   794
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   795
    if public_subscription != None or private_subscription != None:
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   796
      # get the current user
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   797
      user_entity = user_logic.logic.getForCurrentAccount()
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   798
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   799
      # create the fields that should be in the ReviewFollower entity
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   800
      fields = {'link_id': user_entity.link_id,
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   801
                'scope': entity,
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2150
diff changeset
   802
                'scope_path': entity.key().id_or_name(),
1883
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   803
                'user': user_entity
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   804
               }
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   805
      # get the keyname for the ReviewFollower entity
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   806
      key_name = review_follower_logic.getKeyNameFromFields(fields)
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   807
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   808
      # determine which subscription properties we should change
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   809
      if public_subscription != None:
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   810
        fields['subscribed_public'] = public_subscription
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   811
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   812
      if private_subscription != None:
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   813
        fields['subscribed_private'] = private_subscription
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   814
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   815
      # update the ReviewFollower
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   816
      review_follower_logic.updateOrCreateFromKeyName(fields, key_name)
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   817
1620
45f4e9cd9100 Added access check to student_proposal review.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1613
diff changeset
   818
    # 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
   819
    initial = {'score': 0}
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   820
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   821
    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
   822
      # 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
   823
      initial['mentor'] = entity.mentor.link_id
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   824
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   825
    context['form'] = form(initial)
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   826
2051
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   827
    # create the special form for mentors
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   828
    comment_public = ['public', 'comment']
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   829
    comment_private = ['score']
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   830
    comment_admin = ['rank', 'mentor']
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   831
    class FilterForm(object):
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   832
      """Helper class used for form filtering.
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   833
      """
2051
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   834
      def __init__(self, form, fields):
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   835
        self.__form = form
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   836
        self.__fields = fields
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   837
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   838
      @property
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   839
      def fields(self):
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   840
        """Property that returns all fields as dictionary."""
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   841
        fields = self.__form.fields.iteritems()
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   842
        return dict([(k, i) for k, i in fields if k in self.__fields])
2051
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   843
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   844
      def __iter__(self):
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   845
        for field in self.__form:
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   846
          if field.name not in self.__fields:
2051
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   847
            continue
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
   848
          yield field
2051
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   849
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   850
      _marker = []
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   851
      def __getattr__(self, key, default=_marker):
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   852
        if default is self._marker:
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   853
          return getattr(self.__form, key)
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   854
        else:
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   855
          return getattr(self.__form, key, default)
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   856
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   857
    context['form'] = form(initial)
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   858
    context['comment_public'] = FilterForm(context['form'], comment_public)
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   859
    context['comment_private'] = FilterForm(context['form'], comment_private)
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   860
    context['comment_admin'] = FilterForm(context['form'], comment_admin)
cecbef1289a5 Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2041
diff changeset
   861
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   862
    # get all the extra information that should be in the context
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   863
    review_context = self._getDefaultReviewContext(entity, org_admin, mentor)
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   864
    context = dicts.merge(context, review_context)
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   865
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   866
    template = params['review_template']
1666
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   867
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   868
    return responses.respond(request, template, context=context)
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   869
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   870
  def _getDefaultReviewContext(self, entity, org_admin,
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   871
                               mentor):
1758
e035f81d367b Some minor style fixes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1752
diff changeset
   872
    """Returns the default context for the review page.
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   873
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   874
    Args:
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   875
      entity: Student Proposal entity
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   876
      org_admin: org admin entity for the current user/proposal (iff available)
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   877
      mentor: mentor entity for the current user/proposal (iff available)
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   878
    """
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   879
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   880
    from soc.logic.models.review import logic as review_logic
1883
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   881
    from soc.logic.models.review_follower import logic as review_follower_logic
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   882
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   883
    context = {}
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   884
1898
7f18e83a129f Hook up the new template tag for StudentProposal reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1895
diff changeset
   885
    context['student'] = entity.scope
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   886
    context['student_name'] = entity.scope.name()
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   887
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   888
    if entity.mentor:
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   889
      context['mentor_name'] = entity.mentor.name()
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   890
    else:
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   891
      context['mentor_name'] = "No mentor assigned"
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   892
1666
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   893
    # set the possible mentors in the context
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   894
    possible_mentors = entity.possible_mentors
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   895
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   896
    if not possible_mentors:
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   897
      context['possible_mentors'] = "None"
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   898
    else:
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   899
      mentor_names = []
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   900
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   901
      for mentor_key in possible_mentors:
2185
09ca8e661728 Fix too long line and redefining variable 'review' from outer scope in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2179
diff changeset
   902
        possible_mentor = mentor_logic.logic.getFromKeyName(
09ca8e661728 Fix too long line and redefining variable 'review' from outer scope in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2179
diff changeset
   903
            mentor_key.id_or_name())
2179
efc3a50a81ef Undid superfluas replacement of .name() with .name_or_id()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2177
diff changeset
   904
        mentor_names.append(possible_mentor.name())
1666
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   905
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   906
      context['possible_mentors'] = ', '.join(mentor_names)
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   907
1741
0da1285f5bc0 Public reviews are now shown on the public page for the student proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1715
diff changeset
   908
    # order the reviews by ascending creation date
0da1285f5bc0 Public reviews are now shown on the public page for the student proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1715
diff changeset
   909
    order = ['created']
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   910
1741
0da1285f5bc0 Public reviews are now shown on the public page for the student proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1715
diff changeset
   911
    # get the public reviews
2173
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   912
    public_reviews = review_logic.getReviewsForEntity(entity,
1741
0da1285f5bc0 Public reviews are now shown on the public page for the student proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1715
diff changeset
   913
        is_public=True, order=order)
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   914
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   915
    # get the private reviews
2173
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   916
    private_reviews = review_logic.getReviewsForEntity(entity,
1741
0da1285f5bc0 Public reviews are now shown on the public page for the student proposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1715
diff changeset
   917
        is_public=False, order=order)
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   918
2173
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   919
    # store the reviews in the context
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   920
    context['public_reviews'] = public_reviews
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   921
    context['private_reviews'] = private_reviews
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   922
2174
19ed1c42e836 Added a warning message to alert the user that reviews are not editable.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2173
diff changeset
   923
    # create a summary of all the private reviews
2173
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   924
    review_summary = {}
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   925
2185
09ca8e661728 Fix too long line and redefining variable 'review' from outer scope in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2179
diff changeset
   926
    for private_review in private_reviews:
2174
19ed1c42e836 Added a warning message to alert the user that reviews are not editable.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2173
diff changeset
   927
      # make sure there is a reviewer
2185
09ca8e661728 Fix too long line and redefining variable 'review' from outer scope in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2179
diff changeset
   928
      reviewer = private_review.reviewer
2173
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   929
      if not reviewer:
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   930
        continue
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   931
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   932
      reviewer_key = reviewer.key()
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   933
      reviewer_summary = review_summary.get(reviewer_key)
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   934
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   935
      if reviewer_summary:
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   936
        # we already have something on file for this reviewer
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   937
        old_total_score = reviewer_summary['total_score']
2185
09ca8e661728 Fix too long line and redefining variable 'review' from outer scope in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2179
diff changeset
   938
        reviewer_summary['total_score'] = old_total_score + private_review.score
2173
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   939
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   940
        old_total_comments = reviewer_summary['total_comments']
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   941
        reviewer_summary['total_comments'] = old_total_comments + 1
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   942
      else:
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   943
        review_summary[reviewer_key] = {
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   944
            'name': reviewer.name(),
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   945
            'total_comments': 1,
2185
09ca8e661728 Fix too long line and redefining variable 'review' from outer scope in soc.views.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2179
diff changeset
   946
            'total_score': private_review.score}
2173
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   947
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   948
    context['review_summary'] = review_summary
27731db8ab1e Added overview of private reviews to the Student Proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2160
diff changeset
   949
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   950
    # which button should we show to the mentor?
1666
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   951
    if mentor:
2091
dd3eb2770205 Make "Mark as Ineligible" reversable and make this feature available for mentors too.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2076
diff changeset
   952
      context['is_mentor'] = True
1666
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   953
      if mentor.key() in possible_mentors:
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   954
        # show "No longer willing to mentor"
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   955
        context['remove_me_as_mentor'] = True
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   956
      else:
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   957
        # show "I am willing to mentor"
cdb7e5581694 Mentor buttons only show up depending on if you are already on the possible mentors list.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1639
diff changeset
   958
        context['add_me_as_mentor'] = True
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   959
1779
cdd11aa8dbc7 Org admins can mark a StudentProposal as invalid if they for any reason find it ineligible.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1758
diff changeset
   960
    if org_admin:
cdd11aa8dbc7 Org admins can mark a StudentProposal as invalid if they for any reason find it ineligible.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1758
diff changeset
   961
      context['is_org_admin'] = True
cdd11aa8dbc7 Org admins can mark a StudentProposal as invalid if they for any reason find it ineligible.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1758
diff changeset
   962
1883
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   963
    user_entity = user_logic.logic.getForCurrentAccount()
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   964
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   965
    # check if the current user is subscribed to public or private reviews
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   966
    fields = {'scope': entity,
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   967
              'user': user_entity,}
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   968
    follower_entity = review_follower_logic.getForFields(fields, unique=True)
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   969
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   970
    if follower_entity:
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   971
      context['is_subscribed_public'] =  follower_entity.subscribed_public
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   972
      context['is_subscribed_private'] = follower_entity.subscribed_private
ce564c03d90a The StudentProposal review view now also allow you to subscribe to public/private reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1882
diff changeset
   973
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
   974
    return context
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   975
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   976
  def _adjustPossibleMentors(self, entity, mentor, choice):
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   977
    """Adjusts the possible mentors list for a proposal.
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   978
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   979
    Args:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   980
      entity: Student Proposal entity
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   981
      mentor: Mentor entity
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   982
      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
   983
    """
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   984
    possible_mentors = entity.possible_mentors
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   985
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   986
    if choice == '1':
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   987
      # 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
   988
      if mentor.key() not in possible_mentors:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   989
        possible_mentors.append(mentor.key())
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   990
        fields = {'possible_mentors': possible_mentors}
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   991
        self._logic.updateEntityProperties(entity, fields)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   992
    elif choice == '0':
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   993
      # remove the mentor from the possible mentors list
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   994
      if mentor.key() in possible_mentors:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   995
        possible_mentors.remove(mentor.key())
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   996
        fields = {'possible_mentors': possible_mentors}
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   997
        self._logic.updateEntityProperties(entity, fields)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   998
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
   999
  def _adjustMentor(self, entity, mentor_id):
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1000
    """Changes the mentor to the given link_id.
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1001
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1002
    Args:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1003
      entity: Student Proposal entity
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1004
      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
  1005
                 Iff not given then removes the assigned mentor
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1006
    """
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1007
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1008
    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
  1009
      # no need to change
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1010
      return
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1011
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1012
    if mentor_id:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1013
      # try to locate the mentor
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1014
      fields = {'link_id': mentor_id,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1015
                'scope': entity.org,
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1016
                'status': 'active'}
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1017
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1018
      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
  1019
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1020
      if not mentor_entity:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1021
        # no mentor found, do not update
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1022
        return
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1023
    else:
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1024
      # reset to None
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1025
      mentor_entity = None
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1026
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1027
    # update the proposal
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1028
    properties = {'mentor': mentor_entity}
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1029
    self._logic.updateEntityProperties(entity, properties)
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1030
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
  1031
  def _createReviewFor(self, entity, reviewer, comment, 
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
  1032
                       score=0, is_public=True):
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
  1033
    """Creates a review for the given proposal and sends 
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
  1034
       out a message to all followers.
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1035
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1036
    Args:
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1037
      entity: Student Proposal entity for which the review should be created
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1038
      reviewer: A role entity of the reviewer (if possible, else None)
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1039
      comment: The textual contents of the review
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1040
      score: The score of the review (only used if the review is not public)
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1041
      is_public: Determines if the review is a public review
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1042
    """
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1043
1894
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1044
    from soc.logic.helper import notifications as notifications_helper
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1045
    from soc.logic.models.review import logic as review_logic
1894
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1046
    from soc.logic.models.review_follower import logic as review_follower_logic
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1047
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1048
    # create the fields for the review entity
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2051
diff changeset
  1049
    fields = {'link_id': 't%i' % (int(time.time()*100)),
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1050
        'scope': entity,
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2150
diff changeset
  1051
        'scope_path': entity.key().id_or_name(),
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1052
        'author': user_logic.logic.getForCurrentAccount(),
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1053
        'content': comment,
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1054
        'is_public': is_public,
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1055
        'reviewer': reviewer
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1056
        }
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1057
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1058
    # add the given score if the review is not public
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1059
    if not is_public:
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1060
      fields['score'] = score
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1061
1894
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1062
    # create a new Review
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1063
    key_name = review_logic.getKeyNameFromFields(fields)
1894
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1064
    review_entity = review_logic.updateOrCreateFromKeyName(fields, key_name)
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1065
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1066
    # get all followers
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1067
    fields = {'scope': entity}
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1068
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1069
    if is_public:
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1070
      fields['subscribed_public'] = True
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1071
    else:
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1072
      fields['subscribed_private'] = True
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1073
1894
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1074
    followers = review_follower_logic.getForFields(fields)
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1075
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1076
    if is_public:
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1077
      # redirect to public page
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1078
      redirect_url = redirects.getPublicRedirect(entity, self._params)
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1079
    else:
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1080
      # redirect to review page
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1081
      redirect_url = redirects.getReviewRedirect(entity, self._params)
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1082
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1083
    for follower in followers:
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1084
      # sent to every follower except the reviewer
1895
564b066c313c Notifications will not be sent out to the reviewer.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1894
diff changeset
  1085
      if follower.user.key() != review_entity.author.key():
1894
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1086
        notifications_helper.sendNewReviewNotification(follower.user,
da52a47b5a6b Send out a message on a new StudentProposal review to all followers.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1890
diff changeset
  1087
            review_entity, entity.title, redirect_url)
1715
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1088
3ec1a9518452 Added the review capability to the student_proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1666
diff changeset
  1089
1426
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
  1090
view = View()
dc3a7f618b68 Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
  1091
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
  1092
admin = decorators.view(view.admin)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
  1093
apply = decorators.view(view.apply)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
  1094
create = decorators.view(view.create)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
  1095
delete = decorators.view(view.delete)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
  1096
edit = decorators.view(view.edit)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
  1097
list = decorators.view(view.list)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
  1098
list_orgs = decorators.view(view.listOrgs)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
  1099
list_self = decorators.view(view.listSelf)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
  1100
public = decorators.view(view.public)
1613
59e5cc89e509 Added student proposal review page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1584
diff changeset
  1101
review = decorators.view(view.review)
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
  1102
export = decorators.view(view.export)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1569
diff changeset
  1103
pick = decorators.view(view.pick)