コード例 #1
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
コード例 #2
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
コード例 #3
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
コード例 #4
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