author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Wed, 15 Oct 2008 13:47:10 +0000 | |
changeset 333 | d3e85f6144cc |
parent 329 | 2d90d49ce78a |
child 338 | 0d78f41dde9b |
permissions | -rw-r--r-- |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
2 |
# |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
4 |
# |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
8 |
# |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
10 |
# |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
16 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
17 |
"""Developer views for editing and examining Documents. |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
18 |
""" |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
19 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
21 |
'"Todd Larsen" <tlarsen@google.com>', |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
22 |
] |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
23 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
24 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
25 |
from google.appengine.api import users |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
26 |
|
324
05e21c089be6
Add missing import in soc/views/site/sponsor/list.py which caused exception when app was deployed and first site you visited was "List Site Sponsors". Update files according to recent django update and django backwards incompatibility (for example newforms is changed to forms).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
321
diff
changeset
|
27 |
from django import forms |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
28 |
from django import http |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
29 |
from django.utils.translation import ugettext_lazy |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
30 |
|
313
c25b1b680ba7
Bugfixes to the latest revision
Sverre Rabbelier <srabbelier@gmail.com>
parents:
309
diff
changeset
|
31 |
from soc.logic import models |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
32 |
from soc.logic import out_of_band |
298
c76a366c7ab4
Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents:
294
diff
changeset
|
33 |
from soc.logic import path_link_name |
316
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
314
diff
changeset
|
34 |
from soc.logic.models import document |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
35 |
from soc.logic.site import id_user |
316
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
314
diff
changeset
|
36 |
|
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
314
diff
changeset
|
37 |
from soc.views import helper |
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
314
diff
changeset
|
38 |
from soc.views import simple |
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
314
diff
changeset
|
39 |
from soc.views.helper import access |
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
314
diff
changeset
|
40 |
from soc.views.user import profile |
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
314
diff
changeset
|
41 |
|
303
4f1bb54ddae5
Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
299
diff
changeset
|
42 |
import soc.models.document |
274
56e1c1721299
Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents:
272
diff
changeset
|
43 |
import soc.views.helper.forms |
269
0f1acc4c3e1e
Move helpers/request.py to helper/requests.py to avoid conflict with common
Todd Larsen <tlarsen@google.com>
parents:
267
diff
changeset
|
44 |
import soc.views.helper.requests |
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
271
diff
changeset
|
45 |
import soc.views.helper.responses |
271
01e90bb21b7e
Replace helpers/custom_widgets.py with helper/widgets.py.
Todd Larsen <tlarsen@google.com>
parents:
269
diff
changeset
|
46 |
import soc.views.helper.widgets |
303
4f1bb54ddae5
Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
299
diff
changeset
|
47 |
import soc.views.out_of_band |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
48 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
49 |
|
274
56e1c1721299
Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents:
272
diff
changeset
|
50 |
class EditForm(helper.forms.DbModelForm): |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
51 |
"""Django form displayed when Developer edits a Document. |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
52 |
""" |
324
05e21c089be6
Add missing import in soc/views/site/sponsor/list.py which caused exception when app was deployed and first site you visited was "List Site Sponsors". Update files according to recent django update and django backwards incompatibility (for example newforms is changed to forms).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
321
diff
changeset
|
53 |
doc_key_name = forms.fields.CharField(widget=forms.HiddenInput) |
271
01e90bb21b7e
Replace helpers/custom_widgets.py with helper/widgets.py.
Todd Larsen <tlarsen@google.com>
parents:
269
diff
changeset
|
54 |
content = forms.fields.CharField(widget=helper.widgets.TinyMCE()) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
55 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
56 |
class Meta: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
57 |
model = soc.models.document.Document |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
58 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
59 |
#: list of model fields which will *not* be gathered by the form |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
60 |
exclude = ['inheritance_line', 'user', 'created', 'modified'] |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
61 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
62 |
def clean_partial_path(self): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
63 |
partial_path = self.cleaned_data.get('partial_path') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
64 |
# TODO(tlarsen): combine path and link_name and check for uniqueness |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
65 |
return partial_path |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
66 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
67 |
def clean_link_name(self): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
68 |
link_name = self.cleaned_data.get('link_name') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
69 |
# TODO(tlarsen): combine path and link_name and check for uniqueness |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
70 |
return link_name |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
71 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
72 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
73 |
DEF_SITE_DOCS_EDIT_TMPL = 'soc/site/docs/edit.html' |
247
4997b54b0400
Fixed typo in DEF_CREATE_NEW_DOC_MSG.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
237
diff
changeset
|
74 |
DEF_CREATE_NEW_DOC_MSG = ' You can create a new document by visiting the' \ |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
75 |
' <a href="/site/docs/edit">Create ' \ |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
76 |
'a New Document</a> page.' |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
77 |
|
290
2a92b866ed40
Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
285
diff
changeset
|
78 |
SUBMIT_MESSAGES = ( |
2a92b866ed40
Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
285
diff
changeset
|
79 |
ugettext_lazy('Document saved.'), |
2a92b866ed40
Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
285
diff
changeset
|
80 |
) |
2a92b866ed40
Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
285
diff
changeset
|
81 |
|
305
972d28056d9d
Minor style and import fixes
Sverre Rabbelier <srabbelier@gmail.com>
parents:
303
diff
changeset
|
82 |
|
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
83 |
def getDocForForm(form): |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
84 |
"""Extracts doc fields from a form and creates a new doc from it |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
85 |
""" |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
86 |
|
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
87 |
user = users.get_current_user() |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
88 |
if user: |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
89 |
email = user.email() |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
90 |
else: |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
91 |
email = None |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
92 |
|
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
93 |
partial_path = form.cleaned_data.get('partial_path') |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
94 |
link_name = form.cleaned_data.get('link_name') |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
95 |
|
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
96 |
properties = {} |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
97 |
properties['partial_path'] = partial_path |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
98 |
properties['link_name'] = link_name |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
99 |
properties['title'] = form.cleaned_data.get('title') |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
100 |
properties['short_name'] = form.cleaned_data.get('short_name') |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
101 |
properties['abstract'] = form.cleaned_data.get('abstract') |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
102 |
properties['content'] = form.cleaned_data.get('content') |
309
7190b224c701
Made the existing code use the new soc.logic.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
305
diff
changeset
|
103 |
properties['user'] = models.user.logic.getFromFields(email=email) |
329
2d90d49ce78a
Add is_featured boolean property to the Work model, so that Works can be
Todd Larsen <tlarsen@google.com>
parents:
324
diff
changeset
|
104 |
properties['is_featured'] = form.cleaned_data.get('is_featured') |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
105 |
|
309
7190b224c701
Made the existing code use the new soc.logic.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
305
diff
changeset
|
106 |
doc = document.logic.updateOrCreateFromFields(properties, |
321
f17ecd21ca33
Some indentations fixes. Changed all the email=id function arguments to email=id.email().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
316
diff
changeset
|
107 |
partial_path=partial_path, |
f17ecd21ca33
Some indentations fixes. Changed all the email=id function arguments to email=id.email().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
316
diff
changeset
|
108 |
link_name=link_name) |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
109 |
return doc |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
110 |
|
305
972d28056d9d
Minor style and import fixes
Sverre Rabbelier <srabbelier@gmail.com>
parents:
303
diff
changeset
|
111 |
|
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
112 |
def edit(request, partial_path=None, link_name=None, |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
113 |
template=DEF_SITE_DOCS_EDIT_TMPL): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
114 |
"""View for a Developer to modify the properties of a Document Model entity. |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
115 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
116 |
Args: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
117 |
request: the standard django request object |
251
8f23804302d0
Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents:
247
diff
changeset
|
118 |
partial_path: the Document's site-unique "path" extracted from the URL, |
8f23804302d0
Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents:
247
diff
changeset
|
119 |
minus the trailing link_name |
8f23804302d0
Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents:
247
diff
changeset
|
120 |
link_name: the last portion of the Document's site-unique "path" |
8f23804302d0
Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents:
247
diff
changeset
|
121 |
extracted from the URL |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
122 |
template: the "sibling" template (or a search list of such templates) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
123 |
from which to construct the public.html template name (or names) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
124 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
125 |
Returns: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
126 |
A subclass of django.http.HttpResponse which either contains the form to |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
127 |
be filled out, or a redirect to the correct view in the interface. |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
128 |
""" |
294
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
129 |
|
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
130 |
try: |
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
131 |
access.checkIsDeveloper(request) |
303
4f1bb54ddae5
Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
299
diff
changeset
|
132 |
except soc.views.out_of_band.AccessViolationResponse, alt_response: |
294
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
133 |
return alt_response.response() |
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
134 |
|
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
135 |
# create default template context for use with any templates |
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
271
diff
changeset
|
136 |
context = helper.responses.getUniversalContext(request) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
137 |
logged_in_id = users.get_current_user() |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
138 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
139 |
doc = None # assume that no Document entity will be found |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
140 |
|
298
c76a366c7ab4
Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents:
294
diff
changeset
|
141 |
path = path_link_name.combinePath([partial_path, link_name]) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
142 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
143 |
# try to fetch Document entity corresponding to path if one exists |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
144 |
try: |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
145 |
if path: |
309
7190b224c701
Made the existing code use the new soc.logic.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
305
diff
changeset
|
146 |
doc = document.logic.getFromFields(partial_path=partial_path, |
321
f17ecd21ca33
Some indentations fixes. Changed all the email=id function arguments to email=id.email().
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
316
diff
changeset
|
147 |
link_name=link_name) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
148 |
except out_of_band.ErrorResponse, error: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
149 |
# show custom 404 page when path doesn't exist in Datastore |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
150 |
error.message = error.message + DEF_CREATE_NEW_DOC_MSG |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
151 |
return simple.errorResponse(request, error, template, context) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
152 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
153 |
if request.method == 'POST': |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
154 |
form = EditForm(request.POST) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
155 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
156 |
if form.is_valid(): |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
157 |
doc = getDocForForm(form) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
158 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
159 |
if not doc: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
160 |
return http.HttpResponseRedirect('/') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
161 |
|
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
162 |
new_path = path_link_name.combinePath([doc.partial_path, doc.link_name]) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
163 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
164 |
# redirect to new /site/docs/edit/new_path?s=0 |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
165 |
# (causes 'Profile saved' message to be displayed) |
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
271
diff
changeset
|
166 |
return helper.responses.redirectToChangedSuffix( |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
167 |
request, path, new_path, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
168 |
params=profile.SUBMIT_PROFILE_SAVED_PARAMS) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
169 |
else: # method == 'GET': |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
170 |
# try to fetch Document entity corresponding to path if one exists |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
171 |
if path: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
172 |
if doc: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
173 |
# is 'Profile saved' parameter present, but referrer was not ourself? |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
174 |
# (e.g. someone bookmarked the GET that followed the POST submit) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
175 |
if (request.GET.get(profile.SUBMIT_MSG_PARAM_NAME) |
269
0f1acc4c3e1e
Move helpers/request.py to helper/requests.py to avoid conflict with common
Todd Larsen <tlarsen@google.com>
parents:
267
diff
changeset
|
176 |
and (not helper.requests.isReferrerSelf(request, suffix=path))): |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
177 |
# redirect to aggressively remove 'Profile saved' query parameter |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
178 |
return http.HttpResponseRedirect(request.path) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
179 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
180 |
# referrer was us, so select which submit message to display |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
181 |
# (may display no message if ?s=0 parameter is not present) |
290
2a92b866ed40
Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
285
diff
changeset
|
182 |
context['notice'] = ( |
269
0f1acc4c3e1e
Move helpers/request.py to helper/requests.py to avoid conflict with common
Todd Larsen <tlarsen@google.com>
parents:
267
diff
changeset
|
183 |
helper.requests.getSingleIndexedParamValue( |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
184 |
request, profile.SUBMIT_MSG_PARAM_NAME, |
290
2a92b866ed40
Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
285
diff
changeset
|
185 |
values=SUBMIT_MESSAGES)) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
186 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
187 |
# populate form with the existing User entity |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
188 |
form = EditForm(initial={'doc_key_name': doc.key().name(), |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
189 |
'title': doc.title, 'partial_path': doc.partial_path, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
190 |
'link_name': doc.link_name, 'short_name': doc.short_name, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
191 |
'abstract': doc.abstract, 'content': doc.content, |
329
2d90d49ce78a
Add is_featured boolean property to the Work model, so that Works can be
Todd Larsen <tlarsen@google.com>
parents:
324
diff
changeset
|
192 |
'user': doc.user, 'is_featured': doc.is_featured}) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
193 |
else: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
194 |
if request.GET.get(profile.SUBMIT_MSG_PARAM_NAME): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
195 |
# redirect to aggressively remove 'Profile saved' query parameter |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
196 |
return http.HttpResponseRedirect(request.path) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
197 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
198 |
context['lookup_error'] = ugettext_lazy( |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
199 |
'Document with that path not found.') |
298
c76a366c7ab4
Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents:
294
diff
changeset
|
200 |
form = EditForm(initial={'link_name': link_name}) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
201 |
else: # no link name specified in the URL |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
202 |
if request.GET.get(profile.SUBMIT_MSG_PARAM_NAME): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
203 |
# redirect to aggressively remove 'Profile saved' query parameter |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
204 |
return http.HttpResponseRedirect(request.path) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
205 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
206 |
# no link name specified, so start with an empty form |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
207 |
form = EditForm() |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
208 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
209 |
context.update({'form': form, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
210 |
'existing_doc': doc}) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
211 |
|
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
271
diff
changeset
|
212 |
return helper.responses.respond(request, template, context) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
213 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
214 |
|
274
56e1c1721299
Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents:
272
diff
changeset
|
215 |
class CreateForm(helper.forms.DbModelForm): |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
216 |
"""Django form displayed when Developer creates a Document. |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
217 |
""" |
271
01e90bb21b7e
Replace helpers/custom_widgets.py with helper/widgets.py.
Todd Larsen <tlarsen@google.com>
parents:
269
diff
changeset
|
218 |
content = forms.fields.CharField(widget=helper.widgets.TinyMCE()) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
219 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
220 |
class Meta: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
221 |
model = soc.models.document.Document |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
222 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
223 |
#: list of model fields which will *not* be gathered by the form |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
224 |
exclude = ['inheritance_line', 'user', 'created', 'modified'] |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
225 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
226 |
def clean_partial_path(self): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
227 |
partial_path = self.cleaned_data.get('partial_path') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
228 |
# TODO(tlarsen): combine path and link_name and check for uniqueness |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
229 |
return partial_path |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
230 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
231 |
def clean_link_name(self): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
232 |
link_name = self.cleaned_data.get('link_name') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
233 |
# TODO(tlarsen): combine path and link_name and check for uniqueness |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
234 |
return link_name |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
235 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
236 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
237 |
DEF_SITE_DOCS_CREATE_TMPL = 'soc/site/docs/edit.html' |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
238 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
239 |
def create(request, template=DEF_SITE_DOCS_CREATE_TMPL): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
240 |
"""View for a Developer to create a new Document entity. |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
241 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
242 |
Args: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
243 |
request: the standard django request object |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
244 |
template: the "sibling" template (or a search list of such templates) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
245 |
from which to construct the public.html template name (or names) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
246 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
247 |
Returns: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
248 |
A subclass of django.http.HttpResponse which either contains the form to |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
249 |
be filled out, or a redirect to the correct view in the interface. |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
250 |
""" |
294
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
251 |
|
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
252 |
try: |
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
253 |
access.checkIsDeveloper(request) |
303
4f1bb54ddae5
Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
299
diff
changeset
|
254 |
except soc.views.out_of_band.AccessViolationResponse, alt_response: |
294
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
255 |
return alt_response.response() |
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
256 |
|
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
257 |
# create default template context for use with any templates |
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
271
diff
changeset
|
258 |
context = helper.responses.getUniversalContext(request) |
290
2a92b866ed40
Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
285
diff
changeset
|
259 |
logged_in_id = users.get_current_user() |
2a92b866ed40
Create a submit_buttons block in group edit profile template so that submit buttons can be customized. Replace submit_message usage with new notice block (still work in progress in Lookup User views). Add customized edit profile template for Sponsor with delete button (not used yet, upcoming commit). Add delete Sponsor request handler.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
285
diff
changeset
|
260 |
|
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
261 |
if request.method == 'POST': |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
262 |
form = CreateForm(request.POST) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
263 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
264 |
if form.is_valid(): |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
265 |
doc = getDocForForm(form) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
266 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
267 |
if not doc: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
268 |
return http.HttpResponseRedirect('/') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
269 |
|
298
c76a366c7ab4
Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents:
294
diff
changeset
|
270 |
new_path = path_link_name.combinePath([doc.partial_path, doc.link_name]) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
271 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
272 |
# redirect to new /site/docs/edit/new_path?s=0 |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
273 |
# (causes 'Profile saved' message to be displayed) |
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
271
diff
changeset
|
274 |
return helper.responses.redirectToChangedSuffix( |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
275 |
request, None, new_path, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
276 |
params=profile.SUBMIT_PROFILE_SAVED_PARAMS) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
277 |
else: # method == 'GET': |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
278 |
# no link name specified, so start with an empty form |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
279 |
form = CreateForm() |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
280 |
|
285
52e206a6a417
Style fix, as requested by Todd to dict usage
Sverre Rabbelier <srabbelier@gmail.com>
parents:
274
diff
changeset
|
281 |
context['form'] = form |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
282 |
|
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
271
diff
changeset
|
283 |
return helper.responses.respond(request, template, context) |
314
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
284 |
|
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
285 |
|
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
286 |
def delete(request, partial_path=None, link_name=None, |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
287 |
template=DEF_SITE_DOCS_EDIT_TMPL): |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
288 |
"""Request handler for a Developer to delete Document Model entity. |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
289 |
|
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
290 |
Args: |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
291 |
request: the standard django request object |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
292 |
partial_path: the Document's site-unique "path" extracted from the URL, |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
293 |
minus the trailing link_name |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
294 |
link_name: the last portion of the Document's site-unique "path" |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
295 |
extracted from the URL |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
296 |
template: the "sibling" template (or a search list of such templates) |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
297 |
from which to construct the public.html template name (or names) |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
298 |
|
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
299 |
Returns: |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
300 |
A subclass of django.http.HttpResponse which redirects |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
301 |
to /site/docs/list. |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
302 |
""" |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
303 |
|
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
304 |
try: |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
305 |
access.checkIsDeveloper(request) |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
306 |
except soc.views.out_of_band.AccessViolationResponse, alt_response: |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
307 |
return alt_response.response() |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
308 |
|
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
309 |
# create default template context for use with any templates |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
310 |
context = helper.responses.getUniversalContext(request) |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
311 |
|
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
312 |
existing_doc = None |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
313 |
path = path_link_name.combinePath([partial_path, link_name]) |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
314 |
|
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
315 |
# try to fetch Document entity corresponding to path if one exists |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
316 |
try: |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
317 |
if path: |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
318 |
existing_doc = document.logic.getFromFields(partial_path=partial_path, |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
319 |
link_name=link_name) |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
320 |
except out_of_band.ErrorResponse, error: |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
321 |
# show custom 404 page when path doesn't exist in Datastore |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
322 |
error.message = error.message + DEF_CREATE_NEW_DOC_MSG |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
323 |
return simple.errorResponse(request, error, template, context) |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
324 |
|
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
325 |
if existing_doc: |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
326 |
document.logic.delete(existing_doc) |
dfaf249c12b2
Rearrange imports in home.py so they apply to new discussed format (separate "from ..." and "import ..." blocks). Add Delete Document functionality.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
313
diff
changeset
|
327 |
|
329
2d90d49ce78a
Add is_featured boolean property to the Work model, so that Works can be
Todd Larsen <tlarsen@google.com>
parents:
324
diff
changeset
|
328 |
return http.HttpResponseRedirect('/site/docs/list') |