Beispiel #1
0
    def update(self):
        params = t.request.params

        topic_id = params['subtopic_topic_id']
        topic = Topic.find(topic_id)

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

        old_name = subtopic['name']
        new_index = params['subtopic_index']
        new_name = topic['index'] + '_' + new_index + '_' + params[
            'subtopic_display_name']

        session = model.Session
        matched_tag = session.query(Tag).filter(
            Tag.name == subtopic['name']).first()
        matched_tag.name = new_name
        model.Session.commit()

        reindex_packages_with_changed_topic(old_name)

        t.redirect_to(
            controller='ckanext.topics.controllers.topic:TopicController',
            action='index')
Beispiel #2
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')
Beispiel #3
0
    def edit(self):
        subtopic_id = t.request.params['id']
        subtopic = Subtopic.find(subtopic_id)

        extra_vars = {'subtopic': subtopic, 'controller_action': 'update'}

        return t.render('subtopic/edit.html', extra_vars=extra_vars)