Esempio n. 1
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')
Esempio n. 2
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')
Esempio n. 3
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')
Esempio n. 4
0
    def by_topic(cls, topic_id_or_name):
        topic_subtopics = []
        topic = Topic.find(topic_id_or_name)

        for subtopic in cls.all():
            if (subtopic['topic_id'] == topic['id']):
                topic_subtopics.append(subtopic)

        return topic_subtopics
Esempio n. 5
0
    def create(self):
        context = {'user': t.c.user}

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

        display_name = t.request.params['topic_display_name']
        full_name = str(Topic.get_new_topic_index()) + '_' + display_name

        t.get_action('tag_create')(context, {
            'name': full_name,
            'vocabulary_id': Topic.vocabulary_id()
        })

        t.redirect_to(
            controller='ckanext.topics.controllers.topic:TopicController',
            action='index')
Esempio n. 6
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)
Esempio n. 7
0
    def update_subtopic_topic_index(cls, subtopic, new_topic_index):
        topic = Topic.find(subtopic['topic_id'])

        new_name = new_topic_index + '_' + subtopic['index'] + '_' + 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()
Esempio n. 8
0
    def new(self):
        topic_id = t.request.params['topic_id']
        topic = Topic.find(topic_id)

        extra_vars = {
            'subtopic': {
                'topic_id': topic_id
            },
            'controller_action': 'create'
        }

        return t.render('subtopic/edit.html', extra_vars=extra_vars)
Esempio n. 9
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)
Esempio n. 10
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')
Esempio n. 11
0
def get_topic_name(topic_id):
    topic = Topic.find(topic_id)
    if (topic != None):
        return topic['display_name']
Esempio n. 12
0
def topic_display_name(topic_name):
    # same behavior for subtopic
    return Topic.topic_display_name(topic_name)
Esempio n. 13
0
def custom_topics():
    return Topic.all()
Esempio n. 14
0
 def subtopic_topic_id(cls, subtopic_name):
     topic_index = cls.subtopic_topic_index(subtopic_name)
     topic = Topic.find_by_index(topic_index)
     if topic:
         return topic['id']