def update(self): params = t.request.params topic_id = params['topic_id'] topic = Topic.find(topic_id) old_index = topic['index'] new_index = params['topic_index'] old_topic_name = topic['name'] new_name = new_index + '_' + params['topic_display_name'] if (old_index != new_index): subtopics = Subtopic.by_topic(topic_id) for subtopic in subtopics: Subtopic.update_subtopic_topic_index(subtopic, new_index) session = model.Session matched_tag = session.query(Tag).filter(Tag.id == topic['id']).first() matched_tag.name = new_name model.Session.commit() reindex_packages_with_changed_topic(old_topic_name) t.redirect_to( controller='ckanext.topics.controllers.topic:TopicController', action='index')
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')