<commit_before># -*- coding: utf-8 -*-
"""
    zine.views.admin
    ~~~~~~~~~~~~~~~~

    This module implements the admin views. The admin interface is only
    available for admins, editors and authors but not for subscribers. For
    subscribers a simplified account management system exists at /account.

    :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
"""
from datetime import datetime
from os import remove, sep as pathsep
from os.path import exists
from urlparse import urlparse

from werkzeug import escape
from werkzeug.exceptions import NotFound, BadRequest, Forbidden

from zine.privileges import assert_privilege, require_privilege, \
     CREATE_ENTRIES, EDIT_OWN_ENTRIES, EDIT_OTHER_ENTRIES, \
     CREATE_PAGES, EDIT_OWN_PAGES, EDIT_OTHER_PAGES, MODERATE_COMMENTS, \
     MANAGE_CATEGORIES, BLOG_ADMIN
from zine.i18n import _
from zine.application import get_request, url_for, emit_event, \
     render_response, get_application
from zine.models import User, Group, Post, Category, Comment, \
     STATUS_DRAFT, STATUS_PUBLISHED, COMMENT_MODERATED, COMMENT_UNMODERATED, \
     COMMENT_BLOCKED_USER, COMMENT_BLOCKED_SPAM
from zine.database import db, comments as comment_table, posts, \
     post_categories, post_links, secure_database_uri
from zine.utils import dump_json, load_json
from zine.utils.validators import is_valid_email, is_valid_url, check
from zine.utils.admin import flash, load_zine_reddit, require_admin_privilege
from zine.utils.text import gen_slug
from zine.utils.pagination import AdminPagination
from zine.utils.http import redirect_back, redirect_to, redirect
from zine.i18n import parse_datetime, format_system_datetime, \
     list_timezones, has_timezone, list_languages, has_language
from zine.importers import list_import_queue, load_import_dump, \
     delete_import_dump
from zine.pluginsystem import install_package, InstallationError, \
     SetupError, get_object_name
from zine.pingback import pingback, PingbackError
from zine.forms import LoginForm, ChangePasswordForm, PluginForm, \
     LogOptionsForm, EntryForm, PageForm, BasicOptionsForm, URLOptionsForm, \
     PostDeleteForm, EditCommentForm, DeleteCommentForm, \
     ApproveCommentForm, BlockCommentForm, EditCategoryForm, \
     DeleteCategoryForm, EditUserForm, DeleteUserForm, \
     CommentMassModerateForm, CacheOptionsForm, EditGroupForm, \
     DeleteGroupForm, ThemeOptionsForm, DeleteImportForm, ExportForm, \
     MaintenanceModeForm, MarkCommentForm, make_config_form, make_import_form


#: how many posts / comments should be displayed per page?
PER_PAGE = 20


