106 return link_name |
106 return link_name |
107 |
107 |
108 |
108 |
109 DEF_SITE_DOCS_CREATE_TMPL = 'soc/site/docs/edit.html' |
109 DEF_SITE_DOCS_CREATE_TMPL = 'soc/site/docs/edit.html' |
110 |
110 |
111 def create(request, template=DEF_SITE_DOCS_CREATE_TMPL): |
111 def create(request, page=None, template=DEF_SITE_DOCS_CREATE_TMPL): |
112 """View for a Developer to create a new Document entity. |
112 """View for a Developer to create a new Document entity. |
113 |
113 |
114 Args: |
114 Args: |
115 request: the standard django request object |
115 request: the standard django request object |
|
116 page: a soc.logic.site.page.Page object which is abstraction that combines |
|
117 a Django view with sidebar menu info |
116 template: the "sibling" template (or a search list of such templates) |
118 template: the "sibling" template (or a search list of such templates) |
117 from which to construct the public.html template name (or names) |
119 from which to construct the public.html template name (or names) |
118 |
120 |
119 Returns: |
121 Returns: |
120 A subclass of django.http.HttpResponse which either contains the form to |
122 A subclass of django.http.HttpResponse which either contains the form to |
162 doc_key_name = forms.fields.CharField(widget=forms.HiddenInput) |
164 doc_key_name = forms.fields.CharField(widget=forms.HiddenInput) |
163 created_by = forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(), |
165 created_by = forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(), |
164 required=False) |
166 required=False) |
165 |
167 |
166 |
168 |
167 def edit(request, partial_path=None, link_name=None, |
169 def edit(request, page=None, partial_path=None, link_name=None, |
168 template=DEF_SITE_DOCS_EDIT_TMPL): |
170 template=DEF_SITE_DOCS_EDIT_TMPL): |
169 """View for a Developer to modify the properties of a Document Model entity. |
171 """View for a Developer to modify the properties of a Document Model entity. |
170 |
172 |
171 Args: |
173 Args: |
172 request: the standard django request object |
174 request: the standard django request object |
|
175 page: a soc.logic.site.page.Page object which is abstraction that combines |
|
176 a Django view with sidebar menu info |
173 partial_path: the Document's site-unique "path" extracted from the URL, |
177 partial_path: the Document's site-unique "path" extracted from the URL, |
174 minus the trailing link_name |
178 minus the trailing link_name |
175 link_name: the last portion of the Document's site-unique "path" |
179 link_name: the last portion of the Document's site-unique "path" |
176 extracted from the URL |
180 extracted from the URL |
177 template: the "sibling" template (or a search list of such templates) |
181 template: the "sibling" template (or a search list of such templates) |
200 doc = document.logic.getFromFields(partial_path=partial_path, |
204 doc = document.logic.getFromFields(partial_path=partial_path, |
201 link_name=link_name) |
205 link_name=link_name) |
202 except out_of_band.ErrorResponse, error: |
206 except out_of_band.ErrorResponse, error: |
203 # show custom 404 page when path doesn't exist in Datastore |
207 # show custom 404 page when path doesn't exist in Datastore |
204 error.message = error.message + DEF_CREATE_NEW_DOC_MSG |
208 error.message = error.message + DEF_CREATE_NEW_DOC_MSG |
205 return simple.errorResponse(request, error, template, context) |
209 return simple.errorResponse(request, error, template, context, page) |
206 |
210 |
207 if request.method == 'POST': |
211 if request.method == 'POST': |
208 form = EditForm(request.POST) |
212 form = EditForm(request.POST) |
209 |
213 |
210 if form.is_valid(): |
214 if form.is_valid(): |
265 'existing_doc': doc}) |
269 'existing_doc': doc}) |
266 |
270 |
267 return helper.responses.respond(request, template, context) |
271 return helper.responses.respond(request, template, context) |
268 |
272 |
269 |
273 |
270 def delete(request, partial_path=None, link_name=None, |
274 def delete(request, page=None, partial_path=None, link_name=None, |
271 template=DEF_SITE_DOCS_EDIT_TMPL): |
275 template=DEF_SITE_DOCS_EDIT_TMPL): |
272 """Request handler for a Developer to delete Document Model entity. |
276 """Request handler for a Developer to delete Document Model entity. |
273 |
277 |
274 Args: |
278 Args: |
275 request: the standard django request object |
279 request: the standard django request object |
|
280 page: a soc.logic.site.page.Page object which is abstraction that combines |
|
281 a Django view with sidebar menu info |
276 partial_path: the Document's site-unique "path" extracted from the URL, |
282 partial_path: the Document's site-unique "path" extracted from the URL, |
277 minus the trailing link_name |
283 minus the trailing link_name |
278 link_name: the last portion of the Document's site-unique "path" |
284 link_name: the last portion of the Document's site-unique "path" |
279 extracted from the URL |
285 extracted from the URL |
280 template: the "sibling" template (or a search list of such templates) |
286 template: the "sibling" template (or a search list of such templates) |
302 existing_doc = document.logic.getFromFields(partial_path=partial_path, |
308 existing_doc = document.logic.getFromFields(partial_path=partial_path, |
303 link_name=link_name) |
309 link_name=link_name) |
304 except out_of_band.ErrorResponse, error: |
310 except out_of_band.ErrorResponse, error: |
305 # show custom 404 page when path doesn't exist in Datastore |
311 # show custom 404 page when path doesn't exist in Datastore |
306 error.message = error.message + DEF_CREATE_NEW_DOC_MSG |
312 error.message = error.message + DEF_CREATE_NEW_DOC_MSG |
307 return simple.errorResponse(request, error, template, context) |
313 return simple.errorResponse(request, error, template, context, page) |
308 |
314 |
309 if existing_doc: |
315 if existing_doc: |
310 document.logic.delete(existing_doc) |
316 document.logic.delete(existing_doc) |
311 |
317 |
312 return http.HttpResponseRedirect('/site/docs/list') |
318 return http.HttpResponseRedirect('/site/docs/list') |