예제 #1
0
파일: admin.py 프로젝트: Theer108/invenio
def kb_delete(req, kb, ln=CFG_SITE_LANG, chosen_option=""):
    """
    Deletes an existing kb

    @param kb the kb id to delete
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = """ &gt; <a class="navtrail" href="%s/kb?ln=%s">%s</a> &gt; %s""" % (
        CFG_SITE_SECURE_URL,
        ln,
        _("Manage Knowledge Bases"),
        _("Delete Knowledge Base"),
    )

    try:
        dummy = getUid(req)
    except:
        return error_page("Error", req)

    (auth_code, auth_msg) = check_user(req, "cfgbibknowledge")
    if not auth_code:
        kb_id = wash_url_argument(kb, "int")
        kb_name = bibknowledge.get_kb_name(kb_id)
        if kb_name is None:
            return page(
                title=_("Unknown Knowledge Base"),
                body="",
                language=ln,
                navtrail=navtrail_previous_links,
                errors=[("ERR_KB_ID_UNKNOWN", kb)],
                lastupdated=__lastupdated__,
                req=req,
            )

        # Ask confirmation to user if not already done
        chosen_option = wash_url_argument(chosen_option, "str")
        if chosen_option == "":
            return dialog_box(
                req=req,
                ln=ln,
                title="Delete %s" % kb_name,
                message="""Are you sure you want to
                              delete knowledge base <i>%s</i>?"""
                % kb_name,
                navtrail=navtrail_previous_links,
                options=[_("Cancel"), _("Delete")],
            )

        elif chosen_option == _("Delete"):
            bibknowledge.delete_kb(kb_name)

        redirect_to_url(req, "kb?ln=%(ln)s" % {"ln": ln})
    else:
        navtrail_previous_links = """ &gt; <a class="navtrail" href="%s/kb">%s</a>""" % (
            CFG_SITE_SECURE_URL,
            _("Manage Knowledge Bases"),
        )

        return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
예제 #2
0
def issue_control(req,
                  journal_name="",
                  issue=[],
                  ln=CFG_SITE_LANG,
                  action="cfg"):
    """
    Page that allows full control over creating, backtracing, adding to,
    removing from issues.
    """
    navtrail_previous_links = wjn.getnavtrail(
        ' &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py">WebJournal Admin</a> &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py/administrate?journal_name=%s">%s</a>'
        % (CFG_SITE_URL, CFG_SITE_URL, journal_name, journal_name))

    ln = wash_language(ln)
    _ = gettext_set_language(ln)

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)
    try:
        journal_name = wash_journal_name(ln, journal_name)
        action = wash_url_argument(action, 'str')
        issue = wash_url_argument(issue, 'list')
        issues = [wash_issue_number(ln,journal_name, _issue) \
                  for _issue in issue \
                  if _issue != "ww/YYYY"]
    except InvenioWebJournalNoJournalOnServerError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalNoNameError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalNoCurrentIssueError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalIssueNumberBadlyFormedError as e:
        register_exception(req=req)
        return e.user_box()

    auth = acc_authorize_action(getUid(req),
                                'cfgwebjournal',
                                name="%s" % journal_name,
                                with_editor_rights='yes')
    if auth[0] == 0:
        return page(title=_("Publishing Interface"),
                    body=wjn.perform_request_issue_control(
                        journal_name=journal_name,
                        issues=issues,
                        ln=ln,
                        action=action),
                    uid=uid,
                    language=ln,
                    req=req,
                    navtrail=navtrail_previous_links,
                    lastupdated=__lastupdated__)
    else:
        return page_not_authorized(req=req,
                                   text=auth[1],
                                   navtrail=navtrail_previous_links)
예제 #3
0
def perform_request_comments(req=None, ln=CFG_SITE_LANG, uid="", comID="", recID="", reviews=0, abuse=False, collection=""):
    """
    Display the list of comments/reviews along with information about the comment.

    Display the comment given by its ID, or the list of comments for
    the given record ID.
    If abuse == True, only list records reported as abuse.
    If comID and recID are not provided, list all comments, or all
    abused comments (check parameter 'abuse')
    """
    ln = wash_language(ln)
    uid = wash_url_argument(uid, 'int')
    comID = wash_url_argument(comID, 'int')
    recID = wash_url_argument(recID, 'int')
    reviews = wash_url_argument(reviews, 'int')
    collection = wash_url_argument(collection, 'str')

    user_info = collect_user_info(req)
    user_collections = ['Show all']
    user_collections.extend(get_user_collections(req))
    if collection and collection != 'Show all':
        (auth_code, auth_msg) = acc_authorize_action(req, 'moderatecomments', collection=collection)
        if auth_code:
            return webcomment_templates.tmpl_admin_comments(ln=ln, uid=uid,
                                                            comID=comID,
                                                            recID=recID,
                                                            comment_data=None,
                                                            reviews=reviews,
                                                            error=1,
                                                            user_collections=user_collections,
                                                            collection=collection)
    if collection:
        if recID or uid:
            comments = query_get_comments(uid, comID, recID, reviews, ln, abuse=abuse, user_collections=user_collections, collection=collection)
        else:
            comments = query_get_comments('', comID, '', reviews, ln, abuse=abuse, user_collections=user_collections, collection=collection)
    else:
        if recID or uid:
            comments = query_get_comments(uid, comID, recID, reviews, ln, abuse=abuse, user_collections=user_collections, collection=user_collections[0])
        else:
            comments = query_get_comments('', comID, '', reviews, ln, abuse=abuse, user_collections=user_collections, collection=user_collections[0])
    if comments:
        return webcomment_templates.tmpl_admin_comments(ln=ln, uid=uid,
                                                        comID=comID,
                                                        recID=recID,
                                                        comment_data=comments,
                                                        reviews=reviews,
                                                        error=0,
                                                        user_collections=user_collections,
                                                        collection=collection)
    else:
        return webcomment_templates.tmpl_admin_comments(ln=ln, uid=uid,
                                                        comID=comID,
                                                        recID=recID,
                                                        comment_data=comments,
                                                        reviews=reviews,
                                                        error=2,
                                                        user_collections=user_collections,
                                                        collection=collection)
예제 #4
0
def perform_request_latest(req=None,
                           ln=CFG_SITE_LANG,
                           comments=1,
                           top=10,
                           collection=""):
    """
    Display the list of latest comments/reviews along with information about the comment.

    @param req: request object for obtaining user information
    @param ln: language
    @param comments: boolean activated if using comments, deactivated for reviews
    @param top: Specify number of results to be shown
    @param collection: filter by collection
    """
    ln = wash_language(ln)
    comments = wash_url_argument(comments, 'int')
    top = wash_url_argument(top, 'int')
    collection = wash_url_argument(collection, 'str')

    user_info = collect_user_info(req)
    user_collections = ['Show all']
    user_collections.extend(get_user_collections(req))
    if collection and collection != 'Show all':
        (auth_code, auth_msg) = acc_authorize_action(req,
                                                     'moderatecomments',
                                                     collection=collection)
        if auth_code:
            return webcomment_templates.tmpl_admin_latest(
                ln=ln,
                comment_data=None,
                comments=comments,
                error=1,
                user_collections=user_collections,
                collection=collection)
    if collection:
        comments_retrieved = query_get_latest(comments, ln, top,
                                              user_collections, collection)
    else:
        comments_retrieved = query_get_latest(comments, ln, top,
                                              user_collections,
                                              user_collections[0])
    if comments_retrieved:
        return webcomment_templates.tmpl_admin_latest(
            ln=ln,
            comment_data=comments_retrieved,
            comments=comments,
            error=0,
            user_collections=user_collections,
            collection=collection)
    else:
        return webcomment_templates.tmpl_admin_latest(
            ln=ln,
            comment_data=comments_retrieved,
            comments=comments,
            error=2,
            user_collections=user_collections,
            collection=collection)
예제 #5
0
파일: admin.py 프로젝트: Theer108/invenio
def kb_edit_mapping(req, kb, key, mapFrom, mapTo, update="", delete="", sortby="to", ln=CFG_SITE_LANG):
    """
    Edit a mapping to in kb. Edit can be "update old value" or "delete existing value"

    @param kb the knowledge base id to edit
    @param key the key of the mapping that will be modified
    @param mapFrom the new key of the mapping
    @param mapTo the new value of the mapping
    @param update contains a value if the mapping is to be updated
    @param delete contains a value if the mapping is to be deleted
    @param sortby the sorting criteria ('from' or 'to')
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = """ &gt; <a class="navtrail" href="%s/kb?ln=%s">%s</a>""" % (
        CFG_SITE_SECURE_URL,
        ln,
        _("Manage Knowledge Bases"),
    )

    try:
        dummy = getUid(req)
    except:
        return error_page("Error", req)

    (auth_code, auth_msg) = check_user(req, "cfgbibknowledge")
    if not auth_code:
        kb_id = wash_url_argument(kb, "int")
        kb_name = bibknowledge.get_kb_name(kb_id)

        if kb_name is None:
            return page(
                title=_("Unknown Knowledge Base"),
                body="",
                language=ln,
                navtrail=navtrail_previous_links,
                errors=[("ERR_KB_ID_UNKNOWN", kb)],
                lastupdated=__lastupdated__,
                req=req,
            )

        key = wash_url_argument(key, "str")
        if delete != "":
            # Delete
            bibknowledge.remove_kb_mapping(kb_name, key)
        if update != "":
            # Update
            new_key = wash_url_argument(mapFrom, "str")
            new_value = wash_url_argument(mapTo, "str")
            bibknowledge.update_kb_mapping(kb_name, key, new_key, new_value)

        redirect_to_url(req, "kb?ln=%(ln)s&kb=%(kb)s&sortby=%(sortby)s" % {"ln": ln, "kb": kb_id, "sortby": sortby})
    else:
        return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
