コード例 #1
0
ファイル: kernel.py プロジェクト: sandeez/lino
    def run_callback(self, request, thread_id, button_id):
        """Continue the action which was started in a previous request and
        which asked for user interaction via a :class:`Callback`.

        This is called from `lino.core.views.Callbacks`.

        """
        # logger.info("20131212 get_callback %s %s", thread_id, button_id)

        # 20140304 Also set a renderer so that callbacks can use it
        # (feature needed by beid.FindByBeIdAction).

        thread_id = int(thread_id)
        cb = self.pending_threads.pop(thread_id, None)
        if cb is None:
            ar = ActorRequest(request, renderer=self.default_renderer)
            logger.debug("No callback %r in %r" % (
                thread_id, list(self.pending_threads.keys())))
            ar.error("Unknown callback %r" % thread_id)
            return self.render_action_response(ar)

        # e.g. SubmitInsertClient must set `data_record` in the
        # callback request ("ar2"), not the original request ("ar"),
        # i.e. the methods to create an instance and to fill
        # `data_record` must run on the callback request.  So the
        # callback request must be a clone of the original request.
        # New since 20140421
        ar = cb.ar.actor.request_from(cb.ar)
        for k in CLONEABLE_ATTRS:
            setattr(ar, k, getattr(cb.ar, k))

        for c in cb.choices:
            if c.name == button_id:
                a = ar.bound_action.action
                if self.site.log_each_action_request and not a.readonly:
                    logger.info("run_callback {0} {1} {2}".format(
                        thread_id, cb.message, c.name))
                c.func(ar)
                return self.render_action_response(ar)

        ar.error("Invalid button %r for callback" % (button_id, thread_id))
        return self.render_action_response(ar)
コード例 #2
0
ファイル: kernel.py プロジェクト: DarioGT/lino
    def run_callback(self, request, thread_id, button_id):
        """Continue the action which was started in a previous request and
        which asked for user interaction via a :class:`Callback`.

        This is called from `lino.core.views.Callbacks`.

        """
        # logger.info("20131212 get_callback %s %s", thread_id, button_id)

        # 20140304 Also set a renderer so that callbacks can use it
        # (feature needed by beid.FindByBeIdAction).

        thread_id = int(thread_id)
        cb = self.pending_threads.pop(thread_id, None)
        if cb is None:
            ar = ActorRequest(request, renderer=self.default_renderer)
            logger.debug("No callback %r in %r" %
                         (thread_id, self.pending_threads.keys()))
            ar.error("Unknown callback %r" % thread_id)
            return self.render_action_response(ar)

        # e.g. SubmitInsertClient must set `data_record` in the
        # callback request ("ar2"), not the original request ("ar"),
        # i.e. the methods to create an instance and to fill
        # `data_record` must run on the callback request.  So the
        # callback request must be a clone of the original request.
        # New since 20140421
        ar = cb.ar.actor.request_from(cb.ar)
        for k in CLONEABLE_ATTRS:
            setattr(ar, k, getattr(cb.ar, k))

        for c in cb.choices:
            if c.name == button_id:
                a = ar.bound_action.action
                if self.site.log_each_action_request and not a.readonly:
                    logger.info("run_callback {0} {1} {2}".format(
                        thread_id, cb.message, c.name))
                c.func(ar)
                return self.render_action_response(ar)

        ar.error("Invalid button %r for callback" % (button_id, thread_id))
        return self.render_action_response(ar)
コード例 #3
0
ファイル: kernel.py プロジェクト: ManuelWeidmann/lino
    def run_callback(self, request, thread_id, button_id):
        """
        Return an existing (pending) callback.
        This is called from `lino.ui.views.Callbacks`.
        """
        # logger.info("20131212 get_callback %s %s", thread_id, button_id)

        # 20140304 Also set a renderer so that callbacks can use it
        # (feature needed by beid.FindByBeIdAction).

        ar = ActorRequest(request, renderer=self.default_renderer)

        thread_id = int(thread_id)
        cb = self.pending_threads.pop(thread_id, None)
        #~ d = self.pop_thread(int(thread_id))
        if cb is None:
            logger.debug("No callback %r in %r" % (
                thread_id, self.pending_threads.keys()))
            ar.error("Unknown callback %r" % thread_id)
            return self.render_action_response(ar)

        # e.g. SubmitInsertClient must set `data_record` in the
        # callback request ("ar2", not "ar"), i.e. the methods to
        # create an instance and to fill `data_record` must run on the
        # callback request.  So the callback request must be a clone
        # of the original request.  New since 20140421
        ar.actor = cb.ar.actor
        ar.ah = cb.ar.ah
        ar.bound_action = cb.ar.bound_action
        ar.create_kw = cb.ar.create_kw
        ar.known_values = cb.ar.known_values
        ar.param_values = cb.ar.param_values
        ar.action_param_values = cb.ar.action_param_values
        ar.data_iterator = cb.ar.data_iterator

        # for k in ('data_record', 'goto_record_id'):
        #     v = cb.ar.response.get(k, None)
        #     if v is not None:
        #         ar.response[k] = v
                
        for c in cb.choices:
            if c.name == button_id:
                c.func(ar)
                return self.render_action_response(ar)

        ar.error("Invalid button %r for callback" % (button_id, thread_id))
        return self.render_action_response(ar)