Beispiel #1
0
    def continuation_here(self,
                          request_dict={},
                          default_cont="",
                          base_here=None):
        """
        Returns a URL that returns control to the current page, to be passed as a
        continuation_uri parameter to any subsidiary pages invoked.  Such continuation 
        URIs are cascaded, so that the return URI includes a the `continuation_url` 
        for the current page.

        request_dict    is a request dictionary that is expected to contain the 
                        continuation_url value to use, and other parameters to 
                        be included an any continuation back to the current page.
        default_cont    is a default continuation URI to be used for returning from 
                        the current page if the current POST request does not specify
                        a continuation_url query parameter.
        base_here       if specified, overrides the current request path as the base URI
                        to be used to return to the currently displayed page (e.g. when
                        current request URI is non-idempotent, such as creating a new 
                        entity).
        """
        # Note: use default if request/form parameter is present but blank:
        if not base_here:
            base_here = self.get_request_path()
        continuation_next = self.continuation_next(request_dict, default_cont)
        return uri_with_params(
            base_here,
            continuation_params({"continuation_url": continuation_next},
                                request_dict))
 def complete_remove_entity(self, coll_id, type_id, entity_id,
                            default_continuation_url, request_params):
     """
     Complete action to remove an entity.
     """
     continuation_url = (request_params.get('completion_url', None)
                         or default_continuation_url)
     continuation_url_params = continuation_params(request_params)
     viewinfo = DisplayInfo(self, "delete", request_params,
                            continuation_url)
     viewinfo.get_site_info(self.get_request_host())
     viewinfo.get_coll_info(coll_id)
     viewinfo.get_type_info(type_id)
     viewinfo.check_authorization("delete")
     if viewinfo.http_response:
         return viewinfo.http_response
     typeinfo = viewinfo.entitytypeinfo
     message_vals = {
         'id': entity_id,
         'type_id': type_id,
         'coll_id': coll_id
     }
     messages = ({
         'entity_removed':
         typeinfo.entitymessages['entity_removed'] % message_vals
     })
     err = typeinfo.entityclass.remove(typeinfo.entityparent, entity_id)
     if err:
         return self.redirect_error(continuation_url,
                                    continuation_url_params,
                                    error_message=str(err))
     return self.redirect_info(continuation_url,
                               continuation_url_params,
                               info_message=messages['entity_removed'])
Beispiel #3
0
    def continuation_here(self, request_dict={}, default_cont="", base_here=None):
        """
        Returns a URL that returns control to the current page, to be passed as a
        continuation_uri parameter to any subsidiary pages invoked.  Such continuation 
        URIs are cascaded, so that the return URI includes a the `continuation_url` 
        for the current page.

        request_dict    is a request dictionary that is expected to contain the 
                        continuation_url value to use, and other parameters to 
                        be included an any continuation back to the current page.
        default_cont    is a default continuation URI to be used for returning from 
                        the current page if the current POST request does not specify
                        a continuation_url query parameter.
        base_here       if specified, overrides the current request path as the base URI
                        to be used to return to the currently displayed page (e.g. when
                        current request URI is non-idempotent, such as creating a new 
                        entity).
        """
        # Note: use default if request/form parameter is present but blank:
        if not base_here:
            base_here = self.get_request_path()
        continuation_next = self.continuation_next(request_dict, default_cont)
        return uri_with_params(base_here, 
            continuation_params({"continuation_url": continuation_next}, request_dict)
            )
 def complete_remove_entity(self, 
         coll_id, type_id, entity_id, 
         default_continuation_url, request_params):
     """
     Complete action to remove an entity.
     """
     continuation_url = (
         request_params.get('completion_url', None) or
         default_continuation_url
         )
     continuation_url_params = continuation_params(request_params)
     viewinfo = DisplayInfo(self, "delete", request_params, continuation_url)
     viewinfo.get_site_info(self.get_request_host())
     viewinfo.get_coll_info(coll_id)
     viewinfo.get_type_info(type_id)
     viewinfo.check_authorization("delete")
     if viewinfo.http_response:
         return viewinfo.http_response
     typeinfo     = viewinfo.entitytypeinfo
     message_vals = {'id': entity_id, 'type_id': type_id, 'coll_id': coll_id}
     messages     = (
         { 'entity_removed': typeinfo.entitymessages['entity_removed']%message_vals
         })
     err = typeinfo.entityclass.remove(typeinfo.entityparent, entity_id)
     if err:
         return self.redirect_error(
             continuation_url, continuation_url_params, error_message=str(err)
             )
     return self.redirect_info(
         continuation_url, continuation_url_params, 
         info_message=messages['entity_removed']
         )
