예제 #1
0
    def new_tag_for_display(self):

        btn_type = 'warning' if self.tag[0] == "@" else 'info'

        template = tag_template.format(
            id=0,
            tag=new_tag_template.format(tag=html_escape(self.tag)),
            btn_type=btn_type,
            new='data-new-tag="{}" '.format(html_escape(self.tag)))

        return template
예제 #2
0
파일: kv.py 프로젝트: ra2003/mercury
def ui(keys):

    if keys is None:
        return None

    kv_ui = []

    for n in keys:

        kv_ui.append(
            blank_item.format(
                n.id,
                "<b><a title=\"Edit\" onclick=\"edit_kv({});\" href=\"#\">{}</a>:</b> <i>{}</i>"
                .format(n.id, html_escape(n.key), html_escape(n.value))))

    return ''.join(kv_ui)
예제 #3
0
파일: page.py 프로젝트: syegulalp/mercury
def page_media_upload(page_id):

    user = auth.is_logged_in(request)
    page = Page.load(page_id)
    permission = auth.is_page_editor(user, page)

    overwrite = []

    for n in request.files:
        x = request.files.get(n)
        media_path = _join(page.blog.path, page.blog.media_path_generated)
        file_path = _join(media_path, x.filename)
        if _exists(file_path):
            from core.error import FileExistsError
            raise FileExistsError("File '{}' already exists on the server.".format(
                utils.html_escape(x.filename)))
        else:
            Media.register_media(x.filename, file_path, user, page=page)
            if not _exists(media_path):
                makedirs(media_path)
            x.save(file_path)

    tags = template_tags(page=page)

    return template('edit/page_media_list.tpl',
        **tags.__dict__)
예제 #4
0
def page_media_upload(page_id):

    user = auth.is_logged_in(request)
    page = Page.load(page_id)
    permission = auth.is_page_editor(user, page)

    overwrite = []

    for n in request.files:
        x = request.files.get(n)
        media_path = _join(page.blog.path, page.blog.media_path_generated)
        file_path = _join(media_path, x.filename)
        if _exists(file_path):
            from core.error import FileExistsError
            raise FileExistsError(
                "File '{}' already exists on the server.".format(
                    utils.html_escape(x.filename)))
        else:
            Media.register_media(x.filename, file_path, user, page=page)
            if not _exists(media_path):
                makedirs(media_path)
            x.save(file_path)

    tags = template_tags(page=page)

    return template('edit/page_media_list.tpl', **tags.__dict__)
예제 #5
0
파일: kv.py 프로젝트: syegulalp/mercury
def ui(keys):

    if keys is None:
        return None

    kv_ui = []

    for n in keys:

        kv_ui.append(blank_item.format(
            n.id,
            "<b><a title=\"Edit\" onclick=\"edit_kv({});\" href=\"#\">{}</a>:</b> <i>{}</i>".format(
                n.id,
                html_escape(n.key), html_escape(n.value))
            ))

    return ''.join(kv_ui)
예제 #6
0
    def for_listing(self):

        template = tag_link_template.format(id=self.id,
                                            url=BASE_URL + "/blog/" +
                                            str(self.blog.id) + "/tag/" +
                                            str(self.id),
                                            tag=html_escape(self.tag))

        return template
예제 #7
0
파일: menu.py 프로젝트: ra2003/mercury
def _page_listing(page):

    if page.title:
        page_title = html_escape(page.title)
    else:
        page_title = "[<i>Untitled</i>]"

    return '<a href="{}/page/{}/edit">{}</a>'.format(BASE_URL, page.id,
                                                     page_title)
예제 #8
0
파일: menu.py 프로젝트: syegulalp/mercury
def _page_listing(page):

    if page.title:
        page_title = html_escape(page.title)
    else:
        page_title = "[<i>Untitled</i>]"

    return '<a href="{}/page/{}/edit">{}</a>'.format(
        BASE_URL,
        page.id,
        page_title
    )
예제 #9
0
 def for_listing(self):
     '''
     Returns a version of the object title as an HTML link, with an escaped title.
     '''
     try:
         listing_id = "id='list_item_" + str(self.id) + "'"
     except AttributeError:
         listing_id = self.listing_id
     return "<a {id} href='{link}'>{text}</a>".format(id=listing_id,
                                                      link=self.link_format,
                                                      text=html_escape(
                                                          self.n_t))
예제 #10
0
    def for_display(self):

        btn_type = 'warning' if self.tag[0] == "@" else 'info'

        template = tag_template.format(
            id=self.id,
            btn_type=btn_type,
            new='',
            tag=tag_link_template.format(id=self.id,
                                         url=BASE_URL + "/blog/" +
                                         str(self.blog.id) + "/tag/" +
                                         str(self.id),
                                         tag=html_escape(self.tag)))

        return template
예제 #11
0
파일: tags.py 프로젝트: syegulalp/mercury
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
예제 #12
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
예제 #13
0
 def as_text(self):
     '''
     Returns a text-only, auto-escaped version of the object title.
     '''
     return html_escape(self.n_t)