Esempio n. 1
0
    def destroy(self):
        context = {'user': t.c.user}

        params = t.request.params

        subtopic_id = t.request.params['id']
        subtopic = Subtopic.find(subtopic_id)

        old_name = subtopic['name']

        Subtopic.destroy(context, subtopic_id)

        # Update indexes of following subtopics
        destroyed_index = subtopic['index']
        for subtopic in Subtopic.all():
            if subtopic['index'] > destroyed_index:
                new_subtopic_index = AlphabeticIndex.previous_letter(
                    subtopic['index'])
                Subtopic.update_subtopic_index(subtopic, new_subtopic_index)

        reindex_packages_with_changed_topic(old_name)

        t.redirect_to(
            controller='ckanext.topics.controllers.topic:TopicController',
            action='index')
Esempio n. 2
0
    def destroy(self):
        context = {'user': t.c.user}

        topic_id = t.request.params['id']
        topic = Topic.find(topic_id)

        old_topic_name = topic['name']

        # destroy topic and related subtopics
        for subtopic in Subtopic.by_topic(topic['id']):
            Subtopic.destroy(context, subtopic['id'])

        Topic.destroy(context, topic['id'])

        destroyed_index = topic['index']

        # update indexes of following topics and subtopics
        for topic in Topic.all():
            if topic['index'] > destroyed_index:
                topic_subtopics = Subtopic.by_topic(topic['id'])

                # decrement topic index
                new_topic_index = AlphabeticIndex.previous_letter(
                    topic['index'])
                Topic.update_topic_index(topic, new_topic_index)

                # decrement subtopics topic index
                for subtopic in topic_subtopics:
                    Subtopic.update_subtopic_topic_index(
                        subtopic, new_topic_index)

        reindex_packages_with_changed_topic(old_topic_name)

        t.redirect_to(
            controller='ckanext.topics.controllers.topic:TopicController',
            action='index')