Ejemplo n.º 1
0
    def _handle_history(self, kwargs):
        if kwargs['filename'] == self.filename:
            id_ = kwargs['id_']

            # The history event may have effects also on target and backlinks
            backlinks = links_api.find_back_links(self.filename, id_)
            target = links_api.find_link_target(self.filename, id_)

            if target is False:
                rbits = 3 if len(backlinks) > 0 else 0

                # Find any possible old target and update it
                # This fixes for example the case of undoing the linking
                # of an item to another, which wouldn't update the tree
                # icon of the old target because this function would be
                # called *after* removing the link, so the old target
                # would not be retrievable through a database query
                old_target = links_api.get_last_known_target(
                    self.filename, id_)

                if old_target is not None:
                    self._reset_item_no_tree_update(old_target)

            elif target is None:
                rbits = 5 if len(backlinks) > 0 else 2

            else:
                rbits = 4 if len(backlinks) > 0 else 1

                target_target = links_api.find_link_target(
                    self.filename, target)

                if target_target is False:
                    target_rbits = 3
                elif target_target is None:
                    target_rbits = 5
                else:
                    target_rbits = 4

                self._update_item_no_tree_update(target, target_rbits)

            self._update_item_no_tree_update(id_, rbits)

            for blink in backlinks:
                blink_backlinks = links_api.find_back_links(
                    self.filename, blink)
                blink_rbits = 4 if len(blink_backlinks) > 0 else 1
                self._update_item_no_tree_update(blink, blink_rbits)
Ejemplo n.º 2
0
    def _handle_upsert_link(self, kwargs):
        if kwargs['filename'] == self.filename:
            id_ = kwargs['id_']
            target = kwargs['target']
            oldtarget = kwargs['oldtarget']
            backlinks = links_api.find_back_links(self.filename, id_)
            target_target = links_api.find_link_target(self.filename, target)

            if target is None:
                rbits = 5 if len(backlinks) > 0 else 2
            else:
                rbits = 4 if len(backlinks) > 0 else 1

            if target_target is False:
                target_rbits = 3
            elif target_target is None:
                target_rbits = 5
            else:
                target_rbits = 4

            self._update_item(id_, rbits)

            if target is not None:
                self._update_item(target, target_rbits)

            # oldtarget may not exist anymore
            if oldtarget is not False and core_api.is_item(self.filename,
                                                                    oldtarget):
                self._reset_item(oldtarget)
Ejemplo n.º 3
0
    def _handle_upsert_link(self, kwargs):
        if kwargs['filename'] == self.filename:
            id_ = kwargs['id_']
            target = kwargs['target']
            oldtarget = kwargs['oldtarget']
            backlinks = links_api.find_back_links(self.filename, id_)
            target_target = links_api.find_link_target(self.filename, target)

            if target is None:
                rbits = 5 if len(backlinks) > 0 else 2
            else:
                rbits = 4 if len(backlinks) > 0 else 1

            if target_target is False:
                target_rbits = 3
            elif target_target is None:
                target_rbits = 5
            else:
                target_rbits = 4

            self._update_item(id_, rbits)

            if target is not None:
                self._update_item(target, target_rbits)

            # oldtarget may not exist anymore
            if oldtarget is not False and core_api.is_item(
                    self.filename, oldtarget):
                self._reset_item(oldtarget)
