author | Lennard de Rijk <ljvderijk@gmail.com> |
Tue, 24 Feb 2009 20:28:16 +0000 | |
changeset 1491 | acf7e32de8ca |
parent 1484 | 6b00a2a43eaf |
child 1498 | 00293057b009 |
permissions | -rw-r--r-- |
1426
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
2 |
# |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
4 |
# |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
8 |
# |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
10 |
# |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
16 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
17 |
"""Views for Student Proposal. |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
18 |
""" |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
19 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
21 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
22 |
] |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
23 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
24 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
25 |
import datetime |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
26 |
import time |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
27 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
28 |
from django import forms |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
29 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
30 |
from soc.logic import cleaning |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
31 |
from soc.logic import dicts |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
32 |
from soc.logic.models import organization as org_logic |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
33 |
from soc.logic.models import student as student_logic |
1469
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
34 |
from soc.logic.models import user as user_logic |
1426
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
35 |
from soc.views.helper import access |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
36 |
from soc.views.helper import decorators |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
37 |
from soc.views.helper import redirects |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
38 |
from soc.views.helper import widgets |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
39 |
from soc.views.models import base |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
40 |
from soc.views.models import student as student_view |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
41 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
42 |
import soc.logic.models.student_proposal |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
43 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
44 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
45 |
class View(base.View): |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
46 |
"""View methods for the Student Proposal model. |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
47 |
""" |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
48 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
49 |
def __init__(self, params=None): |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
50 |
"""Defines the fields and methods required for the base View class |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
51 |
to provide the user with list, public, create, edit and delete views. |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
52 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
53 |
Params: |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
54 |
params: a dict with params for this View |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
55 |
""" |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
56 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
57 |
rights = access.Checker(params) |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
58 |
rights['create'] = ['checkIsDeveloper'] |
1467
c5f99265a680
Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1430
diff
changeset
|
59 |
rights['edit'] = [('checkCanStudentPropose', 'scope_path'), |
c5f99265a680
Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1430
diff
changeset
|
60 |
('checkRoleAndStatusForStudentProposal', |
c5f99265a680
Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1430
diff
changeset
|
61 |
[['proposer'], ['active'], ['new', 'pending']])] |
1426
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
62 |
rights['delete'] = ['checkIsDeveloper'] |
1467
c5f99265a680
Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1430
diff
changeset
|
63 |
rights['show'] = [ |
c5f99265a680
Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1430
diff
changeset
|
64 |
('checkRoleAndStatusForStudentProposal', |
c5f99265a680
Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1430
diff
changeset
|
65 |
[['proposer', 'org_admin', 'mentor', 'host'], |
c5f99265a680
Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1430
diff
changeset
|
66 |
['active', 'inactive'], ['new', 'pending', 'accepted', 'rejected']])] |
1426
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
67 |
rights['list'] = ['checkIsDeveloper'] |
1482
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
68 |
rights['list_orgs'] = [ |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
69 |
('checkIsStudent', ['scope_path', ['active']]), |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
70 |
('checkCanStudentPropose', 'scope_path')] |
1469
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
71 |
rights['list_self'] = [ |
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
72 |
('checkIsStudent', ['scope_path', ['active', 'inactive']])] |
1467
c5f99265a680
Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1430
diff
changeset
|
73 |
rights['apply'] = [ |
c5f99265a680
Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1430
diff
changeset
|
74 |
('checkIsStudent', ['scope_path', ['active']]), |
c5f99265a680
Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1430
diff
changeset
|
75 |
('checkCanStudentPropose', 'scope_path')] |
1426
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
76 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
77 |
new_params = {} |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
78 |
new_params['logic'] = soc.logic.models.student_proposal.logic |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
79 |
new_params['rights'] = rights |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
80 |
new_params['name'] = "Student Proposal" |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
81 |
new_params['url_name'] = "student_proposal" |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
82 |
new_params['sidebar_grouping'] = 'Student Proposal' |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
83 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
84 |
new_params['scope_view'] = student_view |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
85 |
new_params['scope_redirect'] = redirects.getCreateRedirect |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
86 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
87 |
new_params['no_create_with_key_fields'] = True |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
88 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
89 |
patterns = [ |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
90 |
(r'^%(url_name)s/(?P<access_type>apply)/%(scope)s$', |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
91 |
'soc.views.models.%(module_name)s.create', |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
92 |
'Create a new %(name)s'), |
1469
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
93 |
(r'^%(url_name)s/(?P<access_type>list_self)/%(scope)s$', |
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
94 |
'soc.views.models.%(module_name)s.list_self', |
1482
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
95 |
'List my %(name_plural)s'), |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
96 |
(r'^%(url_name)s/(?P<access_type>list_orgs)/%(scope)s$', |
1484
6b00a2a43eaf
Changed the method and variable name in student_proposal to match the access type.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1482
diff
changeset
|
97 |
'soc.views.models.%(module_name)s.list_orgs', |
1469
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
98 |
'List my %(name_plural)s') |
1426
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
99 |
] |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
100 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
101 |
new_params['extra_django_patterns'] = patterns |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
102 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
103 |
new_params['extra_dynaexclude'] = ['org', 'program', 'score', |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
104 |
'status', 'mentor', 'link_id'] |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
105 |
|
1430
ff8cc6b15e6a
Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1426
diff
changeset
|
106 |
new_params['create_extra_dynaproperties'] = { |
1426
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
107 |
'content': forms.fields.CharField(required=True, |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
108 |
widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})), |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
109 |
'scope_path': forms.CharField(widget=forms.HiddenInput, |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
110 |
required=True), |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
111 |
'organization': forms.CharField(label='Organization Link ID', |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
112 |
required=True), |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
113 |
'clean_organization': cleaning.clean_link_id('organization'), |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
114 |
'clean_additional_info': cleaning.clean_url('additional_info'), |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
115 |
'clean': cleaning.validate_student_proposal('organization', |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
116 |
'scope_path', student_logic, org_logic), |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
117 |
} |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
118 |
|
1430
ff8cc6b15e6a
Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1426
diff
changeset
|
119 |
new_params['edit_extra_dynaproperties'] = { |
1426
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
120 |
'organization': forms.CharField(label='Organization Link ID', |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
121 |
widget=widgets.ReadOnlyInput), |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
122 |
'link_id': forms.CharField(widget=forms.HiddenInput) |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
123 |
} |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
124 |
|
1467
c5f99265a680
Changed the access checks in student_proposal view to use the newly created checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1430
diff
changeset
|
125 |
# TODO(ljvderijk) students should be able to withdraw their proposals |
1426
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
126 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
127 |
params = dicts.merge(params, new_params) |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
128 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
129 |
super(View, self).__init__(params=params) |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
130 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
131 |
def _editGet(self, request, entity, form): |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
132 |
"""See base.View._editGet(). |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
133 |
""" |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
134 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
135 |
form.fields['link_id'].initial = entity.link_id |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
136 |
form.fields['organization'].initial = entity.org.link_id |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
137 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
138 |
return super(View, self)._editGet(request, entity, form) |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
139 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
140 |
def _editPost(self, request, entity, fields): |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
141 |
"""See base.View._editPost(). |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
142 |
""" |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
143 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
144 |
if not entity: |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
145 |
fields['link_id'] = 't%i' % (time.time()) |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
146 |
else: |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
147 |
fields['link_id'] = entity.link_id |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
148 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
149 |
# fill in the scope via call to super |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
150 |
super(View, self)._editPost(request, entity, fields) |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
151 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
152 |
if not entity: |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
153 |
# creating a new application so set the program and org field |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
154 |
fields['program'] = fields['scope'].scope |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
155 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
156 |
filter = {'scope': fields['program'], |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
157 |
'link_id': fields['organization']} |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
158 |
fields['org'] = org_logic.logic.getForFields(filter, unique=True) |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
159 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
160 |
# explicitly change the last_modified_on since the content has been edited |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
161 |
fields['last_modified_on'] = datetime.datetime.now() |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
162 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
163 |
def _public(self, request, entity, context): |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
164 |
"""See base.View._public(). |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
165 |
""" |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
166 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
167 |
context['student_name'] = entity.scope.name() |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
168 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
169 |
if entity.mentor: |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
170 |
context['mentor_name'] = entity.mentor.name() |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
171 |
else: |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
172 |
context['mentor_name'] = "No mentor assigned" |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
173 |
|
1469
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
174 |
@decorators.merge_params |
1482
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
175 |
@decorators.check_access |
1484
6b00a2a43eaf
Changed the method and variable name in student_proposal to match the access type.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1482
diff
changeset
|
176 |
def listOrgs(self, request, access_type, |
1491
acf7e32de8ca
Style fixes in student_proposal and organization view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1484
diff
changeset
|
177 |
page_name=None, params=None, **kwargs): |
1482
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
178 |
"""Lists all organization which the given student can propose to. |
1469
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
179 |
|
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
180 |
For params see base.View.public(). |
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
181 |
""" |
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
182 |
|
1482
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
183 |
from soc.views.models import organization as org_view |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
184 |
|
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
185 |
student_entity = student_logic.logic.getFromKeyName(kwargs['scope_path']) |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
186 |
|
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
187 |
filter = {'scope' : student_entity.scope, |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
188 |
'status': 'active'} |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
189 |
|
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
190 |
list_params = org_view.view.getParams().copy() |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
191 |
list_params['list_description'] = ('List of %(name_plural)s you can send ' |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
192 |
'your proposal to.') % list_params |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
193 |
list_params['list_action'] = (redirects.getStudentProposalRedirect, |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
194 |
{'student_key': student_entity.key().name(), |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
195 |
'url_name': params['url_name']}) |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
196 |
|
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
197 |
return self.list(request, access_type=access_type, page_name=page_name, |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
198 |
params=list_params, filter=filter, **kwargs) |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
199 |
|
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
200 |
@decorators.merge_params |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
201 |
@decorators.check_access |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
202 |
def listSelf(self, request, access_type, |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
203 |
page_name=None, params=None, **kwargs): |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
204 |
"""Lists all proposals from the current logged-in user for the given student. |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
205 |
|
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
206 |
For params see base.View.public(). |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
207 |
""" |
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
208 |
|
5229a40d4792
Added view which lists all orgs a student can propose to.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1469
diff
changeset
|
209 |
student_entity = student_logic.logic.getFromKeyName(kwargs['scope_path']) |
1469
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
210 |
|
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
211 |
filter = {'scope' : student_entity, |
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
212 |
'status': ['new', 'pending', 'accepted', 'rejected']} |
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
213 |
|
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
214 |
list_params = params.copy() |
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
215 |
list_params['list_description'] = 'List of my %(name_plural)s' % list_params |
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
216 |
|
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
217 |
return self.list(request, access_type=access_type, page_name=page_name, |
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
218 |
params=list_params, filter=filter, **kwargs) |
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
219 |
|
1426
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
220 |
view = View() |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
221 |
|
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
222 |
admin = view.admin |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
223 |
create = view.create |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
224 |
delete = view.delete |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
225 |
edit = view.edit |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
226 |
list = view.list |
1484
6b00a2a43eaf
Changed the method and variable name in student_proposal to match the access type.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1482
diff
changeset
|
227 |
list_orgs = view.listOrgs |
1469
d69b00439d59
Added listing of your own student proposals.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1467
diff
changeset
|
228 |
list_self = view.listSelf |
1426
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
229 |
public = view.public |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
230 |
export = view.export |
dc3a7f618b68
Added student_proposal view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
231 |
pick = view.pick |