app/soc/views/models/student_project.py
author Lennard de Rijk <ljvderijk@gmail.com>
Thu, 30 Jul 2009 10:49:19 +0200
changeset 2691 f8e0a007d99b
parent 2689 18d8486fd411
child 2693 7bda04a2b6c3
permissions -rw-r--r--
Pre-storing the information for setStudentProjectSurveyInfo. This is a rename from getStudentProjectSurveyInfo because it now sets the info directly in the list content. This is done because Django queries the wrapper method every time the info is called in the template.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Views for Student Project.
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
    25
import logging
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
import time
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
from django import forms
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
    29
from django import http
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
from soc.logic import cleaning
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
from soc.logic import dicts
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
from soc.logic.models import mentor as mentor_logic
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    34
from soc.logic.models.organization import logic as org_logic
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    35
from soc.logic.models.org_admin import logic as org_admin_logic
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
from soc.logic.models import student as student_logic
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    37
from soc.logic.models.student_project import logic as project_logic
2117
f1a1a75cdb00 Add missing imports, remove unsused imports, fix too long lines and some other style fixes in soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2115
diff changeset
    38
from soc.views import out_of_band
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
from soc.views.helper import access
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
from soc.views.helper import decorators
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    41
from soc.views.helper import dynaform
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    42
from soc.views.helper import forms as forms_helper
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    43
from soc.views.helper import lists
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    44
from soc.views.helper import params as params_helper
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
from soc.views.helper import redirects
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    46
from soc.views.helper import responses
2125
c24e8423cd1a Added public info as TinyMCE to the edit pages.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2122
diff changeset
    47
from soc.views.helper import widgets
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
from soc.views.models import base
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
from soc.views.models import organization as org_view
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
import soc.logic.models.student_project
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
class View(base.View):
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
  """View methods for the Student Project model.
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
  """
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
  def __init__(self, params=None):
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
    """Defines the fields and methods required for the base View class
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
    to provide the user with list, public, create, edit and delete views.
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
    Params:
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    63
      params: a dict with params for this View
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
    """
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
    rights = access.Checker(params)
2241
5e5b7f5d9a89 Allow anyone to see student projects
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2183
diff changeset
    67
    rights['any_access'] = ['allow']
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    rights['create'] = ['checkIsDeveloper']
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1936
diff changeset
    69
    rights['edit'] = ['checkIsDeveloper']
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
    rights['delete'] = ['checkIsDeveloper']
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    71
    rights['show'] = ['allow']
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
    rights['list'] = ['checkIsDeveloper']
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    73
    rights['manage'] = [('checkHasActiveRoleForScope',
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    74
                         org_admin_logic),
2573
f09f317769c4 Changed the StudentProject model to handle a dynamic amount of GradeRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2360
diff changeset
    75
        ('checkStudentProjectHasStatus', [['accepted']])]
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    76
    rights['manage_overview'] = [('checkHasActiveRoleForScope',
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    77
                         org_admin_logic)]