Ejemplo n.º 4
0
    def _handle_history(self, kwargs):
        if kwargs['filename'] == self.filename:
            id_ = kwargs['id_']

            # The history event may have effects also on target and backlinks
            backlinks = links_api.find_back_links(self.filename, id_)
            target = links_api.find_link_target(self.filename, id_)

            if target is False:
                rbits = 3 if len(backlinks) > 0 else 0

                # Find any possible old target and update it
                # This fixes for example the case of undoing the linking
                # of an item to another, which wouldn't update the tree
                # icon of the old target because this function would be
                # called *after* removing the link, so the old target
                # would not be retrievable through a database query
                old_target = links_api.get_last_known_target(self.filename, id_)

                if old_target is not None:
                    self._reset_item_no_tree_update(old_target)

            elif target is None:
                rbits = 5 if len(backlinks) > 0 else 2

            else:
                rbits = 4 if len(backlinks) > 0 else 1

                target_target = links_api.find_link_target(self.filename,
                                                                        target)

                if target_target is False:
                    target_rbits = 3
                elif target_target is None:
                    target_rbits = 5
                else:
                    target_rbits = 4

                self._update_item_no_tree_update(target, target_rbits)

            self._update_item_no_tree_update(id_, rbits)

            for blink in backlinks:
                blink_backlinks = links_api.find_back_links(self.filename,
                                                                        blink)
                blink_rbits = 4 if len(blink_backlinks) > 0 else 1
                self._update_item_no_tree_update(blink, blink_rbits)
Ejemplo n.º 5
0
    def _compute_rbits(self, id_):
        backlinks = links_api.find_back_links(self.filename, id_)
        target = links_api.find_link_target(self.filename, id_)

        if target is False:
            rbits = 3 if len(backlinks) > 0 else 0
        elif target is None:
            rbits = 5 if len(backlinks) > 0 else 2
        else:
            rbits = 4 if len(backlinks) > 0 else 1

        return rbits
Ejemplo n.º 6
0
    def _handle_break_links(self, kwargs):
        if kwargs['filename'] == self.filename:
            for id_ in kwargs['ids']:
                backlinks = links_api.find_back_links(self.filename, id_)
                rbits = 5 if len(backlinks) > 0 else 2
                self._update_item(id_, rbits)

            oldtarget = kwargs['oldtarget']

            # oldtarget may not exist anymore
            if core_api.is_item(self.filename, oldtarget):
                self._reset_item(oldtarget)
Ejemplo n.º 7
0
    def _compute_rbits(self, id_):
        backlinks = links_api.find_back_links(self.filename, id_)
        target = links_api.find_link_target(self.filename, id_)

        if target is False:
            rbits = 3 if len(backlinks) > 0 else 0
        elif target is None:
            rbits = 5 if len(backlinks) > 0 else 2
        else:
            rbits = 4 if len(backlinks) > 0 else 1

        return rbits
Ejemplo n.º 8
0
    def _handle_break_links(self, kwargs):
        if kwargs['filename'] == self.filename:
            for id_ in kwargs['ids']:
                backlinks = links_api.find_back_links(self.filename, id_)
                rbits = 5 if len(backlinks) > 0 else 2
                self._update_item(id_, rbits)

            oldtarget = kwargs['oldtarget']

            # oldtarget may not exist anymore
            if core_api.is_item(self.filename, oldtarget):
                self._reset_item(oldtarget)
Ejemplo n.º 9
0
    def _handle_delete_link(self, kwargs):
        if kwargs['filename'] == self.filename:
            id_ = kwargs['id_']
            backlinks = links_api.find_back_links(self.filename, id_)
            rbits = 3 if len(backlinks) > 0 else 0

            # id_ may not exist anymore
            if core_api.is_item(self.filename, id_):
                self._update_item(id_, rbits)

            oldtarget = kwargs['oldtarget']

            # oldtarget may not exist anymore
            if core_api.is_item(self.filename, oldtarget):
                self._reset_item(oldtarget)
Ejemplo n.º 10
0
    def _handle_delete_link(self, kwargs):
        if kwargs['filename'] == self.filename:
            id_ = kwargs['id_']
            backlinks = links_api.find_back_links(self.filename, id_)
            rbits = 3 if len(backlinks) > 0 else 0

            # id_ may not exist anymore
            if core_api.is_item(self.filename, id_):
                self._update_item(id_, rbits)

            oldtarget = kwargs['oldtarget']

            # oldtarget may not exist anymore
            if core_api.is_item(self.filename, oldtarget):
                self._reset_item(oldtarget)