69 DEF_SITE_DOCS_EDIT_TMPL = 'soc/site/docs/edit.html' |
69 DEF_SITE_DOCS_EDIT_TMPL = 'soc/site/docs/edit.html' |
70 DEF_CREATE_NEW_DOC_MSG = ' You can create a new document by visiting the' \ |
70 DEF_CREATE_NEW_DOC_MSG = ' You can create a new document by visiting the' \ |
71 ' <a href="/site/docs/edit">Create ' \ |
71 ' <a href="/site/docs/edit">Create ' \ |
72 'a New Document</a> page.' |
72 'a New Document</a> page.' |
73 |
73 |
|
74 SUBMIT_MESSAGES = ( |
|
75 ugettext_lazy('Document saved.'), |
|
76 ) |
|
77 |
74 def edit(request, partial_path=None, linkname=None, |
78 def edit(request, partial_path=None, linkname=None, |
75 template=DEF_SITE_DOCS_EDIT_TMPL): |
79 template=DEF_SITE_DOCS_EDIT_TMPL): |
76 """View for a Developer to modify the properties of a Document Model entity. |
80 """View for a Developer to modify the properties of a Document Model entity. |
77 |
81 |
78 Args: |
82 Args: |
137 new_linkname = form.cleaned_data.get('link_name') |
141 new_linkname = form.cleaned_data.get('link_name') |
138 title = form.cleaned_data.get('title') |
142 title = form.cleaned_data.get('title') |
139 short_name = form.cleaned_data.get('short_name') |
143 short_name = form.cleaned_data.get('short_name') |
140 abstract = form.cleaned_data.get('abstract') |
144 abstract = form.cleaned_data.get('abstract') |
141 content = form.cleaned_data.get('content') |
145 content = form.cleaned_data.get('content') |
142 doc_key_name = form.cleaned_data.get('doc_key_name') |
|
143 |
146 |
144 doc = soc.logic.document.updateOrCreateDocument( |
147 doc = soc.logic.document.updateOrCreateDocument( |
145 partial_path=new_partial_path, link_name=new_linkname, |
148 partial_path=new_partial_path, link_name=new_linkname, |
146 title=title, short_name=short_name, abstract=abstract, |
149 title=title, short_name=short_name, abstract=abstract, |
147 content=content, user=id_user.getUserFromId(logged_in_id)) |
150 content=content, user=id_user.getUserFromId(logged_in_id)) |
167 # redirect to aggressively remove 'Profile saved' query parameter |
170 # redirect to aggressively remove 'Profile saved' query parameter |
168 return http.HttpResponseRedirect(request.path) |
171 return http.HttpResponseRedirect(request.path) |
169 |
172 |
170 # referrer was us, so select which submit message to display |
173 # referrer was us, so select which submit message to display |
171 # (may display no message if ?s=0 parameter is not present) |
174 # (may display no message if ?s=0 parameter is not present) |
172 context['submit_message'] = ( |
175 context['notice'] = ( |
173 helper.requests.getSingleIndexedParamValue( |
176 helper.requests.getSingleIndexedParamValue( |
174 request, profile.SUBMIT_MSG_PARAM_NAME, |
177 request, profile.SUBMIT_MSG_PARAM_NAME, |
175 values=profile.SUBMIT_MESSAGES)) |
178 values=SUBMIT_MESSAGES)) |
176 |
179 |
177 # populate form with the existing User entity |
180 # populate form with the existing User entity |
178 form = EditForm(initial={'doc_key_name': doc.key().name(), |
181 form = EditForm(initial={'doc_key_name': doc.key().name(), |
179 'title': doc.title, 'partial_path': doc.partial_path, |
182 'title': doc.title, 'partial_path': doc.partial_path, |
180 'link_name': doc.link_name, 'short_name': doc.short_name, |
183 'link_name': doc.link_name, 'short_name': doc.short_name, |
203 |
206 |
204 |
207 |
205 class CreateForm(helper.forms.DbModelForm): |
208 class CreateForm(helper.forms.DbModelForm): |
206 """Django form displayed when Developer creates a Document. |
209 """Django form displayed when Developer creates a Document. |
207 """ |
210 """ |
208 doc_key_name = forms.CharField(widget=forms.HiddenInput) |
|
209 content = forms.fields.CharField(widget=helper.widgets.TinyMCE()) |
211 content = forms.fields.CharField(widget=helper.widgets.TinyMCE()) |
210 |
212 |
211 class Meta: |
213 class Meta: |
212 model = soc.models.document.Document |
214 model = soc.models.document.Document |
213 |
215 |
240 be filled out, or a redirect to the correct view in the interface. |
242 be filled out, or a redirect to the correct view in the interface. |
241 """ |
243 """ |
242 # create default template context for use with any templates |
244 # create default template context for use with any templates |
243 context = helper.responses.getUniversalContext(request) |
245 context = helper.responses.getUniversalContext(request) |
244 |
246 |
|
247 logged_in_id = users.get_current_user() |
|
248 |
|
249 alt_response = simple.getAltResponseIfNotDeveloper(request, |
|
250 context=context, |
|
251 id=logged_in_id) |
|
252 if alt_response: |
|
253 return alt_response |
|
254 |
245 alt_response = simple.getAltResponseIfNotDeveloper(request, |
255 alt_response = simple.getAltResponseIfNotDeveloper(request, |
246 context=context) |
256 context=context) |
247 if alt_response: |
257 if alt_response: |
248 return alt_response |
258 return alt_response |
249 |
|
250 if request.method == 'POST': |
259 if request.method == 'POST': |
251 form = CreateForm(request.POST) |
260 form = CreateForm(request.POST) |
252 |
261 |
253 if form.is_valid(): |
262 if form.is_valid(): |
254 new_partial_path = form.cleaned_data.get('partial_path') |
263 new_partial_path = form.cleaned_data.get('partial_path') |
255 new_linkname = form.cleaned_data.get('link_name') |
264 new_linkname = form.cleaned_data.get('link_name') |
256 title = form.cleaned_data.get('title') |
265 title = form.cleaned_data.get('title') |
257 short_name = form.cleaned_data.get('short_name') |
266 short_name = form.cleaned_data.get('short_name') |
258 abstract = form.cleaned_data.get('abstract') |
267 abstract = form.cleaned_data.get('abstract') |
259 content = form.cleaned_data.get('content') |
268 content = form.cleaned_data.get('content') |
260 doc_key_name = form.cleaned_data.get('doc_key_name') |
|
261 |
269 |
262 doc = soc.logic.document.updateOrCreateDocument( |
270 doc = soc.logic.document.updateOrCreateDocument( |
263 partial_path=new_partial_path, link_name=new_linkname, |
271 partial_path=new_partial_path, link_name=new_linkname, |
264 title=title, short_name=short_name, abstract=abstract, |
272 title=title, short_name=short_name, abstract=abstract, |
265 content=content, user=id_user.getUserFromId(logged_in_id)) |
273 content=content, user=id_user.getUserFromId(logged_in_id)) |