def render_admin_response(template_name, _active_menu_item=None, **values):
    """Works pretty much like the normal `render_response` function but
    it emits some events to collect navigation items and injects that
    into the template context. This also gets the flashes messages from
    the user session and injects them into the template context after the
    plugins have provided theirs in the `before-admin-response-rendered`
    event.

    The second parameter can be the active menu item if wanted. For example
    ``'options.overview'`` would show the overview button in the options
    submenu. If the menu is a standalone menu like the dashboard (no
    child items) you can also just use ``'dashboard'`` to highlight that.
    """
    request = get_request()

    manage_items = [
        ('entries', url_for('admin/manage_entries'), _(u'Entries')),
        ('pages', url_for('admin/manage_pages'), _(u'Pages')),
        ('categories', url_for('admin/manage_categories'), _(u'Categories'))
    ]

    # set up the core navigation bar
    navigation_bar = [
        ('dashboard', url_for('admin/index'), _(u'Dashboard'), []),
        ('write', url_for('admin/new_entry'), _(u'Write'), [
            ('entry', url_for('admin/new_entry'), _(u'Entry')),
            ('page', url_for('admin/new_page'), _(u'Page'))
        ]),
        ('manage', url_for('admin/manage_entries'), _(u'Manage'), manage_items),
        ('comments', url_for('admin/manage_comments'), _(u'Comments'), [
            ('overview', url_for('admin/manage_comments'), _(u'Overview')),
            ('unmoderated', url_for('admin/show_unmoderated_comments'),
             _(u'Awaiting Moderation (%d)') %
             Comment.query.unmoderated().count()),
            ('approved', url_for('admin/show_approved_comments'),
             _(u'Approved Comments (%d)') % Comment.query.approved().count()),
            ('blocked', url_for('admin/show_blocked_comments'),
             _(u'Blocked Comments (%d)') % Comment.query.blocked().count()),
            ('spam', url_for('admin/show_spam_comments'),
             _(u'Spam Comments (%d)') % Comment.query.spam().count())
        ])
    ]

    # set up the administration menu bar
    if request.user.has_privilege(BLOG_ADMIN):
        navigation_bar.extend([
            ('options', url_for('admin/options'), _(u'Options'), [
                ('basic', url_for('admin/basic_options'), _(u'Basic')),
                ('urls', url_for('admin/urls'), _(u'URLs')),
                ('theme', url_for('admin/theme'), _(u'Theme')),
                ('plugins', url_for('admin/plugins'), _(u'Plugins')),
                ('cache', url_for('admin/cache'), _(u'Cache'))
            ])
        ])
        manage_items.extend([
            ('users', url_for('admin/manage_users'), _(u'Users')),
            ('groups', url_for('admin/manage_groups'), _(u'Groups'))
        ])

    # add the about items to the navigation bar
    system_items = [
        ('help', url_for('admin/help'), _(u'Help')),
        ('about', url_for('admin/about_zine'), _(u'About'))
    ]
    if request.user.has_privilege(BLOG_ADMIN):
        system_items[0:0] = [
            ('information', url_for('admin/information'),
             _(u'Information')),<commit_msg>Less verbose tabs for the new comment admin panel.<commit_after># -*- coding: utf-8 -*-
"""
    zine.views.admin
    ~~~~~~~~~~~~~~~~

    This module implements the admin views. The admin interface is only
    available for admins, editors and authors but not for subscribers. For
    subscribers a simplified account management system exists at /account.

    :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
"""
from datetime import datetime
from os import remove, sep as pathsep
from os.path import exists
from urlparse import urlparse

from werkzeug import escape
from werkzeug.exceptions import NotFound, BadRequest, Forbidden

from zine.privileges import assert_privilege, require_privilege, \
     CREATE_ENTRIES, EDIT_OWN_ENTRIES, EDIT_OTHER_ENTRIES, \
     CREATE_PAGES, EDIT_OWN_PAGES, EDIT_OTHER_PAGES, MODERATE_COMMENTS, \
     MANAGE_CATEGORIES, BLOG_ADMIN
from zine.i18n import _
from zine.application import get_request, url_for, emit_event, \
     render_response, get_application
from zine.models import User, Group, Post, Category, Comment, \
     STATUS_DRAFT, STATUS_PUBLISHED, COMMENT_MODERATED, COMMENT_UNMODERATED, \
     COMMENT_BLOCKED_USER, COMMENT_BLOCKED_SPAM
from zine.database import db, comments as comment_table, posts, \
     post_categories, post_links, secure_database_uri
from zine.utils import dump_json, load_json
from zine.utils.validators import is_valid_email, is_valid_url, check
from zine.utils.admin import flash, load_zine_reddit, require_admin_privilege
from zine.utils.text import gen_slug
from zine.utils.pagination import AdminPagination
from zine.utils.http import redirect_back, redirect_to, redirect
from zine.i18n import parse_datetime, format_system_datetime, \
     list_timezones, has_timezone, list_languages, has_language
from zine.importers import list_import_queue, load_import_dump, \
     delete_import_dump
from zine.pluginsystem import install_package, InstallationError, \
     SetupError, get_object_name
from zine.pingback import pingback, PingbackError
from zine.forms import LoginForm, ChangePasswordForm, PluginForm, \
     LogOptionsForm, EntryForm, PageForm, BasicOptionsForm, URLOptionsForm, \
     PostDeleteForm, EditCommentForm, DeleteCommentForm, \
     ApproveCommentForm, BlockCommentForm, EditCategoryForm, \
     DeleteCategoryForm, EditUserForm, DeleteUserForm, \
     CommentMassModerateForm, CacheOptionsForm, EditGroupForm, \
     DeleteGroupForm, ThemeOptionsForm, DeleteImportForm, ExportForm, \
     MaintenanceModeForm, MarkCommentForm, make_config_form, make_import_form


#: how many posts / comments should be displayed per page?
PER_PAGE = 20


def render_admin_response(template_name, _active_menu_item=None, **values):
    """Works pretty much like the normal `render_response` function but
    it emits some events to collect navigation items and injects that
    into the template context. This also gets the flashes messages from
    the user session and injects them into the template context after the
    plugins have provided theirs in the `before-admin-response-rendered`
    event.

    The second parameter can be the active menu item if wanted. For example
    ``'options.overview'`` would show the overview button in the options
    submenu. If the menu is a standalone menu like the dashboard (no
    child items) you can also just use ``'dashboard'`` to highlight that.
    """
    request = get_request()

    manage_items = [
        ('entries', url_for('admin/manage_entries'), _(u'Entries')),
        ('pages', url_for('admin/manage_pages'), _(u'Pages')),
        ('categories', url_for('admin/manage_categories'), _(u'Categories'))
    ]

    # set up the core navigation bar
    navigation_bar = [
        ('dashboard', url_for('admin/index'), _(u'Dashboard'), []),
        ('write', url_for('admin/new_entry'), _(u'Write'), [
            ('entry', url_for('admin/new_entry'), _(u'Entry')),
            ('page', url_for('admin/new_page'), _(u'Page'))
        ]),
        ('manage', url_for('admin/manage_entries'), _(u'Manage'), manage_items),
        ('comments', url_for('admin/manage_comments'), _(u'Comments'), [
            ('overview', url_for('admin/manage_comments'), _(u'Overview')),
            ('unmoderated', url_for('admin/show_unmoderated_comments'),
             _(u'Awaiting Moderation (%d)') %
             Comment.query.unmoderated().count()),
            ('approved', url_for('admin/show_approved_comments'),
             _(u'Approved (%d)') % Comment.query.approved().count()),
            ('blocked', url_for('admin/show_blocked_comments'),
             _(u'Blocked (%d)') % Comment.query.blocked().count()),
            ('spam', url_for('admin/show_spam_comments'),
             _(u'Spam (%d)') % Comment.query.spam().count())
        ])
    ]

    # set up the administration menu bar
    if request.user.has_privilege(BLOG_ADMIN):
        navigation_bar.extend([
            ('options', url_for('admin/options'), _(u'Options'), [
                ('basic', url_for('admin/basic_options'), _(u'Basic')),
                ('urls', url_for('admin/urls'), _(u'URLs')),
                ('theme', url_for('admin/theme'), _(u'Theme')),
                ('plugins', url_for('admin/plugins'), _(u'Plugins')),
                ('cache', url_for('admin/cache'), _(u'Cache'))
            ])
        ])
        manage_items.extend([
            ('users', url_for('admin/manage_users'), _(u'Users')),
            ('groups', url_for('admin/manage_groups'), _(u'Groups'))
        ])

    # add the about items to the navigation bar
    system_items = [
        ('help', url_for('admin/help'), _(u'Help')),
        ('about', url_for('admin/about_zine'), _(u'About'))
    ]
    if request.user.has_privilege(BLOG_ADMIN):
        system_items[0:0] = [
            ('information', url_for('admin/information'),
             _(u'Information')),
{'fraction_non_alphanumeric': 0.11877426979571164, 'fraction_numerical': 0.00219483369913895, 'mean_word_length': 3.6844602609727164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '192307', 'n_tokens_mistral': 3566, 'n_tokens_neox': 3427, 'n_words': 910}