コード例 #1
0
ファイル: webjournaladmin.py プロジェクト: chokribr/invenio-1
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)
コード例 #2
0
ファイル: webinterface.py プロジェクト: chokribr/invenio-1
    def article(self, req, form):
        """
        Article page.
        Washes all the parameters and stores them in journal_defaults dict
        for subsequent format_elements.
        Passes on to logic function and eventually returns HTML.
        """
        argd = wash_urlargd(form, {'name': (str, ""),
                                    'issue': (str, ""),
                                    'category': (str, ""),
                                    'number': (str, ""),
                                    'ln': (str, ""),
                                   }
                            )
        try:
            ln = wash_journal_language(argd['ln'])
            journal_name = wash_journal_name(ln, argd['name'])
            issue = wash_issue_number(ln, journal_name,
                                      argd['issue'])
            issue_year = issue.split('/')[1]
            issue_number = issue.split('/')[0]
            category = wash_category(ln, argd['category'], journal_name, issue_number)
            number = wash_article_number(ln, argd['number'], journal_name)
            recid = get_recid_from_legacy_number(issue, category, int(number))
        except InvenioWebJournalNoJournalOnServerError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoNameError as e:
            return e.user_box(req)
        except InvenioWebJournalNoCurrentIssueError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalIssueNumberBadlyFormedError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoArticleNumberError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoCategoryError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalJournalIdNotFoundDBError as e:
            register_exception(req=req)
            return e.user_box(req)

        if recid != -1:
            # Found a corresponding record
            redirect_to_url(req, CFG_SITE_URL + \
                            '/journal/' + journal_name + '/' + issue_year + \
                            '/' + issue_number + '/' + category + \
                            '/' + str(recid) + '?ln=' + ln)
        else:
            # Corresponding record not found. Display index
            redirect_to_url(req, CFG_SITE_URL + \
                            '/journal/' + journal_name + '/' + issue_year + \
                            '/' + issue_number + '/' + category + \
                            '?ln=' + ln)
コード例 #3
0
ファイル: webinterface.py プロジェクト: mhellmic/b2share
    def article(self, req, form):
        """
        Article page.
        Washes all the parameters and stores them in journal_defaults dict
        for subsequent format_elements.
        Passes on to logic function and eventually returns HTML.
        """
        argd = wash_urlargd(form, {'name': (str, ""),
                                    'issue': (str, ""),
                                    'category': (str, ""),
                                    'number': (str, ""),
                                    'ln': (str, ""),
                                   }
                            )
        try:
            ln = wash_journal_language(argd['ln'])
            journal_name = wash_journal_name(ln, argd['name'])
            issue = wash_issue_number(ln, journal_name,
                                      argd['issue'])
            issue_year = issue.split('/')[1]
            issue_number = issue.split('/')[0]
            category = wash_category(ln, argd['category'], journal_name, issue_number)
            number = wash_article_number(ln, argd['number'], journal_name)
            recid = get_recid_from_legacy_number(issue, category, int(number))
        except InvenioWebJournalNoJournalOnServerError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoNameError as e:
            return e.user_box(req)
        except InvenioWebJournalNoCurrentIssueError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalIssueNumberBadlyFormedError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoArticleNumberError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoCategoryError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalJournalIdNotFoundDBError as e:
            register_exception(req=req)
            return e.user_box(req)

        if recid != -1:
            # Found a corresponding record
            redirect_to_url(req, CFG_SITE_URL + \
                            '/journal/' + journal_name + '/' + issue_year + \
                            '/' + issue_number + '/' + category + \
                            '/' + str(recid) + '?ln=' + ln)
        else:
            # Corresponding record not found. Display index
            redirect_to_url(req, CFG_SITE_URL + \
                            '/journal/' + journal_name + '/' + issue_year + \
                            '/' + issue_number + '/' + category + \
                            '?ln=' + ln)