예제 #6
0
def format_template_show_attributes(req, bft, ln=CFG_SITE_LANG, new=0):
    """
    Page for template name and descrition attributes edition.

    This is also the first page shown when a format template
    has just been added. In that case new is different from
    False and we can offer specific option to user (for ex
    let him make a duplicate of existing template).

    @param req: the request object
    @param ln: language
    @param bft: the name of the template to show
    @param new: if "False", the template has not just been added
    @return: a web page
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = bibformatadminlib.getnavtrail(''' &gt; <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/format_templates_manage?ln=%s">%s</a>''' % (CFG_SITE_SECURE_URL, ln, _("Manage Format Templates")))

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        format_template = wash_url_argument(bft, 'str')
        format_name = bibformat_engine.get_format_template_attrs(bft)['name']
        is_new = wash_url_argument(new, 'int')

        if not bibformatadminlib.can_read_format_template(bft): #No read permission
            try:
                raise InvenioBibFormatError(_('Format template %(x_name)s cannot not be read. %(x_text)s', x_name=format_template, x_text=""))
            except InvenioBibFormatError as exc:
                register_exception(req=req)
                return page(title=_("Restricted Format Template"),
                            body = """You don't have permission
                            to view this format template.""",
                            language=ln,
                            navtrail = navtrail_previous_links,
                            lastupdated=__lastupdated__,
                            req=req)

        return page(title=_("Format Template %(x_name)s Attributes", x_name=format_name),
                    body=bibformatadminlib.perform_request_format_template_show_attributes(bft, ln=ln, new=is_new),
                    uid=uid,
                    language=ln,
                    navtrail = navtrail_previous_links ,
                    lastupdated=__lastupdated__,
                    req=req)

    else:
        return page_not_authorized(req=req, text=auth_msg)
예제 #7
0
파일: admin.py 프로젝트: chokribr/invenio-1
def kb_delete(req, kb, ln=CFG_SITE_LANG, chosen_option=""):
    """
    Deletes an existing kb

    @param kb the kb id to delete
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = ''' &gt; <a class="navtrail" href="%s/kb?ln=%s">%s</a> &gt; %s''' % (
        CFG_SITE_SECURE_URL, ln, _("Manage Knowledge Bases"),
        _("Delete Knowledge Base"))

    try:
        dummy = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibknowledge')
    if not auth_code:
        kb_id = wash_url_argument(kb, 'int')
        kb_name = bibknowledge.get_kb_name(kb_id)
        if kb_name is None:
            return page(title=_("Unknown Knowledge Base"),
                        body="",
                        language=ln,
                        navtrail=navtrail_previous_links,
                        errors=[("ERR_KB_ID_UNKNOWN", kb)],
                        lastupdated=__lastupdated__,
                        req=req)

        #Ask confirmation to user if not already done
        chosen_option = wash_url_argument(chosen_option, 'str')
        if chosen_option == "":
            return dialog_box(req=req,
                              ln=ln,
                              title="Delete %s" % kb_name,
                              message="""Are you sure you want to
                              delete knowledge base <i>%s</i>?""" % kb_name,
                              navtrail=navtrail_previous_links,
                              options=[_("Cancel"), _("Delete")])

        elif chosen_option == _("Delete"):
            bibknowledge.delete_kb(kb_name)

        redirect_to_url(req, "kb?ln=%(ln)s" % {'ln': ln})
    else:
        navtrail_previous_links = ''' &gt; <a class="navtrail" href="%s/kb">%s</a>''' % (
            CFG_SITE_SECURE_URL, _("Manage Knowledge Bases"))

        return page_not_authorized(req=req,
                                   text=auth_msg,
                                   navtrail=navtrail_previous_links)
예제 #8
0
def issue_control(req, journal_name="", issue=[],
                  ln=CFG_SITE_LANG, action="cfg"):
    """
    Page that allows full control over creating, backtracing, adding to,
    removing from issues.
    """
    navtrail_previous_links = wjn.getnavtrail(' &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py">WebJournal Admin</a> &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py/administrate?journal_name=%s">%s</a>' % (CFG_SITE_URL, CFG_SITE_URL, journal_name, journal_name))

    ln = wash_language(ln)
    _ = gettext_set_language(ln)

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)
    try:
        journal_name = wash_journal_name(ln, journal_name)
        action = wash_url_argument(action, 'str')
        issue = wash_url_argument(issue, 'list')
        issues = [wash_issue_number(ln,journal_name, _issue) \
                  for _issue in issue \
                  if _issue != "ww/YYYY"]
    except InvenioWebJournalNoJournalOnServerError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalNoNameError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalNoCurrentIssueError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalIssueNumberBadlyFormedError as e:
        register_exception(req=req)
        return e.user_box()

    auth = acc_authorize_action(getUid(req), 'cfgwebjournal',
                                name="%s" % journal_name,
                                with_editor_rights='yes')
    if auth[0] == 0:
        return page(title=_("Publishing Interface"),
                    body=wjn.perform_request_issue_control(journal_name=journal_name,
                                                           issues=issues,
                                                           ln=ln,
                                                           action=action),
                    uid=uid,
                    language=ln,
                    req=req,
                    navtrail = navtrail_previous_links,
                    lastupdated=__lastupdated__)
    else:
        return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
예제 #9
0
def regenerate(req, journal_name="", issue="", ln=CFG_SITE_LANG,
               confirmed_p="", publish_draft_articles_p=""):
    """
    Clears the cache for the given issue.
    """
    navtrail_previous_links = wjn.getnavtrail(' &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py">WebJournal Admin</a> &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py/administrate?journal_name=%s">%s</a>' % (CFG_SITE_URL, CFG_SITE_URL, journal_name, journal_name))

    ln = wash_language(ln)
    _ = gettext_set_language(ln)

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    try:
        journal_name = wash_journal_name(ln, journal_name)
        issue_number = wash_issue_number(ln, journal_name,
                                         issue)
        confirmed_p = wash_url_argument(confirmed_p, 'str') == "confirmed"
        publish_draft_articles_p = wash_url_argument(publish_draft_articles_p, 'str') == "move"

    except InvenioWebJournalNoJournalOnServerError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalNoNameError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalNoCurrentIssueError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalIssueNumberBadlyFormedError as e:
        register_exception(req=req)
        return e.user_box()

    auth = acc_authorize_action(getUid(req), 'cfgwebjournal',
                                name="%s" % journal_name)
    if auth[0] == 0:
        return page(title=confirmed_p and _("Issue regenerated") or _("Regenerate Issue"),
                    body=wjn.perform_regenerate_issue(ln=ln,
                                                      journal_name=journal_name,
                                                      issue=issue,
                                                      confirmed_p=confirmed_p,
                                                      publish_draft_articles_p=publish_draft_articles_p),
                    uid=uid,
                    language=ln,
                    req=req,
                    navtrail = navtrail_previous_links,
                    lastupdated=__lastupdated__)
    else:
        return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
예제 #10
0
def configure(req, journal_name=None, ln=CFG_SITE_LANG, xml_config=u'', action='edit'):
    """
    Let admins configure the journal settings
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)

    if journal_name is None:
        navtrail_previous_links = wjn.getnavtrail(' &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py">WebJournal Admin</a>' % CFG_SITE_URL)
    else:
        navtrail_previous_links = wjn.getnavtrail(' &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py">WebJournal Admin</a> &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py/administrate?journal_name=%s">%s</a>' % (CFG_SITE_URL, CFG_SITE_URL, journal_name, journal_name))

    if action in ['add', 'addDone']:
        page_title = _('Add Journal')
    else:
        page_title = _("Edit Settings")

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    try:
        journal_name = wash_journal_name(ln, journal_name, guess=False)
        xml_config = wash_url_argument(xml_config, 'str')
        action = wash_url_argument(action, 'str')
    except InvenioWebJournalNoJournalOnServerError as e:
        # Ok, no journal. Let the admin add one...
        pass
    except InvenioWebJournalNoNameError as e:
        register_exception(req=req)
        return e.user_box()

    auth = acc_authorize_action(getUid(req), 'cfgwebjournal',
                                name="%s" % journal_name,
                                with_editor_rights='yes')
    if auth[0] == 0:
        return page(title=page_title,
                    body=wjn.perform_request_configure(journal_name=journal_name,
                                                       ln=ln,
                                                       xml_config=xml_config,
                                                       action=action),
                    uid=uid,
                    language=ln,
                    req=req,
                    navtrail = navtrail_previous_links,
                    lastupdated=__lastupdated__)
    else:
        return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
예제 #11
0
def output_format_update_attributes(req, bfo, ln=CFG_SITE_LANG,
                                    name = "", description="",
                                    code="", content_type="",
                                    names_trans=[], visibility="0"):
    """
    Update the name, description and code of given output format

    @param req: the request object
    @param ln: language
    @param description: the new description
    @param name: the new name
    @param code: the new short code (== new bfo) of the output format
    @param content_type: the new content_type of the output format
    @param bfo: the filename of the output format to update
    @param names_trans: the translations in the same order as the languages from get_languages()
    @param visibility: the visibility of the output format in the output formats list (public pages)
    @return: a web page (or redirection to a web page)
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:

        name = wash_url_argument(name, 'str')
        description = wash_url_argument(description, 'str')
        bfo = wash_url_argument(bfo, 'str')
        code = wash_url_argument(code, 'str')
        visibility = wash_url_argument(visibility, 'int')
        bfo = bibformatadminlib.update_output_format_attributes(bfo,
                                                                name,
                                                                description,
                                                                code,
                                                                content_type,
                                                                names_trans,
                                                                visibility)

        redirect_to_url(req, "output_format_show?ln=%(ln)s&bfo=%(bfo)s" % {'ln':ln,
                                                                           'bfo':bfo,
                                                                           'names_trans':names_trans})
    else:
        return page_not_authorized(req=req,
                                   text=auth_msg)
