コード例 #1
0
ファイル: blog.py プロジェクト: syegulalp/mercury
def blog_delete_preview(blog_id, preview_id):

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

    f = lambda:None
    f.blog = blog

    if preview_id == 'all':
        previews_to_delete = blog.fileinfos.where(FileInfo.preview_path.is_null(False))
        message = 'All previews for blog {} deleted.'.format(blog.for_display)
        f.msg = 'Delete all'
    else:
        previews_to_delete = blog.fileinfos.where(FileInfo.id == preview_id)
        message = 'Preview for fileinfo {} deleted.'.format(preview_id)
        f.msg = 'Delete preview {}'.format(preview_id)

    for n in previews_to_delete:
        if n.page is not None:
            n.page.delete_preview()
        else:
            n.template_mapping.template.delete_preview()

    tags = template_tags(blog_id=blog.id, user=user)

    from core.utils import Status

    tags.status = Status(
        type='success',
        message=message,
        close=False,
        )

    return report(tags, 'blog_delete_preview', f)
コード例 #2
0
ファイル: category.py プロジェクト: ra2003/mercury
def delete_category(blog_id, category_id, confirm='N'):
    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_admin(user, blog)

    category = Category.load(category_id, blog_id=blog.id)
    auth.check_category_editing_lock(blog)

    tags = template_tags(blog=blog, user=user)

    from core.utils import Status

    if request.forms.getunicode('confirm') == user.logout_nonce:
        message = 'Category {} successfully deleted'.format(category.for_log)
        url = '{}/blog/{}/categories'.format(BASE_URL, blog.id)
        action = 'Return to the category listing'

        reparent_categories = Category.update(
            parent_category=category.parent_category).where(
                Category.parent_category == category)
        reparent_categories.execute()

        delete_category = PageCategory.delete().where(
            PageCategory.category == category.id)
        delete_category.execute()

        category.delete_instance()

        tags.status = Status(type='success',
                             message=message,
                             action=action,
                             url=url,
                             close=False)

    else:
        message = (
            'You are about to delete category <b>{}</b> from blog <b>{}</b>.'.
            format(category.for_display, blog.for_display))

        yes = {
            'label': 'Yes, delete this category',
            'id': 'delete',
            'name': 'confirm',
            'value': user.logout_nonce
        }
        no = {
            'label': 'No, return to category properties',
            'url': '{}/blog/{}/category/{}'.format(BASE_URL, blog.id,
                                                   category.id)
        }

        tags.status = Status(message=message,
                             type='warning',
                             close=False,
                             yes=yes,
                             no=no)

    tags.category = category

    return report(tags, 'blog_delete_category', category)
コード例 #3
0
ファイル: user.py プロジェクト: syegulalp/mercury
def blog_user(user_id, blog_id):
    # Obtains user edit in blog context.
    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_admin(user, blog)
    user_to_edit = User.find(user_id)

    return edit_user(user_to_edit, editing_user=user, context=blog_context, blog=blog)
コード例 #4
0
ファイル: blog.py プロジェクト: syegulalp/mercury
def blog_list_users(blog_id):

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

    return listing(request, blog, blog.users,
                   'blog_users', 'blog_list_users',
                   user=user,
                   tags_data={'blog':blog}
                   )
コード例 #5
0
ファイル: user.py プロジェクト: ra2003/mercury
def blog_user(user_id, blog_id):
    # Obtains user edit in blog context.
    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_admin(user, blog)
    user_to_edit = User.find(user_id)

    return edit_user(user_to_edit,
                     editing_user=user,
                     context=blog_context,
                     blog=blog)
コード例 #6
0
def blog_settings(blog_id, nav_setting):

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

    auth.check_settings_lock(blog)

    tags = template_tags(blog_id=blog.id, user=user)

    tags.nav_default = nav_setting

    return blog_settings_output(tags)
コード例 #7
0
def blog_list_users(blog_id):

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

    return listing(request,
                   blog,
                   blog.users,
                   'blog_users',
                   'blog_list_users',
                   user=user,
                   tags_data={'blog': blog})
コード例 #8
0
ファイル: blog.py プロジェクト: syegulalp/mercury
def blog_settings(blog_id, nav_setting):

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

    auth.check_settings_lock(blog)

    tags = template_tags(blog_id=blog.id,
        user=user)

    tags.nav_default = nav_setting

    return blog_settings_output(tags)
