author | Lennard de Rijk <ljvderijk@gmail.com> |
Tue, 06 Jan 2009 21:21:09 +0000 | |
changeset 770 | eb2e69312953 |
parent 769 | a0ee643fe832 |
child 771 | 0b1beae179f5 |
permissions | -rw-r--r-- |
643 | 1 |
#!/usr/bin/python2.5 |
2 |
# |
|
3 |
# Copyright 2008 the Melange authors. |
|
4 |
# |
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 |
# you may not use this file except in compliance with the License. |
|
7 |
# You may obtain a copy of the License at |
|
8 |
# |
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
|
10 |
# |
|
11 |
# Unless required by applicable law or agreed to in writing, software |
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 |
# See the License for the specific language governing permissions and |
|
15 |
# limitations under the License. |
|
16 |
||
17 |
"""Views for Programs. |
|
18 |
""" |
|
19 |
||
20 |
__authors__ = [ |
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
|
769
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
22 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
643 | 23 |
] |
24 |
||
25 |
||
26 |
from django import forms |
|
27 |
||
666
b9b0506efe8d
Fix import sorting and docstring typos in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
663
diff
changeset
|
28 |
from soc.logic import cleaning |
643 | 29 |
from soc.logic import dicts |
769
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
30 |
from soc.logic.models import timeline as timeline_logic |
666
b9b0506efe8d
Fix import sorting and docstring typos in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
663
diff
changeset
|
31 |
from soc.views import helper |
700
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
32 |
from soc.views.helper import access |
643 | 33 |
from soc.views.helper import redirects |
34 |
from soc.views.models import base |
|
714
3e2ce3d8057a
Add missing dots in docstrings, proper sorting of imports and small docstring typo fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
712
diff
changeset
|
35 |
from soc.views.models import document as document_view |
643 | 36 |
from soc.views.models import sponsor as sponsor_view |
705
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
700
diff
changeset
|
37 |
from soc.views.sitemap import sidebar |
643 | 38 |
|
769
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
39 |
import gsoc.models.timeline |
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
40 |
import soc.models.timeline |
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
41 |
|
643 | 42 |
import soc.logic.models.program |
43 |
||
44 |
||
45 |
class View(base.View): |
|
666
b9b0506efe8d
Fix import sorting and docstring typos in soc.views.models.program module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
663
diff
changeset
|
46 |
"""View methods for the Program model. |
643 | 47 |
""" |
48 |
||
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
49 |
def __init__(self, params=None): |
643 | 50 |
"""Defines the fields and methods required for the base View class |
51 |
to provide the user with list, public, create, edit and delete views. |
|
52 |
||
53 |
Params: |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
54 |
params: a dict with params for this View |
700
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
55 |
""" |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
56 |
|
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
57 |
rights = {} |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
58 |
rights['any_access'] = [access.allow] |
712
b9e4cc00f30a
Some forgotten changes with the access_type commit
Sverre Rabbelier <srabbelier@gmail.com>
parents:
705
diff
changeset
|
59 |
rights['show'] = [access.allow] |
643 | 60 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
61 |
new_params = {} |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
62 |
new_params['logic'] = soc.logic.models.program.logic |
700
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
63 |
new_params['rights'] = rights |
643 | 64 |
|
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
660
diff
changeset
|
65 |
new_params['scope_view'] = sponsor_view |
681
48983ecf4665
Cleanups in group and program
Sverre Rabbelier <srabbelier@gmail.com>
parents:
680
diff
changeset
|
66 |
new_params['scope_redirect'] = redirects.getCreateRedirect |
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
660
diff
changeset
|
67 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
68 |
new_params['name'] = "Program" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
69 |
new_params['name_short'] = "Program" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
70 |
new_params['name_plural'] = "Programs" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
71 |
new_params['url_name'] = "program" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
72 |
new_params['module_name'] = "program" |
643 | 73 |
|
769
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
74 |
new_params['extra_dynaexclude'] = ['home', 'timeline'] |
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
75 |
new_params['create_extra_dynafields'] = { |
649 | 76 |
'description': forms.fields.CharField(widget=helper.widgets.TinyMCE( |
668
77f9a6ea6e67
Some style and typo fixes in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
666
diff
changeset
|
77 |
attrs={'rows':10, 'cols':40})), |
77f9a6ea6e67
Some style and typo fixes in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
666
diff
changeset
|
78 |
'scope_path': forms.CharField(widget=forms.HiddenInput, required=True), |
769
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
79 |
'workflow' : forms.ChoiceField(choices=[('gsoc','Project-based'), |
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
80 |
('ghop','Task-based')], required=True), |
649 | 81 |
'clean_link_id': cleaning.clean_link_id, |
643 | 82 |
} |
83 |
||
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
84 |
params = dicts.merge(params, new_params) |
643 | 85 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
86 |
super(View, self).__init__(params=params) |
769
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
87 |
|
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
88 |
def _editPost(self, request, entity, fields): |
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
89 |
"""See base._editPost(). |
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
90 |
""" |
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
91 |
|
770
eb2e69312953
Fixed a bug where a new timeline would get created on every edit of an existing program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
769
diff
changeset
|
92 |
if not entity: |
eb2e69312953
Fixed a bug where a new timeline would get created on every edit of an existing program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
769
diff
changeset
|
93 |
# there is no existing entity so create a new timeline |
eb2e69312953
Fixed a bug where a new timeline would get created on every edit of an existing program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
769
diff
changeset
|
94 |
fields['timeline'] = self._createTimelineForType(fields['workflow']) |
eb2e69312953
Fixed a bug where a new timeline would get created on every edit of an existing program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
769
diff
changeset
|
95 |
else: |
eb2e69312953
Fixed a bug where a new timeline would get created on every edit of an existing program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
769
diff
changeset
|
96 |
# use the timeline from the entity |
eb2e69312953
Fixed a bug where a new timeline would get created on every edit of an existing program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
769
diff
changeset
|
97 |
fields['timeline'] = entity.timeline |
769
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
98 |
|
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
99 |
def _createTimelineForType(self, type): |
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
100 |
"""Creates and stores a timeline model for the given type of program |
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
101 |
""" |
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
102 |
|
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
103 |
timelines = {'gsoc' : gsoc.models.timeline.Timeline(), |
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
104 |
'ghop' : soc.models.timeline.Timeline()} |
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
105 |
|
a0ee643fe832
Added an elementary workflow choosing method to program creation.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
755
diff
changeset
|
106 |
return timelines[type].put() |
643 | 107 |
|
700
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
108 |
def getExtraMenus(self, request, params=None): |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
109 |
"""Returns the extra menu's for this view. |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
110 |
|
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
111 |
A menu item is generated for each program that is currently |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
112 |
running. The public page for each program is added as menu item, |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
113 |
as well as all public documents for that program. |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
114 |
|
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
115 |
Args: |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
116 |
request: unused |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
117 |
params: a dict with params for this View. |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
118 |
""" |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
119 |
|
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
120 |
params = dicts.merge(params, self._params) |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
121 |
logic = params['logic'] |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
122 |
|
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
123 |
entities = logic.getForLimitAndOffset(1000) |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
124 |
|
712
b9e4cc00f30a
Some forgotten changes with the access_type commit
Sverre Rabbelier <srabbelier@gmail.com>
parents:
705
diff
changeset
|
125 |
doc_params = document_view.view.getParams() |
700
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
126 |
menus = [] |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
127 |
|
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
128 |
for entity in entities: |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
129 |
menu = {} |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
130 |
menu['heading'] = entity.short_name |
705
0ab17e14df95
Move document sidebar entries extraction to document.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
700
diff
changeset
|
131 |
items = document_view.view.getMenusForScope(entity, params) |
712
b9e4cc00f30a
Some forgotten changes with the access_type commit
Sverre Rabbelier <srabbelier@gmail.com>
parents:
705
diff
changeset
|
132 |
menu['items'] = sidebar.getSidebarMenu(request, items, params=doc_params) |
700
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
133 |
menus.append(menu) |
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
134 |
|
8baf8367340d
Dynamically add sidebar items for programs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
681
diff
changeset
|
135 |
return menus |
647
355ac73823a1
Swap order of merged params to fix sponsor select view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
643
diff
changeset
|
136 |
|
643 | 137 |
view = View() |
138 |
||
139 |
create = view.create |
|
140 |
delete = view.delete |
|
141 |
edit = view.edit |
|
142 |
list = view.list |
|
143 |
public = view.public |