Beispiel #5
0
 def get_continuation_url(self):
     """
     Generate continuation URL for return back to the current request page
     """
     chere = ""
     if self._extras is None:
         log.warning("bound_field.get_continuation_url() - no extra context provided")
     else:
         requrl = self._extras.get("request_url", "")
         if requrl:
             chere  = uri_with_params(requrl, continuation_params(self._extras))
     # log.debug('bound_field.get_continuation_url %s'%(chere,))
     return chere
Beispiel #6
0
 def get_continuation_url(self):
     """
     Generate continuation URL for return back to the current request page
     """
     chere = ""
     if self._extras is None:
         log.warning(
             "bound_field.get_continuation_url() - no extra context provided"
         )
     else:
         requrl = self._extras.get("request_url", "")
         if requrl:
             chere = uri_with_params(requrl,
                                     continuation_params(self._extras))
     # log.debug('bound_field.get_continuation_url %s'%(chere,))
     return chere
Beispiel #7
0
 def post(self, request, coll_id, type_id):
     """
     Process options to complete action to remove an entity data record.
     """
     log.debug("EntityDataDeleteConfirmedView.post: %r" % (request.POST))
     if "entity_delete" in request.POST:
         entity_id = request.POST['entity_id']
         continuation_url = (request.POST.get('completion_url', None) or
                             self.view_uri("AnnalistEntityDefaultListAll",
                                           coll_id=coll_id))
         continuation_url_params = continuation_params(request.POST.dict())
         # log.info("continuation_params %r"%(continuation_params,))
         return self.complete_remove_entity(coll_id, type_id, entity_id,
                                            continuation_url,
                                            continuation_url_params)
     return self.error(self.error400values())
Beispiel #8
0
    def continuation_urls(self, request_dict, default_cont, base_here=None):
        """
        Returns a tuple of two continuation URI dictionary values:

        [0] { 'continuation_url': continuation_next }
        [1] { 'continuation_url': continuation_here }

        where:

        `continuation_next` is the URI to use after the current page has completed
        processing, which is either supplied as a parameter to the current page or 
        set to an indicated default.

        `continuation_here` is a URI that returns control to the current page, to be passed
        as a contionuation_uri parameter to any subsidiary pages invoked.  Such continuation 
        URIs are cascaded, so that the return URI includes a the `continuation_url` for the 
        current page.

        request_dict    is a request dictionary that is expected to contain a 
                        to continuation_url value to use, other parameters to be 
                        included an any continuation back to the current page.
        default_cont    is a default continuation URI to be used for returning from 
                        the current page if the current POST request does not specify
                        a continuation_url query parameter.
        base_here       if specified, overrides the current request path as the base URI
                        to be used to return to the currently displayed page (e.g. when
                        current request URI is non-idempotent, such as creating a new 
                        entity).
        """
        # Note: use default if request/form parameter is present but blank:
        continuation_url = request_dict.get(
            "continuation_url") or default_cont or None
        if not base_here:
            base_here = self.get_request_path()
        if continuation_url:
            continuation_next = {"continuation_url": continuation_url}
        else:
            continuation_next = {}
        continuation_here = uri_with_params(
            base_here,
            continuation_params(continuation_next, request_dict.dict()))
        # continuation_here   = uri_with_continuation_params(
        #     base_here, continuation_next, request_dict.dict()
        #     )
        return (continuation_next, {"continuation_url": continuation_here})
