Exemplo n.º 1
0
def tag_edit(blog_id, tag_id):
    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_editor(user, blog)

    auth.check_tag_editing_lock(blog)

    try:
        tag = Tag.get(Tag.id == tag_id,
                      Tag.blog == blog_id)
    except Tag.DoesNotExist:
        raise Tag.DoesNotExist("No such tag #{} in blog {}.".format(
            tag_id,
            blog.for_log))

    tags = template_tags(
        user=user)

    from core.utils import html_escape

    if request.method == "POST":

        new_tag_name = request.forms.getunicode('tag_name')
        if new_tag_name != tag.tag:

            try:
                Tag.get(Tag.tag == new_tag_name)

            except Tag.DoesNotExist:
                tag_count = tag.pages.count()

                msg = "Tag changed from {} to <b>{}</b>. {} pages (and their archives) have been queued for republishing.".format(
                    tag.for_log,
                    html_escape(new_tag_name),
                    tag_count)

                tag.tag = new_tag_name
                tag.save()

                if tag_count > 0:

                    from core.cms import queue
                    from core.models import db

                    with db.atomic() as txn:

                        queue.queue_page_actions(tag.pages.published)
                        queue.queue_ssi_actions(blog)
                        queue.queue_index_actions(blog, True)

                tags.status = Status(
                    type='info',
                    message=msg
                    )

            else:

                msg = "Tag not renamed. A tag with the name '{}' already exists.".format(
                    html_escape(new_tag_name)
                )

                tags.status = Status(
                    type='danger',
                    message=msg,
                    no_sure=True)
    else:
        tag_modified = tag_recently_modified(tag)
        if tag_modified:
            tags.status = Status(
                    type='danger',
                    message=tag_modified,
                    no_sure=True)

    tpl = template('edit/tag',
        menu=generate_menu('blog_edit_tag', tag),
        search_context=(search_contexts['sites'], None),
        tag=tag,
        **tags.__dict__)

    return tpl
Exemplo n.º 2
0
def tag_edit(blog_id, tag_id):
    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_editor(user, blog)

    auth.check_tag_editing_lock(blog)

    try:
        tag = Tag.get(Tag.id == tag_id, Tag.blog == blog_id)
    except Tag.DoesNotExist:
        raise Tag.DoesNotExist("No such tag #{} in blog {}.".format(
            tag_id, blog.for_log))

    tags = template_tags(user=user)

    from core.utils import html_escape

    if request.method == "POST":

        new_tag_name = request.forms.getunicode('tag_name')
        if new_tag_name != tag.tag:

            try:
                Tag.get(Tag.tag == new_tag_name)

            except Tag.DoesNotExist:
                tag_count = tag.pages.count()

                msg = "Tag changed from {} to <b>{}</b>. {} pages (and their archives) have been queued for republishing.".format(
                    tag.for_log, html_escape(new_tag_name), tag_count)

                tag.tag = new_tag_name
                tag.save()

                if tag_count > 0:

                    from core.cms import queue
                    from core.models import db

                    with db.atomic() as txn:

                        queue.queue_page_actions(tag.pages.published)
                        queue.queue_ssi_actions(blog)
                        queue.queue_index_actions(blog, True)

                tags.status = Status(type='info', message=msg)

            else:

                msg = "Tag not renamed. A tag with the name '{}' already exists.".format(
                    html_escape(new_tag_name))

                tags.status = Status(type='danger', message=msg, no_sure=True)
    else:
        tag_modified = tag_recently_modified(tag)
        if tag_modified:
            tags.status = Status(type='danger',
                                 message=tag_modified,
                                 no_sure=True)

    tpl = template('edit/tag',
                   menu=generate_menu('blog_edit_tag', tag),
                   search_context=(search_contexts['sites'], None),
                   tag=tag,
                   **tags.__dict__)

    return tpl
