Exemplo n.º 1
0
def tag_search_results(request, blog_id=None, site_id=None):

    try:
        search_terms = request.query['search']
    except KeyError:
        raise KeyError('No search field in query.')

    if search_terms == "":
        raise ValueError('Search field is empty.')

    search_terms_enc = utf8_escape(search_terms)

    from core.models import Tag

    # TODO: move to DB.media_search for indexing

    tags_searched = (Tag.select(Tag.id)
        .where(Tag.tag.contains(search_terms_enc))
        .order_by(Tag.tag.asc()).tuples())

    # if site_id is not None:
        # tags_searched.select().where(Tag.blog.site == site_id)
    if blog_id is not None:
        tags_searched.select().where(Tag.blog == blog_id)

    return tags_searched, search_terms
Exemplo n.º 2
0
def tag_search_results(request, blog_id=None, site_id=None):

    try:
        search_terms = request.query['search']
    except KeyError:
        raise KeyError('No search field in query.')

    if search_terms == "":
        raise ValueError('Search field is empty.')

    search_terms_enc = utf8_escape(search_terms)

    from core.models import Tag

    # TODO: move to DB.media_search for indexing

    tags_searched = (Tag.select(Tag.id).where(
        Tag.tag.contains(search_terms_enc)).order_by(Tag.tag.asc()).tuples())

    # if site_id is not None:
    # tags_searched.select().where(Tag.blog.site == site_id)
    if blog_id is not None:
        tags_searched.select().where(Tag.blog == blog_id)

    return tags_searched, search_terms
Exemplo n.º 3
0
def add_tags_to_page(tag_text, page):
    tag_list = Tag.select().where(Tag.id << tag_text)

    tags_to_delete = TagAssociation.delete().where(
        TagAssociation.page == page, ~TagAssociation.tag << (tag_list))

    tags_to_delete.execute()

    tags_in_page = page.tags.select(Tag.id).tuples()

    tags_to_add = tag_list.select().where(~Tag.id << (tags_in_page))

    for n in tags_to_add:
        add_tag = TagAssociation(tag=n, page=page)

        add_tag.save()

    new_tags = json.loads(request.forms.getunicode('new_tags'))

    for n in new_tags:
        new_tag = Tag(tag=n, blog=page.blog)
        new_tag.save()

        add_tag = TagAssociation(tag=new_tag, page=page)

        add_tag.save()

    return tags_to_add, tags_to_delete, new_tags
Exemplo n.º 4
0
def add_tags_to_page (tag_text, page, no_delete=False):
    '''
    Takes a list of tags, in JSON text format, and adds them to the page in question.
    Any tags not already in the system will be added.

    :param tag_text:
        List of tags to add.
    :param page:
        Page object to add the tags to.
    :param no_delete:
        When set to True, this will preserve tags already in the page if they are
        not found in tag_text. By default this is False, so any tags not specified in
        tag_text that exist in the page will be removed.
    '''
    tag_list = Tag.select().where(Tag.id << tag_text)

    if no_delete is False:

        tags_to_delete = TagAssociation.delete().where(
            TagAssociation.page == page,
            ~ TagAssociation.tag << (tag_list))

        tags_to_delete.execute()
    else:
        tags_to_delete = None

    tags_in_page = page.tags_all.select(Tag.id).tuples()

    tags_to_add = tag_list.select().where(~Tag.id << (tags_in_page))

    for n in tags_to_add:
        add_tag = TagAssociation(
           tag=n,
           page=page)

        add_tag.save()

    import json
    new_tags = json.loads(request.forms.getunicode('new_tags'))

    for n in new_tags:
        if n != '':
            new_tag = Tag(
                tag=n,
                blog=page.blog)
            new_tag.save()

            add_tag = TagAssociation(
                tag=new_tag,
                page=page)

            add_tag.save()

    return tags_to_add, tags_to_delete, new_tags
Exemplo n.º 5
0
def tag_get(blog_id, tag_name):

    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_member(user, blog)

    tag_name = url_unescape(tag_name)

    tag_list = Tag.select().where(Tag.tag.contains(tag_name), Tag.blog == blog)

    import json
    tag_list_json = json.dumps([{'tag': t.tag, 'id': t.id} for t in tag_list])

    return tag_list_json
Exemplo n.º 6
0
def add_tags_to_page(tag_text, page, no_delete=False):
    '''
    Takes a list of tags, in JSON text format, and adds them to the page in question.
    Any tags not already in the system will be added.

    :param tag_text:
        List of tags to add.
    :param page:
        Page object to add the tags to.
    :param no_delete:
        When set to True, this will preserve tags already in the page if they are
        not found in tag_text. By default this is False, so any tags not specified in
        tag_text that exist in the page will be removed.
    '''
    tag_list = Tag.select().where(Tag.id << tag_text)

    if no_delete is False:

        tags_to_delete = TagAssociation.delete().where(
            TagAssociation.page == page, ~TagAssociation.tag << (tag_list))

        tags_to_delete.execute()
    else:
        tags_to_delete = None

    tags_in_page = page.tags_all.select(Tag.id).tuples()

    tags_to_add = tag_list.select().where(~Tag.id << (tags_in_page))

    for n in tags_to_add:
        add_tag = TagAssociation(tag=n, page=page)

        add_tag.save()

    import json
    new_tags = json.loads(request.forms.getunicode('new_tags'))

    for n in new_tags:
        if n != '':
            new_tag = Tag(tag=n, blog=page.blog)
            new_tag.save()

            add_tag = TagAssociation(tag=new_tag, page=page)

            add_tag.save()

    return tags_to_add, tags_to_delete, new_tags
Exemplo n.º 7
0
def tag_get(blog_id, tag_name):

    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_member(user, blog)

    tag_name = url_unescape(tag_name)

    tag_list = Tag.select().where(
        Tag.tag.contains(tag_name),
        Tag.blog == blog)

    import json
    tag_list_json = json.dumps([{'tag':t.tag,
                                'id':t.id} for t in tag_list])

    return tag_list_json
Exemplo n.º 8
0
def tags_get(blog_id, limit, page_limit):

    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_member(user, blog)

    from core.models import TagAssociation

    blog_pages = blog.pages.published.select(Page.id).order_by(Page.publication_date.desc()).limit(page_limit)
    tag_assc = TagAssociation.select(TagAssociation.tag).where(TagAssociation.page << blog_pages)
    tag_list = Tag.select(Tag.tag, Tag.id).where(Tag.id << tag_assc)

    # tag_list = Blog.load(blog_id).tags_all.order_by(Tag.id.desc())

    if limit:
        tag_list = tag_list.limit(limit)

    import json
    tag_list_json = json.dumps([{'tag':t.tag,
                                'id':t.id} for t in tag_list])
    return tag_list_json
Exemplo n.º 9
0
def tags_get(blog_id, limit, page_limit):

    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_member(user, blog)

    from core.models import TagAssociation

    blog_pages = blog.pages.published.select(Page.id).order_by(
        Page.publication_date.desc()).limit(page_limit)
    tag_assc = TagAssociation.select(
        TagAssociation.tag).where(TagAssociation.page << blog_pages)
    tag_list = Tag.select(Tag.tag, Tag.id).where(Tag.id << tag_assc)

    # tag_list = Blog.load(blog_id).tags_all.order_by(Tag.id.desc())

    if limit:
        tag_list = tag_list.limit(limit)

    import json
    tag_list_json = json.dumps([{'tag': t.tag, 'id': t.id} for t in tag_list])
    return tag_list_json