Beispiel #9
0
 def post(self, request, coll_id):
     """
     Update some aspect of the current collection
     """
     # Note: in many cases, this function redirects to a URI that displays a form
     #       to gather further details of values to update.  Values returned by
     #       POST to this view are then passed as URI segments in the GET request
     #       that renders the form.  Maybe there's an easier way than all this
     #       URI-wrangling?
     redirect_uri = None
     http_response = None
     viewinfo = self.collection_edit_setup(coll_id, "config",
                                           request.POST.dict())
     if viewinfo.http_response:
         return viewinfo.http_response
     if "close" in request.POST:
         redirect_uri = viewinfo.get_continuation_next()
     if "migrate" in request.POST:
         msgs = migrate_coll_data(viewinfo.collection)
         msg_vals = {'id': coll_id}
         if msgs:
             for msg in msgs:
                 log.warning(msg)
             err = message.MIGRATE_COLLECTION_ERROR % msg_vals
             msg = "\n".join([err] + msgs)
             log.error(msg)
             http_response = self.error(
                 dict(self.error500values(), message=msg))
         else:
             # Redisplay current page with completion message
             viewuri = self.get_request_path()
             http_response = self.redirect_info(
                 self.get_request_path(),
                 view_params=continuation_params(uri_param_dict(viewuri)),
                 info_message=message.MIGRATED_COLLECTION_DATA % msg_vals)
         return http_response
     # Edit collection metadata
     if "metadata" in request.POST:
         redirect_uri = self.item_edit_uri(layout.SITEDATA_ID, "_coll",
                                           "Collection_view", coll_id,
                                           message.NO_COLLECTION_METADATA,
                                           viewinfo.get_continuation_here(),
                                           viewinfo.get_continuation_url())
     # Record types
     type_id = request.POST.get('typelist', None)
     if "type_new" in request.POST:
         redirect_uri = self.item_new_uri(coll_id, "_type", "Type_view",
                                          viewinfo.get_continuation_here())
     if "type_copy" in request.POST:
         redirect_uri = self.item_copy_uri(coll_id, "_type", "Type_view",
                                           type_id,
                                           message.NO_TYPE_FOR_COPY,
                                           viewinfo.get_continuation_here(),
                                           viewinfo.get_continuation_url())
     if "type_edit" in request.POST:
         redirect_uri = self.item_edit_uri(coll_id, "_type", "Type_view",
                                           type_id,
                                           message.NO_TYPE_FOR_COPY,
                                           viewinfo.get_continuation_here(),
                                           viewinfo.get_continuation_url())
     if "type_delete" in request.POST:
         http_response = viewinfo.confirm_delete_entity_response(
             layout.TYPE_TYPEID,
             type_id,
             self.view_uri("AnnalistRecordTypeDeleteView", coll_id=coll_id),
             form_action_field="type_delete",
             form_value_field="typelist",
             response_messages={
                 "no_entity": message.NO_TYPE_FOR_DELETE,
                 "confirm_completion": message.REMOVE_RECORD_TYPE
             })
     # List views
     list_id = request.POST.get('listlist', None)
     if "list_new" in request.POST:
         redirect_uri = self.item_new_uri(coll_id, "_list", "List_view",
                                          viewinfo.get_continuation_here())
     if "list_copy" in request.POST:
         redirect_uri = self.item_copy_uri(coll_id, "_list", "List_view",
                                           list_id,
                                           message.NO_LIST_FOR_COPY,
                                           viewinfo.get_continuation_here(),
                                           viewinfo.get_continuation_url())
     if "list_edit" in request.POST:
         redirect_uri = self.item_edit_uri(coll_id, "_list", "List_view",
                                           list_id,
                                           message.NO_LIST_FOR_COPY,
                                           viewinfo.get_continuation_here(),
                                           viewinfo.get_continuation_url())
     if "list_delete" in request.POST:
         http_response = viewinfo.confirm_delete_entity_response(
             layout.LIST_TYPEID,
             list_id,
             self.view_uri("AnnalistRecordListDeleteView", coll_id=coll_id),
             form_action_field="list_delete",
             form_value_field="listlist",
             response_messages={
                 "no_entity": message.NO_LIST_FOR_DELETE,
                 "confirm_completion": message.REMOVE_RECORD_LIST
             })
     # Record views
     view_id = request.POST.get('viewlist', None)
     if "view_new" in request.POST:
         redirect_uri = self.item_new_uri(coll_id, "_view", "View_view",
                                          viewinfo.get_continuation_here())
     if "view_copy" in request.POST:
         redirect_uri = self.item_copy_uri(coll_id, "_view", "View_view",
                                           view_id,
                                           message.NO_VIEW_FOR_COPY,
                                           viewinfo.get_continuation_here(),
                                           viewinfo.get_continuation_url())
     if "view_edit" in request.POST:
         redirect_uri = self.item_edit_uri(coll_id, "_view", "View_view",
                                           view_id,
                                           message.NO_VIEW_FOR_COPY,
                                           viewinfo.get_continuation_here(),
                                           viewinfo.get_continuation_url())
     if "view_delete" in request.POST:
         http_response = viewinfo.confirm_delete_entity_response(
             layout.VIEW_TYPEID,
             view_id,
             self.view_uri("AnnalistRecordViewDeleteView", coll_id=coll_id),
             form_action_field="view_delete",
             form_value_field="viewlist",
             response_messages={
                 "no_entity": message.NO_VIEW_FOR_DELETE,
                 "confirm_completion": message.REMOVE_RECORD_VIEW
             })
     # Invoke selected view and/or render status response
     if redirect_uri:
         http_response = http_response or HttpResponseRedirect(redirect_uri)
     if http_response:
         return http_response
     e = Annalist_Error(
         request.POST,
         "Unexpected values in POST to " + self.get_request_path())
     log.exception(str(e))
     return self.error(
         dict(self.error500values(),
              message=str(e) + " - see server log for details"))