예제 #12
0
def hot(req, ln=CFG_SITE_LANG, comments=1, top=10, collection=""):
    """
    View most active comments/reviews
    @param req: request object to obtain user information
    @param ln: language
    @param comments: boolean enabled for comments, disabled for reviews
    @param top: number of results to be shown
    @param collection: filter results by collection
    """
    ln = wash_language(ln)
    collection = wash_url_argument(collection, 'str')
    _ = gettext_set_language(ln)
    navtrail_previous_links = getnavtrail()
    navtrail_previous_links += ' &gt; <a class="navtrail" href="%s/admin/webcomment/webcommentadmin.py/">' % CFG_SITE_URL
    navtrail_previous_links += _("WebComment Admin") + '</a>'

    user_info = collect_user_info(req)
    (auth_code, auth_msg) = acc_authorize_action(user_info, 'cfgwebcomment')
    if auth_code:
        return page_not_authorized(req=req,
                                   text=auth_msg,
                                   navtrail=navtrail_previous_links)
    return page(title=(comments == '0' and _("View most reviewed records")
                       or _("View most commented records")),
                body=perform_request_hot(req,
                                         ln=ln,
                                         comments=comments,
                                         top=top,
                                         collection=collection),
                uid=user_info['uid'],
                language=ln,
                navtrail=navtrail_previous_links,
                lastupdated=__lastupdated__,
                req=req)
예제 #13
0
def hot(req, ln=CFG_SITE_LANG, comments=1, top=10, collection=""):
    """
    View most active comments/reviews
    @param req: request object to obtain user information
    @param ln: language
    @param comments: boolean enabled for comments, disabled for reviews
    @param top: number of results to be shown
    @param collection: filter results by collection
    """
    ln = wash_language(ln)
    collection = wash_url_argument(collection, 'str')
    _ = gettext_set_language(ln)
    navtrail_previous_links = getnavtrail()
    navtrail_previous_links += ' &gt; <a class="navtrail" href="%s/admin/webcomment/webcommentadmin.py/">' % CFG_SITE_URL
    navtrail_previous_links += _("WebComment Admin") + '</a>'

    user_info = collect_user_info(req)
    (auth_code, auth_msg) = acc_authorize_action(user_info, 'cfgwebcomment')
    if auth_code:
        return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
    return page(title=(comments=='0' and _("View most reviewed records") or
                           _("View most commented records")),
                    body=perform_request_hot(req, ln=ln, comments=comments, top=top, collection=collection),
                    uid=user_info['uid'],
                    language=ln,
                    navtrail = navtrail_previous_links,
                    lastupdated=__lastupdated__,
                    req=req)
예제 #14
0
def format_element_show_dependencies(req, bfe, ln=CFG_SITE_LANG):
    """
    Shows format element dependencies

    @param req: the request object
    @param req: the request object
    @param bfe: the name of the bfe to show
    @param ln: language
    @return: a web page
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = bibformatadminlib.getnavtrail(''' &gt; <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/format_elements_doc?ln=%s">%s</a>''' % (CFG_SITE_SECURE_URL, ln , _("Format Elements Documentation")))
    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        bfe = wash_url_argument(bfe, 'str')
        return page(title=_("Format Element %(x_name)s Dependencies", x_name=bfe),
                body=bibformatadminlib.perform_request_format_element_show_dependencies(bfe=bfe, ln=ln),
                uid=uid,
                language=ln,
                navtrail = navtrail_previous_links,
                lastupdated=__lastupdated__,
                req=req)
    else:
        return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
예제 #15
0
def output_formats_manage(req, ln=CFG_SITE_LANG, sortby="code"):
    """
    Main page for output formats management. Check for authentication and print output formats list.

    @param req: the request object
    @param ln: language
    @param sortby: the sorting crieteria (can be 'code' or 'name')
    @return: a web page
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = bibformatadminlib.getnavtrail()

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        sortby = wash_url_argument(sortby, 'str')
        return page(title=_("Manage Output Formats"),
                body=bibformatadminlib.perform_request_output_formats_management(ln=ln, sortby=sortby),
                uid=uid,
                language=ln,
                navtrail = navtrail_previous_links,
                lastupdated=__lastupdated__,
                req=req)
    else:
        return page_not_authorized(req=req,
                                   text=auth_msg,
                                   navtrail=navtrail_previous_links)
예제 #16
0
def format_templates_manage(req, ln=CFG_SITE_LANG, checking='0'):
    """
    Main page for formats templates management. Check for authentication and print formats list.

    @param req: the request object
    @param ln: language
    @param checking: if 0, basic checking. Else perform extensive checking (time-consuming)
    @return: a web page
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = bibformatadminlib.getnavtrail()

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        checking_level = wash_url_argument(checking, 'int')
        return page(title=_("Manage Format Templates"),
                body=bibformatadminlib.perform_request_format_templates_management(ln=ln, checking=checking_level),
                uid=uid,
                language=ln,
                navtrail = navtrail_previous_links,
                lastupdated=__lastupdated__,
                req=req)
    else:
        return page_not_authorized(req=req,
                                   text=auth_msg,
                                   navtrail=navtrail_previous_links)
예제 #17
0
def format_template_show_dependencies(req, bft, ln=CFG_SITE_LANG):
    """
    Show the dependencies (on elements) of the given format.

    @param req: the request object
    @param ln: language
    @param bft: the filename of the template to show
    @return: a web page
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = bibformatadminlib.getnavtrail(''' &gt; <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/format_templates_manage?ln=%s">%s</a>''' % (CFG_SITE_SECURE_URL, ln, _("Manage Format Templates")))

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        format_template = wash_url_argument(bft, 'str')
        format_name = bibformat_engine.get_format_template_attrs(bft)['name']

        return page(title=_("Format Template %(x_name)s Dependencies", x_name=format_name),
                    body=bibformatadminlib.perform_request_format_template_show_dependencies(bft, ln=ln),
                    uid=uid,
                    language=ln,
                    navtrail = navtrail_previous_links,
                    lastupdated=__lastupdated__,
                    req=req)

    else:
        return page_not_authorized(req=req, text=auth_msg)
예제 #18
0
def getnavtrail(previous = '', ln=CFG_SITE_LANG):
    """Get the navtrail"""
    previous = wash_url_argument(previous, 'str')
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail = """<a class="navtrail" href="%s/help/admin">%s</a> """ % (CFG_SITE_URL, _("Admin Area"))
    navtrail = navtrail + previous
    return navtrail
예제 #19
0
파일: adminlib.py 프로젝트: SCOAP3/invenio
def perform_request_undel_single_com(ln=CFG_SITE_LANG, id=id):
    """
    Mark comment referenced by id as active
    """
    ln = wash_language(ln)
    id = wash_url_argument(id, 'int')

    return query_undel_single_comment(id)
예제 #20
0
def perform_request_undel_single_com(ln=CFG_SITE_LANG, id=id):
    """
    Mark comment referenced by id as active
    """
    ln = wash_language(ln)
    id = wash_url_argument(id, 'int')

    return query_undel_single_comment(id)