コード例 #9
0
ファイル: blog.py プロジェクト: syegulalp/mercury
def blog_previews_list(blog_id):

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

    previews = blog.fileinfos.where(FileInfo.preview_path.is_null(False))

    return listing(request, blog, previews,
               'blog_previews', 'blog_previews',
               user=user,
               msg_float=False,
               tags_data={'blog':blog}
               )
コード例 #10
0
def blog_previews_list(blog_id):

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

    previews = blog.fileinfos.where(FileInfo.preview_path.is_null(False))

    return listing(request,
                   blog,
                   previews,
                   'blog_previews',
                   'blog_previews',
                   user=user,
                   msg_float=False,
                   tags_data={'blog': blog})
コード例 #11
0
def blog_create_user(blog_id):
    '''
    Creates a user and gives it certain permissions within the context of a given blog
    '''

    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_admin(user, blog)
    tags = template_tags(blog_id=blog.id, user=user)

    edit_user = Struct()
    edit_user.name = ""
    edit_user.email = ""

    return template(
        'edit/user_settings',
        section_title="Create new blog user",
        # search_context=(search_context['sites'], None),
        edit_user=edit_user,
        **tags.__dict__)
コード例 #12
0
ファイル: blog.py プロジェクト: syegulalp/mercury
def blog_create_user(blog_id):
    '''
    Creates a user and gives it certain permissions within the context of a given blog
    '''

    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_admin(user, blog)
    tags = template_tags(blog_id=blog.id,
        user=user)

    edit_user = Struct()
    edit_user.name = ""
    edit_user.email = ""

    return template('edit/user_settings',
        section_title="Create new blog user",
        # search_context=(search_context['sites'], None),
        edit_user=edit_user,
        **tags.__dict__
        )
コード例 #13
0
def blog_delete_preview(blog_id, preview_id):

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

    f = lambda: None
    f.blog = blog

    if preview_id == 'all':
        previews_to_delete = blog.fileinfos.where(
            FileInfo.preview_path.is_null(False))
        message = 'All previews for blog {} deleted.'.format(blog.for_display)
        f.msg = 'Delete all'
    else:
        previews_to_delete = blog.fileinfos.where(FileInfo.id == preview_id)
        message = 'Preview for fileinfo {} deleted.'.format(preview_id)
        f.msg = 'Delete preview {}'.format(preview_id)

    for n in previews_to_delete:
        if n.page is not None:
            n.page.delete_preview()
        else:
            n.template_mapping.template.delete_preview()

    tags = template_tags(blog_id=blog.id, user=user)

    from core.utils import Status

    tags.status = Status(
        type='success',
        message=message,
        close=False,
    )

    return report(tags, 'blog_delete_preview', f)
コード例 #14
0
ファイル: blog.py プロジェクト: syegulalp/mercury
def blog_settings_save(blog_id, nav_setting):

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

    _get = request.forms.getunicode

    # this could also be normalized?:
    # blog.form_gets([list here])
    # & you could always add custom fields after the fact

    blog.name = _get('blog_name', blog.name)
    blog.description = _get('blog_description', blog.description)
    blog.set_timezone = _get('blog_timezone')

    blog.url = _get('blog_url', blog.url)
    blog.path = _get('blog_path', blog.path)
    blog.base_extension = _get('blog_base_extension', blog.base_extension)
    blog.media_path = _get('blog_media_path', blog.media_path)

    from core.utils import Status
    from core.libs.peewee import IntegrityError
    errors = []

    try:
        blog.validate()
        blog.save()
    except IntegrityError as e:
        from core.utils import field_error
        errors.append(field_error(e))
    except Exception as e:
        errors.extend(e.args[0])

    # We could condense this all to:
    # blog.validate_and_save()
    # and just have it return errors as a list?

    if len(errors) > 0:

        status = Status(
            type='danger',
            no_sure=True,
            message='Blog settings could not be saved due to the following problems:',
            message_list=errors)
    else:
        status = Status(
            type='success',
            message="Settings for <b>{}</b> saved successfully.<hr/>It is recommended that you <a href='{}/blog/{}/purge'>republish this blog</a> immediately.".format(
                blog.for_display, BASE_URL, blog.id))

        logger.info("Settings for blog {} edited by user {}.".format(
            blog.for_log,
            user.for_log))

    tags = template_tags(user=user)

    tags.blog = blog
    tags.nav_default = nav_setting

    if status is not None:
        tags.status = status

    return blog_settings_output(tags)
