author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Thu, 09 Oct 2008 18:11:37 +0000 | |
changeset 292 | 1cece5192e26 |
parent 290 | 2a92b866ed40 |
child 294 | 1fdaab4a6ef2 |
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 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
27 |
from django import http |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
28 |
from django import newforms as forms |
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 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
31 |
from soc.logic import document |
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 |
251
8f23804302d0
Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents:
247
diff
changeset
|
33 |
from soc.logic import path_linkname |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
34 |
from soc.logic.site import id_user |
269
0f1acc4c3e1e
Move helpers/request.py to helper/requests.py to avoid conflict with common
Todd Larsen <tlarsen@google.com>
parents:
267
diff
changeset
|
35 |
from soc.views import helper |
274
56e1c1721299
Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents:
272
diff
changeset
|
36 |
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
|
37 |
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
|
38 |
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
|
39 |
import soc.views.helper.widgets |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
40 |
from soc.views import simple |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
41 |
from soc.views.user import profile |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
42 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
43 |
import soc.models.document |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
44 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
45 |
|
274
56e1c1721299
Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents:
272
diff
changeset
|
46 |
class EditForm(helper.forms.DbModelForm): |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
47 |
"""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
|
48 |
""" |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
49 |
doc_key_name = forms.CharField(widget=forms.HiddenInput) |
271
01e90bb21b7e
Replace helpers/custom_widgets.py with helper/widgets.py.
Todd Larsen <tlarsen@google.com>
parents:
269
diff
changeset
|
50 |
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
|
51 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
52 |
class Meta: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
53 |
model = soc.models.document.Document |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
54 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
55 |
#: 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
|
56 |
exclude = ['inheritance_line', 'user', 'created', 'modified'] |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
57 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
58 |
def clean_partial_path(self): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
59 |
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
|
60 |
# 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
|
61 |
return partial_path |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
62 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
63 |
def clean_link_name(self): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
64 |
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
|
65 |
# 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
|
66 |
return link_name |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
67 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
68 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
' <a href="/site/docs/edit">Create ' \ |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
72 |
'a New Document</a> page.' |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
73 |
|
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
|
74 |
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
|
75 |
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
|
76 |
) |
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
|
77 |
|
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
78 |
def edit(request, partial_path=None, linkname=None, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
79 |
template=DEF_SITE_DOCS_EDIT_TMPL): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
80 |
"""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
|
81 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
82 |
Args: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
83 |
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
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
extracted from the URL |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
88 |
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
|
89 |
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
|
90 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
91 |
Returns: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
""" |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
95 |
# 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
|
96 |
context = helper.responses.getUniversalContext(request) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
97 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
98 |
logged_in_id = users.get_current_user() |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
99 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
100 |
alt_response = simple.getAltResponseIfNotDeveloper(request, context, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
101 |
id=logged_in_id) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
102 |
if alt_response: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
103 |
# not a developer |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
104 |
return alt_response |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
105 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
106 |
alt_response = simple.getAltResponseIfNotLoggedIn(request, context, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
107 |
id=logged_in_id) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
108 |
if alt_response: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
109 |
# not logged in |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
110 |
return alt_response |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
111 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
112 |
alt_response = simple.getAltResponseIfNotUser(request, context, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
113 |
id = logged_in_id) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
114 |
if alt_response: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
115 |
# no existing User entity for logged in Google Account. User entity is |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
116 |
# required for creating Documents |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
117 |
return alt_response |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
118 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
119 |
alt_response = simple.getAltResponseIfNotDeveloper(request, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
120 |
context=context) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
121 |
if alt_response: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
122 |
return alt_response |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
123 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
124 |
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
|
125 |
|
251
8f23804302d0
Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents:
247
diff
changeset
|
126 |
path = path_linkname.combinePath([partial_path, linkname]) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
127 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
128 |
# 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
|
129 |
try: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
130 |
doc = document.getDocumentIfPath(path) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
131 |
except out_of_band.ErrorResponse, error: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
132 |
# 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
|
133 |
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
|
134 |
return simple.errorResponse(request, error, template, context) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
135 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
136 |
if request.method == 'POST': |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
137 |
form = EditForm(request.POST) |
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 |
if form.is_valid(): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
140 |
new_partial_path = form.cleaned_data.get('partial_path') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
141 |
new_linkname = form.cleaned_data.get('link_name') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
142 |
title = form.cleaned_data.get('title') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
143 |
short_name = form.cleaned_data.get('short_name') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
144 |
abstract = form.cleaned_data.get('abstract') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
145 |
content = form.cleaned_data.get('content') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
146 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
147 |
doc = soc.logic.document.updateOrCreateDocument( |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
148 |
partial_path=new_partial_path, link_name=new_linkname, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
149 |
title=title, short_name=short_name, abstract=abstract, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
150 |
content=content, user=id_user.getUserFromId(logged_in_id)) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
151 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
152 |
if not doc: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
153 |
return http.HttpResponseRedirect('/') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
154 |
|
251
8f23804302d0
Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents:
247
diff
changeset
|
155 |
new_path = path_linkname.combinePath([new_partial_path, new_linkname]) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
156 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
157 |
# 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
|
158 |
# (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
|
159 |
return helper.responses.redirectToChangedSuffix( |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
160 |
request, path, new_path, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
161 |
params=profile.SUBMIT_PROFILE_SAVED_PARAMS) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
162 |
else: # method == 'GET': |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
163 |
# 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
|
164 |
if path: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
165 |
if doc: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
166 |
# 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
|
167 |
# (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
|
168 |
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
|
169 |
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
|
170 |
# 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
|
171 |
return http.HttpResponseRedirect(request.path) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
172 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
173 |
# 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
|
174 |
# (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
|
175 |
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
|
176 |
helper.requests.getSingleIndexedParamValue( |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
177 |
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
|
178 |
values=SUBMIT_MESSAGES)) |
237
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 |
# populate form with the existing User entity |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
181 |
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
|
182 |
'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
|
183 |
'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
|
184 |
'abstract': doc.abstract, 'content': doc.content, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
185 |
'user': doc.user}) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
186 |
else: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
187 |
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
|
188 |
# 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
|
189 |
return http.HttpResponseRedirect(request.path) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
190 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
191 |
context['lookup_error'] = ugettext_lazy( |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
192 |
'Document with that path not found.') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
193 |
form = EditForm(initial={'link_name': linkname}) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
194 |
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
|
195 |
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
|
196 |
# 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
|
197 |
return http.HttpResponseRedirect(request.path) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
198 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
199 |
# 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
|
200 |
form = EditForm() |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
201 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
202 |
context.update({'form': form, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
203 |
'existing_doc': doc}) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
204 |
|
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
271
diff
changeset
|
205 |
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
|
206 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
207 |
|
274
56e1c1721299
Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents:
272
diff
changeset
|
208 |
class CreateForm(helper.forms.DbModelForm): |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
209 |
"""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
|
210 |
""" |
271
01e90bb21b7e
Replace helpers/custom_widgets.py with helper/widgets.py.
Todd Larsen <tlarsen@google.com>
parents:
269
diff
changeset
|
211 |
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
|
212 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
213 |
class Meta: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
214 |
model = soc.models.document.Document |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
215 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
216 |
#: 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
|
217 |
exclude = ['inheritance_line', 'user', 'created', 'modified'] |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
218 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
219 |
def clean_partial_path(self): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
220 |
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
|
221 |
# 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
|
222 |
return partial_path |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
223 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
224 |
def clean_link_name(self): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
225 |
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
|
226 |
# 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
|
227 |
return link_name |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
228 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
229 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
230 |
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
|
231 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
232 |
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
|
233 |
"""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
|
234 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
235 |
Args: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
236 |
request: the standard django request object |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
237 |
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
|
238 |
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
|
239 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
240 |
Returns: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
241 |
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
|
242 |
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
|
243 |
""" |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
244 |
# 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
|
245 |
context = helper.responses.getUniversalContext(request) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
246 |
|
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
|
247 |
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
|
248 |
|
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
|
249 |
alt_response = simple.getAltResponseIfNotDeveloper(request, |
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
|
250 |
context=context, |
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
|
251 |
id=logged_in_id) |
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
|
252 |
if alt_response: |
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
|
253 |
return alt_response |
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
|
254 |
|
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
255 |
alt_response = simple.getAltResponseIfNotDeveloper(request, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
256 |
context=context) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
257 |
if alt_response: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
258 |
return alt_response |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
259 |
if request.method == 'POST': |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
260 |
form = CreateForm(request.POST) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
261 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
262 |
if form.is_valid(): |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
263 |
new_partial_path = form.cleaned_data.get('partial_path') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
264 |
new_linkname = form.cleaned_data.get('link_name') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
265 |
title = form.cleaned_data.get('title') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
266 |
short_name = form.cleaned_data.get('short_name') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
267 |
abstract = form.cleaned_data.get('abstract') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
268 |
content = form.cleaned_data.get('content') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
269 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
270 |
doc = soc.logic.document.updateOrCreateDocument( |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
271 |
partial_path=new_partial_path, link_name=new_linkname, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
272 |
title=title, short_name=short_name, abstract=abstract, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
273 |
content=content, user=id_user.getUserFromId(logged_in_id)) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
274 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
275 |
if not doc: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
276 |
return http.HttpResponseRedirect('/') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
277 |
|
251
8f23804302d0
Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents:
247
diff
changeset
|
278 |
new_path = path_linkname.combinePath([new_partial_path, new_linkname]) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
279 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
280 |
# 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
|
281 |
# (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
|
282 |
return helper.responses.redirectToChangedSuffix( |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
283 |
request, None, new_path, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
284 |
params=profile.SUBMIT_PROFILE_SAVED_PARAMS) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
285 |
else: # method == 'GET': |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
286 |
# 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
|
287 |
form = CreateForm() |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
288 |
|
285
52e206a6a417
Style fix, as requested by Todd to dict usage
Sverre Rabbelier <srabbelier@gmail.com>
parents:
274
diff
changeset
|
289 |
context['form'] = form |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
290 |
|
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
271
diff
changeset
|
291 |
return helper.responses.respond(request, template, context) |