예제 #21
0
def del_com(req, ln=CFG_SITE_LANG, action="delete", **hidden):
    """
    private function
    Delete a comment
    @param req: request object to obtain user information
    @param ln: language
    @param **hidden: ids of comments to delete sent as individual variables comidX=on, where X is id
    """
    ln = wash_language(ln)
    action = wash_url_argument(action, 'str')
    _ = gettext_set_language(ln)
    navtrail_previous_links = getnavtrail()
    navtrail_previous_links += ' &gt; <a class="navtrail" href="%s/admin/webcomment/webcommentadmin.py/">' % CFG_SITE_URL
    navtrail_previous_links += _("WebComment Admin") + '</a>'

    try:
        uid = getUid(req)
    except Error:
        return page(title=_("Internal Error"),
                    body=create_error_box(req, verbose=0, ln=ln),
                    description="%s - Internal Error" % CFG_SITE_NAME,
                    keywords="%s, Internal Error" % CFG_SITE_NAME,
                    language=ln,
                    req=req)

    (auth_code, auth_msg) = check_user(req, 'cfgwebcomment')
    if (auth_code != 'false'):
        comIDs = []
        args = hidden.keys()
        for var in args:
            try:
                comIDs.append(int(var.split('comid')[1]))
            except:
                pass
        if action == 'delete':
            body = perform_request_del_com(ln=ln, comIDs=comIDs)
            title = _("Delete comments")
        elif action == 'unreport':
            body = suppress_abuse_report(ln=ln, comIDs=comIDs)
            title = _("Suppress abuse reports")
        elif action == 'undelete':
            body = perform_request_undel_com(ln=ln, comIDs=comIDs)
            title = _("Undelete comments")
        else:
            redirect_to_url(
                req,
                CFG_SITE_SECURE_URL + '/admin/webcomment/webcommentadmin.py')
        return page(title=title,
                    body=body,
                    uid=uid,
                    language=ln,
                    navtrail=navtrail_previous_links,
                    lastupdated=__lastupdated__,
                    req=req)
    else:
        return page_not_authorized(req=req,
                                   text=auth_msg,
                                   navtrail=navtrail_previous_links)
예제 #22
0
def index(req, ln=CFG_SITE_LANG, action='', bsrID='', sm_name='', sm_def_type='', sm_def_value='', sm_washer='', sm_locale=''):
    """
    Display the initial(main) page
    """
    navtrail_previous_links = bsc.getnavtrail()

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    auth = bsc.check_user(req,'cfgbibsort')
    if not auth[0]:
        action = wash_url_argument(action, 'str')
        bsrID = wash_url_argument(bsrID, 'int')
        sm_name = wash_url_argument(sm_name, 'str')
        sm_def_type = wash_url_argument(sm_def_type, 'str')
        sm_def_value = wash_url_argument(sm_def_value, 'str')
        sm_washer = wash_url_argument(sm_washer, 'str')
        sm_locale = wash_url_argument(sm_locale, 'str')
        return page(title="BibSort Admin Interface",
                body=bsc.perform_index(ln, action, bsrID, sm_name, sm_def_type, sm_def_value, sm_washer, sm_locale),
                uid=uid,
                language=ln,
                navtrail = navtrail_previous_links,
                lastupdated=__lastupdated__,
                req=req)
    else:
        return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
예제 #23
0
파일: admin.py 프로젝트: Theer108/invenio
def kb_show(req, kb, sortby="to", ln=CFG_SITE_LANG, startat=0, search=""):
    """
    Shows the content of the given knowledge base id. Check for authentication and kb existence.
    Before displaying the content of the knowledge base, check if a form was submitted asking for
    adding, editing or removing a value.

    @param ln language
    @param kb the kb id to show
    @param sortby the sorting criteria ('from' or 'to')
    @param startat the number from which start showing mapping rules in kb
    @param search search for this string in the kb
    """

    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = """
         &gt; <a class="navtrail"
         href="%s/kb?ln=%s">%s</a>""" % (
        CFG_SITE_SECURE_URL,
        ln,
        _("Manage Knowledge Bases"),
    )

    try:
        uid = getUid(req)
    except:
        return error_page("Error", req)

    (auth_code, auth_msg) = check_user(req, "cfgbibknowledge")
    if not auth_code:
        kb_id = wash_url_argument(kb, "int")
        kb_name = bibknowledge.get_kb_name(kb_id)

        if kb_name is None:
            return page(
                title=_("Unknown Knowledge Base"),
                body="",
                language=ln,
                navtrail=navtrail_previous_links,
                errors=[("ERR_KB_ID_UNKNOWN", kb)],
                lastupdated=__lastupdated__,
                req=req,
            )
        return page(
            title=_("Knowledge Base %(x_name)s", x_name=kb_name),
            body=bibknowledgeadminlib.perform_request_knowledge_base_show(
                ln=ln, kb_id=kb_id, sortby=sortby, startat=startat, search_term=search
            ),
            uid=uid,
            language=ln,
            navtrail=navtrail_previous_links,
            lastupdated=__lastupdated__,
            req=req,
        )
    else:
        return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
예제 #24
0
def perform_request_unreport_single_com(ln=CFG_SITE_LANG, id=""):
    """
    private function
    Unreport a single comment
    @param ln: language
    @param id: comment id to be deleted
    """
    ln = wash_language(ln)
    id = wash_url_argument(id, 'int')
    return query_suppress_abuse_report(id)
예제 #25
0
def perform_request_del_single_com_auth(ln=CFG_SITE_LANG, id=id):
    """
    private function
    Delete a single comment requested by the author
    @param ln: language
    @param id: comment id to be deleted
    """
    ln = wash_language(ln)
    id = wash_url_argument(id, 'int')
    return query_delete_comment_auth(id)
예제 #26
0
파일: adminlib.py 프로젝트: SCOAP3/invenio
def perform_request_unreport_single_com(ln=CFG_SITE_LANG, id=""):
    """
    private function
    Unreport a single comment
    @param ln: language
    @param id: comment id to be deleted
    """
    ln = wash_language(ln)
    id = wash_url_argument(id, 'int')
    return query_suppress_abuse_report(id)
예제 #27
0
파일: adminlib.py 프로젝트: SCOAP3/invenio
def perform_request_del_single_com_auth(ln=CFG_SITE_LANG, id=id):
    """
    private function
    Delete a single comment requested by the author
    @param ln: language
    @param id: comment id to be deleted
    """
    ln = wash_language(ln)
    id = wash_url_argument(id, 'int')
    return query_delete_comment_auth(id)
예제 #28
0
파일: admin.py 프로젝트: chokribr/invenio-1
def kb_show(req, kb, sortby="to", ln=CFG_SITE_LANG, startat=0, search=""):
    """
    Shows the content of the given knowledge base id. Check for authentication and kb existence.
    Before displaying the content of the knowledge base, check if a form was submitted asking for
    adding, editing or removing a value.

    @param ln language
    @param kb the kb id to show
    @param sortby the sorting criteria ('from' or 'to')
    @param startat the number from which start showing mapping rules in kb
    @param search search for this string in the kb
    """

    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = '''
         &gt; <a class="navtrail"
         href="%s/kb?ln=%s">%s</a>''' % (CFG_SITE_SECURE_URL, ln,
                                         _("Manage Knowledge Bases"))

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibknowledge')
    if not auth_code:
        kb_id = wash_url_argument(kb, 'int')
        kb_name = bibknowledge.get_kb_name(kb_id)

        if kb_name is None:
            return page(title=_("Unknown Knowledge Base"),
                        body="",
                        language=ln,
                        navtrail=navtrail_previous_links,
                        errors=[("ERR_KB_ID_UNKNOWN", kb)],
                        lastupdated=__lastupdated__,
                        req=req)
        return page(
            title=_("Knowledge Base %(x_name)s", x_name=kb_name),
            body=bibknowledgeadminlib.perform_request_knowledge_base_show(
                ln=ln,
                kb_id=kb_id,
                sortby=sortby,
                startat=startat,
                search_term=search),
            uid=uid,
            language=ln,
            navtrail=navtrail_previous_links,
            lastupdated=__lastupdated__,
            req=req)
    else:
        return page_not_authorized(req=req,
                                   text=auth_msg,
                                   navtrail=navtrail_previous_links)
예제 #29
0
def del_com(req, ln=CFG_SITE_LANG, action="delete", **hidden):
    """
    private function
    Delete a comment
    @param req: request object to obtain user information
    @param ln: language
    @param **hidden: ids of comments to delete sent as individual variables comidX=on, where X is id
    """
    ln = wash_language(ln)
    action = wash_url_argument(action, 'str')
    _ = gettext_set_language(ln)
    navtrail_previous_links = getnavtrail()
    navtrail_previous_links += ' &gt; <a class="navtrail" href="%s/admin/webcomment/webcommentadmin.py/">' % CFG_SITE_URL
    navtrail_previous_links += _("WebComment Admin") + '</a>'

    try:
        uid = getUid(req)
    except Error:
        return page(title=_("Internal Error"),
                    body = create_error_box(req, verbose=0, ln=ln),
                    description="%s - Internal Error" % CFG_SITE_NAME,
                    keywords="%s, Internal Error" % CFG_SITE_NAME,
                    language=ln,
                    req=req)

    (auth_code, auth_msg) = check_user(req,'cfgwebcomment')
    if (auth_code != 'false'):
        comIDs = []
        args = hidden.keys()
        for var in args:
            try:
                comIDs.append(int(var.split('comid')[1]))
            except:
                pass
        if action == 'delete':
            body = perform_request_del_com(ln=ln, comIDs=comIDs)
            title = _("Delete comments")
        elif action == 'unreport':
            body = suppress_abuse_report(ln=ln, comIDs=comIDs)
            title = _("Suppress abuse reports")
        elif action == 'undelete':
            body = perform_request_undel_com(ln=ln, comIDs=comIDs)
            title = _("Undelete comments")
        else:
            redirect_to_url(req, CFG_SITE_SECURE_URL + '/admin/webcomment/webcommentadmin.py')
        return page(title=title,
                    body=body,
                    uid=uid,
                    language=ln,
                    navtrail = navtrail_previous_links,
                    lastupdated=__lastupdated__,
                    req=req)
    else:
        return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