Exemplo n.º 3
0
def tag_delete(blog_id, tag_id):
    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_publisher(user, blog)

    auth.check_tag_editing_lock(blog)

    try:
        tag = Tag.get(Tag.id == tag_id,
                      Tag.blog == blog_id)
    except Tag.DoesNotExist:
        raise Tag.DoesNotExist("No such tag #{} in blog {}.".format(
            tag_id,
            blog.for_log))

    from settings import BASE_URL
    tag_page_count = tag.pages.count()

    if request.forms.getunicode('confirm') == user.logout_nonce:

        from core.models import db

        if tag_page_count > 0:
            p_count = tag.pages.published.count()

            from core.cms import queue

            with db.atomic() as txn:
                queue.queue_page_actions(tag.pages.published)
                queue.queue_ssi_actions(blog)
                queue.queue_index_actions(blog, True)

            recommendation = '''
<p><b>{}</b> pages affected by this change have been pushed to the queue.</p>
'''.format(p_count)
        else:
            recommendation = '''
<p>No pages were associated with this tag.</p>
'''
        with db.atomic() as txn:
            tag.delete_instance(recursive=True)

        status = Status(
            type='success',
            close=False,
            message='''
Tag <b>{}</b> was successfully deleted from blog <b>{}</b>.</p>{}
'''.format(tag.for_log, blog.for_display, recommendation)
            )

    else:

        if tag_page_count > 0:
            recommendation = '''
<p><b>There are still <a target="_blank" href="{}/blog/{}/tag/{}/pages">{} pages</a> associated with this tag.</b></p>
'''.format(BASE_URL, blog.id, tag.id, tag_page_count)

            tag_modified = tag_recently_modified(tag)
            if tag_modified:
                recommendation += "<p><b>" + tag_modified + "</b></p>"

        else:
            recommendation = ''

        status = Status(
                type='warning',
                close=False,
                message='''
    You are about to delete tag <b>{}</b> in blog <b>{}</b>.</p>{}
    '''.format(tag.for_listing, blog.for_display, recommendation),
                url='{}/blog/{}/tag/{}/delete'.format(
                    BASE_URL, blog.id, tag.id),
                yes={'id':'delete',
                    'name':'confirm',
                    'label':'Yes, I want to delete this tag',
                    'value':user.logout_nonce},
                no={'label':'No, don\'t delete this tag',
                    'url':'{}/blog/{}/tag/{}'.format(
                    BASE_URL, blog.id, tag.id)}
                )

    tags = template_tags(
        user=user)
    tags.status = status

    return report(tags, 'blog_delete_tag', tag)
Exemplo n.º 4
0
def tag_delete(blog_id, tag_id):
    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_publisher(user, blog)

    auth.check_tag_editing_lock(blog)

    try:
        tag = Tag.get(Tag.id == tag_id, Tag.blog == blog_id)
    except Tag.DoesNotExist:
        raise Tag.DoesNotExist("No such tag #{} in blog {}.".format(
            tag_id, blog.for_log))

    from settings import BASE_URL
    tag_page_count = tag.pages.count()

    if request.forms.getunicode('confirm') == user.logout_nonce:

        from core.models import db

        if tag_page_count > 0:
            p_count = tag.pages.published.count()

            from core.cms import queue

            with db.atomic() as txn:
                queue.queue_page_actions(tag.pages.published)
                queue.queue_ssi_actions(blog)
                queue.queue_index_actions(blog, True)

            recommendation = '''
<p><b>{}</b> pages affected by this change have been pushed to the queue.</p>
'''.format(p_count)
        else:
            recommendation = '''
<p>No pages were associated with this tag.</p>
'''
        with db.atomic() as txn:
            tag.delete_instance(recursive=True)

        status = Status(type='success',
                        close=False,
                        message='''
Tag <b>{}</b> was successfully deleted from blog <b>{}</b>.</p>{}
'''.format(tag.for_log, blog.for_display, recommendation))

    else:

        if tag_page_count > 0:
            recommendation = '''
<p><b>There are still <a target="_blank" href="{}/blog/{}/tag/{}/pages">{} pages</a> associated with this tag.</b></p>
'''.format(BASE_URL, blog.id, tag.id, tag_page_count)

            tag_modified = tag_recently_modified(tag)
            if tag_modified:
                recommendation += "<p><b>" + tag_modified + "</b></p>"

        else:
            recommendation = ''

        status = Status(type='warning',
                        close=False,
                        message='''
    You are about to delete tag <b>{}</b> in blog <b>{}</b>.</p>{}
    '''.format(tag.for_listing, blog.for_display, recommendation),
                        url='{}/blog/{}/tag/{}/delete'.format(
                            BASE_URL, blog.id, tag.id),
                        yes={
                            'id': 'delete',
                            'name': 'confirm',
                            'label': 'Yes, I want to delete this tag',
                            'value': user.logout_nonce
                        },
                        no={
                            'label':
                            'No, don\'t delete this tag',
                            'url':
                            '{}/blog/{}/tag/{}'.format(BASE_URL, blog.id,
                                                       tag.id)
                        })

    tags = template_tags(user=user)
    tags.status = status

    return report(tags, 'blog_delete_tag', tag)