39 from soc.views import sitemap |
39 from soc.views import sitemap |
40 |
40 |
41 import soc.logic |
41 import soc.logic |
42 import soc.logic.lists |
42 import soc.logic.lists |
43 import soc.views.helper.lists |
43 import soc.views.helper.lists |
44 import soc.views.helper.responses |
|
45 import soc.views.helper.params |
44 import soc.views.helper.params |
46 |
45 |
47 |
46 |
48 class View(object): |
47 class View(object): |
49 """Views for entity classes. |
48 """Views for entity classes. |
101 kwargs: the Key Fields for the specified entity |
100 kwargs: the Key Fields for the specified entity |
102 """ |
101 """ |
103 |
102 |
104 # create default template context for use with any templates |
103 # create default template context for use with any templates |
105 context = helper.responses.getUniversalContext(request) |
104 context = helper.responses.getUniversalContext(request) |
|
105 helper.responses.useJavaScript(context, params['js_uses_all']) |
106 context['page_name'] = page_name |
106 context['page_name'] = page_name |
107 entity = None |
107 entity = None |
108 |
108 |
109 if not all(kwargs.values()): |
109 if not all(kwargs.values()): |
110 #TODO: Change this into a proper redirect |
110 #TODO: Change this into a proper redirect |
149 kwargs: the Key Fields for the specified entity |
149 kwargs: the Key Fields for the specified entity |
150 """ |
150 """ |
151 |
151 |
152 # create default template context for use with any templates |
152 # create default template context for use with any templates |
153 context = helper.responses.getUniversalContext(request) |
153 context = helper.responses.getUniversalContext(request) |
|
154 helper.responses.useJavaScript(context, params['js_uses_all']) |
154 context['page_name'] = page_name |
155 context['page_name'] = page_name |
155 |
156 |
156 try: |
157 try: |
157 entity = self._logic.getFromKeyFieldsOr404(kwargs) |
158 entity = self._logic.getFromKeyFieldsOr404(kwargs) |
158 except out_of_band.Error, error: |
159 except out_of_band.Error, error: |
198 return self.public(request, access_type, page_name=page_name, |
199 return self.public(request, access_type, page_name=page_name, |
199 params=params, **kwargs) |
200 params=params, **kwargs) |
200 |
201 |
201 # create default template context for use with any templates |
202 # create default template context for use with any templates |
202 context = helper.responses.getUniversalContext(request) |
203 context = helper.responses.getUniversalContext(request) |
|
204 helper.responses.useJavaScript(context, params['js_uses_all']) |
203 context['page_name'] = page_name |
205 context['page_name'] = page_name |
204 entity = None |
206 entity = None |
205 |
207 |
206 if not all(kwargs.values()): |
208 if not all(kwargs.values()): |
207 #TODO: Change this into a proper redirect |
209 #TODO: Change this into a proper redirect |
292 params: a dict with params for this View |
294 params: a dict with params for this View |
293 kwargs: The Key Fields for the specified entity |
295 kwargs: The Key Fields for the specified entity |
294 """ |
296 """ |
295 |
297 |
296 context = helper.responses.getUniversalContext(request) |
298 context = helper.responses.getUniversalContext(request) |
|
299 helper.responses.useJavaScript(context, params['js_uses_all']) |
297 context['page_name'] = page_name |
300 context['page_name'] = page_name |
298 entity = None |
301 entity = None |
299 |
302 |
300 try: |
303 try: |
301 if all(kwargs.values()): |
304 if all(kwargs.values()): |
485 to display the list of all entities for this View. |
488 to display the list of all entities for this View. |
486 """ |
489 """ |
487 |
490 |
488 context = dicts.merge(context, |
491 context = dicts.merge(context, |
489 helper.responses.getUniversalContext(request)) |
492 helper.responses.getUniversalContext(request)) |
|
493 helper.responses.useJavaScript(context, params['js_uses_all']) |
490 context['page_name'] = page_name |
494 context['page_name'] = page_name |
491 context['list'] = soc.logic.lists.Lists(contents) |
495 context['list'] = soc.logic.lists.Lists(contents) |
492 |
496 |
493 context['entity_type'] = params['name'] |
497 context['entity_type'] = params['name'] |
494 context['entity_type_plural'] = params['name_plural'] |
498 context['entity_type_plural'] = params['name_plural'] |
521 error_edit: see name |
525 error_edit: see name |
522 delete_redirect: The delete_redirect value is used as the url to |
526 delete_redirect: The delete_redirect value is used as the url to |
523 redirect to after having successfully deleted the entity. |
527 redirect to after having successfully deleted the entity. |
524 """ |
528 """ |
525 |
529 |
526 # create default template context for use with any templates |
|
527 context = helper.responses.getUniversalContext(request) |
|
528 context['page_name'] = page_name |
|
529 entity = None |
|
530 |
|
531 try: |
530 try: |
532 entity = self._logic.getFromKeyFieldsOr404(kwargs) |
531 entity = self._logic.getFromKeyFieldsOr404(kwargs) |
533 except out_of_band.Error, error: |
532 except out_of_band.Error, error: |
534 error.message_fmt = ( |
533 error.message_fmt = ( |
535 error.message_fmt + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % { |
534 error.message_fmt + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % { |
536 'entity_type_lower' : params['name'].lower(), |
535 'entity_type_lower' : params['name'].lower(), |
537 'entity_type' : params['name'], |
536 'entity_type' : params['name'], |
538 'create' : params['missing_redirect']}) |
537 'create' : params['missing_redirect']}) |
539 return helper.responses.errorResponse( |
538 return helper.responses.errorResponse( |
540 error, request, template=params['error_edit'], context=context) |
539 error, request, template=params['error_edit']) |
541 |
|
542 if not entity: |
|
543 #TODO: Create a proper error page for this |
|
544 return http.HttpResponseRedirect('/') |
|
545 |
540 |
546 if not self._logic.isDeletable(entity): |
541 if not self._logic.isDeletable(entity): |
547 # TODO: Update the notice area telling the user that they |
542 # TODO: Update the notice area telling the user that they |
548 # can't delete the entity |
543 # can't delete the entity |
549 pass |
544 pass |