예제 #30
0
def format_template_delete(req, bft, ln=CFG_SITE_LANG, chosen_option=""):
    """
    Delete a format template

    @param req: the request object
    @param bft: the filename of the template to delete
    @param ln: language
    @param chosen_option: empty string when user has not yet confirm. Else "Delete" to confirm
    @return: a web page (or redirection to a web page)
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = bibformatadminlib.getnavtrail('''
    &gt; <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/format_templates_manage?ln=%s">%s</a> &gt; %s''' % (CFG_SITE_SECURE_URL, ln ,_("Manage Format Templates"),_("Delete Format Template")))

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        #Ask confirmation to user if not already done
        chosen_option = wash_url_argument(chosen_option, 'str')
        if chosen_option == "":
            format_template = wash_url_argument(bft, 'str')
            format_name = bibformat_engine.get_format_template_attrs(bft)['name']
            return dialog_box(req=req,
                              ln=ln,
                              title="Delete %s" % format_name,
                              message="Are you sure you want to delete" \
                              "format template <i>%s</i>?" % format_name,
                              navtrail=navtrail_previous_links,
                              options=[_("Cancel"), _("Delete")])

        elif chosen_option==_("Delete"):
            bibformatadminlib.delete_format_template(bft)

        redirect_to_url(req, "format_templates_manage?ln=%(ln)s" % {'ln':ln})
    else:
        return page_not_authorized(req=req, text=auth_msg)
예제 #31
0
파일: admin.py 프로젝트: Theer108/invenio
def kb_show_dependencies(req, kb, ln=CFG_SITE_LANG, sortby="to"):
    """
    Shows the dependencies of a given kb

    @param kb the kb id to show
    @param ln language
    @param sortby the sorting criteria ('from' or 'to')
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = """ &gt; <a class="navtrail" href="%s/kb?ln=%s">%s</a>""" % (
        CFG_SITE_SECURE_URL,
        ln,
        _("Manage Knowledge Bases"),
    )

    try:
        uid = getUid(req)
    except:
        return error_page("Error", req)

    (auth_code, auth_msg) = check_user(req, "cfgbibknowledge")
    if not auth_code:
        kb_id = wash_url_argument(kb, "int")
        kb_name = bibknowledge.get_kb_name(kb_id)

        if kb_name is None:
            return page(
                title=_("Unknown Knowledge Base"),
                body="",
                language=ln,
                navtrail=navtrail_previous_links,
                errors=[("ERR_KB_ID_UNKNOWN", kb)],
                lastupdated=__lastupdated__,
                req=req,
            )

        return page(
            title=_("Knowledge Base %(x_name)s Dependencies", x_name=kb_name),
            body=bibknowledgeadminlib.perform_request_knowledge_base_show_dependencies(
                ln=ln, kb_id=kb_id, sortby=sortby
            ),
            uid=uid,
            language=ln,
            navtrail=navtrail_previous_links,
            lastupdated=__lastupdated__,
            req=req,
        )
    else:
        return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
예제 #32
0
def loan_on_desk_step4(req, list_of_books=None, user_info=None, due_date=None,
                       note=None, ln=CFG_SITE_LANG):
    """
    http://cds.cern.ch/admin/bibcirculation/bibcirculationadmin.py/loan_on_desk_step5
    """

    user_info = eval(user_info)

    list_of_books = eval(list_of_books)
    due_date = wash_url_argument(due_date, 'list')


    return bal.loan_on_desk_step4(req, list_of_books, user_info,
                                  due_date, note, ln)
예제 #33
0
def format_template_update_attributes(req, bft, ln=CFG_SITE_LANG,
                                      name = "", description="",
                                      duplicate=None):
    """
    Update the name and description of given format template

    @param req: the request object
    @param ln: language
    @param description: the new description
    @param name: the new name
    @param bft: the filename of the template to update
    @param duplicate: the filename of template that we want to copy (the code)
    @return: a web page (or redirection to a web page)
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:

        if duplicate is not None:
            duplicate = wash_url_argument(duplicate, 'str')
        name = wash_url_argument(name, 'str')
        description = wash_url_argument(description, 'str')
        bft = bibformatadminlib.update_format_template_attributes(bft,
                                                                  name,
                                                                  description,
                                                                  duplicate)

        redirect_to_url(req, "format_template_show?ln=%(ln)s&bft=%(bft)s" % {'ln':ln, 'bft':bft})
    else:
        return page_not_authorized(req=req, text=auth_msg)
예제 #34
0
def index(req, ln=CFG_SITE_LANG, journal_name=None, action=""):
    """
    Main administration page.

    Lists the journals, and offers options to edit them, delete them
    or add new journals
    """
    navtrail_previous_links = wjn.getnavtrail()

    ln = wash_language(ln)
    _ = gettext_set_language(ln)

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    try:
        journal_name = wash_journal_name(ln, journal_name)
        action = wash_url_argument(action, 'str')
    except InvenioWebJournalNoJournalOnServerError as e:
        # Ok, no journal. Let the admin add one...
        pass
    except InvenioWebJournalNoNameError as e:
        register_exception(req=req)
        return e.user_box()
    if action in ['delete', 'askDelete']:
        # To perform these, one must be authorized
        auth = acc_authorize_action(getUid(req),
                                    'cfgwebjournal',
                                    name=journal_name,
                                    with_editor_rights='yes')
    else:
        auth = acc_authorize_action(getUid(req), 'cfgwebjournal')
    if auth[0] == 0:
        return page(title=_('WebJournal Admin'),
                    body=wjn.perform_index(ln=ln,
                                           journal_name=journal_name,
                                           action=action,
                                           uid=getUid(req)),
                    uid=uid,
                    language=ln,
                    req=req,
                    navtrail=navtrail_previous_links,
                    lastupdated=__lastupdated__)
    else:
        return page_not_authorized(req=req,
                                   text=auth[1],
                                   navtrail=navtrail_previous_links)
예제 #35
0
def output_format_show_attributes(req, bfo, ln=CFG_SITE_LANG):
    """
    Page for output format names and descrition attributes edition.

    @param req: the request object
    @param ln: language
    @param bfo: the filename of the template to show
    @return: a web page
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = bibformatadminlib.getnavtrail(''' &gt; <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/output_formats_manage?ln=%s">%s</a>''' % (CFG_SITE_SECURE_URL, ln , _("Manage Output Formats")))

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        bfo = wash_url_argument(bfo, 'str')

        if not bibformatadminlib.can_read_output_format(bfo): #No read permission
            try:
                raise InvenioBibFormatError(_('Output format %(x_name)s cannot not be read. %(x_text)s', x_name=bfo, x_text=""))
            except InvenioBibFormatError as exc:
                register_exception(req=req)
                return page(title=_("Restricted Output Format"),
                            body = """You don't have permission to
                            view this output format.""",
                            language=ln,
                            navtrail = navtrail_previous_links,
                            lastupdated=__lastupdated__,
                            req=req)

        output_format = bibformat_engine.get_output_format(code=bfo,
                                                           with_attributes=True)
        name = output_format['attrs']['names']['generic']

        return page(title=_("Output Format %(x_name)s Attributes", x_name=name),
                    body=bibformatadminlib.perform_request_output_format_show_attributes(bfo, ln=ln),
                    uid=uid,
                    language=ln,
                    navtrail = navtrail_previous_links ,
                    lastupdated=__lastupdated__,
                    req=req)

    else:
        return page_not_authorized(req=req, text=auth_msg)
예제 #36
0
파일: adminlib.py 프로젝트: SCOAP3/invenio
def perform_request_latest(req=None, ln=CFG_SITE_LANG, comments=1, top=10, collection=""):
    """
    Display the list of latest comments/reviews along with information about the comment.

    @param req: request object for obtaining user information
    @param ln: language
    @param comments: boolean activated if using comments, deactivated for reviews
    @param top: Specify number of results to be shown
    @param collection: filter by collection
    """
    ln = wash_language(ln)
    comments = wash_url_argument(comments, 'int')
    top = wash_url_argument(top, 'int')
    collection = wash_url_argument(collection, 'str')

    user_info = collect_user_info(req)
    user_collections = ['Show all']
    user_collections.extend(get_user_collections(req))
    if collection and collection != 'Show all':
        (auth_code, auth_msg) = acc_authorize_action(req, 'moderatecomments', collection=collection)
        if auth_code:
            return webcomment_templates.tmpl_admin_latest(ln=ln,
                                                          comment_data=None,
                                                          comments=comments, error=1, user_collections=user_collections, collection=collection)
    if collection:
        comments_retrieved = query_get_latest(comments, ln, top, user_collections, collection)
    else:
        comments_retrieved = query_get_latest(comments, ln, top, user_collections, user_collections[0])
    if comments_retrieved:
        return webcomment_templates.tmpl_admin_latest(ln=ln,
                                                      comment_data=comments_retrieved,
                                                      comments=comments, error=0, user_collections=user_collections, collection=collection)
    else:
        return webcomment_templates.tmpl_admin_latest(ln=ln,
                                                      comment_data=comments_retrieved,
                                                      comments=comments, error=2, user_collections=user_collections, collection=collection)