コード例 #4
0
ファイル: webinterface.py プロジェクト: Theer108/invenio
    def search(self, req, form):
        """
        Display search interface
        """
        argd = wash_urlargd(
            form,
            {
                "name": (str, ""),
                "issue": (str, ""),
                "archive_year": (str, ""),
                "archive_issue": (str, ""),
                "archive_select": (str, "False"),
                "archive_date": (str, ""),
                "archive_search": (str, "False"),
                "ln": (str, CFG_SITE_LANG),
                "verbose": (int, 0),
            },
        )
        try:
            # FIXME: if journal_name is empty, redirect
            ln = wash_journal_language(argd["ln"])
            washed_journal_name = wash_journal_name(ln, argd["name"])
            archive_issue = wash_issue_number(ln, washed_journal_name, argd["archive_issue"])
            archive_date = wash_archive_date(ln, washed_journal_name, argd["archive_date"])
            archive_select = argd["archive_select"]
            archive_search = argd["archive_search"]
        except InvenioWebJournalNoJournalOnServerError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoNameError as e:
            return e.user_box(req)
        except InvenioWebJournalNoCurrentIssueError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalIssueNumberBadlyFormedError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalArchiveDateWronglyFormedError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalJournalIdNotFoundDBError as e:
            register_exception(req=req)
            return e.user_box(req)

        html = perform_request_search(
            req=req,
            journal_name=washed_journal_name,
            ln=ln,
            archive_issue=archive_issue,
            archive_select=archive_select,
            archive_date=archive_date,
            archive_search=archive_search,
            verbose=argd["verbose"],
        )
        return html
コード例 #5
0
ファイル: webjournaladmin.py プロジェクト: SCOAP3/invenio
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)
コード例 #6
0
ファイル: webjournaladmin.py プロジェクト: SCOAP3/invenio
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)
コード例 #7
0
ファイル: webinterface.py プロジェクト: chokribr/invenio-1
    def search(self, req, form):
        """
        Display search interface
        """
        argd = wash_urlargd(form, {'name': (str, ""),
                                   'issue': (str, ""),
                                   'archive_year': (str, ""),
                                   'archive_issue': (str, ""),
                                   'archive_select': (str, "False"),
                                   'archive_date': (str, ""),
                                   'archive_search': (str, "False"),
                                   'ln': (str, CFG_SITE_LANG),
                                   'verbose': (int, 0)})
        try:
            # FIXME: if journal_name is empty, redirect
            ln = wash_journal_language(argd['ln'])
            washed_journal_name = wash_journal_name(ln, argd['name'])
            archive_issue = wash_issue_number(ln, washed_journal_name,
                                              argd['archive_issue'])
            archive_date = wash_archive_date(ln, washed_journal_name,
                                             argd['archive_date'])
            archive_select = argd['archive_select']
            archive_search = argd['archive_search']
        except InvenioWebJournalNoJournalOnServerError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoNameError as e:
            return e.user_box(req)
        except InvenioWebJournalNoCurrentIssueError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalIssueNumberBadlyFormedError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalArchiveDateWronglyFormedError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalJournalIdNotFoundDBError as e:
            register_exception(req=req)
            return e.user_box(req)

        html = perform_request_search(req=req,
                                      journal_name=washed_journal_name,
                                      ln=ln,
                                      archive_issue=archive_issue,
                                      archive_select=archive_select,
                                      archive_date=archive_date,
                                      archive_search=archive_search,
                                      verbose=argd['verbose'])
        return html
コード例 #8
0
ファイル: webinterface.py プロジェクト: chokribr/invenio-1
    def index(self, req, form):
        """
        Index page.
        Washes all the parameters and stores them in journal_defaults dict
        for subsequent format_elements.
        Passes on to logic function and eventually returns HTML.
        """
        argd = wash_urlargd(form, {'name': (str, ""),
                                    'issue': (str, ""),
                                    'category': (str, ""),
                                    'ln': (str, "")}
                            )
        try:
            ln = wash_journal_language(argd['ln'])
            journal_name = wash_journal_name(ln, argd['name'])
            issue_number = wash_issue_number(ln, journal_name,
                                             argd['issue'])
            category = wash_category(ln, argd['category'], journal_name, issue_number)
        except InvenioWebJournalNoJournalOnServerError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoNameError as e:
            return e.user_box(req)
        except InvenioWebJournalNoCurrentIssueError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalIssueNumberBadlyFormedError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoCategoryError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalJournalIdNotFoundDBError as e:
            register_exception(req=req)
            return e.user_box(req)
        # the journal_defaults will be used by format elements that have no
        # direct access to the params here, no more checking needed
        req.journal_defaults = {"name": journal_name,
                                "issue": issue_number,
                                "ln": ln,
                                "category": category}

        html = perform_request_index(req, journal_name, issue_number, ln,
                              category)
        return html