Beispiel #10
0
 def __getattr__(self, name):
     """
     Get a bound field description attribute.  If the attribute name is "field_value"
     then the value corresponding to the field description is retrieved from the entity,
     otherwise the named attribute is retrieved from thge field description.
     """
     # log.info("self._key %s, __getattr__ %s"%(self._key, name))
     # log.info("self._key %s"%self._key)
     # log.info("self._entity %r"%self._entity)
     if name in [
             "entity_id", "entity_link", "entity_type_id",
             "entity_type_link"
     ]:
         return self._entityvals.get(name, "")
     elif name == "field_value_key":
         return self._key
     elif name == "context_extra_values":
         return self._extras
     elif name == "field_placeholder":
         return self._field_description.get(
             'field_placeholder', "@@bound_field.field_placeholder@@")
     elif name == "continuation_url":
         if self._extras is None:
             log.warning(
                 "bound_field.continuation_url - no extra context provided")
             return ""
         cont = self._extras.get("request_url", "")
         if cont:
             cont = uri_with_params(cont, continuation_params(self._extras))
         return cont
     elif name == "entity_link_continuation":
         return self.entity_link + self.get_continuation_param()
     elif name == "entity_type_link_continuation":
         return self.entity_type_link + self.get_continuation_param()
     elif name == "field_value":
         field_val = None
         if self._key in self._entityvals:
             field_val = self._entityvals[self._key]
         elif self._extras and self._key in self._extras:
             field_val = self._extras[self._key]
         if field_val is None:
             # Return default value, or empty string.
             # Used to populate form field value when no value supplied, or provide per-field default
             field_val = self._field_description.get(
                 'field_default_value', None)
             if field_val is None:
                 field_val = ""
         return field_val
     elif name == "field_value_link":
         # Used to get link corresponding to a value, if such exists
         return self.get_field_link()
     elif name == "field_value_link_continuation":
         # Used to get link corresponding to a value, if such exists
         return self.get_field_link() + self.get_continuation_param()
     elif name == "field_description":
         # Used to get link corresponding to a value, if such exists
         return self._field_description
     elif name == "options":
         return self.get_field_options()
     else:
         # log.info("bound_field[%s] -> %r"%(name, self._field_description[name]))
         return self._field_description[name]