예제 #37
0
def modifytranslations(req, ln=CFG_SITE_LANG, bsrID='', trans=None, confirm=0):
    """
    Display the modify translations page
    """
    navtrail_previous_links = bsc.getnavtrail()+ """&gt; <a class="navtrail" href="%s/admin/bibsort/bibsortadmin.py/">BibSort Admin Interface</a> """ % (CFG_SITE_URL)

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    auth = bsc.check_user(req,'cfgbibsort')
    if not auth[0]:
        bsrID = wash_url_argument(bsrID, 'int')
        confirm = wash_url_argument(confirm, 'int')
        return page(title="Modify translations",
                    body=bsc.perform_modifytranslations(ln, bsrID, trans, confirm),
                    uid=uid,
                    language=ln,
                    navtrail = navtrail_previous_links,
                    lastupdated=__lastupdated__,
                    req=req)
    else:
        return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
예제 #38
0
파일: admin.py 프로젝트: chokribr/invenio-1
def kb_show_attributes(req, kb, ln=CFG_SITE_LANG, sortby="to"):
    """
    Shows the attributes (name, description) of a given kb

    @param ln language
    @param kb the kb id to show
    @param sortby the sorting criteria ('from' or 'to')
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = ''' &gt; <a class="navtrail" href="%s/kb?ln=%s">%s</a>''' % (
        CFG_SITE_SECURE_URL, ln, _("Manage Knowledge Bases"))

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibknowledge')
    if not auth_code:

        kb_id = wash_url_argument(kb, 'int')
        kb_name = bibknowledge.get_kb_name(kb_id)

        if kb_name is None:
            return page(title=_("Unknown Knowledge Base"),
                        body="",
                        language=ln,
                        navtrail=navtrail_previous_links,
                        errors=[("ERR_KB_ID_UNKNOWN", kb)],
                        lastupdated=__lastupdated__,
                        req=req)

        return page(title=_("Knowledge Base %(x_name)s Attributes",
                            x_name=kb_name),
                    body=bibknowledgeadminlib.
                    perform_request_knowledge_base_show_attributes(
                        ln=ln, kb_id=kb_id, sortby=sortby),
                    uid=uid,
                    language=ln,
                    navtrail=navtrail_previous_links,
                    lastupdated=__lastupdated__,
                    req=req)
    else:
        return page_not_authorized(req=req,
                                   text=auth_msg,
                                   navtrail=navtrail_previous_links)
예제 #39
0
def loan_on_desk_step4(req,
                       list_of_books=None,
                       user_info=None,
                       due_date=None,
                       note=None,
                       ln=CFG_SITE_LANG):
    """
    http://cds.cern.ch/admin/bibcirculation/bibcirculationadmin.py/loan_on_desk_step5
    """

    user_info = eval(user_info)

    list_of_books = eval(list_of_books)
    due_date = wash_url_argument(due_date, 'list')

    return bal.loan_on_desk_step4(req, list_of_books, user_info, due_date,
                                  note, ln)
예제 #40
0
def index(req, ln=CFG_SITE_LANG, journal_name=None, action=""):
    """
    Main administration page.

    Lists the journals, and offers options to edit them, delete them
    or add new journals
    """
    navtrail_previous_links = wjn.getnavtrail()

    ln = wash_language(ln)
    _ = gettext_set_language(ln)

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    try:
        journal_name = wash_journal_name(ln, journal_name)
        action = wash_url_argument(action, 'str')
    except InvenioWebJournalNoJournalOnServerError as e:
        # Ok, no journal. Let the admin add one...
        pass
    except InvenioWebJournalNoNameError as e:
        register_exception(req=req)
        return e.user_box()
    if action in ['delete', 'askDelete']:
        # To perform these, one must be authorized
        auth = acc_authorize_action(getUid(req), 'cfgwebjournal',
                                    name=journal_name, with_editor_rights='yes')
    else:
        auth = acc_authorize_action(getUid(req), 'cfgwebjournal')
    if auth[0] == 0:
        return page(title=_('WebJournal Admin'),
                    body=wjn.perform_index(ln=ln,
                                           journal_name=journal_name,
                                           action=action,
                                           uid=getUid(req)),
                    uid=uid,
                    language=ln,
                    req=req,
                    navtrail = navtrail_previous_links,
                    lastupdated=__lastupdated__)
    else:
        return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
예제 #41
0
def perform_request_undel_com(ln=CFG_SITE_LANG, comIDs=[]):
    """
    private function
    Undelete the comments and say whether successful or not
    @param ln: language
    @param comIDs: list of comment ids
    """
    ln = wash_language(ln)
    comIDs = wash_url_argument(comIDs, 'list')
    # map ( fct, list, arguments of function)
    comIDs = map(wash_url_argument, comIDs, ('int '*len(comIDs)).split(' ')[:-1])

    if not comIDs:
        comIDs = map(coerce, comIDs, ('0 '*len(comIDs)).split(' ')[:-1])
        return webcomment_templates.tmpl_admin_undel_com(del_res=comIDs, ln=ln)

    del_res = []
    for comID in comIDs:
        del_res.append((comID, query_undel_single_comment(comID)))
    return webcomment_templates.tmpl_admin_undel_com(del_res=del_res, ln=ln)
예제 #42
0
def suppress_abuse_report(ln=CFG_SITE_LANG, comIDs=[]):
    """
    private function
    suppress the abuse reports for the given comIDs.
    @param ln: language
    @param comIDs: list of ids to suppress attached reports.
    """
    ln = wash_language(ln)
    comIDs = wash_url_argument(comIDs, 'list')
    # map ( fct, list, arguments of function)
    comIDs = map(wash_url_argument, comIDs, ('int '*len(comIDs)).split(' ')[:-1])

    if not comIDs:
        comIDs = map(coerce, comIDs, ('0 '*len(comIDs)).split(' ')[:-1])
        return webcomment_templates.tmpl_admin_del_com(del_res=comIDs, ln=ln)

    del_res = []
    for comID in comIDs:
        del_res.append((comID, query_suppress_abuse_report(comID)))
    return webcomment_templates.tmpl_admin_suppress_abuse_report(del_res=del_res, ln=ln)
예제 #43
0
def update_detailed_record_options(req, colID, ln=CFG_SITE_LANG, tabs=[], recurse=0):
    """Update the preferences for the tab to show/hide in the detailed record page. """

    _tabs = wash_url_argument(tabs, 'list')
    navtrail_previous_links = wsc.getnavtrail() + """&gt; <a class="navtrail" href="%s/admin/websearch/websearchadmin.py/">WebSearch Admin</a> """ % (CFG_SITE_URL)

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    auth = check_user(req,'cfgwebsearch')
    if not auth[0]:
        return page(title="Edit Collection",
                    body = wsc.perform_update_detailed_record_options(colID, ln, _tabs, recurse),
                    uid=uid,
                    language=ln,
                    req=req,
                    navtrail = navtrail_previous_links,
                    lastupdated=__lastupdated__)
    else:
        return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
예제 #44
0
def alert(req,
          journal_name="",
          ln=CFG_SITE_LANG,
          sent="False",
          plainText=u"",
          htmlMail="",
          recipients="",
          subject="",
          issue="",
          force="False"):
    """
    Sends an email alert, in HTML/PlainText or only PlainText to a mailing
    list to alert for new journal releases.
    """
    navtrail_previous_links = wjn.getnavtrail(
        ' &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py">WebJournal Admin</a> &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py/administrate?journal_name=%s">%s</a>'
        % (CFG_SITE_URL, CFG_SITE_URL, journal_name, journal_name))

    ln = wash_language(ln)
    _ = gettext_set_language(ln)

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    try:
        journal_name = wash_journal_name(ln, journal_name)
        issue = wash_issue_number(ln, journal_name, issue)
        plain_text = wash_url_argument(plainText, 'str')
        html_mail = wash_url_argument(htmlMail, 'str')
        recipients = wash_url_argument(recipients, 'str')
        subject = wash_url_argument(subject, 'str')
        sent = wash_url_argument(sent, 'str')
        force = wash_url_argument(force, 'str')
    except InvenioWebJournalNoJournalOnServerError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalNoNameError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalNoCurrentIssueError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalIssueNumberBadlyFormedError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalJournalIdNotFoundDBError as e:
        register_exception(req=req)
        return e.user_box()

    auth = acc_authorize_action(getUid(req),
                                'cfgwebjournal',
                                name="%s" % journal_name,
                                with_editor_rights='yes')
    if auth[0] == 0:
        return page(title=_("Email Alert System"),
                    body=wjn.perform_request_alert(journal_name=journal_name,
                                                   issue=issue,
                                                   ln=ln,
                                                   sent=sent,
                                                   plain_text=plain_text,
                                                   subject=subject,
                                                   recipients=recipients,
                                                   html_mail=html_mail,
                                                   force=force),
                    uid=uid,
                    language=ln,
                    req=req,
                    navtrail=navtrail_previous_links,
                    lastupdated=__lastupdated__)
    else:
        return page_not_authorized(req=req,
                                   text=auth[1],
                                   navtrail=navtrail_previous_links)
예제 #45
0
def regenerate(req,
               journal_name="",
               issue="",
               ln=CFG_SITE_LANG,
               confirmed_p="",
               publish_draft_articles_p=""):
    """
    Clears the cache for the given issue.
    """
    navtrail_previous_links = wjn.getnavtrail(
        ' &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py">WebJournal Admin</a> &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py/administrate?journal_name=%s">%s</a>'
        % (CFG_SITE_URL, CFG_SITE_URL, journal_name, journal_name))

    ln = wash_language(ln)
    _ = gettext_set_language(ln)

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    try:
        journal_name = wash_journal_name(ln, journal_name)
        issue_number = wash_issue_number(ln, journal_name, issue)
        confirmed_p = wash_url_argument(confirmed_p, 'str') == "confirmed"
        publish_draft_articles_p = wash_url_argument(publish_draft_articles_p,
                                                     'str') == "move"

    except InvenioWebJournalNoJournalOnServerError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalNoNameError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalNoCurrentIssueError as e:
        register_exception(req=req)
        return e.user_box()
    except InvenioWebJournalIssueNumberBadlyFormedError as e:
        register_exception(req=req)
        return e.user_box()

    auth = acc_authorize_action(getUid(req),
                                'cfgwebjournal',
                                name="%s" % journal_name)
    if auth[0] == 0:
        return page(title=confirmed_p and _("Issue regenerated")
                    or _("Regenerate Issue"),
                    body=wjn.perform_regenerate_issue(
                        ln=ln,
                        journal_name=journal_name,
                        issue=issue,
                        confirmed_p=confirmed_p,
                        publish_draft_articles_p=publish_draft_articles_p),
                    uid=uid,
                    language=ln,
                    req=req,
                    navtrail=navtrail_previous_links,
                    lastupdated=__lastupdated__)
    else:
        return page_not_authorized(req=req,
                                   text=auth[1],
                                   navtrail=navtrail_previous_links)
예제 #46
0
def configure(req,
              journal_name=None,
              ln=CFG_SITE_LANG,
              xml_config=u'',
              action='edit'):
    """
    Let admins configure the journal settings
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)

    if journal_name is None:
        navtrail_previous_links = wjn.getnavtrail(
            ' &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py">WebJournal Admin</a>'
            % CFG_SITE_URL)
    else:
        navtrail_previous_links = wjn.getnavtrail(
            ' &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py">WebJournal Admin</a> &gt; <a class="navtrail" href="%s/admin/webjournal/webjournaladmin.py/administrate?journal_name=%s">%s</a>'
            % (CFG_SITE_URL, CFG_SITE_URL, journal_name, journal_name))

    if action in ['add', 'addDone']:
        page_title = _('Add Journal')
    else:
        page_title = _("Edit Settings")

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    try:
        journal_name = wash_journal_name(ln, journal_name, guess=False)
        xml_config = wash_url_argument(xml_config, 'str')
        action = wash_url_argument(action, 'str')
    except InvenioWebJournalNoJournalOnServerError as e:
        # Ok, no journal. Let the admin add one...
        pass
    except InvenioWebJournalNoNameError as e:
        register_exception(req=req)
        return e.user_box()

    auth = acc_authorize_action(getUid(req),
                                'cfgwebjournal',
                                name="%s" % journal_name,
                                with_editor_rights='yes')
    if auth[0] == 0:
        return page(title=page_title,
                    body=wjn.perform_request_configure(
                        journal_name=journal_name,
                        ln=ln,
                        xml_config=xml_config,
                        action=action),
                    uid=uid,
                    language=ln,
                    req=req,
                    navtrail=navtrail_previous_links,
                    lastupdated=__lastupdated__)
    else:
        return page_not_authorized(req=req,
                                   text=auth[1],
                                   navtrail=navtrail_previous_links)
