Пример #1
0
    def create(self):
        context = {'user': t.c.user}

        params = t.request.params
        topic_id = params['subtopic_topic_id']
        display_name = params['subtopic_display_name']

        if (Subtopic.topic_subtopics_count(topic_id) >=
                AlphabeticIndex.max_items()):
            t.redirect_to(
                controller='ckanext.topics.controllers.topic:TopicController',
                action='index')

        topic = Topic.find(topic_id)

        subtopic_index = Subtopic.get_new_subtopic_index(topic_id)

        name = topic['index'] + '_' + subtopic_index + '_' + display_name

        result = t.get_action('tag_create')(
            context, {
                'name': name,
                'vocabulary_id': Subtopic.vocabulary_id()
            })

        t.redirect_to(
            controller='ckanext.topics.controllers.topic:TopicController',
            action='index')
Пример #2
0
    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')
Пример #3
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')
Пример #4
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)
Пример #5
0
    def edit(self):
        topic_id = t.request.params['id']
        topic = Topic.find(topic_id)

        extra_vars = {
            'topic': topic,
            'subtopics': Subtopic.by_topic(topic_id),
            'controller_action': 'update'
        }

        return t.render('topic/edit.html', extra_vars=extra_vars)
Пример #6
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')
Пример #7
0
    def index(self):
        topics = Topic.all()
        subtopics = Subtopic.all()

        for topic in topics:
            topic['subtopics'] = []
            for subtopic in subtopics:
                if (topic['id'] == subtopic['topic_id']):
                    topic['subtopics'].append(subtopic)

        extra_vars = {'topics': topics}

        return t.render('topic/index.html', extra_vars=extra_vars)
Пример #8
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')
Пример #9
0
def custom_subtopics():
    return Subtopic.all()