Ejemplo n.º 1
0
    def generate_link_from_actionlist(self, actionlist):
        """
        returns a link that describes a call to a view that results of the actionlist
        """
        target = {}
        target['s'] = self.get_page()
        target['v'] = deepcopy(self.get_space_widget_mapping())
        target['b'] = deepcopy(self.get_box_mapping())
        target['c'] = deepcopy(self.get_widget_param_mapping())
        
        for action in actionlist.get_actions():
            if action.get_url() is not None:
                return action.get_url()
            elif action.get_view_id() is not None:
                view = View.get_from_id(action.get_view_id())
                name = view.get_name()
                return "/web/"+quote(name)
            elif action.get_space() is not None and action.get_widget_id() is not None:
                target['v'][action.get_space()] = action.get_widget_id()
                #delete any parameters of this widget. otherwise link will only
                #load current state of that widget again
                if target['c'].has_key(action.get_widget_id()):
                    del(target['c'][action.get_widget_id()])

        #AJAX-rendermode regarded here: ↓
        encoder = JSONEncoder()
        viewjsonstring = quote(encoder.encode(target))
        checkview = View.get_from_json(viewjsonstring)
        existing_name = checkview.check_has_name()
        if existing_name == False:
            return "/web/?"+viewjsonstring
        else:
            return "/web/"+existing_name
Ejemplo n.º 2
0
    def generate_link_from_dict(self, dct):
        """
        Creates a link by analyzing a view-dictionary and merging it to this view
        The incoming dictionary can be thought of as a diff that is added to the 
        existing view.
        Does not affect the View itself.
        """
        target = {}
        target['s'] = self.get_page()
        target['v'] = deepcopy(self.get_space_widget_mapping())
        target['b'] = deepcopy(self.get_box_mapping())
        target['c'] = deepcopy(self.get_widget_param_mapping())
        
        if dct.has_key('s'):
            target['s'] = dct['s']
        if dct.has_key('v'):
            target['v'].update(dct['v'])
        if dct.has_key('b'):
            target['b'].update(dct['b'])
        if dct.has_key('c'):
            for widget_id in dct['c'].keys():
                target['c'][widget_id] = dct['c'][widget_id]
        if dct.has_key('p'):
            target['p'] = dct['p']

        encoder = JSONEncoder()
        viewjsonstring = quote(encoder.encode(target))
        checkview = View.get_from_json(viewjsonstring)
        existing_name = checkview.check_has_name()
        if existing_name == False:
            return "/web/?"+viewjsonstring
        else:
            return "/web/"+existing_name