コード例 #15
0
ファイル: category.py プロジェクト: syegulalp/mercury
def delete_category(blog_id, category_id, confirm='N'):
    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_admin(user, blog)

    category = Category.load(category_id, blog_id=blog.id)
    auth.check_category_editing_lock(blog)

    tags = template_tags(
        blog=blog,
        user=user)

    from core.utils import Status

    if request.forms.getunicode('confirm') == user.logout_nonce:
        message = 'Category {} successfully deleted'.format(
            category.for_log)
        url = '{}/blog/{}/categories'.format(BASE_URL, blog.id)
        action = 'Return to the category listing'

        reparent_categories = Category.update(
            parent_category=category.parent_category).where(
                Category.parent_category == category)
        reparent_categories.execute()

        delete_category = PageCategory.delete().where(
            PageCategory.category == category.id)
        delete_category.execute()

        category.delete_instance()

        tags.status = Status(
            type='success',
            message=message,
            action=action,
            url=url,
            close=False)

    else:
        message = ('You are about to delete category <b>{}</b> from blog <b>{}</b>.'.format(
            category.for_display,
            blog.for_display))

        yes = {
                'label':'Yes, delete this category',
                'id':'delete',
                'name':'confirm',
                'value':user.logout_nonce}
        no = {
            'label':'No, return to category properties',
            'url':'{}/blog/{}/category/{}'.format(
                BASE_URL, blog.id, category.id)
            }

        tags.status = Status(
            message=message,
            type='warning',
            close=False,
            yes=yes,
            no=no
            )

    tags.category = category

    return report(tags, 'blog_delete_category', category)
コード例 #16
0
ファイル: category.py プロジェクト: syegulalp/mercury
def edit_category(blog_id, category_id):
    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_admin(user, blog)

    category = Category.load(category_id, blog_id=blog.id)
    auth.check_category_editing_lock(blog)

    category_list = [n for n in blog.categories]

    top_level_category = Category(
        id=None,
        title='[Top-level category]',
        parent=None
        )

    category_list.insert(0, top_level_category)

    tags = template_tags(
        blog=blog,
        user=user)

    from core.utils import Status
    status = []

    if request.method == "POST":
        new_category_title = request.forms.getunicode('category_title')
        old_category_title = category.title

        if new_category_title != old_category_title:

            category.title = new_category_title
            category.save()

            status.append(
                ['Category <b>{}</b> was renamed to <b>{}</b>.',
                [old_category_title, new_category_title]])

        old_parent_category = category.parent_category
        try:
            new_parent_category = int(request.forms.getunicode('category_parent'))
        except ValueError:
            new_parent_category = None

        new_basename = request.forms.getunicode('category_basename')
        if category.basename != new_basename:
            category.basename = new_basename
            category.save()

            status.append(['Category basename was changed.',
                []])

        if old_parent_category != new_parent_category:
            category.parent_category = new_parent_category
            category.save()

            if new_parent_category is not None:
                new_category = Category.load(
                    category_id=new_parent_category,
                    blog=blog)
            else:
                new_category = top_level_category

            status.append(['Category <b>{}</b> was reparented to <b>{}</b>.',
                [category.title, new_category.for_log]])

        if request.forms.getunicode('default') == "Y":
            clear_default_categories = Category.update(
                default=False).where(
                    Category.blog == blog,
                    Category.default == True)
            clear_default_categories.execute()
            category.default = True
            category.save()

            status.append(['Category <b>{}</b> was set to default for blog <b>{}</b>.',
                [category.title, blog.for_log]])

    if len(status) > 0:
        message = ''
        vals = []
        for n in status:
            message += n[0]
            for m in n[1]:
                vals.append(m)
            vals.append('{}/blog/{}/purge'.format(BASE_URL, blog.id))
        tags.status = Status(type='success',
            message=message + '<br/><a href="{}">Purge and republish this blog</a> to make these changes take effect.',
            vals=vals)

    # from core.ui_kv import kv_ui
    from core.ui import kv
    kv_ui_data = kv.ui(category.kv_list())

    from core.ui import sidebar
    tags.sidebar = sidebar.render_sidebar(
            panel_set='edit_category',
            # status_badge=status_badge,
            kv_object='Category',
            kv_objectid=category.id,
            kv_ui=kv_ui_data)

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

    return tpl