コード例 #9
0
ファイル: webinterface.py プロジェクト: mhellmic/b2share
    def index(self, req, form):
        """
        Index page.
        Washes all the parameters and stores them in journal_defaults dict
        for subsequent format_elements.
        Passes on to logic function and eventually returns HTML.
        """
        argd = wash_urlargd(form, {'name': (str, ""),
                                    'issue': (str, ""),
                                    'category': (str, ""),
                                    'ln': (str, "")}
                            )
        try:
            ln = wash_journal_language(argd['ln'])
            journal_name = wash_journal_name(ln, argd['name'])
            issue_number = wash_issue_number(ln, journal_name,
                                             argd['issue'])
            category = wash_category(ln, argd['category'], journal_name, issue_number)
        except InvenioWebJournalNoJournalOnServerError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoNameError as e:
            return e.user_box(req)
        except InvenioWebJournalNoCurrentIssueError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalIssueNumberBadlyFormedError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoCategoryError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalJournalIdNotFoundDBError as e:
            register_exception(req=req)
            return e.user_box(req)
        # the journal_defaults will be used by format elements that have no
        # direct access to the params here, no more checking needed
        req.journal_defaults = {"name": journal_name,
                                "issue": issue_number,
                                "ln": ln,
                                "category": category}

        html = perform_request_index(req, journal_name, issue_number, ln,
                              category)
        return html
コード例 #10
0
ファイル: webjournaladmin.py プロジェクト: SCOAP3/invenio
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)
コード例 #11
0
ファイル: webinterface.py プロジェクト: Theer108/invenio
    def __call__(self, req, form):
        """ Maybe resolve the final / of a directory """
        path = req.uri[1:].split("/")
        journal_name = None
        journal_issue_year = None
        journal_issue_number = None
        specific_category = None
        category = None
        article_id = None
        if len(path) > 1:
            journal_name = path[1]
        if len(path) > 2 and path[2].isdigit():
            journal_issue_year = path[2]
        elif len(path) > 2 and not path[2].isdigit():
            specific_category = urllib.unquote(path[2])
        if len(path) > 3 and path[3].isdigit():
            journal_issue_number = path[3]
        if len(path) > 4:
            category = urllib.unquote(path[4])
        if len(path) > 5 and path[5].isdigit():
            article_id = int(path[5])

        ## Support for legacy journal/[empty]?(args*) urls. There are
        ## these parameters only in that case
        argd = wash_urlargd(
            form,
            {
                "name": (str, ""),
                "issue": (str, ""),
                "category": (str, ""),
                "ln": (str, CFG_SITE_LANG),
                "number": (int, None),
                "verbose": (int, 0),
            },
        )

        if "name" in form.keys() or "issue" in form.keys() or "category" in form.keys():
            ln = wash_journal_language(argd["ln"])
            try:
                journal_name = wash_journal_name(ln, argd["name"])
            except InvenioWebJournalNoJournalOnServerError as e:
                register_exception(req=req)
                return e.user_box(req)
            except InvenioWebJournalNoNameError as e:
                return e.user_box(req)
            try:
                issue = wash_issue_number(ln, journal_name, argd["issue"])
                issue_year = issue.split("/")[1]
                issue_number = issue.split("/")[0]
            except InvenioWebJournalIssueNumberBadlyFormedError as e:
                register_exception(req=req)
                return e.user_box(req)
            except InvenioWebJournalJournalIdNotFoundDBError as e:
                register_exception(req=req)
                return e.user_box(req)
            category = wash_category(ln, argd["category"], journal_name, issue).replace(" ", "%20")
            redirect_to_url(
                req,
                CFG_SITE_URL
                + "/journal/%(name)s/%(issue_year)s/%(issue_number)s/%(category)s/?ln=%(ln)s"
                % {
                    "name": journal_name,
                    "issue_year": issue_year,
                    "issue_number": issue_number,
                    "category": category,
                    "ln": ln,
                },
            )

        ## End support for legacy urls

        # Check that given journal name exists and that it is written
        # with correct casing.
        redirect_p = False
        try:
            washed_journal_name = wash_journal_name(argd["ln"], journal_name)
            if washed_journal_name != journal_name:
                redirect_p = True
        except InvenioWebJournalNoNameError as e:
            return e.user_box(req)
        except InvenioWebJournalNoJournalOnServerError as e:
            register_exception(req=req)
            return e.user_box(req)

        # If some parameters are missing, deduce them and
        # redirect
        if not journal_issue_year or not journal_issue_number or not category or redirect_p or specific_category:
            if not journal_issue_year or not journal_issue_number:
                journal_issue = get_current_issue(argd["ln"], washed_journal_name)
                journal_issue_year = journal_issue.split("/")[1]
                journal_issue_number = journal_issue.split("/")[0]
            if not category or specific_category:
                categories = get_journal_categories(
                    washed_journal_name, journal_issue_number + "/" + journal_issue_year
                )
                if not categories:
                    # Mmh, it seems that this issue has no
                    # category. Ok get all of them regardless of the
                    # issue
                    categories = get_journal_categories(washed_journal_name)
                    if not categories:
                        # Mmh we really have no category!
                        try:
                            raise InvenioWebJournalIssueNotFoundDBError(argd["ln"], journal_name, "")
                        except InvenioWebJournalIssueNotFoundDBError as e:
                            register_exception(req=req)
                            return e.user_box(req)
                if not category:
                    category = categories[0].replace(" ", "%20")
                if specific_category:
                    category = specific_category.replace(" ", "%20")
            redirect_to_url(
                req,
                CFG_SITE_URL
                + "/journal/%(name)s/%(issue_year)s/%(issue_number)s/%(category)s/?ln=%(ln)s"
                % {
                    "name": washed_journal_name,
                    "issue_year": journal_issue_year,
                    "issue_number": journal_issue_number,
                    "category": category,
                    "ln": argd["ln"],
                },
            )

        journal_issue = ""
        if journal_issue_year is not None and journal_issue_number is not None:
            journal_issue = journal_issue_number + "/" + journal_issue_year

        try:
            journal_name = washed_journal_name
            issue = wash_issue_number(argd["ln"], journal_name, journal_issue)
            category = wash_category(argd["ln"], category, journal_name, issue)
        except InvenioWebJournalNoJournalOnServerError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoNameError as e:
            return e.user_box(req)
        except InvenioWebJournalIssueNumberBadlyFormedError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoCategoryError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalJournalIdNotFoundDBError as e:
            register_exception(req=req)
            return e.user_box(req)

        editor = False
        if acc_authorize_action(getUid(req), "cfgwebjournal", name="%s" % journal_name)[0] == 0:
            editor = True

        if article_id is None:
            html = perform_request_index(
                req, journal_name, journal_issue, argd["ln"], category, editor, verbose=argd["verbose"]
            )
        else:
            html = perform_request_article(
                req, journal_name, journal_issue, argd["ln"], category, article_id, editor, verbose=argd["verbose"]
            )
            # register event in webstat
            try:
                register_customevent(
                    "journals", ["display", journal_name, journal_issue, category, argd["ln"], article_id]
                )
            except:
                register_exception(suffix="Do the webstat tables exists? Try with 'webstatadmin --load-config'")
        return html