Beispiel #11
0
 def post(self, request, coll_id):
     """
     Update some aspect of the current collection
     """
     # Note: in many cases, this function redirects to a URI that displays a form
     #       to gather further details of values to update.  Values returned by
     #       POST to this view are then passed as URI segments in the GET request
     #       that renders the form.  Maybe there's an easier way than all this 
     #       URI-wrangling?
     redirect_uri  = None
     http_response = None
     viewinfo = self.collection_edit_setup(coll_id, "config", request.POST.dict())
     if viewinfo.http_response:
         return viewinfo.http_response
     if "close" in request.POST:
         redirect_uri = viewinfo.get_continuation_next()
     if "migrate" in request.POST:
         msgs = migrate_coll_data(viewinfo.collection)
         msg_vals = {'id': coll_id}
         if msgs:
             for msg in msgs:
                 log.warning(msg)
             err = message.MIGRATE_COLLECTION_ERROR%msg_vals
             msg = "\n".join([err]+msgs)
             log.error(msg)
             http_response = self.error(dict(self.error500values(),message=msg))
         else:
             # Redisplay current page with completion message
             viewuri = self.get_request_path()
             http_response = self.redirect_info(
                 self.get_request_path(),
                 view_params=continuation_params(uri_param_dict(viewuri)),
                 info_message=message.MIGRATED_COLLECTION_DATA%msg_vals
                 )
         return http_response
     # Edit collection metadata
     if "metadata" in request.POST:
         redirect_uri = self.item_edit_uri(
             layout.SITEDATA_ID, "_coll", "Collection_view", coll_id, 
             message.NO_COLLECTION_METADATA, 
             viewinfo.get_continuation_here(),
             viewinfo.get_continuation_url()
             )
     # Record types
     type_id = request.POST.get('typelist', None)
     if "type_new" in request.POST:
         redirect_uri = self.item_new_uri(
             coll_id, "_type", "Type_view", 
             viewinfo.get_continuation_here()
             )
     if "type_copy" in request.POST:
         redirect_uri = self.item_copy_uri(
             coll_id, "_type", "Type_view", type_id, 
             message.NO_TYPE_FOR_COPY, 
             viewinfo.get_continuation_here(),
             viewinfo.get_continuation_url()
             )
     if "type_edit" in request.POST:
         redirect_uri = self.item_edit_uri(
             coll_id, "_type", "Type_view", type_id, 
             message.NO_TYPE_FOR_COPY, 
             viewinfo.get_continuation_here(),
             viewinfo.get_continuation_url()
             )
     if "type_delete" in request.POST:
         http_response = viewinfo.confirm_delete_entity_response(
             layout.TYPE_TYPEID, type_id, 
             self.view_uri("AnnalistRecordTypeDeleteView", coll_id=coll_id),
             form_action_field="type_delete",
             form_value_field="typelist",
             response_messages=
                 { "no_entity":          message.NO_TYPE_FOR_DELETE
                 , "confirm_completion": message.REMOVE_RECORD_TYPE
                 }
             )
     # List views
     list_id = request.POST.get('listlist', None)
     if "list_new" in request.POST:
         redirect_uri = self.item_new_uri(
             coll_id, "_list", "List_view", 
             viewinfo.get_continuation_here()
             )
     if "list_copy" in request.POST:
         redirect_uri = self.item_copy_uri(
             coll_id, "_list", "List_view", list_id, 
             message.NO_LIST_FOR_COPY, 
             viewinfo.get_continuation_here(),
             viewinfo.get_continuation_url()
             )
     if "list_edit" in request.POST:
         redirect_uri = self.item_edit_uri(
             coll_id, "_list", "List_view", list_id, 
             message.NO_LIST_FOR_COPY, 
             viewinfo.get_continuation_here(),
             viewinfo.get_continuation_url()
             )
     if "list_delete" in request.POST:
         http_response = viewinfo.confirm_delete_entity_response(
             layout.LIST_TYPEID, list_id, 
             self.view_uri("AnnalistRecordListDeleteView", coll_id=coll_id),
             form_action_field="list_delete",
             form_value_field="listlist",
             response_messages=
                 { "no_entity":          message.NO_LIST_FOR_DELETE
                 , "confirm_completion": message.REMOVE_RECORD_LIST
                 }
             )
     # Record views
     view_id = request.POST.get('viewlist', None)
     if "view_new" in request.POST:
         redirect_uri = self.item_new_uri(
             coll_id, "_view", "View_view", 
             viewinfo.get_continuation_here()
             )
     if "view_copy" in request.POST:
         redirect_uri = self.item_copy_uri(
             coll_id, "_view", "View_view", view_id, 
             message.NO_VIEW_FOR_COPY, 
             viewinfo.get_continuation_here(),
             viewinfo.get_continuation_url()
             )
     if "view_edit" in request.POST:
         redirect_uri = self.item_edit_uri(
             coll_id, "_view", "View_view", view_id, 
             message.NO_VIEW_FOR_COPY, 
             viewinfo.get_continuation_here(),
             viewinfo.get_continuation_url()
             )
     if "view_delete" in request.POST:
         http_response = viewinfo.confirm_delete_entity_response(
             layout.VIEW_TYPEID, view_id, 
             self.view_uri("AnnalistRecordViewDeleteView", coll_id=coll_id),
             form_action_field="view_delete",
             form_value_field="viewlist",
             response_messages=
                 { "no_entity":          message.NO_VIEW_FOR_DELETE
                 , "confirm_completion": message.REMOVE_RECORD_VIEW
                 }
             )
     # Invoke selected view and/or render status response
     if redirect_uri:
         http_response = http_response or HttpResponseRedirect(redirect_uri)
     if http_response:
         return http_response
     e = Annalist_Error(request.POST, "Unexpected values in POST to "+self.get_request_path())
     log.exception(str(e))
     return self.error(
         dict(self.error500values(),
             message=str(e)+" - see server log for details"
             )
         )