2360
e389d26949db Style and pylint fixes in Melange modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2330
diff changeset
    78
    # TODO: lack of better name here!
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    79
    rights['st_edit'] = ['checkIsMyStudentProject',
2152
3c3f0cd9873d Brown paper bag fix for Student Project Manage and Edit access check.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2146
diff changeset
    80
        ('checkStudentProjectHasStatus',
2573
f09f317769c4 Changed the StudentProject model to handle a dynamic amount of GradeRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2360
diff changeset
    81
            [['accepted', 'completed']])
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    82
        ]
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    83
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    84
    new_params = {}
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    85
    new_params['logic'] = soc.logic.models.student_project.logic
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    86
    new_params['rights'] = rights
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    87
    new_params['name'] = "Student Project"
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    88
    new_params['url_name'] = "student_project"
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    89
    new_params['sidebar_grouping'] = 'Students'
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    90
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    91
    new_params['scope_view'] = org_view
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
    new_params['scope_redirect'] = redirects.getCreateRedirect
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    93
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    94
    new_params['no_create_with_key_fields'] = True
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    95
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    96
    new_params['extra_dynaexclude'] = ['program', 'status', 'link_id',
2183
4e036dcc79ba Added additional_mentors property to StudentProject.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2177
diff changeset
    97
                                       'mentor', 'additional_mentors',
2637
0ae090b18a5e Excluded the new StudentProject failed_evaluations property from Forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2573
diff changeset
    98
                                       'student', 'passed_evaluations',
0ae090b18a5e Excluded the new StudentProject failed_evaluations property from Forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2573
diff changeset
    99
                                       'failed_evaluations']
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   100
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   101
    new_params['create_extra_dynaproperties'] = {
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   102
        'scope_path': forms.CharField(widget=forms.HiddenInput,
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   103
            required=True),
2125
c24e8423cd1a Added public info as TinyMCE to the edit pages.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2122
diff changeset
   104
        'public_info': forms.fields.CharField(required=True,
c24e8423cd1a Added public info as TinyMCE to the edit pages.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2122
diff changeset
   105
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   106
        'student_id': forms.CharField(label='Student Link ID',
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   107
            required=True),
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   108
        'mentor_id': forms.CharField(label='Mentor Link ID',
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   109
            required=True),
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   110
        'clean_abstract': cleaning.clean_content_length('abstract'),
2125
c24e8423cd1a Added public info as TinyMCE to the edit pages.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2122
diff changeset
   111
        'clean_public_info': cleaning.clean_html_content('public_info'),
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   112
        'clean_student': cleaning.clean_link_id('student'),
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   113
        'clean_mentor': cleaning.clean_link_id('mentor'),
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   114
        'clean_additional_info': cleaning.clean_url('additional_info'),
2122
b709f9d1566a Added feed_url to StudentProject.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2121
diff changeset
   115
        'clean_feed_url': cleaning.clean_feed_url,
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   116
        'clean': cleaning.validate_student_project('scope_path',
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   117
            'mentor_id', 'student_id')
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   118
        }
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   119
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   120
    new_params['edit_extra_dynaproperties'] = {
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   121
        'link_id': forms.CharField(widget=forms.HiddenInput),
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   122
        }
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   123
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   124
    patterns = [
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   125
        (r'^%(url_name)s/(?P<access_type>manage_overview)/%(scope)s$',
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   126
        'soc.views.models.%(module_name)s.manage_overview',
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   127
        'Overview of %(name_plural)s to Manage for'),
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   128
        (r'^%(url_name)s/(?P<access_type>manage)/%(key_fields)s$',
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   129
        'soc.views.models.%(module_name)s.manage',
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   130
        'Manage %(name)s'),
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   131
        (r'^%(url_name)s/(?P<access_type>st_edit)/%(key_fields)s$',
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   132
        'soc.views.models.%(module_name)s.st_edit',
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   133
        'Edit my %(name)s'),
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   134
    ]
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   135
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   136
    new_params['extra_django_patterns'] = patterns
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   137
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   138
    new_params['edit_template'] = 'soc/student_project/edit.html'
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   139
    new_params['manage_template'] = 'soc/student_project/manage.html'
2685
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2640
diff changeset
   140
    new_params['manage_overview_heading'] = \
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2640
diff changeset
   141
        'soc/student_project/list/heading_manage.html'
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2640
diff changeset
   142
    new_params['manage_overview_row'] = \
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2640
diff changeset
   143
        'soc/student_project/list/row_manage.html'
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   144
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   145
    params = dicts.merge(params, new_params)
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   146
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   147
    super(View, self).__init__(params=params)
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   148
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   149
    # create the form that students will use to edit their projects
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   150
    dynaproperties = {
2125
c24e8423cd1a Added public info as TinyMCE to the edit pages.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2122
diff changeset
   151
        'public_info': forms.fields.CharField(required=True,
c24e8423cd1a Added public info as TinyMCE to the edit pages.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2122
diff changeset
   152
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   153
        'clean_abstract': cleaning.clean_content_length('abstract'),
2125
c24e8423cd1a Added public info as TinyMCE to the edit pages.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2122
diff changeset
   154
        'clean_public_info': cleaning.clean_html_content('public_info'),
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   155
        'clean_additional_info': cleaning.clean_url('additional_info'),
2122
b709f9d1566a Added feed_url to StudentProject.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2121
diff changeset
   156
        'clean_feed_url': cleaning.clean_feed_url,
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   157
        }
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   158
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   159
    student_edit_form = dynaform.newDynaForm(
2177
e2c193e1f631 Do not rely on dicts.merge to change target
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2154
diff changeset
   160
        dynabase = self._params['dynabase'],
e2c193e1f631 Do not rely on dicts.merge to change target
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2154
diff changeset
   161
        dynamodel = self._params['logic'].getModel(),
e2c193e1f631 Do not rely on dicts.merge to change target
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2154
diff changeset
   162
        dynaexclude = self._params['create_dynaexclude'],
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   163
        dynaproperties = dynaproperties,
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   164
    )
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   165
2177
e2c193e1f631 Do not rely on dicts.merge to change target
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2154
diff changeset
   166
    self._params['student_edit_form'] = student_edit_form
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   167
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   168
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   169
  def _editGet(self, request, entity, form):
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   170
    """See base.View._editGet().
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   171
    """
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   172
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   173
    form.fields['link_id'].initial = entity.link_id
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   174
    form.fields['student_id'].initial = entity.student.link_id
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   175
    form.fields['mentor_id'].initial = entity.mentor.link_id
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   176
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   177
    return super(View, self)._editGet(request, entity, form)
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   178
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   179
  def _editPost(self, request, entity, fields):
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   180
    """See base.View._editPost().
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   181
    """
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   182
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   183
    if not entity:
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1936
diff changeset
   184
      fields['link_id'] = 't%i' % (int(time.time()*100))
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   185
    else:
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   186
      fields['link_id'] = entity.link_id
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   187
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   188
    # fill in the scope via call to super
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   189
    super(View, self)._editPost(request, entity, fields)
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   190
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   191
    # editing a project so set the program, student and mentor field
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   192
    if entity:
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   193
      organization = entity.scope
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   194
    else:
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   195
      organization = fields['scope']
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   196
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   197
    fields['program'] = organization.scope
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   198
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   199
    filter = {'scope': fields['program'],
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   200
              'link_id': fields['student_id']}
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   201
    fields['student'] = student_logic.logic.getForFields(filter, unique=True)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   202
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   203
    filter = {'scope': organization,
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   204
              'link_id': fields['mentor_id'],
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   205
              'status': 'active'}
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   206
    fields['mentor'] = mentor_logic.logic.getForFields(filter, unique=True)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   207
2280
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   208
  def _public(self, request, entity, context):
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   209
    """Adds the names of all additional mentors to the context.
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   210
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   211
    For params see base.View._public()
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   212
    """
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   213
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   214
    additional_mentors = entity.additional_mentors
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   215
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   216
    if not additional_mentors:
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   217
      context['additional_mentors'] = []
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   218
    else:
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   219
      mentor_names = []
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   220
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   221
      for mentor_key in additional_mentors:
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   222
        additional_mentor = mentor_logic.logic.getFromKeyName(
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   223
            mentor_key.id_or_name())
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   224
        mentor_names.append(additional_mentor.name())
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   225
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   226
      context['additional_mentors'] = ', '.join(mentor_names)
157f6b8de010 Show all Co-Mentors on the Student Project public page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2279
diff changeset
   227
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   228
  @decorators.merge_params
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   229
  @decorators.check_access
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   230
  def manage(self, request, access_type,
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   231
             page_name=None, params=None, **kwargs):
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   232
    """View that allows Organization Admins to manage their Student Projects.
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   233
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   234
    For params see base.View().public()
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   235
    """
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   236
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   237
    try:
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   238
      entity = self._logic.getFromKeyFieldsOr404(kwargs)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   239
    except out_of_band.Error, error:
2117
f1a1a75cdb00 Add missing imports, remove unsused imports, fix too long lines and some other style fixes in soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2115
diff changeset
   240
      return responses.errorResponse(
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   241
          error, request, template=params['error_public'])
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   242
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   243
    get_dict = request.GET
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   244
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   245
    if 'remove' in get_dict:
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   246
      # get the mentor to remove
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   247
      fields = {'link_id': get_dict['remove'],
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   248
                'scope': entity.scope}
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   249
      mentor = mentor_logic.logic.getForFields(fields, unique=True)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   250
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   251
      additional_mentors = entity.additional_mentors
2360
e389d26949db Style and pylint fixes in Melange modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2330
diff changeset
   252
      # pylint: disable-msg=E1103
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   253
      if additional_mentors and mentor.key() in additional_mentors:
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   254
        # remove the mentor from the additional mentors list
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   255
        additional_mentors.remove(mentor.key())
2281
a702d92a57a6 Style fixes in app.soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2280
diff changeset
   256
        fields = {'additional_mentors': additional_mentors}
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   257
        project_logic.updateEntityProperties(entity, fields)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   258
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   259
      # redirect to the same page without GET arguments
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   260
      redirect = request.path
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   261
      return http.HttpResponseRedirect(redirect)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   262
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   263
    template = params['manage_template']
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   264
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   265
    # get the context for this webpage
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   266
    context = responses.getUniversalContext(request)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   267
    responses.useJavaScript(context, params['js_uses_all'])
2117
f1a1a75cdb00 Add missing imports, remove unsused imports, fix too long lines and some other style fixes in soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2115
diff changeset
   268
    context['page_name'] = "%s '%s' from %s" % (page_name, entity.title,
f1a1a75cdb00 Add missing imports, remove unsused imports, fix too long lines and some other style fixes in soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2115
diff changeset
   269
                                                entity.student.name())
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   270
    context['entity'] = entity
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   271
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   272
    # get all mentors for this organization
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   273
    fields = {'scope': entity.scope,
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   274
              'status': 'active'}
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   275
    mentors = mentor_logic.logic.getForFields(fields)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   276
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   277
    choices = [(mentor.link_id,'%s (%s)' %(mentor.name(), mentor.link_id))
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   278
                  for mentor in mentors]
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   279
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   280
    # create the form that org admins will use to reassign a mentor
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   281
    dynafields = [
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   282
        {'name': 'mentor_id',
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   283
         'base': forms.ChoiceField,
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   284
         'label': 'Primary Mentor',
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   285
         'required': True,
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   286
         'passthrough': ['required', 'choices', 'label'],
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   287
         'choices': choices,
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   288
        },]
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   289
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   290
    dynaproperties = params_helper.getDynaFields(dynafields)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   291
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   292
    mentor_edit_form = dynaform.newDynaForm(
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   293
        dynabase = params['dynabase'],
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   294
        dynaproperties = dynaproperties,
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   295
    )
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   296
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   297
    params['mentor_edit_form'] = mentor_edit_form
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   298
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   299
    additional_mentors = entity.additional_mentors
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   300
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   301
    # we want to show the names of the additional mentors in the context
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   302
    # therefore they need to be resolved to entities first
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   303
    additional_mentors_context = []
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   304
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   305
    for mentor_key in additional_mentors:
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   306
      mentor_entity = mentor_logic.logic.getFromKeyName(
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   307
          mentor_key.id_or_name())
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   308
      additional_mentors_context.append(mentor_entity)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   309
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   310
    context['additional_mentors'] = additional_mentors_context
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   311
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   312
    # all mentors who are not already an additional mentor or
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   313
    # the primary mentor are allowed to become an additional mentor
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   314
    possible_additional_mentors = [m for m in mentors if 
2281
a702d92a57a6 Style fixes in app.soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2280
diff changeset
   315
        (m.key() not in additional_mentors) 
a702d92a57a6 Style fixes in app.soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2280
diff changeset
   316
        and (m.key() != entity.mentor.key())]
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   317
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   318
    # create the information to be shown on the additional mentor form
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   319
    additional_mentor_choices = [
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   320
        (mentor.link_id,'%s (%s)' %(mentor.name(), mentor.link_id))
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   321
        for mentor in possible_additional_mentors]
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   322
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   323
    dynafields = [
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   324
        {'name': 'mentor_id',
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   325
         'base': forms.ChoiceField,
2279
e31414fd3b2a Changed Additional Mentors to Co-Mentors in the manage view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2278
diff changeset
   326
         'label': 'Co-Mentor',
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   327
         'required': True,
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   328
         'passthrough': ['required', 'choices', 'label'],
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   329
         'choices': additional_mentor_choices,
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   330
        },]
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   331
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   332
    dynaproperties = params_helper.getDynaFields(dynafields)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   333
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   334
    additional_mentor_form = dynaform.newDynaForm(
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   335
        dynabase = params['dynabase'],
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   336
        dynaproperties = dynaproperties,
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   337
    )
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   338
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   339
    params['additional_mentor_form'] = additional_mentor_form
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   340
2688
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   341
    context['evaluation_list'] = self._getEvaluationLists(request, params,
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   342
                                                          entity)
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   343
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   344
    if request.POST:
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   345
      return self.managePost(request, template, context, params, entity,
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   346
                             **kwargs)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   347
    else: #request.GET
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   348
      return self.manageGet(request, template, context, params, entity,
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   349
                            **kwargs)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   350
2688
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   351
  def _getEvaluationLists(self, request, params, entity):
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   352
    """Returns List Object containing the list to be shown on the Student 
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   353
    Project's manage page.
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   354
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   355
    This list contains all Surveys that have at least one record and will also 
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   356
    contain information about the presence (or absence) of a accompanying 
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   357
    record for the given Student Project.
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   358
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   359
    Args:
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   360
      request: Django HTTP Request Object
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   361
      params: the params dict for this View
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   362
      entity: a StudentProject entity for which the Surveys(Records) should be
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   363
              retrieved
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   364
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   365
    Returns:
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   366
      A List Object as specified by this method.
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   367
    """
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   368
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   369
    from soc.views.helper import list_info
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   370
    from soc.views.models.grading_project_survey import view as \
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   371
        grading_survey_view
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   372
    from soc.views.models.project_survey import view as project_survey_view
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   373
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   374
    fields = {'scope_path': entity.program.key().id_or_name()}
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   375
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   376
    # get the GradingProjectSurvey list
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   377
    gps_params = grading_survey_view.getParams().copy()
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   378
    gps_params['list_key_order'] = None
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   379
    gps_params['list_heading'] = gps_params['manage_student_project_heading']
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   380
    gps_params['list_row'] = gps_params['manage_student_project_row']
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   381
    gps_params['list_info'] = (
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   382
        list_info.getProjectSurveyInfoForProject(entity, gps_params), None)
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   383
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   384
    #list all surveys for this Project's Program
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   385
    fields['scope_path'] = entity.program.key().id_or_name()
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   386
    gps_params['list_description'] = \
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   387
        'List of all Mentor Evaluations for this Project'
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   388
    gps_params['list_action'] = None
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   389
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   390
    gps_list = lists.getListContent(
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   391
        request, gps_params, fields, idx=0)
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   392
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   393
    # get the ProjectSurvey list
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   394
    ps_params = project_survey_view.getParams().copy()
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   395
    ps_params['list_key_order'] = None
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   396
    ps_params['list_heading'] = ps_params['manage_student_project_heading']
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   397
    ps_params['list_row'] = ps_params['manage_student_project_row']
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   398
    ps_params['list_info'] = (
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   399
        list_info.getProjectSurveyInfoForProject(entity, ps_params), None)
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   400
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   401
    ps_params['list_description'] = \
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   402
        'List of all Student Evaluations for this Project'
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   403
    ps_params['list_action'] = None
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   404
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   405
    #list all surveys for this Project's Program
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   406
    fields['scope_path'] = entity.program.key().id_or_name()
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   407
    ps_list = lists.getListContent(
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   408
        request, ps_params, fields, idx=1)
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   409
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   410
    # store both lists in the content
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   411
    content = [gps_list, ps_list]
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   412
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   413
    for list in content:
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   414
      # remove all the surveys that have no records attached
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   415
      list['data'] = [i for i in list['data'] if
2689
18d8486fd411 Renamed hasAtLeastOneRecord to hasRecord.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2688
diff changeset
   416
                      list['logic'].hasRecord(i)]
2688
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   417
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   418
    # return the List Object with the filtered list content
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   419
    return soc.logic.lists.Lists(content)
dfe0439a0711 Added list of Surveys to the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   420
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   421
  def manageGet(self, request, template, context, params, entity, **kwargs):
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   422
    """Handles the GET request for the project's manage page.
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   423
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   424
    Args:
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   425
        template: the template used for this view
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   426
        entity: the student project entity
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   427
        rest: see base.View.public()
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   428
    """
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   429
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   430
    # populate form with the current mentor
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   431
    initial = {'mentor_id': entity.mentor.link_id}
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   432
    context['mentor_edit_form'] = params['mentor_edit_form'](initial=initial)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   433
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   434
    context['additional_mentor_form'] = params['additional_mentor_form']()
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   435
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   436
    return responses.respond(request, template, context)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   437
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   438
  def managePost(self, request, template, context, params, entity, **kwargs):
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   439
    """Handles the POST request for the project's manage page.
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   440
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   441
    Args:
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   442
        template: the template used for this view
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   443
        entity: the student project entity
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   444
        rest: see base.View.public()
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   445
    """
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   446
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   447
    post_dict = request.POST
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   448
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   449
    if 'set_mentor' in post_dict:
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   450
      form = params['mentor_edit_form'](post_dict)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   451
      return self._manageSetMentor(request, template, context, params, entity,
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   452
                                   form)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   453
    elif 'add_additional_mentor' in post_dict:
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   454
      form = params['additional_mentor_form'](post_dict)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   455
      return self._manageAddAdditionalMentor(request, template, context,
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   456
                                             params, entity, form)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   457
    else:
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   458
      # unexpected error return the normal page
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   459
      logging.warning('Unexpected POST data found')
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   460
      return self.manageGet(request, template, context, params, entity)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   461
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   462
  def _manageSetMentor(self, request, template, context, params, entity, form):
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   463
    """Handles the POST request for changing a Projects's mentor.
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   464
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   465
    Args:
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   466
        template: the template used for this view
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   467
        entity: the student project entity
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   468
        form: instance of the form used to set the mentor
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   469
        rest: see base.View.public()
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   470
    """
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   471
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   472
    if not form.is_valid():
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   473
      context['mentor_edit_form'] = form
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   474
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   475
      # add an a fresh additional mentors form
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   476
      context['additional_mentor_form'] = params['additional_mentor_form']()
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   477
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   478
      return responses.respond(request, template, context)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   479
2117
f1a1a75cdb00 Add missing imports, remove unsused imports, fix too long lines and some other style fixes in soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2115
diff changeset
   480
    _, fields = forms_helper.collectCleanedFields(form)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   481
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   482
    # get the mentor from the form
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   483
    fields = {'link_id': fields['mentor_id'],
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   484
              'scope': entity.scope,
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   485
              'status': 'active'}
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   486
    mentor = mentor_logic.logic.getForFields(fields, unique=True)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   487
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   488
    # update the project with the assigned mentor
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   489
    fields = {'mentor': mentor}
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   490
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   491
    additional_mentors = entity.additional_mentors
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   492
2360
e389d26949db Style and pylint fixes in Melange modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2330
diff changeset
   493
    # pylint: disable-msg=E1103
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   494
    if additional_mentors and mentor.key() in additional_mentors:
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   495
      # remove the mentor that is now becoming the primary mentor
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   496
      additional_mentors.remove(mentor.key())
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   497
      fields['additional_mentors'] = additional_mentors
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   498
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   499
    # update the project with the new mentor and possible 
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   500
    # new set of additional mentors
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   501
    project_logic.updateEntityProperties(entity, fields)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   502
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   503
    # redirect to the same page
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   504
    redirect = request.path
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   505
    return http.HttpResponseRedirect(redirect)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   506
2281
a702d92a57a6 Style fixes in app.soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2280
diff changeset
   507
  def _manageAddAdditionalMentor(self, request, template, 
a702d92a57a6 Style fixes in app.soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2280
diff changeset
   508
                                 context, params, entity, form):
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   509
    """Handles the POST request for changing a Projects's additional mentors.
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   510
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   511
    Args:
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   512
        template: the template used for this view
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   513
        entity: the student project entity
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   514
        form: instance of the form used to add an additional mentor
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   515
        rest: see base.View.public()
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   516
    """
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   517
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   518
    if not form.is_valid():
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   519
      context['additional_mentor_form'] = form
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   520
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   521
      # add a fresh edit mentor form
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   522
      initial = {'mentor_id': entity.mentor.link_id}
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   523
      context['mentor_edit_form'] = params['mentor_edit_form'](initial=initial)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   524
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   525
      return responses.respond(request, template, context)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   526
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   527
    _, fields = forms_helper.collectCleanedFields(form)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   528
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   529
    # get the mentor from the form
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   530
    fields = {'link_id': fields['mentor_id'],
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   531
              'scope': entity.scope,
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   532
              'status': 'active'}
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   533
    mentor = mentor_logic.logic.getForFields(fields, unique=True)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   534
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   535
    # add this mentor to the additional mentors
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   536
    if not entity.additional_mentors:
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   537
      additional_mentors = [mentor.key()]
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   538
    else:
2640
da8aa1ff6943 Fixed an error occuring when assigning more then one secondary mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2637
diff changeset
   539
      additional_mentors = entity.additional_mentors
da8aa1ff6943 Fixed an error occuring when assigning more then one secondary mentors.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2637
diff changeset
   540
      additional_mentors.append(mentor.key())
2278
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   541
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   542
    fields = {'additional_mentors': additional_mentors}
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   543
    project_logic.updateEntityProperties(entity, fields)
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   544
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   545
    # redirect to the same page
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   546
    redirect = request.path
c4d40ab98f71 Added functionality to set additional mentors for a Student Project.
Lennard de Rijk
parents: 2241
diff changeset
   547
    return http.HttpResponseRedirect(redirect)
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   548
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   549
  @decorators.merge_params
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   550
  @decorators.check_access
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   551
  def manageOverview(self, request, access_type,
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   552
             page_name=None, params=None, **kwargs):
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   553
    """View that allows Organization Admins to see an overview of 
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   554
       their Organization's Student Projects.
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   555
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   556
    For params see base.View().public()
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   557
    """
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   558
2685
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2640
diff changeset
   559
    from soc.views.helper import list_info
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2640
diff changeset
   560
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   561
    # make sure the organization exists
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   562
    org_entity = org_logic.getFromKeyNameOr404(kwargs['scope_path'])
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   563
    fields = {'scope': org_entity}
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   564
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   565
    # get the context for this webpage
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   566
    context = responses.getUniversalContext(request)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   567
    responses.useJavaScript(context, params['js_uses_all'])
2117
f1a1a75cdb00 Add missing imports, remove unsused imports, fix too long lines and some other style fixes in soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2115
diff changeset
   568
    context['page_name'] = '%s %s' % (page_name, org_entity.name)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   569
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   570
    list_params = params.copy()
2685
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2640
diff changeset
   571
    list_params['list_heading'] = params['manage_overview_heading']
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2640
diff changeset
   572
    list_params['list_row'] = params['manage_overview_row']
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   573
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   574
    #list all active projects
2573
f09f317769c4 Changed the StudentProject model to handle a dynamic amount of GradeRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2360
diff changeset
   575
    fields['status'] = 'accepted'
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   576
    active_params = list_params.copy()
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   577
    active_params['list_description'] = \
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   578
        'List of all active %(name_plural)s' % list_params
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   579
    active_params['list_action'] = (redirects.getManageRedirect, list_params)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   580
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   581
    active_list = lists.getListContent(
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   582
        request, active_params, fields, idx=0)
2691
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   583
    # set the needed info
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   584
    active_list = list_info.setStudentProjectSurveyInfo(active_list,
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   585
                                                        org_entity.scope)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   586
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   587
    # list all failed projects
2573
f09f317769c4 Changed the StudentProject model to handle a dynamic amount of GradeRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2360
diff changeset
   588
    fields['status'] = 'failed'
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   589
    failed_params = list_params.copy()
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   590
    failed_params['list_description'] = ('List of all failed %(name_plural)s, '
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   591
        'these cannot be managed.') % list_params
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   592
    failed_params['list_action'] = (redirects.getPublicRedirect, list_params)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   593
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   594
    failed_list = lists.getListContent(
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   595
        request, failed_params, fields, idx=1, need_content=True)
2691
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   596
    # set the needed info
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   597
    failed_list = list_info.setStudentProjectSurveyInfo(failed_list,
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   598
                                                        org_entity.scope)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   599
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   600
    #list all completed projects
2573
f09f317769c4 Changed the StudentProject model to handle a dynamic amount of GradeRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2360
diff changeset
   601
    fields['status'] = 'completed'
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   602
    completed_params = list_params.copy()
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   603
    completed_params['list_description'] = ('List of %(name_plural)s that have '
2117
f1a1a75cdb00 Add missing imports, remove unsused imports, fix too long lines and some other style fixes in soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2115
diff changeset
   604
        'successfully completed the program, '
f1a1a75cdb00 Add missing imports, remove unsused imports, fix too long lines and some other style fixes in soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2115
diff changeset
   605
        'these cannot be managed.' % list_params)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   606
    completed_params['list_action'] = (redirects.getPublicRedirect, list_params)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   607
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   608
    completed_list = lists.getListContent(
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   609
        request, completed_params, fields, idx=2, need_content=True)
2691
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   610
    # set the needed info
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   611
    completed_list = list_info.setStudentProjectSurveyInfo(completed_list,
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   612
                                                           org_entity.scope)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   613
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   614
    # always show the list with active projects
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   615
    content = [active_list]
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   616
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   617
    if failed_list != None:
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   618
      # do not show empty failed list
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   619
      content.append(failed_list)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   620
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   621
    if completed_list != None:
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   622
      # do not show empty completed list
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   623
      content.append(completed_list)
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   624
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   625
    # call the _list method from base to display the list
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   626
    return self._list(request, list_params, content,
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   627
                      context['page_name'], context)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   628
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   629
  @decorators.merge_params
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   630
  @decorators.check_access
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   631
  def stEdit(self, request, access_type,
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   632
             page_name=None, params=None, **kwargs):
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   633
    """View that allows students to edit information about their project.
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   634
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   635
    For params see base.View().public()
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   636
    """
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   637
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   638
    try:
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   639
      entity = self._logic.getFromKeyFieldsOr404(kwargs)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   640
    except out_of_band.Error, error:
2117
f1a1a75cdb00 Add missing imports, remove unsused imports, fix too long lines and some other style fixes in soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2115
diff changeset
   641
      return responses.errorResponse(
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   642
          error, request, template=params['error_public'])
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   643
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   644
    # get the context for this webpage
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   645
    context = responses.getUniversalContext(request)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   646
    responses.useJavaScript(context, params['js_uses_all'])
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   647
    context['page_name'] = page_name
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   648
    # cancel should go to the public view
2330
068540d91bde Now clicking cancel button returns user to previous page. Fixes issue 569.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2281
diff changeset
   649
    params['cancel_redirect'] = redirects.getPublicRedirect(entity, params)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   650
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   651
    if request.POST:
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   652
      return self.stEditPost(request, context, params, entity, **kwargs)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   653
    else: #request.GET
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   654
      return self.stEditGet(request, context, params, entity, **kwargs)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   655
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   656
  def stEditGet(self, request, context, params, entity, **kwargs):
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   657
    """Handles the GET request for the student's edit page.
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   658
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   659
    Args:
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   660
        entity: the student project entity
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   661
        rest: see base.View.public()
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   662
    """
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   663
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   664
    # populate form with the existing entity
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   665
    form = params['student_edit_form'](instance=entity)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   666
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   667
    return self._constructResponse(request, entity, context, form, params)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   668
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   669
  def stEditPost(self, request, context, params, entity, **kwargs):
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   670
    """Handles the POST request for the student's edit page.
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   671
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   672
    Args:
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   673
        entity: the student project entity
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   674
        rest: see base.View.public()
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   675
    """
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   676
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   677
    form = params['student_edit_form'](request.POST)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   678
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   679
    if not form.is_valid():
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   680
      return self._constructResponse(request, entity, context, form, params)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   681
2117
f1a1a75cdb00 Add missing imports, remove unsused imports, fix too long lines and some other style fixes in soc.views.models.student_project module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2115
diff changeset
   682
    _, fields = forms_helper.collectCleanedFields(form)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   683
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   684
    project_logic.updateEntityProperties(entity, fields)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   685
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   686
    return self.stEditGet(request, context, params, entity, **kwargs)
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   687
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   688
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   689
view = View()
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   690
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   691
admin = decorators.view(view.admin)
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   692
create = decorators.view(view.create)
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   693
delete = decorators.view(view.delete)
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   694
edit = decorators.view(view.edit)
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   695
list = decorators.view(view.list)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   696
manage = decorators.view(view.manage)
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   697
manage_overview = decorators.view(view.manageOverview)
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   698
public = decorators.view(view.public)
2115
fafd021def7e Major update to the views concerning StudentProjects.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   699
st_edit = decorators.view(view.stEdit)
1936
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   700
export = decorators.view(view.export)
ea886e0aedc4 Added basic student project view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   701
pick = decorators.view(view.pick)