예제 #47
0
파일: admin.py 프로젝트: chokribr/invenio-1
def kb_add_mapping(req,
                   kb,
                   mapFrom,
                   mapTo,
                   sortby="to",
                   ln=CFG_SITE_LANG,
                   forcetype=None,
                   replacements=None,
                   kb_type=None):
    """
    Adds a new mapping to a kb.

    @param ln language
    @param kb the kb id to show
    @param sortby the sorting criteria ('from' or 'to')
    @param forcetype indicates if this function should ask about replacing left/right sides (None or 'no')
                     replace in current kb ('curr') or in all ('all')
    @param replacements an object containing kbname+++left+++right strings.
                     Can be a string or an array of strings
    @param kb_type None for normal from-to kb's, 't' for taxonomies
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)

    navtrail_previous_links = ''' &gt; <a class="navtrail" href="%s/kb?ln=%s">%s</a>''' % (
        CFG_SITE_SECURE_URL, ln, _("Manage Knowledge Bases"))

    try:
        dummy = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibknowledge')
    if not auth_code:

        kb_id = wash_url_argument(kb, 'int')
        kb_name = bibknowledge.get_kb_name(kb_id)

        if kb_name is None:
            return page(title=_("Unknown Knowledge Base"),
                        body="",
                        language=ln,
                        navtrail=navtrail_previous_links,
                        errors=[("ERR_KB_ID_UNKNOWN", kb)],
                        lastupdated=__lastupdated__,
                        req=req)

        key = wash_url_argument(mapFrom, 'str')
        value = wash_url_argument(mapTo, 'str')

        #check if key or value already exists in some KB
        left_sides_match = bibknowledge.get_kb_mappings("", key, "")
        #check that the match is exact
        left_sides = []
        for m in left_sides_match:
            if m['key'] == key:
                left_sides.append(m)

        right_sides_match = bibknowledge.get_kb_mappings("", "", value)
        right_sides = []
        for m in right_sides_match:
            if m['value'] == value:
                right_sides.append(m)

        if (len(right_sides) == 0) and (len(left_sides) == 0):
            #no problems, just add in current
            forcetype = "curr"

        #likewise, if this is a taxonomy, just pass on
        if kb_type == 't':
            forcetype = "curr"

        if forcetype and not forcetype == "no":
            pass
        else:
            if len(left_sides) > 0:
                return page(
                    title=_("Left side exists"),
                    body=bibknowledgeadminlib.perform_request_verify_rule(
                        ln, kb_id, key, value, "left", kb_name, left_sides),
                    language=ln,
                    navtrail=navtrail_previous_links,
                    lastupdated=__lastupdated__,
                    req=req)

            if len(right_sides) > 0:
                return page(
                    title=_("Right side exists"),
                    body=bibknowledgeadminlib.perform_request_verify_rule(
                        ln, kb_id, key, value, "right", kb_name, right_sides),
                    language=ln,
                    navtrail=navtrail_previous_links,
                    lastupdated=__lastupdated__,
                    req=req)

        if forcetype == "curr":
            bibknowledge.add_kb_mapping(kb_name, key, value)
        if forcetype == "all":
            #a bit tricky.. remove the rules given in param replacement and add the current
            #rule in the same kb's
            if replacements:
                #"replacements" can be either a string or an array. Let's make it always an array
                if type(replacements) == type("this is a string"):
                    mystr = replacements
                    replacements = []
                    replacements.append(mystr)
                for r in replacements:
                    if r.find("++++") > 0:
                        (rkbname, rleft, dummy) = r.split('++++')
                        bibknowledge.remove_kb_mapping(rkbname, rleft)
                        #add only if this is not yet there..
                        if not bibknowledge.kb_mapping_exists(rkbname, key):
                            bibknowledge.add_kb_mapping(rkbname, key, value)

        redirect_to_url(
            req,
            "kb?ln=%(ln)s&kb=%(kb)s&sortby=%(sortby)s&kb_type=%(kb_type)s" % {
                'ln': ln,
                'kb': kb_id,
                'sortby': sortby,
                'kb_type': kb_type
            })
    else:
        return page_not_authorized(req=req,
                                   text=auth_msg,
                                   navtrail=navtrail_previous_links)
예제 #48
0
파일: admin.py 프로젝트: chokribr/invenio-1
def kb_edit_mapping(req,
                    kb,
                    key,
                    mapFrom,
                    mapTo,
                    update="",
                    delete="",
                    sortby="to",
                    ln=CFG_SITE_LANG):
    """
    Edit a mapping to in kb. Edit can be "update old value" or "delete existing value"

    @param kb the knowledge base id to edit
    @param key the key of the mapping that will be modified
    @param mapFrom the new key of the mapping
    @param mapTo the new value of the mapping
    @param update contains a value if the mapping is to be updated
    @param delete contains a value if the mapping is to be deleted
    @param sortby the sorting criteria ('from' or 'to')
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = ''' &gt; <a class="navtrail" href="%s/kb?ln=%s">%s</a>''' % (
        CFG_SITE_SECURE_URL, ln, _("Manage Knowledge Bases"))

    try:
        dummy = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibknowledge')
    if not auth_code:
        kb_id = wash_url_argument(kb, 'int')
        kb_name = bibknowledge.get_kb_name(kb_id)

        if kb_name is None:
            return page(title=_("Unknown Knowledge Base"),
                        body="",
                        language=ln,
                        navtrail=navtrail_previous_links,
                        errors=[("ERR_KB_ID_UNKNOWN", kb)],
                        lastupdated=__lastupdated__,
                        req=req)

        key = wash_url_argument(key, 'str')
        if delete != "":
            #Delete
            bibknowledge.remove_kb_mapping(kb_name, key)
        if update != "":
            #Update
            new_key = wash_url_argument(mapFrom, 'str')
            new_value = wash_url_argument(mapTo, 'str')
            bibknowledge.update_kb_mapping(kb_name, key, new_key, new_value)

        redirect_to_url(
            req, "kb?ln=%(ln)s&kb=%(kb)s&sortby=%(sortby)s" % {
                'ln': ln,
                'kb': kb_id,
                'sortby': sortby
            })
    else:
        return page_not_authorized(req=req,
                                   text=auth_msg,
                                   navtrail=navtrail_previous_links)
