author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Sat, 15 Nov 2008 21:46:23 +0000 | |
changeset 483 | 70f21691b0e1 |
parent 482 | 839740b061ad |
child 499 | d22e4fe8e64b |
permissions | -rw-r--r-- |
343
1c96c36b58db
Remov "founder" text from the first line of edit.py, this is fix to r799 commit.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
342
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
237
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 |
|
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
17 |
"""Views for editing and examining Documents. |
237
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 |
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
314
diff
changeset
|
35 |
|
9efdc7bc3565
Add missing blank lines between imports and sort all of the imports.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
314
diff
changeset
|
36 |
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
|
37 |
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
|
38 |
from soc.views.helper import access |
365
74dec172944e
Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
361
diff
changeset
|
39 |
from soc.views.helper import decorators |
316
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 |
|
247
4997b54b0400
Fixed typo in DEF_CREATE_NEW_DOC_MSG.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
237
diff
changeset
|
50 |
DEF_CREATE_NEW_DOC_MSG = ' You can create a new document by visiting the' \ |
477
8a8b1bd035c4
Moved from docs -> document
Sverre Rabbelier <srabbelier@gmail.com>
parents:
448
diff
changeset
|
51 |
' <a href="/document/edit">Create ' \ |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
52 |
'a New Document</a> page.' |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
53 |
|
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
|
54 |
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
|
55 |
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
|
56 |
) |
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
|
57 |
|
305
972d28056d9d
Minor style and import fixes
Sverre Rabbelier <srabbelier@gmail.com>
parents:
303
diff
changeset
|
58 |
|
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
59 |
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
|
60 |
"""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
|
61 |
""" |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
62 |
|
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
63 |
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
|
64 |
|
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
65 |
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
|
66 |
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
|
67 |
|
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
68 |
properties = {} |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
properties['content'] = form.cleaned_data.get('content') |
448
075360be6743
Fix not working former_ids. Add support for "Invalid accounts". Now when id from former_ids tries to create a profile "This account is invalid." error message is displayed. Compare emails in lower cases to prevent changing User email to the same email with different character casing (needs some more testing).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
445
diff
changeset
|
74 |
properties['author'] = models.user.logic.getForFields({'id': user}, unique=True) |
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
|
75 |
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
|
76 |
|
435
829fe8302a8b
Refactor out the abundance of dictionary (un)packing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
408
diff
changeset
|
77 |
key_fields = document.logic.getKeyFieldsFromDict(properties) |
829fe8302a8b
Refactor out the abundance of dictionary (un)packing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
408
diff
changeset
|
78 |
|
829fe8302a8b
Refactor out the abundance of dictionary (un)packing
Sverre Rabbelier <srabbelier@gmail.com>
parents:
408
diff
changeset
|
79 |
doc = document.logic.updateOrCreateFromFields(properties, key_fields) |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
80 |
return doc |
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
81 |
|
305
972d28056d9d
Minor style and import fixes
Sverre Rabbelier <srabbelier@gmail.com>
parents:
303
diff
changeset
|
82 |
|
408
7cd6bdfbf95c
Inherit from BaseForm in all forms instead of from DbModelForm. This change doesn't include changes to templates and usage of as_table everywhere (work in progress).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
398
diff
changeset
|
83 |
class CreateForm(helper.forms.BaseForm): |
338
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
84 |
"""Django form displayed when Developer creates a Document. |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
85 |
""" |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
86 |
content = forms.fields.CharField(widget=helper.widgets.TinyMCE( |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
87 |
attrs={'rows':10, 'cols':40})) |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
88 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
89 |
class Meta: |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
90 |
model = soc.models.document.Document |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
91 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
92 |
#: list of model fields which will *not* be gathered by the form |
342
72482d8e5b34
Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents:
338
diff
changeset
|
93 |
exclude = ['inheritance_line', 'author', 'created', 'modified'] |
338
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
94 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
95 |
def clean_partial_path(self): |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
96 |
partial_path = self.cleaned_data.get('partial_path') |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
97 |
# TODO(tlarsen): combine path and link_name and check for uniqueness |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
98 |
return partial_path |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
99 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
100 |
def clean_link_name(self): |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
101 |
link_name = self.cleaned_data.get('link_name') |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
102 |
# TODO(tlarsen): combine path and link_name and check for uniqueness |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
103 |
return link_name |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
104 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
105 |
|
445
31927f21970d
Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents:
435
diff
changeset
|
106 |
DEF_DOCS_CREATE_TMPL = 'soc/models/edit.html' |
338
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
107 |
|
365
74dec172944e
Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
361
diff
changeset
|
108 |
@decorators.view |
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
477
diff
changeset
|
109 |
def create(request, page_name=None, template=DEF_DOCS_CREATE_TMPL): |
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
110 |
"""View to create a new Document entity. |
338
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
111 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
112 |
Args: |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
113 |
request: the standard django request object |
358
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
351
diff
changeset
|
114 |
page: a soc.logic.site.page.Page object which is abstraction that combines |
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
351
diff
changeset
|
115 |
a Django view with sidebar menu info |
338
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
116 |
template: the "sibling" template (or a search list of such templates) |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
117 |
from which to construct the public.html template name (or names) |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
118 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
119 |
Returns: |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
120 |
A subclass of django.http.HttpResponse which either contains the form to |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
121 |
be filled out, or a redirect to the correct view in the interface. |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
122 |
""" |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
123 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
124 |
try: |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
125 |
access.checkIsDeveloper(request) |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
126 |
except soc.views.out_of_band.AccessViolationResponse, alt_response: |
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
127 |
# TODO(tlarsen): change this to just limit the Documents that can be |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
128 |
# created by the User in their current Role |
338
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
129 |
return alt_response.response() |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
130 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
131 |
# create default template context for use with any templates |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
132 |
context = helper.responses.getUniversalContext(request) |
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
477
diff
changeset
|
133 |
context['page_name'] = page_name |
338
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
134 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
135 |
if request.method == 'POST': |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
136 |
form = CreateForm(request.POST) |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
137 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
138 |
if form.is_valid(): |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
139 |
doc = getDocForForm(form) |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
140 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
141 |
if not doc: |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
142 |
return http.HttpResponseRedirect('/') |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
143 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
144 |
new_path = path_link_name.combinePath([doc.partial_path, doc.link_name]) |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
145 |
|
477
8a8b1bd035c4
Moved from docs -> document
Sverre Rabbelier <srabbelier@gmail.com>
parents:
448
diff
changeset
|
146 |
# redirect to new /document/edit/new_path?s=0 |
338
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
147 |
# (causes 'Profile saved' message to be displayed) |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
148 |
return helper.responses.redirectToChangedSuffix( |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
149 |
request, None, new_path, |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
150 |
params=profile.SUBMIT_PROFILE_SAVED_PARAMS) |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
151 |
else: # method == 'GET': |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
152 |
# no link name specified, so start with an empty form |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
153 |
form = CreateForm() |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
154 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
155 |
context['form'] = form |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
156 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
157 |
return helper.responses.respond(request, template, context) |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
158 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
159 |
|
445
31927f21970d
Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents:
435
diff
changeset
|
160 |
DEF_DOCS_EDIT_TMPL = 'soc/models/edit.html' |
338
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
161 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
162 |
class EditForm(CreateForm): |
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
163 |
"""Django form displayed a Document is edited. |
338
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
164 |
""" |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
165 |
doc_key_name = forms.fields.CharField(widget=forms.HiddenInput) |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
166 |
created_by = forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(), |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
167 |
required=False) |
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
168 |
|
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
169 |
|
365
74dec172944e
Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
361
diff
changeset
|
170 |
@decorators.view |
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
477
diff
changeset
|
171 |
def edit(request, page_name=None, partial_path=None, link_name=None, |
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
172 |
template=DEF_DOCS_EDIT_TMPL): |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
173 |
"""View to modify the properties of a Document Model entity. |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
174 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
175 |
Args: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
176 |
request: the standard django request object |
358
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
351
diff
changeset
|
177 |
page: a soc.logic.site.page.Page object which is abstraction that combines |
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
351
diff
changeset
|
178 |
a Django view with sidebar menu info |
251
8f23804302d0
Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents:
247
diff
changeset
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
extracted from the URL |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
183 |
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
|
184 |
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
|
185 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
186 |
Returns: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
""" |
294
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
190 |
|
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
191 |
try: |
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
192 |
access.checkIsDeveloper(request) |
303
4f1bb54ddae5
Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
299
diff
changeset
|
193 |
except soc.views.out_of_band.AccessViolationResponse, alt_response: |
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
194 |
# TODO(tlarsen): change this to just limit the Documents that can be |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
195 |
# edited by the User in their current Role |
294
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
196 |
return alt_response.response() |
1fdaab4a6ef2
Refactor existing code to use the new access module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
290
diff
changeset
|
197 |
|
374
9363b9dc2983
Add the Page object to the context of each view. Update templates to make
Todd Larsen <tlarsen@google.com>
parents:
365
diff
changeset
|
198 |
# 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
|
199 |
context = helper.responses.getUniversalContext(request) |
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
477
diff
changeset
|
200 |
context['page_name'] = page_name |
237
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 |
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
|
203 |
|
298
c76a366c7ab4
Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents:
294
diff
changeset
|
204 |
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
|
205 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
206 |
# 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
|
207 |
try: |
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
208 |
if path: |
309
7190b224c701
Made the existing code use the new soc.logic.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
305
diff
changeset
|
209 |
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
|
210 |
link_name=link_name) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
211 |
except out_of_band.ErrorResponse, error: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
212 |
# 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
|
213 |
error.message = error.message + DEF_CREATE_NEW_DOC_MSG |
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
477
diff
changeset
|
214 |
return simple.errorResponse(request, page_name, error, template, context) |
237
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 |
if request.method == 'POST': |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
217 |
form = EditForm(request.POST) |
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 |
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
|
220 |
doc = getDocForForm(form) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
221 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
222 |
if not doc: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
223 |
return http.HttpResponseRedirect('/') |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
224 |
|
299
a1cc853a56e5
Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents:
298
diff
changeset
|
225 |
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
|
226 |
|
477
8a8b1bd035c4
Moved from docs -> document
Sverre Rabbelier <srabbelier@gmail.com>
parents:
448
diff
changeset
|
227 |
# redirect to new /document/edit/new_path?s=0 |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
228 |
# (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
|
229 |
return helper.responses.redirectToChangedSuffix( |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
230 |
request, path, new_path, |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
231 |
params=profile.SUBMIT_PROFILE_SAVED_PARAMS) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
232 |
else: # method == 'GET': |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
233 |
# 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
|
234 |
if path: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
235 |
if doc: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
236 |
# 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
|
237 |
# (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
|
238 |
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
|
239 |
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
|
240 |
# 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
|
241 |
return http.HttpResponseRedirect(request.path) |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
242 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
243 |
# 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
|
244 |
# (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
|
245 |
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
|
246 |
helper.requests.getSingleIndexedParamValue( |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
247 |
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
|
248 |
values=SUBMIT_MESSAGES)) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
249 |
|
338
0d78f41dde9b
Show "Created by" read-only field in Document Edit view. Update size of TinyMCE widget in Document Edit/Create views. Change user property name to founder in Document model and update files according to this change (now founder is used in Group and Document models). Remove not used variables and imports in views/site/docs/edit.py. Refactor EditForm and CreateForm in views/site/docs/edit.py so that EditForm inherits from CreateForm and just extends it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
329
diff
changeset
|
250 |
# populate form with the existing Document entity |
342
72482d8e5b34
Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents:
338
diff
changeset
|
251 |
author_link_name = doc.author.link_name |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
252 |
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
|
253 |
'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
|
254 |
'link_name': doc.link_name, 'short_name': doc.short_name, |
351
b37fc4c1e189
Eliminate the Work.abstract property and move the Document.content property
Todd Larsen <tlarsen@google.com>
parents:
343
diff
changeset
|
255 |
'content': doc.content, 'author': doc.author, |
365
74dec172944e
Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
361
diff
changeset
|
256 |
'is_featured': doc.is_featured, 'created_by': author_link_name}) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
257 |
else: |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
258 |
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
|
259 |
# 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
|
260 |
return http.HttpResponseRedirect(request.path) |
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 |
context['lookup_error'] = ugettext_lazy( |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
263 |
'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
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
# 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
|
268 |
return http.HttpResponseRedirect(request.path) |
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 |
# 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
|
271 |
form = EditForm() |
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
272 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
273 |
context.update({'form': form, |
398
aa1e786a0b1d
Rename 'existing_doc' and 'document' to entity
Sverre Rabbelier <srabbelier@gmail.com>
parents:
377
diff
changeset
|
274 |
'entity': doc}) |
237
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
275 |
|
272
00cea07656c0
Move helpers/response_helpers.py to helper/responses.py.
Todd Larsen <tlarsen@google.com>
parents:
271
diff
changeset
|
276 |
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
|
277 |
|
d360162714b6
Implements a Site (Developer) generic Document editor form.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
278 |
|
365
74dec172944e
Create decorators module in view/helper and add view decorator that catches exceptions like DeadlineExceededError, MemoryError, AssertionError (this code is being moved from respond function). Add view decorator to all view functions. In addition remove not needed imports from all affected files and fix too long lines.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
361
diff
changeset
|
279 |
@decorators.view |
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
477
diff
changeset
|
280 |
def delete(request, page_name=None, partial_path=None, link_name=None, |
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
281 |
template=DEF_DOCS_EDIT_TMPL): |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
282 |
"""Request handler to delete Document Model entity. |
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
|
283 |
|
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 |
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
|
285 |
request: the standard django request object |
358
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
351
diff
changeset
|
286 |
page: a soc.logic.site.page.Page object which is abstraction that combines |
843d83b87282
Add page=None parameter to all views. Information from page argument (which is soc.logic.site.page.Page object) is going to be used later in views code and for some context values. Fix some indentions in __doc__ strings. Add proper __doc__ string for all() function in sponsor/list.py module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
351
diff
changeset
|
287 |
a Django view with sidebar menu info |
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
|
288 |
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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
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
|
293 |
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
|
294 |
|
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 |
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
|
296 |
A subclass of django.http.HttpResponse which redirects |
477
8a8b1bd035c4
Moved from docs -> document
Sverre Rabbelier <srabbelier@gmail.com>
parents:
448
diff
changeset
|
297 |
to /site/document/list. |
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
|
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 |
|
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 |
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
|
301 |
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
|
302 |
except soc.views.out_of_band.AccessViolationResponse, alt_response: |
377
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
303 |
# TODO(tlarsen): change this to just limit the Documents that can be |
d94ec6f104cc
Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents:
374
diff
changeset
|
304 |
# deleted by the User in their current Role |
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
|
305 |
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
|
306 |
|
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 |
# 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
|
308 |
context = helper.responses.getUniversalContext(request) |
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
477
diff
changeset
|
309 |
context['page_name'] = page_name |
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
|
310 |
|
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 |
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
|
312 |
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
|
313 |
|
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 |
# 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
|
315 |
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
|
316 |
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
|
317 |
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
|
318 |
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
|
319 |
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
|
320 |
# 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
|
321 |
error.message = error.message + DEF_CREATE_NEW_DOC_MSG |
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
477
diff
changeset
|
322 |
return simple.errorResponse(request, page_name, error, 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
|
323 |
|
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 |
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
|
325 |
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
|
326 |
|
477
8a8b1bd035c4
Moved from docs -> document
Sverre Rabbelier <srabbelier@gmail.com>
parents:
448
diff
changeset
|
327 |
return http.HttpResponseRedirect('/document/list') |