コード例 #17
0
def blog_settings_save(blog_id, nav_setting):

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

    _get = request.forms.getunicode

    # this could also be normalized?:
    # blog.form_gets([list here])
    # & you could always add custom fields after the fact

    blog.name = _get('blog_name', blog.name)
    blog.description = _get('blog_description', blog.description)
    blog.set_timezone = _get('blog_timezone')

    blog.url = _get('blog_url', blog.url)
    blog.path = _get('blog_path', blog.path)
    blog.base_extension = _get('blog_base_extension', blog.base_extension)
    blog.media_path = _get('blog_media_path', blog.media_path)

    from core.utils import Status
    from core.libs.peewee import IntegrityError
    errors = []

    try:
        blog.validate()
        blog.save()
    except IntegrityError as e:
        from core.utils import field_error
        errors.append(field_error(e))
    except Exception as e:
        errors.extend(e.args[0])

    # We could condense this all to:
    # blog.validate_and_save()
    # and just have it return errors as a list?

    if len(errors) > 0:

        status = Status(
            type='danger',
            no_sure=True,
            message=
            'Blog settings could not be saved due to the following problems:',
            message_list=errors)
    else:
        status = Status(
            type='success',
            message=
            "Settings for <b>{}</b> saved successfully.<hr/>It is recommended that you <a href='{}/blog/{}/purge'>republish this blog</a> immediately."
            .format(blog.for_display, BASE_URL, blog.id))

        logger.info("Settings for blog {} edited by user {}.".format(
            blog.for_log, user.for_log))

    tags = template_tags(user=user)

    tags.blog = blog
    tags.nav_default = nav_setting

    if status is not None:
        tags.status = status

    return blog_settings_output(tags)
コード例 #18
0
ファイル: category.py プロジェクト: ra2003/mercury
def edit_category(blog_id, category_id):
    user = auth.is_logged_in(request)
    blog = Blog.load(blog_id)
    permission = auth.is_blog_admin(user, blog)

    category = Category.load(category_id, blog_id=blog.id)
    auth.check_category_editing_lock(blog)

    category_list = [n for n in blog.categories]

    top_level_category = Category(id=None,
                                  title='[Top-level category]',
                                  parent=None)

    category_list.insert(0, top_level_category)

    tags = template_tags(blog=blog, user=user)

    from core.utils import Status
    status = []

    if request.method == "POST":
        new_category_title = request.forms.getunicode('category_title')
        old_category_title = category.title

        if new_category_title != old_category_title:

            category.title = new_category_title
            category.save()

            status.append([
                'Category <b>{}</b> was renamed to <b>{}</b>.',
                [old_category_title, new_category_title]
            ])

        old_parent_category = category.parent_category
        try:
            new_parent_category = int(
                request.forms.getunicode('category_parent'))
        except ValueError:
            new_parent_category = None

        new_basename = request.forms.getunicode('category_basename')
        if category.basename != new_basename:
            category.basename = new_basename
            category.save()

            status.append(['Category basename was changed.', []])

        if old_parent_category != new_parent_category:
            category.parent_category = new_parent_category
            category.save()

            if new_parent_category is not None:
                new_category = Category.load(category_id=new_parent_category,
                                             blog=blog)
            else:
                new_category = top_level_category

            status.append([
                'Category <b>{}</b> was reparented to <b>{}</b>.',
                [category.title, new_category.for_log]
            ])

        if request.forms.getunicode('default') == "Y":
            clear_default_categories = Category.update(default=False).where(
                Category.blog == blog, Category.default == True)
            clear_default_categories.execute()
            category.default = True
            category.save()

            status.append([
                'Category <b>{}</b> was set to default for blog <b>{}</b>.',
                [category.title, blog.for_log]
            ])

    if len(status) > 0:
        message = ''
        vals = []
        for n in status:
            message += n[0]
            for m in n[1]:
                vals.append(m)
            vals.append('{}/blog/{}/purge'.format(BASE_URL, blog.id))
        tags.status = Status(
            type='success',
            message=message +
            '<br/><a href="{}">Purge and republish this blog</a> to make these changes take effect.',
            vals=vals)

    # from core.ui_kv import kv_ui
    from core.ui import kv
    kv_ui_data = kv.ui(category.kv_list())

    from core.ui import sidebar
    tags.sidebar = sidebar.render_sidebar(
        panel_set='edit_category',
        # status_badge=status_badge,
        kv_object='Category',
        kv_objectid=category.id,
        kv_ui=kv_ui_data)

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

    return tpl