コード例 #12
0
ファイル: webinterface.py プロジェクト: chokribr/invenio-1
    def __call__(self, req, form):
        """ Maybe resolve the final / of a directory """
        path = req.uri[1:].split('/')
        journal_name = None
        journal_issue_year = None
        journal_issue_number = None
        specific_category = None
        category = None
        article_id = None
        if len(path) > 1:
            journal_name = path[1]
        if len(path) > 2 and path[2].isdigit():
            journal_issue_year = path[2]
        elif len(path) > 2 and not path[2].isdigit():
            specific_category = urllib.unquote(path[2])
        if len(path) > 3 and path[3].isdigit():
            journal_issue_number = path[3]
        if len(path) > 4:
            category = urllib.unquote(path[4])
        if len(path) > 5 and path[5].isdigit():
            article_id = int(path[5])

        ## Support for legacy journal/[empty]?(args*) urls. There are
        ## these parameters only in that case
        argd = wash_urlargd(form, {'name': (str, ""),
                                   'issue': (str, ""),
                                   'category': (str, ""),
                                   'ln': (str, CFG_SITE_LANG),
                                   'number': (int, None),
                                   'verbose': (int, 0)}
                            )

        if 'name' in form.keys() or \
            'issue' in form.keys() or \
            'category' in form.keys():
            ln = wash_journal_language(argd['ln'])
            try:
                journal_name = wash_journal_name(ln, argd['name'])
            except InvenioWebJournalNoJournalOnServerError as e:
                register_exception(req=req)
                return e.user_box(req)
            except InvenioWebJournalNoNameError as e:
                return e.user_box(req)
            try:
                issue = wash_issue_number(ln, journal_name,
                                          argd['issue'])
                issue_year = issue.split('/')[1]
                issue_number = issue.split('/')[0]
            except InvenioWebJournalIssueNumberBadlyFormedError as e:
                register_exception(req=req)
                return e.user_box(req)
            except InvenioWebJournalJournalIdNotFoundDBError as e:
                register_exception(req=req)
                return e.user_box(req)
            category = wash_category(ln, argd['category'], journal_name, issue).replace(' ', '%20')
            redirect_to_url(req, CFG_SITE_URL + '/journal/%(name)s/%(issue_year)s/%(issue_number)s/%(category)s/?ln=%(ln)s' % \
                            {'name': journal_name,
                             'issue_year': issue_year,
                             'issue_number': issue_number,
                             'category': category,
                             'ln': ln})

        ## End support for legacy urls

        # Check that given journal name exists and that it is written
        # with correct casing.
        redirect_p = False
        try:
            washed_journal_name = wash_journal_name(argd['ln'], journal_name)
            if washed_journal_name != journal_name:
                redirect_p = True
        except InvenioWebJournalNoNameError as e:
            return e.user_box(req)
        except InvenioWebJournalNoJournalOnServerError as e:
            register_exception(req=req)
            return e.user_box(req)

        # If some parameters are missing, deduce them and
        # redirect
        if not journal_issue_year or \
           not journal_issue_number or \
           not category or \
           redirect_p or \
           specific_category:
            if not journal_issue_year or not journal_issue_number:
                journal_issue = get_current_issue(argd['ln'], washed_journal_name)
                journal_issue_year = journal_issue.split('/')[1]
                journal_issue_number = journal_issue.split('/')[0]
            if not category or specific_category:
                categories = get_journal_categories(washed_journal_name,
                                                    journal_issue_number + \
                                                    '/' + journal_issue_year)
                if not categories:
                    # Mmh, it seems that this issue has no
                    # category. Ok get all of them regardless of the
                    # issue
                    categories = get_journal_categories(washed_journal_name)
                    if not categories:
                        # Mmh we really have no category!
                        try:
                            raise InvenioWebJournalIssueNotFoundDBError(argd['ln'],
                                                                        journal_name,
                                                                        '')
                        except InvenioWebJournalIssueNotFoundDBError as e:
                            register_exception(req=req)
                            return e.user_box(req)
                if not category:
                    category = categories[0].replace(' ', '%20')
                if specific_category:
                    category = specific_category.replace(' ', '%20')
            redirect_to_url(req, CFG_SITE_URL + '/journal/%(name)s/%(issue_year)s/%(issue_number)s/%(category)s/?ln=%(ln)s' % \
                            {'name': washed_journal_name,
                             'issue_year': journal_issue_year,
                             'issue_number': journal_issue_number,
                             'category': category,
                             'ln': argd['ln']})

        journal_issue = ""
        if journal_issue_year is not None and \
           journal_issue_number is not None:
            journal_issue = journal_issue_number + '/' + \
                            journal_issue_year

        try:
            journal_name = washed_journal_name
            issue = wash_issue_number(argd['ln'], journal_name, journal_issue)
            category = wash_category(argd['ln'], category, journal_name, issue)
        except InvenioWebJournalNoJournalOnServerError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoNameError as e:
            return e.user_box(req)
        except InvenioWebJournalIssueNumberBadlyFormedError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalNoCategoryError as e:
            register_exception(req=req)
            return e.user_box(req)
        except InvenioWebJournalJournalIdNotFoundDBError as e:
            register_exception(req=req)
            return e.user_box(req)

        editor = False
        if acc_authorize_action(getUid(req), 'cfgwebjournal',
                                name="%s" % journal_name)[0] == 0:
            editor = True

        if article_id is None:
            html = perform_request_index(req,
                                         journal_name,
                                         journal_issue,
                                         argd['ln'],
                                         category,
                                         editor,
                                         verbose=argd['verbose'])
        else:
            html = perform_request_article(req,
                                           journal_name,
                                           journal_issue,
                                           argd['ln'],
                                           category,
                                           article_id,
                                           editor,
                                           verbose=argd['verbose'])
            # register event in webstat
            try:
                register_customevent("journals", ["display", journal_name, journal_issue, category, argd['ln'], article_id])
            except:
                register_exception(suffix="Do the webstat tables exists? Try with 'webstatadmin --load-config'")
        return html
コード例 #13
0
ファイル: webjournaladmin.py プロジェクト: chokribr/invenio-1
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)
コード例 #14
0
ファイル: webjournaladmin.py プロジェクト: chokribr/invenio-1
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)