예제 #49
0
파일: admin.py 프로젝트: chokribr/invenio-1
def kb_update_attributes(req,
                         kb="",
                         name="",
                         description="",
                         sortby="to",
                         ln=CFG_SITE_LANG,
                         chosen_option=None,
                         kb_type=None):
    """
    Update the attributes of the kb

    @param ln language
    @param kb the kb id to update
    @param sortby the sorting criteria ('from' or 'to')
    @param name the new name of the kn
    @param description the new description of the kb
    @param chosen_option set to dialog box value
    """

    ln = wash_language(ln)
    _ = gettext_set_language(ln)

    navtrail_previous_links = ''' &gt; <a class="navtrail" href="%s/kb?ln=%s">%s</a>''' % (
        CFG_SITE_SECURE_URL, ln, _("Manage Knowledge Bases"))

    try:
        dummy = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibknowledge')
    if not auth_code:
        kb_id = wash_url_argument(kb, 'int')
        if chosen_option is not None:
            # Update could not be performed.
            # Redirect to kb attributes page
            redirect_to_url(
                req,
                "kb?ln=%(ln)s&amp;action=attributes&amp;kb=%(kb)s&sortby=%(sortby)s&kb_type=%(kb_type)s"
                % {
                    'ln': ln,
                    'kb': kb_id,
                    'sortby': sortby,
                    'kb_type': kb_type
                })

        kb_name = bibknowledge.get_kb_name(kb_id)

        if kb_name is None:
            return page(title=_("Unknown Knowledge Base"),
                        body="",
                        language=ln,
                        navtrail=navtrail_previous_links,
                        errors=[("ERR_KB_ID_UNKNOWN", kb)],
                        lastupdated=__lastupdated__,
                        req=req)

        new_name = wash_url_argument(name, 'str')
        if kb_name != new_name and bibknowledge.kb_exists(new_name):
            #A knowledge base with that name already exist
            #Do not update
            return dialog_box(req=req,
                              ln=ln,
                              title="Name already in use",
                              message="""<i>%s</i> cannot be renamed to %s:
                                        Another knowledge base already has that name.
                                        <br/>Please choose another name.""" %
                              (kb_name, new_name),
                              navtrail=navtrail_previous_links,
                              options=[_("Ok")])

        new_desc = wash_url_argument(description, 'str')
        bibknowledge.update_kb_attributes(kb_name, new_name, new_desc)
        redirect_to_url(
            req, "kb?ln=%(ln)s&kb=%(kb)s&sortby=%(sortby)s" % {
                'ln': ln,
                'kb': kb_id,
                'sortby': sortby
            })
    else:
        return page_not_authorized(req=req,
                                   text=auth_msg,
                                   navtrail=navtrail_previous_links)
예제 #50
0
파일: admin.py 프로젝트: chokribr/invenio-1
def kb_upload(req, kb, ln=CFG_SITE_LANG):
    """
    Uploads file rdffile.
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail = '''<a class="navtrail" href="%s/kb?ln=%s">%s</a>''' % \
               (CFG_SITE_SECURE_URL, ln, _("Knowledge Bases"))

    try:
        dummy = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibknowledge')
    if not auth_code:
        kb_id = wash_url_argument(kb, 'int')
        #get the form
        form = req.form
        #get the contents from the form
        if 'file' not in form or not form['file'].filename:
            return page(title=_("Cannot upload file"),
                        body=_("You have not selected a file to upload"),
                        language=ln,
                        navtrail=navtrail,
                        lastupdated=__lastupdated__,
                        req=req)
        fileitem = form['file']
        uploaddir = CFG_WEBDIR + "/kbfiles"

        #create a upload directory unless already exists
        if os.path.isfile(uploaddir):
            return page(title=_("Cannot upload file"),
                        body = "Cannot create directory " + \
                                uploaddir+" since it already" + \
                                " exists and it is a file",
                        language=ln,
                        navtrail = navtrail,
                        lastupdated=__lastupdated__,
                        req=req)
        if not os.path.isdir(uploaddir):
            try:
                os.mkdir(uploaddir)
            except:
                return page(title=_("Cannot upload file"),
                        body = "Cannot create directory "+uploaddir+ \
                               " maybe no access rights",
                        language=ln,
                        navtrail = navtrail,
                        lastupdated=__lastupdated__,
                        req=req)

        #if we are here we can try to write
        #get the name and the file..
        fn = str(kb_id) + ".rdf"
        open(uploaddir + "/" + fn, 'w').write(fileitem.read())
        body = (_("File %(x_name)s uploaded.",
                  x_name=('kbfiles/' + cgi.escape(fn))))
        body += " <a href='" + CFG_SITE_SECURE_URL + "/kb'>%s</a>" % _("Back")
        return (page(title=_("File uploaded"),
                     body=body,
                     language=ln,
                     navtrail=navtrail,
                     lastupdated=__lastupdated__,
                     req=req))
    else:
        return (page_not_authorized(req=req, text=auth_msg, navtrail=navtrail))
예제 #51
0
def perform_request_delete(comID=-1,
                           recID=-1,
                           uid=-1,
                           reviews="",
                           ln=CFG_SITE_LANG):
    """
    """
    _ = gettext_set_language(ln)

    from invenio.legacy.search_engine import record_exists

    warnings = []

    ln = wash_language(ln)
    comID = wash_url_argument(comID, 'int')
    recID = wash_url_argument(recID, 'int')
    uid = wash_url_argument(uid, 'int')
    # parameter reviews is deduced from comID when needed

    if comID is not None and recID is not None and uid is not None:
        if comID <= 0 and recID <= 0 and uid <= 0:
            if comID != -1:
                try:
                    raise InvenioWebCommentWarning(_('Invalid comment ID.'))
                except InvenioWebCommentWarning as exc:
                    register_exception(stream='warning')
                    warnings.append((exc.message, ''))
                #warnings.append(("WRN_WEBCOMMENT_ADMIN_INVALID_COMID",))
            return webcomment_templates.tmpl_admin_delete_form(ln, warnings)

        if comID > 0 and not recID > 0:
            comment = query_get_comment(comID)

            if comment:
                # Figure out if this is a review or a comment
                c_star_score = 5
                if comment[c_star_score] > 0:
                    reviews = 1
                else:
                    reviews = 0
                return (perform_request_comments(ln=ln,
                                                 comID=comID,
                                                 recID=recID,
                                                 reviews=reviews), None,
                        warnings)
            else:
                try:
                    raise InvenioWebCommentWarning(
                        _('Comment ID %(x_name)s does not exist.',
                          x_name=comID))
                except InvenioWebCommentWarning as exc:
                    register_exception(stream='warning')
                    warnings.append((exc.message, ''))
                #warnings.append(('WRN_WEBCOMMENT_ADMIN_COMID_INEXISTANT', comID))
                return webcomment_templates.tmpl_admin_delete_form(
                    ln, warnings)

        elif recID > 0:
            if record_exists(recID):
                comID = ''
                reviews = wash_url_argument(reviews, 'int')
                return (perform_request_comments(ln=ln,
                                                 comID=comID,
                                                 recID=recID,
                                                 reviews=reviews), None,
                        warnings)
            else:
                try:
                    raise InvenioWebCommentWarning(
                        _('Record ID %(x_rec)s does not exist.', x_rec=comID))
                except InvenioWebCommentWarning as exc:
                    register_exception(stream='warning')
                    warnings.append((exc.message, ''))
                #warnings.append(('WRN_WEBCOMMENT_ADMIN_RECID_INEXISTANT', comID))
                return webcomment_templates.tmpl_admin_delete_form(
                    ln, warnings)
        else:
            return webcomment_templates.tmpl_admin_delete_form(ln, warnings)

    else:
        return webcomment_templates.tmpl_admin_delete_form(ln, warnings)