equal
deleted
inserted
replaced
104 |
104 |
105 |
105 |
106 DEF_DOCS_CREATE_TMPL = 'soc/models/edit.html' |
106 DEF_DOCS_CREATE_TMPL = 'soc/models/edit.html' |
107 |
107 |
108 @decorators.view |
108 @decorators.view |
109 def create(request, page=None, template=DEF_DOCS_CREATE_TMPL): |
109 def create(request, page_name=None, template=DEF_DOCS_CREATE_TMPL): |
110 """View to create a new Document entity. |
110 """View to create a new Document entity. |
111 |
111 |
112 Args: |
112 Args: |
113 request: the standard django request object |
113 request: the standard django request object |
114 page: a soc.logic.site.page.Page object which is abstraction that combines |
114 page: a soc.logic.site.page.Page object which is abstraction that combines |
128 # created by the User in their current Role |
128 # created by the User in their current Role |
129 return alt_response.response() |
129 return alt_response.response() |
130 |
130 |
131 # create default template context for use with any templates |
131 # create default template context for use with any templates |
132 context = helper.responses.getUniversalContext(request) |
132 context = helper.responses.getUniversalContext(request) |
133 context['page'] = page |
133 context['page_name'] = page_name |
134 |
134 |
135 if request.method == 'POST': |
135 if request.method == 'POST': |
136 form = CreateForm(request.POST) |
136 form = CreateForm(request.POST) |
137 |
137 |
138 if form.is_valid(): |
138 if form.is_valid(): |
166 created_by = forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(), |
166 created_by = forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(), |
167 required=False) |
167 required=False) |
168 |
168 |
169 |
169 |
170 @decorators.view |
170 @decorators.view |
171 def edit(request, page=None, partial_path=None, link_name=None, |
171 def edit(request, page_name=None, partial_path=None, link_name=None, |
172 template=DEF_DOCS_EDIT_TMPL): |
172 template=DEF_DOCS_EDIT_TMPL): |
173 """View to modify the properties of a Document Model entity. |
173 """View to modify the properties of a Document Model entity. |
174 |
174 |
175 Args: |
175 Args: |
176 request: the standard django request object |
176 request: the standard django request object |
195 # edited by the User in their current Role |
195 # edited by the User in their current Role |
196 return alt_response.response() |
196 return alt_response.response() |
197 |
197 |
198 # create default template context for use with any templates |
198 # create default template context for use with any templates |
199 context = helper.responses.getUniversalContext(request) |
199 context = helper.responses.getUniversalContext(request) |
200 context['page'] = page |
200 context['page_name'] = page_name |
201 |
201 |
202 doc = None # assume that no Document entity will be found |
202 doc = None # assume that no Document entity will be found |
203 |
203 |
204 path = path_link_name.combinePath([partial_path, link_name]) |
204 path = path_link_name.combinePath([partial_path, link_name]) |
205 |
205 |
209 doc = document.logic.getFromFields(partial_path=partial_path, |
209 doc = document.logic.getFromFields(partial_path=partial_path, |
210 link_name=link_name) |
210 link_name=link_name) |
211 except out_of_band.ErrorResponse, error: |
211 except out_of_band.ErrorResponse, error: |
212 # show custom 404 page when path doesn't exist in Datastore |
212 # show custom 404 page when path doesn't exist in Datastore |
213 error.message = error.message + DEF_CREATE_NEW_DOC_MSG |
213 error.message = error.message + DEF_CREATE_NEW_DOC_MSG |
214 return simple.errorResponse(request, page, error, template, context) |
214 return simple.errorResponse(request, page_name, error, template, context) |
215 |
215 |
216 if request.method == 'POST': |
216 if request.method == 'POST': |
217 form = EditForm(request.POST) |
217 form = EditForm(request.POST) |
218 |
218 |
219 if form.is_valid(): |
219 if form.is_valid(): |
275 |
275 |
276 return helper.responses.respond(request, template, context) |
276 return helper.responses.respond(request, template, context) |
277 |
277 |
278 |
278 |
279 @decorators.view |
279 @decorators.view |
280 def delete(request, page=None, partial_path=None, link_name=None, |
280 def delete(request, page_name=None, partial_path=None, link_name=None, |
281 template=DEF_DOCS_EDIT_TMPL): |
281 template=DEF_DOCS_EDIT_TMPL): |
282 """Request handler to delete Document Model entity. |
282 """Request handler to delete Document Model entity. |
283 |
283 |
284 Args: |
284 Args: |
285 request: the standard django request object |
285 request: the standard django request object |
304 # deleted by the User in their current Role |
304 # deleted by the User in their current Role |
305 return alt_response.response() |
305 return alt_response.response() |
306 |
306 |
307 # create default template context for use with any templates |
307 # create default template context for use with any templates |
308 context = helper.responses.getUniversalContext(request) |
308 context = helper.responses.getUniversalContext(request) |
309 context['page'] = page |
309 context['page_name'] = page_name |
310 |
310 |
311 existing_doc = None |
311 existing_doc = None |
312 path = path_link_name.combinePath([partial_path, link_name]) |
312 path = path_link_name.combinePath([partial_path, link_name]) |
313 |
313 |
314 # try to fetch Document entity corresponding to path if one exists |
314 # try to fetch Document entity corresponding to path if one exists |
317 existing_doc = document.logic.getFromFields(partial_path=partial_path, |
317 existing_doc = document.logic.getFromFields(partial_path=partial_path, |
318 link_name=link_name) |
318 link_name=link_name) |
319 except out_of_band.ErrorResponse, error: |
319 except out_of_band.ErrorResponse, error: |
320 # show custom 404 page when path doesn't exist in Datastore |
320 # show custom 404 page when path doesn't exist in Datastore |
321 error.message = error.message + DEF_CREATE_NEW_DOC_MSG |
321 error.message = error.message + DEF_CREATE_NEW_DOC_MSG |
322 return simple.errorResponse(request, page, error, template, context) |
322 return simple.errorResponse(request, page_name, error, template, context) |
323 |
323 |
324 if existing_doc: |
324 if existing_doc: |
325 document.logic.delete(existing_doc) |
325 document.logic.delete(existing_doc) |
326 |
326 |
327 return http.HttpResponseRedirect('/document/list') |
327 return http.HttpResponseRedirect('/document/list') |