コード例 #1
0
ファイル: goto_engine.py プロジェクト: aw-bib/tind-invenio
def get_redirection_data(label):
    """
    Returns all information about a given redirection identified by label.

    @param label: the label identifying the redirection
    @type label: string

    @returns: a dictionary with the following keys:
        * label: the label
        * plugin: the name of the plugin
        * parameters: the parameters that are passed to the plugin
            (deserialized from JSON)
        * creation_date: datetime object on when the redirection was first
            created.
        * modification_date: datetime object on when the redirection was
            last modified.
    @rtype: dict

    @raises ValueError: in case the label does not exist.
    """
    res = run_sql("SELECT label, plugin, parameters, creation_date, modification_date FROM goto WHERE label=%s", (label, ))
    if res:
        return {'label': res[0][0],
                 'plugin': CFG_GOTO_PLUGINS[res[0][1]],
                 'parameters': json_unicode_to_utf8(json.loads(res[0][2])),
                 'creation_date': res[0][3],
                 'modification_date': res[0][4]}
    else:
        raise ValueError("%s label does not exist" % label)
コード例 #2
0
    def create_authorpage_affiliations(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                author_aff_pubs, author_aff_pubsStatus = get_institute_pubs(
                    person_id)
                if not author_aff_pubs:
                    author_aff_pubs = dict()

                json_response['boxes_info'].update({
                    'affiliations': {
                        'status':
                        author_aff_pubsStatus,
                        'html_content':
                        webauthorprofile_templates.tmpl_affiliations_box(
                            author_aff_pubs,
                            ln='en',
                            add_box=False,
                            loading=not author_aff_pubsStatus)
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #3
0
    def create_authorpage_citations(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                summarize_records, summarize_recordsStatus = get_summarize_records(
                    person_id)
                if not summarize_records:
                    summarize_records = 'None'

                pubs, pubsStatus = get_pubs(person_id)
                if not pubs:
                    pubs = list()

                json_response['boxes_info'].update({
                    'citations': {
                        'status': (summarize_recordsStatus and pubsStatus),
                        'html_content':
                        webauthorprofile_templates.tmpl_citations_box(
                            summarize_records,
                            pubs,
                            ln='en',
                            add_box=False,
                            loading=not (summarize_recordsStatus
                                         and pubsStatus))
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #4
0
    def create_authorpage_pubs_graph(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                pubs_per_year, pubs_per_yearStatus = get_pubs_per_year(
                    person_id)
                if not pubs_per_year:
                    pubs_per_year = dict()

                json_response['boxes_info'].update({
                    'pubs_graph': {
                        'status':
                        pubs_per_yearStatus,
                        'html_content':
                        webauthorprofile_templates.tmpl_graph_box(
                            pubs_per_year,
                            ln='en',
                            add_box=False,
                            loading=not pubs_per_yearStatus)
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #5
0
    def create_authorpage_affiliations(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                author_aff_pubs, author_aff_pubsStatus = get_institute_pubs(
                    person_id)
                if not author_aff_pubs:
                    author_aff_pubs = dict()

                json_response['boxes_info'].update({
                    'affiliations': {
                        'status':
                        author_aff_pubsStatus,
                        'html_content':
                        webauthorprofile_templates.tmpl_affiliations_box(
                            author_aff_pubs,
                            ln='en',
                            add_box=False,
                            loading=not author_aff_pubsStatus)
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #6
0
    def create_authorpage_authors_pubs(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                namesdict, namesdictStatus = get_person_names_dicts(person_id)
                if not namesdict:
                    namesdict = dict()
                try:
                    authorname = namesdict['longest']
                except (IndexError, KeyError):
                    authorname = 'None'

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(person_id)
                bibauthorid_data = {'is_baid': True, 'pid': person_id, 'cid': person_link}
                if not person_link or not person_linkStatus:
                    bibauthorid_data = {'is_baid': True, 'pid': person_id, 'cid': None}
                    person_link = str(person_id)

                pubs, pubsStatus = get_pubs(person_id)
                if not pubs:
                    pubs = list()

                json_response['boxes_info'].update({'authornametitle': {'status': (namesdictStatus and namesdictStatus and pubsStatus), 'html_content': webauthorprofile_templates.tmpl_authornametitle(authorname, bibauthorid_data, pubs, person_link, ln='en', loading=not (namesdictStatus and namesdictStatus and pubsStatus))}})
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #7
0
    def create_authorpage_citations(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                summarize_records, summarize_recordsStatus = get_summarize_records(
                    person_id)
                if not summarize_records:
                    summarize_records = 'None'

                pubs, pubsStatus = get_pubs(person_id)
                if not pubs:
                    pubs = list()

                json_response['boxes_info'].update({
                    'citations': {
                        'status': (summarize_recordsStatus and pubsStatus),
                        'html_content':
                        webauthorprofile_templates.tmpl_citations_box(
                            summarize_records,
                            pubs,
                            ln='en',
                            add_box=False,
                            loading=not (summarize_recordsStatus
                                         and pubsStatus))
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #8
0
 def __iter__(self):
     chunk_size = 200
     page = 0
     while True:
         page += 1
         results = requests.get("https://hepdata.net/search/",
                                params=dict(size=chunk_size, page=page),
                                headers={
                                    'Accept': 'application/json'
                                }).json()['results']
         if not results:
             break
         for i, result in enumerate(results):
             result = json_unicode_to_utf8(result)
             paper_title = result['title']
             inspire_id = result['inspire_id']
             for data in result['data']:
                 data['paper_title'] = paper_title
                 data['inspire_id'] = inspire_id
                 data['position'] = i + 1
                 if data['doi']:
                     self._store_record_in_dump(data)
                     if self._is_hepdata_record_new_or_updated(data):
                         yield data
     self._close_hepdata_dump()
     self._swap_hepdata_dump()
コード例 #9
0
def get_redirection_data(label):
    """
    Returns all information about a given redirection identified by label.

    @param label: the label identifying the redirection
    @type label: string

    @returns: a dictionary with the following keys:
        * label: the label
        * plugin: the name of the plugin
        * parameters: the parameters that are passed to the plugin
            (deserialized from JSON)
        * creation_date: datetime object on when the redirection was first
            created.
        * modification_date: datetime object on when the redirection was
            last modified.
    @rtype: dict

    @raises ValueError: in case the label does not exist.
    """
    res = run_sql(
        "SELECT label, plugin, parameters, creation_date, modification_date FROM goto WHERE label=%s",
        (label, ))
    if res:
        return {
            'label': res[0][0],
            'plugin': CFG_GOTO_PLUGINS[res[0][1]],
            'parameters': json_unicode_to_utf8(json.loads(res[0][2])),
            'creation_date': res[0][3],
            'modification_date': res[0][4]
        }
    else:
        raise ValueError("%s label does not exist" % label)
コード例 #10
0
    def create_authorpage_pubs_graph(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                pubs_per_year, pubs_per_yearStatus = get_pubs_per_year(
                    person_id)
                if not pubs_per_year:
                    pubs_per_year = dict()

                json_response['boxes_info'].update({
                    'pubs_graph': {
                        'status':
                        pubs_per_yearStatus,
                        'html_content':
                        webauthorprofile_templates.tmpl_graph_box(
                            pubs_per_year,
                            ln='en',
                            add_box=False,
                            loading=not pubs_per_yearStatus)
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #11
0
    def _get_user_email_and_id_from_orcid(req):
        """
        Since we are dealing with orcid we can fetch tons of information
        from the user profile.
        """
        from invenio.access_control_config import CFG_OAUTH2_CONFIGURATIONS

        profile = requests.get(CFG_OAUTH2_CONFIGURATIONS['orcid']['request_url'].format(id=req.g['oauth2_orcid']), headers={'Accept': 'application/orcid+json', 'Authorization': 'Bearer %s' % req.g['oauth2_access_token']})
        orcid_record = req.g['orcid_record'] = json_unicode_to_utf8(profile.json())['orcid-profile']
        try:
            orcidid = orcid_record['orcid-identifier']['path']
        except (TypeError, KeyError) as e:
            import cPickle, os, datetime
            from invenio.config import CFG_TMPSHAREDDIR
            ts = str(datetime.datetime.today()).replace(' ', ':')
            fname = os.path.join(CFG_TMPSHAREDDIR,
                                 'orcid_dictionary_problem_%s.cPickle' % str(ts))
            f = open(fname, 'w')
            cPickle.dump((e, profile, orcid_record), f)
            f.close()
            raise Exception("Something is wrong with the dictionary we got from ORCID."
                            "Dumped to temporary file %s" % fname)

        emails = orcid_record['orcid-bio'].get('contact-details', dict()).get('email', list())
        if emails:
            return emails[0], orcidid
        else:
            return None, orcidid
コード例 #12
0
    def create_authorpage_combined_papers(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                pubs, pubsStatus = get_pubs(person_id)
                if not pubs:
                    pubs = list()

                selfpubs, selfpubsStatus = get_self_pubs(person_id)
                if not selfpubs:
                    selfpubs = list()

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(person_id)
                bibauthorid_data = {'is_baid': True, 'pid': person_id, 'cid': None}
                if person_link and person_linkStatus:
                    bibauthorid_data = {'is_baid': True, 'pid': person_id, 'cid': person_link}

                totaldownloads, totaldownloadsStatus = get_total_downloads(person_id)
                if not totaldownloads:
                    totaldownloads = 0

                json_response['boxes_info'].update({'combined_papers': {'status': selfpubsStatus, 'html_content': webauthorprofile_templates.tmpl_papers_with_self_papers_box(pubs, selfpubs, bibauthorid_data, totaldownloads, ln='en', add_box=False, loading=not selfpubsStatus)}})
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #13
0
ファイル: crossrefutils.py プロジェクト: aw-bib/tind-invenio
def query_fundref_api(query, **kwargs):
    """
    Perform a request to the Fundref API.
    """
    sleep(1)
    req = urllib2.Request("http://api.crossref.org%s?%s" % (query, urllib.urlencode(kwargs)), headers={'content-type': 'application/vnd.crossref-api-message+json; version=1.0'})
    res = json_unicode_to_utf8(json.load(CROSSREF_OPENER.open(req)))
    return res['message']
コード例 #14
0
 def get_json_parameters_from_cli(option, dummy_opt_str, value,
                                  dummy_parser):
     try:
         option.parameters = json_unicode_to_utf8(json.loads(value))
     except Exception, err:
         raise optparse.OptionValueError(
             "Cannot parse as a valid JSON serialization the provided parameters: %s. %s"
             % (value, err))
コード例 #15
0
def query_fundref_api(query, **kwargs):
    """
    Perform a request to the Fundref API.
    """
    sleep(1)
    req = urllib2.Request("http://api.crossref.org%s?%s" % (query, urllib.urlencode(kwargs)), headers={'content-type': 'application/vnd.crossref-api-message+json; version=1.0'})
    res = json_unicode_to_utf8(json.load(CROSSREF_OPENER.open(req)))
    return res['message']
コード例 #16
0
    def manage(self, req, form):
        """ Web interface for the management of the info space """
        uid = getUid(req)
        argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG)})

        # If it is an Ajax request, extract any JSON data.
        ajax_request = False
        if 'jsondata' in form:
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            ajax_request = True
            json_response = {}

        # Authorization.
        user_info = collect_user_info(req)
        if user_info['email'] == 'guest':
            # User is not logged in.
            if not ajax_request:
                # Do not display the introductory recID selection box to guest
                # users (as it used to be with v0.99.0):
                dummy_auth_code, auth_message = acc_authorize_action(
                    req, 'runinfomanager')
                referer = '/info'
                return page_not_authorized(req=req,
                                           referer=referer,
                                           text=auth_message)
            else:
                # Session has most likely timed out.
                json_response.update({'status': "timeout"})
                return json.dumps(json_response)
        # Handle request.
        if not ajax_request:
            body, errors, warnings = perform_request_init_info_interface()
            title = 'Info Space Manager'
            return page(title=title,
                        body=body,
                        errors=errors,
                        warnings=warnings,
                        uid=uid,
                        language=argd['ln'],
                        req=req)
        else:
            # Handle AJAX request.
            if json_data["action"] == "listFiles":
                json_response.update(
                    perform_request_edit_file(json_data["filename"]))
                try:
                    return json.dumps(json_response)
                except UnicodeDecodeError:
                    # Error decoding, the file can be a pdf, image or any kind
                    # of file non-editable
                    return json.dumps({"status": "error_file_not_readable"})

            if json_data["action"] == "saveContent":
                return json.dumps(
                    perform_request_save_file(json_data["filename"],
                                              json_data["filecontent"]))
コード例 #17
0
 def __extract_attribute(self, req):
     """
     Load from the request the given assertion, extract all the attribute
     to properly login the user, and verify that the data are actually
     both well formed and signed correctly.
     """
     from invenio.webinterface_handler import wash_urlargd
     args = wash_urlargd(
         req.form, {
             'assertion': (str, ''),
             'robot': (str, ''),
             'digest': (str, ''),
             'login_method': (str, '')
         })
     assertion = args['assertion']
     digest = args['digest']
     robot = args['robot']
     login_method = args['login_method']
     shared_key = load_robot_keys().get(login_method, {}).get(robot)
     if shared_key is None:
         raise InvenioWebAccessExternalAuthError(
             "A key does not exist for robot: %s, login_method: %s" %
             (robot, login_method))
     if not self.verify(shared_key, assertion, digest):
         raise InvenioWebAccessExternalAuthError(
             "The provided assertion does not validate against the digest %s for robot %s"
             % (repr(digest), repr(robot)))
     if self.use_zlib:
         try:
             ## Workaround to Perl implementation that does not add
             ## any padding to the base64 encoding.
             needed_pad = (4 - len(assertion) % 4) % 4
             assertion += needed_pad * '='
             assertion = decompress(base64.urlsafe_b64decode(assertion))
         except:
             raise InvenioWebAccessExternalAuthError(
                 "The provided assertion is corrupted")
     data = json_unicode_to_utf8(json.loads(assertion))
     if not isinstance(data, dict):
         raise InvenioWebAccessExternalAuthError(
             "The provided assertion is invalid")
     timeout = data[self.timeout_attribute_name]
     if timeout < time.time():
         raise InvenioWebAccessExternalAuthError(
             "The provided assertion is expired")
     userip = data.get(self.userip_attribute_name)
     if not self.check_user_ip or (normalize_ip(
             userip, self.check_user_ip) == normalize_ip(
                 req.remote_ip, self.check_user_ip)):
         return data
     else:
         raise InvenioWebAccessExternalAuthError(
             "The provided assertion has been issued for a different IP address (%s instead of %s)"
             % (userip, req.remote_ip))
コード例 #18
0
    def manage(self, req, form):
        """ Web interface for the management of the info space """
        uid = getUid(req)
        argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG)})

        # If it is an Ajax request, extract any JSON data.
        ajax_request = False
        if 'jsondata' in form:
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            ajax_request = True
            json_response = {}

        # Authorization.
        user_info = collect_user_info(req)
        if user_info['email'] == 'guest':
            # User is not logged in.
            if not ajax_request:
                # Do not display the introductory recID selection box to guest
                # users (as it used to be with v0.99.0):
                dummy_auth_code, auth_message = acc_authorize_action(req,
                                                                     'runinfomanager')
                referer = '/info'
                return page_not_authorized(req=req, referer=referer,
                                           text=auth_message)
            else:
                # Session has most likely timed out.
                json_response.update({'status': "timeout"})
                return json.dumps(json_response)
        # Handle request.
        if not ajax_request:
            body, errors, warnings = perform_request_init_info_interface()
            title = 'Info Space Manager'
            return page(title=title,
                        body=body,
                        errors=errors,
                        warnings=warnings,
                        uid=uid,
                        language=argd['ln'],
                        req=req)
        else:
            # Handle AJAX request.
            if json_data["action"] == "listFiles":
                json_response.update(perform_request_edit_file(json_data["filename"]))
                try:
                    return json.dumps(json_response)
                except UnicodeDecodeError:
                    # Error decoding, the file can be a pdf, image or any kind
                    # of file non-editable
                    return json.dumps({"status": "error_file_not_readable"})

            if json_data["action"] == "saveContent":
                return json.dumps(perform_request_save_file(json_data["filename"],
                                                            json_data["filecontent"]))
コード例 #19
0
    def get_limited_access_data_from_orcid(orcid_id, access_token):
        """
        Since we are dealing with orcid we can fetch tons of information
        from the user profile.
        """
        from invenio.access_control_config import CFG_OAUTH2_CONFIGURATIONS

        profile = requests.get(CFG_OAUTH2_CONFIGURATIONS['orcid']['request_url'].format(id=orcid_id), headers={'Accept': 'application/orcid+json', 'Authorization': 'Bearer %s' % access_token})
        if profile.status_code != 200:
            raise NotImplementedError()
        orcid_data = json_unicode_to_utf8(profile.json())['orcid-profile']
        return orcid_data
コード例 #20
0
    def create_authorpage_combined_papers(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                pubs, pubsStatus = get_pubs(person_id)
                if not pubs:
                    pubs = list()

                selfpubs, selfpubsStatus = get_self_pubs(person_id)
                if not selfpubs:
                    selfpubs = list()

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(
                    person_id)
                bibauthorid_data = {
                    'is_baid': True,
                    'pid': person_id,
                    'cid': None
                }
                if person_link and person_linkStatus:
                    bibauthorid_data = {
                        'is_baid': True,
                        'pid': person_id,
                        'cid': person_link
                    }

                totaldownloads, totaldownloadsStatus = get_total_downloads(
                    person_id)
                if not totaldownloads:
                    totaldownloads = 0

                json_response['boxes_info'].update({
                    'combined_papers': {
                        'status':
                        selfpubsStatus,
                        'html_content':
                        webauthorprofile_templates.
                        tmpl_papers_with_self_papers_box(
                            pubs,
                            selfpubs,
                            bibauthorid_data,
                            totaldownloads,
                            ln='en',
                            add_box=False,
                            loading=not selfpubsStatus)
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #21
0
    def get_limited_access_data_from_orcid(orcid_id, access_token):
        """
        Since we are dealing with orcid we can fetch tons of information
        from the user profile.
        """
        from invenio.access_control_config import CFG_OAUTH2_CONFIGURATIONS

        profile = requests.get(CFG_OAUTH2_CONFIGURATIONS['orcid']['request_url'].format(id=orcid_id), headers={'Accept': 'application/orcid+json', 'Authorization': 'Bearer %s' % access_token})
        if profile.status_code != 200:
            raise NotImplementedError()
        orcid_data = json_unicode_to_utf8(profile.json())['orcid-profile']
        return orcid_data
コード例 #22
0
    def templates(self, req, form):
        """handle a edit/templates request"""
        uid = getUid(req)
        argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG)})

        # If it is an Ajax request, extract any JSON data.
        ajax_request = False
        if form.has_key('jsondata'):
            json_data = json.loads(str(form['jsondata']))
            # Deunicode all strings (Invenio doesn't have unicode
            # support).
            json_data = json_unicode_to_utf8(json_data)
            ajax_request = True
            json_response = {'resultCode': 0}

        # Authorization.
        user_info = collect_user_info(req)
        if user_info['email'] == 'guest':
            # User is not logged in.
            if not ajax_request:
                # Do not display the introductory recID selection box to guest
                # users (as it used to be with v0.99.0):
                dummy_auth_code, auth_message = acc_authorize_action(
                    req, 'runbibedit')
                referer = '/edit'
                return page_not_authorized(req=req,
                                           referer=referer,
                                           text=auth_message,
                                           navtrail=navtrail)
            else:
                # Session has most likely timed out.
                json_response.update({'resultCode': 100})
                return json.dumps(json_response)
        # Handle request.
        if not ajax_request:
            # Show BibEdit template management start page.
            body, errors, warnings = perform_request_init_template_interface()
            title = 'Record Editor Template Manager'
            return page(title=title,
                        body=body,
                        errors=errors,
                        warnings=warnings,
                        uid=uid,
                        language=argd['ln'],
                        navtrail=navtrail_bibedit,
                        lastupdated=__lastupdated__,
                        req=req,
                        body_css_classes=['bibedit'])
        else:
            # Handle AJAX request.
            json_response.update(
                perform_request_ajax_template_interface(json_data))
            return json.dumps(json_response)
コード例 #23
0
    def create_authorpage_authors_pubs(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                namesdict, namesdictStatus = get_person_names_dicts(person_id)
                if not namesdict:
                    namesdict = dict()
                try:
                    authorname = namesdict['longest']
                except (IndexError, KeyError):
                    authorname = 'None'

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(
                    person_id)
                bibauthorid_data = {
                    'is_baid': True,
                    'pid': person_id,
                    'cid': person_link
                }
                if not person_link or not person_linkStatus:
                    bibauthorid_data = {
                        'is_baid': True,
                        'pid': person_id,
                        'cid': None
                    }
                    person_link = str(person_id)

                pubs, pubsStatus = get_pubs(person_id)
                if not pubs:
                    pubs = list()

                json_response['boxes_info'].update({
                    'authornametitle': {
                        'status': (namesdictStatus and namesdictStatus
                                   and pubsStatus),
                        'html_content':
                        webauthorprofile_templates.tmpl_authornametitle(
                            authorname,
                            bibauthorid_data,
                            pubs,
                            person_link,
                            ln='en',
                            loading=not (namesdictStatus and namesdictStatus
                                         and pubsStatus))
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #24
0
    def create_authorpage_hepdata(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                hepdict, hepdictStatus = get_hepnames_data(person_id)

                json_response['boxes_info'].update({'hepdata': {'status': hepdictStatus, 'html_content': bibauthorid_template.tmpl_hepnames_box(hepdict, ln='en', add_box=False, loading=not hepdictStatus)}})
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #25
0
    def create_authorpage_citations(self, req, form):
        if 'jsondata' in form:
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)

            if 'personId' in json_data:
                person_id = json_data['personId']

                citation_data, cache_status = get_summarize_records(person_id)
                records, records_cache_status = get_pubs(person_id)
                datasets = get_datasets(person_id)
                if datasets and datasets[0]:
                    datasets = len(datasets[0])
                else:
                    datasets = 0

                citations = {
                    'breakdown_categories': [
                        'Renowned papers (500+)', 'Famous papers (250-499)',
                        'Very well-known papers (100-249)',
                        'Well-known papers (50-99)', 'Known papers (10-49)',
                        'Less known papers (1-9)', 'Unknown papers (0)'
                    ]
                }

                content = "Data not ready. Please wait..."
                if cache_status and citation_data and records and records_cache_status:
                    citations['papers_num'] = len(records)
                    try:
                        citations['papers'], citations['data'] = citation_data[
                            0]
                    except IndexError:
                        pass

                    result = get_canonical_name_of_author(person_id)
                    if result:
                        canonical_name = result[0][0]
                    else:
                        canonical_name = ""
                    content = WebProfilePage.render_citations_summary_content(
                        citations, canonical_name, datasets)
                elif not citation_data and not records:
                    content = "No citations data."

                json_response = {
                    'status': (cache_status and records_cache_status),
                    'html': content
                }

                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #26
0
    def templates(self, req, form):
        """handle a edit/templates request"""
        uid = getUid(req)
        argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG)})

        # If it is an Ajax request, extract any JSON data.
        ajax_request = False
        if form.has_key('jsondata'):
            json_data = json.loads(str(form['jsondata']))
            # Deunicode all strings (Invenio doesn't have unicode
            # support).
            json_data = json_unicode_to_utf8(json_data)
            ajax_request = True
            json_response = {'resultCode': 0}

        # Authorization.
        user_info = collect_user_info(req)
        if user_info['email'] == 'guest':
            # User is not logged in.
            if not ajax_request:
                # Do not display the introductory recID selection box to guest
                # users (as it used to be with v0.99.0):
                dummy_auth_code, auth_message = acc_authorize_action(req,
                                                                     'runbibedit')
                referer = '/edit'
                return page_not_authorized(req=req, referer=referer,
                                           text=auth_message, navtrail=navtrail)
            else:
                # Session has most likely timed out.
                json_response.update({'resultCode': 100})
                return json.dumps(json_response)
        # Handle request.
        if not ajax_request:
            # Show BibEdit template management start page.
            body, errors, warnings = perform_request_init_template_interface()
            title = 'Record Editor Template Manager'
            return page(title       = title,
                        body        = body,
                        errors      = errors,
                        warnings    = warnings,
                        uid         = uid,
                        language    = argd['ln'],
                        navtrail    = navtrail_bibedit,
                        lastupdated = __lastupdated__,
                        req         = req,
                        body_css_classes = ['bibedit'])
        else:
            # Handle AJAX request.
            json_response.update(perform_request_ajax_template_interface(json_data))
            return json.dumps(json_response)
コード例 #27
0
ファイル: bst_hal.py プロジェクト: kaplun/inspire
def hal_record_iterator():
    start = 0
    while True:
        res = requests.get(CFG_HAL_API_URL, params={'start': start,
                                             'q': '(arxivId_s:* OR doiId_s:*)',
                                             'fl': 'arxivId_s,halId_s,doiId_s',
                                             'rows': CFG_HAL_ROWS,
                                             'sort': 'docid asc'}).json()
        if res['response']['docs']:
            for row in res['response']['docs']:
                yield json_unicode_to_utf8(row)
            start += CFG_HAL_ROWS
            write_message("%s out of %s" % (start, res['response']['numFound']))
        else:
            return
コード例 #28
0
    def _get_user_email_and_id_from_orcid(req):
        """
        Since we are dealing with orcid we can fetch tons of information
        from the user profile.
        """
        from invenio.access_control_config import CFG_OAUTH2_CONFIGURATIONS

        profile = requests.get(CFG_OAUTH2_CONFIGURATIONS['orcid']['request_url'].format(id=req.g['oauth2_orcid']), headers={'Accept': 'application/orcid+json', 'Authorization': 'Bearer %s' % req.g['oauth2_access_token']})
        orcid_record = req.g['orcid_record'] = json_unicode_to_utf8(profile.json)['orcid-profile']
        id = orcid_record['orcid']['value']
        emails = orcid_record['orcid-bio'].get('contact-details', {}).get('email', [])
        if emails:
            return emails[0], id
        else:
            return None, id
コード例 #29
0
ファイル: bst_hal.py プロジェクト: turtle321/inspire
def hal_record_iterator():
    start = 0
    while True:
        res = requests.get(CFG_HAL_API_URL, timeout=60, params={
            'start': start,
            'q': '(inspireId_s:* OR arxivId_s:* OR doiId_s:*)',
            'fl': 'inspireId_s,arxivId_s,halId_s,doiId_s',
            'rows': CFG_HAL_ROWS,
            'sort': 'docid asc'
        }).json()
        if res['response']['docs']:
            for row in res['response']['docs']:
                yield json_unicode_to_utf8(row)
            start += CFG_HAL_ROWS
            write_message("%s out of %s" % (start, res['response']['numFound']))
        else:
            return
コード例 #30
0
    def create_authorpage_name_variants(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                namesdict, namesdictStatus = get_person_names_dicts(person_id)
                if not namesdict:
                    namesdict = dict()
                try:
                    db_names_dict = namesdict['db_names_dict']
                except (IndexError, KeyError):
                    db_names_dict = dict()

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(
                    person_id)
                bibauthorid_data = {
                    'is_baid': True,
                    'pid': person_id,
                    'cid': None
                }
                if person_link and person_linkStatus:
                    bibauthorid_data = {
                        'is_baid': True,
                        'pid': person_id,
                        'cid': person_link
                    }

                json_response['boxes_info'].update({
                    'name_variants': {
                        'status':
                        namesdictStatus,
                        'html_content':
                        webauthorprofile_templates.
                        tmpl_author_name_variants_box(
                            db_names_dict,
                            bibauthorid_data,
                            ln='en',
                            add_box=False,
                            loading=not db_names_dict)
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #31
0
    def create_authorpage_name_variants(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                namesdict, namesdictStatus = get_person_names_dicts(person_id)
                if not namesdict:
                    namesdict = dict()
                try:
                    db_names_dict = namesdict['db_names_dict']
                except (IndexError, KeyError):
                    db_names_dict = dict()

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(
                    person_id)
                bibauthorid_data = {
                    'is_baid': True,
                    'pid': person_id,
                    'cid': None
                }
                if person_link and person_linkStatus:
                    bibauthorid_data = {
                        'is_baid': True,
                        'pid': person_id,
                        'cid': person_link
                    }

                json_response['boxes_info'].update({
                    'name_variants': {
                        'status':
                        namesdictStatus,
                        'html_content':
                        webauthorprofile_templates.
                        tmpl_author_name_variants_box(
                            db_names_dict,
                            bibauthorid_data,
                            ln='en',
                            add_box=False,
                            loading=not db_names_dict)
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #32
0
    def create_authorpage_collaborations(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                collab, collabStatus = get_collabtuples(person_id)

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(person_id)
                bibauthorid_data = {'is_baid': True, 'pid': person_id, 'cid': None}
                if person_link and person_linkStatus:
                    bibauthorid_data = {'is_baid': True, 'pid': person_id, 'cid': person_link}

                json_response['boxes_info'].update({'collaborations': {'status': collabStatus, 'html_content': webauthorprofile_templates.tmpl_collab_box(collab, bibauthorid_data, ln='en', add_box=False, loading=not collabStatus)}})
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #33
0
    def create_authorpage_fieldcodes(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                fieldtuples, fieldtuplesStatus = get_fieldtuples(person_id)
                if fieldtuples:
                    pass
                    # fieldtuples = fieldtuples[0:MAX_FIELDCODE_LIST]
                else:
                    fieldtuples = list()

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(
                    person_id)
                bibauthorid_data = {
                    'is_baid': True,
                    'pid': person_id,
                    'cid': None
                }
                if person_link and person_linkStatus:
                    bibauthorid_data = {
                        'is_baid': True,
                        'pid': person_id,
                        'cid': person_link
                    }

                json_response['boxes_info'].update({
                    'fieldcodes': {
                        'status':
                        fieldtuplesStatus,
                        'html_content':
                        webauthorprofile_templates.tmpl_fieldcode_box(
                            fieldtuples,
                            bibauthorid_data,
                            ln='en',
                            add_box=False,
                            loading=not fieldtuplesStatus)
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #34
0
    def create_authorpage_fieldcodes(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                fieldtuples, fieldtuplesStatus = get_fieldtuples(person_id)
                if fieldtuples:
                    pass
                    # fieldtuples = fieldtuples[0:MAX_FIELDCODE_LIST]
                else:
                    fieldtuples = list()

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(
                    person_id)
                bibauthorid_data = {
                    'is_baid': True,
                    'pid': person_id,
                    'cid': None
                }
                if person_link and person_linkStatus:
                    bibauthorid_data = {
                        'is_baid': True,
                        'pid': person_id,
                        'cid': person_link
                    }

                json_response['boxes_info'].update({
                    'fieldcodes': {
                        'status':
                        fieldtuplesStatus,
                        'html_content':
                        webauthorprofile_templates.tmpl_fieldcode_box(
                            fieldtuples,
                            bibauthorid_data,
                            ln='en',
                            add_box=False,
                            loading=not fieldtuplesStatus)
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #35
0
    def create_authorpage_pubs(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                pubs, pubsStatus = get_pubs(person_id)
                if not pubs:
                    pubs = list()

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(person_id)
                bibauthorid_data = {'is_baid': True, 'pid': person_id, 'cid': None}
                if person_link and person_linkStatus:
                    bibauthorid_data = {'is_baid': True, 'pid': person_id, 'cid': person_link}

                json_response['boxes_info'].update({'numpaperstitle': {'status': pubsStatus, 'html_content': webauthorprofile_templates.tmpl_numpaperstitle(bibauthorid_data, pubs)}})
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #36
0
    def json_req_profiler(self, req, form):
        if "ajaxProfile" in form:
            profiler = cProfile.Profile()
            return_val = profiler.runcall(func, self, req, form)

            results = cStringIO.StringIO()
            stats = pstats.Stats(profiler, stream=results)
            stats.sort_stats('cumulative')
            stats.print_stats(100)

            json_in = json.loads(str(form['jsondata']))
            # Deunicode all strings (Invenio doesn't have unicode
            # support).
            json_in = json_unicode_to_utf8(json_in)

            json_data = json.loads(return_val)
            json_data.update({"profilerStats": "<pre style='overflow: scroll'>" + json_in['requestType'] + results.getvalue() + "</pre>"})
            return json.dumps(json_data)
        else:
            return func(self, req, form)
コード例 #37
0
    def json_req_profiler(self, req, form):
        if "ajaxProfile" in form:
            profiler = cProfile.Profile()
            return_val = profiler.runcall(func, self, req, form)

            results = cStringIO.StringIO()
            stats = pstats.Stats(profiler, stream=results)
            stats.sort_stats('cumulative')
            stats.print_stats(100)

            json_in = json.loads(str(form['jsondata']))
            # Deunicode all strings (Invenio doesn't have unicode
            # support).
            json_in = json_unicode_to_utf8(json_in)

            json_data = json.loads(return_val)
            json_data.update({"profilerStats": "<pre style='overflow: scroll'>" + json_in['requestType'] + results.getvalue() + "</pre>"})
            return json.dumps(json_data)
        else:
            return func(self, req, form)
コード例 #38
0
 def __extract_attribute(self, req):
     """
     Load from the request the given assertion, extract all the attribute
     to properly login the user, and verify that the data are actually
     both well formed and signed correctly.
     """
     from invenio.webinterface_handler import wash_urlargd
     args = wash_urlargd(req.form, {
         'assertion': (str, ''),
         'robot': (str, ''),
         'digest': (str, ''),
         'login_method': (str, '')})
     assertion = args['assertion']
     digest = args['digest']
     robot = args['robot']
     login_method = args['login_method']
     shared_key = load_robot_keys().get(login_method, {}).get(robot)
     if shared_key is None:
         raise InvenioWebAccessExternalAuthError("A key does not exist for robot: %s, login_method: %s" % (robot, login_method))
     if not self.verify(shared_key, assertion, digest):
         raise InvenioWebAccessExternalAuthError("The provided assertion does not validate against the digest %s for robot %s" % (repr(digest), repr(robot)))
     if self.use_zlib:
         try:
             ## Workaround to Perl implementation that does not add
             ## any padding to the base64 encoding.
             needed_pad = (4 - len(assertion) % 4) % 4
             assertion += needed_pad * '='
             assertion = decompress(base64.urlsafe_b64decode(assertion))
         except:
             raise InvenioWebAccessExternalAuthError("The provided assertion is corrupted")
     data = json_unicode_to_utf8(json.loads(assertion))
     if not isinstance(data, dict):
         raise InvenioWebAccessExternalAuthError("The provided assertion is invalid")
     timeout = data[self.timeout_attribute_name]
     if timeout < time.time():
         raise InvenioWebAccessExternalAuthError("The provided assertion is expired")
     userip = data.get(self.userip_attribute_name)
     if not self.check_user_ip or (normalize_ip(userip, self.check_user_ip) == normalize_ip(req.remote_ip, self.check_user_ip)):
         return data
     else:
         raise InvenioWebAccessExternalAuthError("The provided assertion has been issued for a different IP address (%s instead of %s)" % (userip, req.remote_ip))
コード例 #39
0
    def create_authorpage_coauthors(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(
                    person_id)
                bibauthorid_data = {
                    'is_baid': True,
                    'pid': person_id,
                    'cid': None
                }
                if person_link and person_linkStatus:
                    bibauthorid_data = {
                        'is_baid': True,
                        'pid': person_id,
                        'cid': person_link
                    }

                coauthors, coauthorsStatus = get_coauthors(person_id)
                if not coauthors:
                    coauthors = dict()

                json_response['boxes_info'].update({
                    'coauthors': {
                        'status':
                        coauthorsStatus,
                        'html_content':
                        webauthorprofile_templates.tmpl_coauthor_box(
                            bibauthorid_data,
                            coauthors,
                            ln='en',
                            add_box=False,
                            loading=not coauthorsStatus)
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #40
0
    def create_authorpage_hepdata(self, req, form):
        if form.has_key('jsondata'):
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)

            webapi.session_bareinit(req)
            session = webapi.get_session(req)
            ulevel = session['personinfo']['ulevel']

            if json_data.has_key('personId'):
                person_id = json_data['personId']

                context, hepdictStatus = get_hepnames_data(person_id)
                if not hepdictStatus:
                    return json.dumps({'status': False, 'html': ''})

                context.update({
                    'cname':
                    webapi.get_canonical_id_from_person_id(person_id),
                    'link_to_record':
                    ulevel == "admin",
                    'hepnames_link':
                    "%s/%s/" % (CFG_BASE_URL, "record"),
                    'new_record_link':
                    'https://%s/submissions/authors?bai=%s' %
                    (CFG_LABS_HOSTNAME,
                     webapi.get_canonical_id_from_person_id(person_id)),
                    'update_link_prefix':
                    "https://%s/submissions/authors/" % CFG_LABS_HOSTNAME,
                    'update_link_suffix':
                    "",
                    'profile_link':
                    "%s/%s" % (CFG_BASE_URL, "author/profile/")
                })

                content = WebProfilePage.render_template(
                    'personal_details_box', context)

                json_response = {'status': hepdictStatus, 'html': content}
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #41
0
    def create_authorpage_keywords(self, req, form):
        if form.has_key('jsondata'):
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                kwtuples, kwtuplesStatus = get_kwtuples(person_id)
                if kwtuples:
                    pass
                    # kwtuples = kwtuples[0:MAX_KEYWORD_LIST]
                else:
                    kwtuples = list()

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(
                    person_id)
                bibauthorid_data = {
                    'is_baid': True,
                    'pid': person_id,
                    'cid': None
                }
                if person_link and person_linkStatus:
                    bibauthorid_data = {
                        'is_baid': True,
                        'pid': person_id,
                        'cid': person_link
                    }

                json_response = {
                    'status':
                    kwtuplesStatus,
                    'html':
                    webauthorprofile_templates.tmpl_keyword_box(
                        kwtuples,
                        bibauthorid_data,
                        ln='en',
                        add_box=False,
                        loading=not kwtuplesStatus)
                }
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #42
0
    def create_authorpage_pubs(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                pubs, pubsStatus = get_pubs(person_id)
                if not pubs:
                    pubs = list()

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(
                    person_id)
                bibauthorid_data = {
                    'is_baid': True,
                    'pid': person_id,
                    'cid': None
                }
                if person_link and person_linkStatus:
                    bibauthorid_data = {
                        'is_baid': True,
                        'pid': person_id,
                        'cid': person_link
                    }

                json_response['boxes_info'].update({
                    'numpaperstitle': {
                        'status':
                        pubsStatus,
                        'html_content':
                        webauthorprofile_templates.tmpl_numpaperstitle(
                            bibauthorid_data, pubs)
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #43
0
    def create_authorpage_pubs_list(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                internal_pubs, internal_pubsStatus = get_internal_publications(
                    person_id)
                external_pubs, external_pubsStatus = get_external_publications(
                    person_id)
                datasets_pubs, datasets_pubsStatus = get_datasets(person_id)

                #                if not internal_pubs:
                #                    internal_pubs = None
                #                if not external_pubs:
                #                    external_pubs = None
                # switched from 'orcid_info' to 'pubs_list'
                json_response['boxes_info'].update({
                    'pubs_list': {
                        'status': (internal_pubsStatus and external_pubsStatus
                                   and datasets_pubsStatus),
                        'html_content':
                        webauthorprofile_templates.tmpl_pubs_list(
                            internal_pubs,
                            external_pubs,
                            datasets_pubs,
                            ln='en',
                            add_box=False,
                            loading=not (internal_pubsStatus
                                         and external_pubsStatus))
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #44
0
    def create_authorpage_hepdata(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                hepdict, hepdictStatus = get_hepnames_data(person_id)

                json_response['boxes_info'].update({
                    'hepdata': {
                        'status':
                        hepdictStatus,
                        'html_content':
                        bibauthorid_template.tmpl_hepnames_box(
                            hepdict,
                            ln='en',
                            add_box=False,
                            loading=not hepdictStatus)
                    }
                })
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #45
0
    def create_authorpage_collaborations(self, req, form):
        if form.has_key('jsondata'):
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                collab, collabStatus = get_collabtuples(person_id)

                person_link, person_linkStatus = get_veryfy_my_pubs_list_link(
                    person_id)
                bibauthorid_data = {
                    'is_baid': True,
                    'pid': person_id,
                    'cid': None
                }
                if person_link and person_linkStatus:
                    bibauthorid_data = {
                        'is_baid': True,
                        'pid': person_id,
                        'cid': person_link
                    }

                json_response = {
                    'status':
                    collabStatus,
                    'html':
                    webauthorprofile_templates.tmpl_collab_box(
                        collab,
                        bibauthorid_data,
                        ln='en',
                        add_box=False,
                        loading=not collabStatus)
                }
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #46
0
    def create_authorpage_pubs_graph(self, req, form):
        if form.has_key('jsondata'):
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                pubs_per_year, pubs_per_yearStatus = get_pubs_per_year(
                    person_id)
                if not pubs_per_year:
                    pubs_per_year = dict()
                securelinks = req.is_https()
                json_response = {
                    'status':
                    pubs_per_yearStatus,
                    'html':
                    webauthorprofile_templates.tmpl_graph_box(
                        pubs_per_year,
                        ln='en',
                        loading=not pubs_per_yearStatus,
                        https=securelinks)
                }
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #47
0
    def create_authorpage_pubs_list(self, req, form):
        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if json_data.has_key('personId'):
                person_id = json_data['personId']

                internal_pubs, internal_pubsStatus = get_internal_publications(person_id)
                external_pubs, external_pubsStatus = get_external_publications(person_id)
                datasets_pubs, datasets_pubsStatus = get_datasets(person_id)

#                if not internal_pubs:
#                    internal_pubs = None
#                if not external_pubs:
#                    external_pubs = None
                # switched from 'orcid_info' to 'pubs_list'
                json_response['boxes_info'].update(
                             {'pubs_list': {'status': (internal_pubsStatus and external_pubsStatus and datasets_pubsStatus),
                             'html_content': webauthorprofile_templates.tmpl_pubs_list(internal_pubs,
                                             external_pubs, datasets_pubs, ln='en',
                              add_box=False, loading=not (internal_pubsStatus and external_pubsStatus))}})
                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #48
0
    def index(self, req, form):
        """Handle all BibMerge requests.
        The responsibilities of this functions are:
        * JSON decoding and encoding.
        * Redirection, if necessary.
        * Authorization.
        * Calling the appropriate function from the engine.
        """
        # If it is an Ajax request, extract any JSON data.
        ajax_request, recid1, recid2 = False, None, None
        argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG)})
        if form.has_key('jsondata'):
            json_data = json.loads(str(form['jsondata']))
            # Deunicode all strings (Invenio doesn't have unicode
            # support).
            json_data = json_unicode_to_utf8(json_data)
            ajax_request = True
            json_response = {}
            if json_data.has_key('recID1'):
                recid1 = json_data['recID1']
            if json_data.has_key('recID2'):
                recid2 = json_data['recID2']

        # Authorization.
        user_info = collect_user_info(req)
        if user_info['email'] == 'guest':
            # User is not logged in.
            if not ajax_request:
                # Do not display the introductory recID selection box to guest
                # users (as it used to be with v0.99.0):
                auth_code, auth_message = acc_authorize_action(req, 'runbibmerge')
                referer = '/merge/'
                return page_not_authorized(req=req, referer=referer,
                                           text=auth_message, navtrail=navtrail)
            else:
                # Session has most likely timed out.
                json_response.update({'resultCode': 1,
                                      'resultText': 'Error: Not logged in'})
                return json.dumps(json_response)

        elif self.recid:
            # Handle RESTful call by storing recid and redirecting to
            # generic URL.
            redirect_to_url(req, '%s/%s/merge/' % (CFG_SITE_SECURE_URL, CFG_SITE_RECORD) )

        if recid1 is not None:
            # Authorize access to record 1.
            auth_code, auth_message = acc_authorize_action(req, 'runbibmerge',
                collection=guess_primary_collection_of_a_record(recid1))
            if auth_code != 0:
                json_response.update({'resultCode': 1, 'resultText': 'No access to record %s' % recid1})
                return json.dumps(json_response)
        if recid2 is not None:
            # Authorize access to record 2.
            auth_code, auth_message = acc_authorize_action(req, 'runbibmerge',
                collection=guess_primary_collection_of_a_record(recid2))
            if auth_code != 0:
                json_response.update({'resultCode': 1, 'resultText': 'No access to record %s' % recid2})
                return json.dumps(json_response)

        # Handle request.
        uid = getUid(req)
        if not ajax_request:
            # Show BibEdit start page.
            body, errors, warnings = perform_request_init()
            metaheaderadd = """<script type="text/javascript" src="%(site)s/js/json2.js"></script>
  <script type="text/javascript" src="%(site)s/js/bibmerge_engine.js"></script>""" % {'site': CFG_SITE_SECURE_URL}
            title = 'Record Merger'
            return page(title         = title,
                        metaheaderadd = metaheaderadd,
                        body          = body,
                        errors        = errors,
                        warnings      = warnings,
                        uid           = uid,
                        language      = argd['ln'],
                        navtrail      = navtrail,
                        lastupdated   = __lastupdated__,
                        req           = req)
        else:
            # Handle AJAX request.
            json_response = perform_request_ajax(req, uid, json_data)
            return json.dumps(json_response)
コード例 #49
0
    def create_authorpage_pubs_list(self, req, form):
        def get_unsorted_datasets(items):
            return [(title, get_inspire_record_url(recid), recid)
                    for recid, title in items.iteritems()][0:10]

        def get_sorted_internal_pubs(items, order):
            result = []
            current_index = 0
            offset = 0
            while (current_index < 10 and current_index + offset < len(order)):
                recid = order[current_index + offset]
                if recid in items:
                    title = items[recid]
                    result.append(
                        (title, get_inspire_record_url(recid), recid))
                    current_index += 1
                else:
                    offset += 1
            return result

        if 'jsondata' in form:
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            if 'personId' in json_data:
                person_id = json_data['personId']

                try:
                    canonical_name = get_canonical_name_of_author(
                        person_id)[0][0]
                    internal_search_pubs = perform_request_search(
                        p="exactauthor:%s" % canonical_name,
                        sf="earliestdate",
                        so="d")
                except IndexError:
                    canonical_name = None
                    internal_search_pubs = []

                internal_pubs, internal_pubsStatus = get_internal_publications(
                    person_id)
                external_pubs, external_pubsStatus = get_external_publications(
                    person_id)
                datasets_pubs, datasets_pubsStatus = get_datasets(person_id)

                if internal_pubs is not None and internal_pubsStatus is True:
                    internal_pubs = \
                        get_sorted_internal_pubs(internal_pubs, internal_search_pubs)
                else:
                    internal_pubs = list()

                if datasets_pubs is not None and datasets_pubsStatus is True:
                    datasets_pubs_to_display = get_unsorted_datasets(
                        datasets_pubs)
                else:
                    datasets_pubs_to_display = list()

                arxiv_pubs = list()
                doi_pubs = list()
                if external_pubs is not None and external_pubsStatus is True:
                    if 'arxiv' in external_pubs:
                        arxiv_pubs = [(title, get_arxiv_url(arxiv_id), 'arxiv')
                                      for arxiv_id, title in
                                      external_pubs['arxiv'].iteritems()]

                    if 'doi' in external_pubs:
                        doi_pubs = [(title, get_doi_url(doi_id), 'doi')
                                    for doi_id, title in
                                    external_pubs['doi'].iteritems()]

                external_pubs = arxiv_pubs + doi_pubs

                all_pubs_search_link = "%s/search?p=exactauthor%%3A%s&sf=earliestdate" % (
                    CFG_BASE_URL, canonical_name)

                if datasets_pubs:
                    datasets_pubs_recs = [
                        'recid%%3A%s' % pub for pub in datasets_pubs
                    ]
                else:
                    datasets_pubs_recs = list()

                #TODO An operator should be introduced as this will not work for authors with many records.
                datasets_search_link = "%s/search?cc=Data&p=%s" % (
                    CFG_BASE_URL, '+or+'.join(datasets_pubs_recs))

                json_response = {
                    'status': (internal_pubsStatus and external_pubsStatus
                               and datasets_pubsStatus),
                    'html':
                    WebProfilePage.render_publications_box_content({
                        "internal_pubs":
                        internal_pubs,
                        "external_pubs":
                        external_pubs,
                        "datasets":
                        datasets_pubs_to_display,
                        "all_pubs_search_link":
                        all_pubs_search_link,
                        "data_sets_search_link":
                        datasets_search_link,
                        "base_url":
                        CFG_BASE_URL
                    })
                }

                req.content_type = 'application/json'
                return json.dumps(json_response)
コード例 #50
0
    def _process_json_request(self, form, req):
        """Takes care about the json requests."""

        argd = wash_urlargd(form, {self._JSON_DATA_KEY: (str, "")})

        # load json data
        json_data_string = argd[self._JSON_DATA_KEY]
        json_data_unicode = json.loads(json_data_string)
        json_data = json_unicode_to_utf8(json_data_unicode)

        language = json_data["language"]
        search_criteria = json_data["searchCriteria"]
        output_tags = json_data["outputTags"]
        output_tags = output_tags.split(",")
        output_tags = [tag.strip() for tag in output_tags]
        action_type = json_data["actionType"]
        current_record_id = json_data["currentRecordID"]
        commands = json_data["commands"]
        output_format = json_data["outputFormat"]
        page_to_display = json_data["pageToDisplay"]
        collection = json_data["collection"]
        compute_modifications = json_data["compute_modifications"]
        checked_records = json_data["checked_records"]

        json_response = {}
        if action_type == self._action_types.test_search:
            json_response.update(
                multi_edit_engine.perform_request_test_search(
                    search_criteria,
                    [],
                    output_format,
                    page_to_display,
                    language,
                    output_tags,
                    collection,
                    req=req,
                    checked_records=checked_records,
                )
            )
            json_response["display_info_box"] = 1
            json_response["info_html"] = ""
            return json.dumps(json_response)

        elif action_type == self._action_types.display_detailed_record:
            json_response.update(
                multi_edit_engine.perform_request_detailed_record(current_record_id, [], output_format, language)
            )
            return json.dumps(json_response)

        elif action_type == self._action_types.preview_results:
            commands_list, upload_mode, tag_list = self._create_commands_list(commands)
            json_response = {}
            json_response.update(
                multi_edit_engine.perform_request_test_search(
                    search_criteria,
                    commands_list,
                    output_format,
                    page_to_display,
                    language,
                    output_tags,
                    collection,
                    compute_modifications,
                    upload_mode,
                    req,
                    checked_records,
                )
            )
            return json.dumps(json_response)

        elif action_type == self._action_types.display_detailed_result:
            commands_list, upload_mode, tag_list = self._create_commands_list(commands)
            json_response.update(
                multi_edit_engine.perform_request_detailed_record(
                    current_record_id, commands_list, output_format, language
                )
            )
            return json.dumps(json_response)

        elif action_type == self._action_types.submit_changes:
            commands_list, upload_mode, tag_list = self._create_commands_list(commands)
            json_response.update(
                multi_edit_engine.perform_request_submit_changes(
                    search_criteria, commands_list, language, upload_mode, tag_list, collection, req, checked_records
                )
            )
            return json.dumps(json_response)

        # In case we obtain wrong action type we return empty page.
        return " "
コード例 #51
0
    def index(self, req, form):
        """Handle all BibMerge requests.
        The responsibilities of this functions are:
        * JSON decoding and encoding.
        * Redirection, if necessary.
        * Authorization.
        * Calling the appropriate function from the engine.
        """
        # If it is an Ajax request, extract any JSON data.
        ajax_request, recid1, recid2 = False, None, None
        argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG)})
        if form.has_key('jsondata'):
            json_data = json.loads(str(form['jsondata']))
            # Deunicode all strings (Invenio doesn't have unicode
            # support).
            json_data = json_unicode_to_utf8(json_data)
            ajax_request = True
            json_response = {}
            try:
                if json_data.has_key('recID1'):
                    recid1 = int(json_data['recID1'])
                    json_data['recID1'] = recid1
                if json_data.has_key('recID2'):
                    if json_data.get('record2Mode') == "recid":
                        recid2 = int(json_data['recID2'])
                        json_data['recID2'] = recid2
            except ValueError:
                json_response.update({
                    'resultCode': 1,
                    'resultText': 'Invalid record ID!'
                })
                return json.dumps(json_response)
            if json_data.has_key("duplicate"):
                if json_data.get('record2Mode') == "recid":
                    json_data["duplicate"] = int(json_data["duplicate"])

        # Authorization.
        user_info = collect_user_info(req)
        if user_info['email'] == 'guest':
            # User is not logged in.
            if not ajax_request:
                # Do not display the introductory recID selection box to guest
                # users (as it used to be with v0.99.0):
                auth_code, auth_message = acc_authorize_action(
                    req, 'runbibmerge')
                referer = '/merge/'
                return page_not_authorized(req=req,
                                           referer=referer,
                                           text=auth_message,
                                           navtrail=navtrail)
            else:
                # Session has most likely timed out.
                json_response.update({
                    'resultCode': 1,
                    'resultText': 'Error: Not logged in'
                })
                return json.dumps(json_response)

        elif self.recid:
            # Handle RESTful call by storing recid and redirecting to
            # generic URL.
            redirect_to_url(
                req, '%s/%s/merge/' % (CFG_SITE_SECURE_URL, CFG_SITE_RECORD))

        if recid1 is not None:
            # Authorize access to record 1.
            auth_code, auth_message = acc_authorize_action(
                req,
                'runbibmerge',
                collection=guess_primary_collection_of_a_record(recid1))
            if auth_code != 0:
                json_response.update({
                    'resultCode':
                    1,
                    'resultText':
                    'No access to record %s' % recid1
                })
                return json.dumps(json_response)
        if recid2 is not None:
            # Authorize access to record 2.
            auth_code, auth_message = acc_authorize_action(
                req,
                'runbibmerge',
                collection=guess_primary_collection_of_a_record(recid2))
            if auth_code != 0:
                json_response.update({
                    'resultCode':
                    1,
                    'resultText':
                    'No access to record %s' % recid2
                })
                return json.dumps(json_response)

        # Handle request.
        uid = getUid(req)
        if not ajax_request:
            # Show BibEdit start page.
            body, errors, warnings = perform_request_init()

            scripts = ["json2.js", "bibmerge_engine.js"]
            metaheaderadd = ""
            for script in scripts:
                metaheaderadd += '<script type="text/javascript" src="%s/%s"></script>' % (
                    CFG_SITE_URL, auto_version_url("js/" + script))

            return page(title='Record Merger',
                        metaheaderadd=metaheaderadd,
                        body=body,
                        errors=errors,
                        warnings=warnings,
                        uid=uid,
                        language=argd['ln'],
                        navtrail=navtrail,
                        lastupdated=__lastupdated__,
                        req=req)
        else:
            # Handle AJAX request.
            json_response = perform_request_ajax(req, uid, json_data)
            return json.dumps(json_response)
コード例 #52
0
    def index(self, req, form):
        """Handle all requests"""

        uid = getUid(req)
        argd = wash_urlargd(form, {'ln' : (str, CFG_SITE_LANG),
                           'state' : (str, '')})
        ln = argd['ln']
        state = argd['state']
        _ = gettext_set_language(ln)

        # Abort if the simplejson module isn't available
        if not CFG_JSON_AVAILABLE:
            title = 'Authorlist Manager'
            body = '''Sorry, the record editor cannot operate when the
                `simplejson' module is not installed.  Please see the INSTALL
                file.'''
            return page(title       = title,
                        body        = body,
                        errors      = [],
                        warnings    = [],
                        uid         = uid,
                        language    = ln,
                        navtrail    = navtrail,
                        lastupdated = __lastupdated__,
                        req         = req)

        # Extract additional JSON data from form
        if 'options' in form:
            options = json.loads(str(form['options']))
            # Deunicode all strings (Invenio doesn't have unicode
            # support).
            options = json_unicode_to_utf8(options)

        # Authorization.
        not_authorized = authorlist_engine.user_authorization(req, ln)
        if not_authorized:
            return not_authorized

        # User is authorized, let's handle different states
        # if no state parameter, load the main page
        if state == '':

            return page(title         = _('Author List Manager'),
                        metaheaderadd = authorlist_templates.index_header(),
                        body          = authorlist_templates.body(),
                        errors        = [],
                        warnings      = [],
                        uid           = uid,
                        language      = ln,
                        navtrail      = navtrail,
                        lastupdated   = __lastupdated__,
                        req           = req)

        elif state == 'itemize':
            data = authorlist_db.itemize(uid)

            req.content_type = 'application/json'
            req.write(json.dumps(data))

        # open paremeter set? initialize a Authorlist instance
        elif state == 'open':
            # if 'id' in url, check if user has right to modify this paper
            try:
                received = wash_urlargd(form, {'id': (str, None)})
                paper_id = received['id']

                if authorlist_engine.check_user_rights(uid, paper_id):
                    return page(title         = _('Author List Manager'),
                        metaheaderadd = authorlist_templates.list_header(),
                        body          = authorlist_templates.body(),
                        errors        = [],
                        warnings      = [],
                        uid           = uid,
                        language      = ln,
                        navtrail      = navtrail,
                        lastupdated   = __lastupdated__,
                        req           = req)
                else:
                    # no rights to modify this paper
                    redirect_to_url(req, '%s/authorlist/' % (CFG_SITE_URL))
            except:
                # redirect to the main page if weird stuff happens
                redirect_to_url(req, '%s/authorlist/' % (CFG_SITE_URL))
                        
        # On load state we will answer with the JSON encoded data of the passed 
        # paper id. Should usually not be directly surfed by the user.
        elif state == 'load':
            try:
                received = wash_urlargd(form, {'id': (str, None)})
                paper_id = received['id']
                data = authorlist_db.load(paper_id)
                
                req.content_type = 'application/json'
                req.write(json.dumps(data))
            except:
                # redirect to the main page if weird stuff happens
                redirect_to_url(req, '%s/authorlist/' % (CFG_SITE_URL))

        # The save state saves the send data in the database using the passed
        # paper id. Responds with a JSON object containing the id of the paper
        # as saved in the database. Should usually not be surfed directly by the
        # user
        elif state == 'save':
            try:
                received = wash_urlargd(form, {'id': (str, None),
                                               'data': (str, '')})
                paper_id = received['id']
                in_data = json.loads(received['data'])
                out_data = authorlist_db.save(paper_id, uid, in_data)

                req.content_type = 'application/json'
                req.write(json.dumps(out_data))
            except:
                # redirect to the main page if something weird happens
                redirect_to_url(req, '%s/authorlist/' % (CFG_SITE_URL))

        # Clones the paper with the given id in the database and responds with a
        # JSON object containing the id of the clone. Should usually not surfed
        # directly by the user.
        elif state == 'clone':
            try:
                received = wash_urlargd(form, {'id': (str, None)})
                paper_id = received['id']
                data = authorlist_db.clone(paper_id, uid)

                req.content_type = 'application/json'
                req.write(json.dumps(data))
            except:
                # redirect to the main page if something weird happens
                redirect_to_url(req, '%s/authorlist/' % (CFG_SITE_URL))

        # Transform the sent data into the format passed in the URL using a
        # authorlist_engine converter. Reponds with the MIME type of the
        # converter and offers it as a download (content-disposition header).
        elif state == 'export':
            try:
                received = wash_urlargd(form, {'format': (str, None),
                                               'data': (str, '')})
                data_format = received['format']
                data = received['data']

                converter = authorlist_engine.Converters.get(data_format)

                attachement = 'attachement; filename="%s"' % converter.FILE_NAME
                req.headers_out['Content-Type'] = converter.CONTENT_TYPE
                req.headers_out['Content-Disposition'] = attachement
                #redirect_to_url(req, authorlist_engine.dumps(data, converter))
                req.write(authorlist_engine.dumps(data, converter))
            except:
                # throw exception if something weird happens
                return sys.exc_info()

        elif state == 'delete':
            try:
                received = wash_urlargd(form, {'id': (str, None)})
                paper_id = received['id']

                data = authorlist_db.delete(paper_id)

                req.content_type = 'application/json'
                req.write(json.dumps(data))
            except:
                # redirect to the main page if something weird happens
                redirect_to_url(req, '%s/authorlist/' % (CFG_SITE_URL))

        elif state == 'import':
            try:
                received = wash_urlargd(form, {'importid': (str, None)})
                recID = received['importid']
                data = authorlist_engine.retrieve_data_from_record(recID)
                req.content_type = 'application/json'
                req.write(json.dumps(data))
            except:
                # redirect to the main page if something weird happens
                redirect_to_url(req, '%s/authorlist/' % (CFG_SITE_URL))

        elif state == 'importxml':
            try:
                received = wash_urlargd(form, {'xmlfile': (Field, None)})
                xml_string = received['xmlfile'].value
                import_data = authorlist_engine.retrieve_data_from_xml(xml_string)
                req.content_type = 'application/json'
                req.write(json.dumps(import_data))
            except:
                # redirect to the main page if something weird happens
                redirect_to_url(req, '%s/authorlist/' % (CFG_SITE_URL))
        # No state given, just go to the main page.
        else:
            redirect_to_url(req, '%s/authorlist/' % (CFG_SITE_URL))
コード例 #53
0
    def create_authorpage_websearch(self, req, form, person_id, ln='en', expire_cache=False):

        recompute_allowed = True

        oldest_cache_date = get_person_oldest_date(person_id)
        if oldest_cache_date:
            delay = datetime.datetime.now() - oldest_cache_date
            if delay > RECOMPUTE_ALLOWED_DELAY:
                if expire_cache:
                    recompute_allowed = False
                    expire_all_cache_for_person(person_id)
            else:
                recompute_allowed = False

        if CFG_WEBAUTHORPROFILE_USE_BIBAUTHORID:
            if person_id < 0:
                return ("Critical Error. PersonID should never be less than 0!")

        pubs, pubsStatus = get_pubs(person_id)
        if not pubs:
            pubs = []

        selfpubs, selfpubsStatus = get_self_pubs(person_id)
        if not selfpubs:
            selfpubs = []

        namesdict, namesdictStatus = get_person_names_dicts(person_id)
        if not namesdict:
            namesdict = {}

        try:
            authorname = namesdict['longest']
            db_names_dict = namesdict['db_names_dict']
        except (IndexError, KeyError):
            authorname = 'None'
            db_names_dict = {}

        #author_aff_pubs, author_aff_pubsStatus = (None, None)
        author_aff_pubs, author_aff_pubsStatus = get_institute_pub_dict(person_id)
        if not author_aff_pubs:
            author_aff_pubs = {}


        coauthors, coauthorsStatus = get_coauthors(person_id)
        if not coauthors:
            coauthors = {}

        summarize_records, summarize_recordsStatus = get_summarize_records(person_id, 'hcs', ln)
        if not summarize_records:
            summarize_records = 'None'

        totaldownloads, totaldownloadsStatus = get_total_downloads(person_id)
        if not totaldownloads:
            totaldownloads = 0

        citedbylist, citedbylistStatus = get_cited_by_list(person_id)
        if not citedbylist:
            citedbylist = 'None'

        kwtuples, kwtuplesStatus = get_kwtuples(person_id)
        if kwtuples:
            pass
            #kwtuples = kwtuples[0:MAX_KEYWORD_LIST]
        else:
            kwtuples = []

        collab, collabStatus = get_collabtuples(person_id)

        vtuples, venuetuplesStatus = get_venuetuples(person_id)
        if vtuples:
            pass
            #vtuples = venuetuples[0:MAX_VENUE_LIST]
        else:
            vtuples = str(vtuples)

        person_link, person_linkStatus = get_veryfy_my_pubs_list_link(person_id)
        if not person_link or not person_linkStatus:
            bibauthorid_data = {"is_baid": True, "pid":person_id, "cid": None}
            person_link = str(person_id)
        else:
            bibauthorid_data = {"is_baid": True, "pid":person_id, "cid": person_link}

        hepdict, hepdictStatus = get_hepnames_data(person_id)

        oldest_cache_date = get_person_oldest_date(person_id)

        #req.write("\nPAGE CONTENT START\n")
        #req.write(str(time.time()))
        #eval = [not_empty(x) or y for x, y in
        beval = [y for _, y in
                                               [(authorname, namesdictStatus) ,
                                               (totaldownloads, totaldownloadsStatus),
                                               (author_aff_pubs, author_aff_pubsStatus),
                                               (citedbylist, citedbylistStatus),
                                               (kwtuples, kwtuplesStatus),
                                               (coauthors, coauthorsStatus),
                                               (vtuples, venuetuplesStatus),
                                               (db_names_dict, namesdictStatus),
                                               (person_link, person_linkStatus),
                                               (summarize_records, summarize_recordsStatus),
                                               (pubs, pubsStatus),
                                               (hepdict, hepdictStatus),
                                               (selfpubs, selfpubsStatus),
                                               (collab, collabStatus)]]
        #not_complete = False in eval
        #req.write(str(eval))

        if form.has_key('jsondata'):
            json_response = {'boxes_info': {}}
            json_data = json.loads(str(form['jsondata']))
            json_data = json_unicode_to_utf8(json_data)
            # loop to check which boxes need content
            json_response['boxes_info'].update({'name_variants': {'status':beval[0], 'html_content': webauthorprofile_templates.tmpl_author_name_variants_box(req, db_names_dict, bibauthorid_data, ln, add_box=False, loading=not beval[0])}})
            json_response['boxes_info'].update({'combined_papers': {'status':(beval[3] and beval[12]), 'html_content': webauthorprofile_templates.tmpl_papers_with_self_papers_box(req, pubs, selfpubs, bibauthorid_data, totaldownloads, ln, add_box=False, loading=not beval[3])}})
            #json_response['boxes_info'].update({'papers': {'status':beval[3], 'html_content': webauthorprofile_templates.tmpl_papers_box(req, pubs, bibauthorid_data, totaldownloads, ln, add_box=False, loading=not beval[3])}})
            json_response['boxes_info'].update({'selfpapers': {'status':beval[12], 'html_content': webauthorprofile_templates.tmpl_self_papers_box(req, selfpubs, bibauthorid_data, totaldownloads, ln, add_box=False, loading=not beval[12])}})
            json_response['boxes_info'].update({'keywords': {'status':beval[4], 'html_content': webauthorprofile_templates.tmpl_keyword_box(kwtuples, bibauthorid_data, ln, add_box=False, loading=not beval[4])}})
            json_response['boxes_info'].update({'affiliations': {'status':beval[2], 'html_content': webauthorprofile_templates.tmpl_affiliations_box(author_aff_pubs, ln, add_box=False, loading=not beval[2])}})
            json_response['boxes_info'].update({'coauthors': {'status':beval[5], 'html_content': webauthorprofile_templates.tmpl_coauthor_box(bibauthorid_data, coauthors, ln, add_box=False, loading=not beval[5])}})
            json_response['boxes_info'].update({'numpaperstitle': {'status':beval[10], 'html_content': webauthorprofile_templates.tmpl_numpaperstitle(bibauthorid_data, pubs)}})
            json_response['boxes_info'].update({'authornametitle': {'status':beval[7], 'html_content': webauthorprofile_templates.tmpl_authornametitle(db_names_dict)}})
            json_response['boxes_info'].update({'citations': {'status':beval[9], 'html_content': summarize_records}})
            json_response['boxes_info'].update({'hepdata': {'status':beval[11], 'html_content':webauthorprofile_templates.tmpl_hepnames(hepdict, ln, add_box=False, loading=not beval[11])}})
            json_response['boxes_info'].update({'collaborations': {'status':beval[13], 'html_content': webauthorprofile_templates.tmpl_collab_box(collab, bibauthorid_data, ln, add_box=False, loading=not beval[13])}})

            req.content_type = 'application/json'
            req.write(json.dumps(json_response))
        else:
            gboxstatus = self.person_id
            if False not in beval:
                gboxstatus = 'noAjax'
            req.write('<script type="text/javascript">var gBOX_STATUS = "%s" </script>' % (gboxstatus))
            req.write(webauthorprofile_templates.tmpl_author_page(req,
                                            pubs, \
                                            selfpubs, \
                                            authorname, \
                                            totaldownloads, \
                                            author_aff_pubs, \
                                            citedbylist, kwtuples, \
                                            coauthors, vtuples, \
                                            db_names_dict, person_link, \
                                            bibauthorid_data, \
                                            summarize_records, \
                                            hepdict, \
                                            collab, \
                                            ln, \
                                            beval, \
                                            oldest_cache_date,
                                            recompute_allowed))
コード例 #54
0
    def index(self, req, form):
        """Handle all BibEdit requests.
        The responsibilities of this functions is:
        * JSON decoding and encoding.
        * Redirection, if necessary.
        * Authorization.
        * Calling the appropriate function from the engine.

        """
        uid = getUid(req)
        argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG)})
        # Abort if the simplejson module isn't available
        if not CFG_JSON_AVAILABLE:
            title = 'Record Editor'
            body = '''Sorry, the record editor cannot operate when the
                `simplejson' module is not installed.  Please see the INSTALL
                file.'''
            return page(title       = title,
                        body        = body,
                        errors      = [],
                        warnings    = [],
                        uid         = uid,
                        language    = argd['ln'],
                        navtrail    = navtrail,
                        lastupdated = __lastupdated__,
                        req         = req,
                        body_css_classes = ['bibedit'])

        # If it is an Ajax request, extract any JSON data.
        ajax_request, recid = False, None
        if form.has_key('jsondata'):
            json_data = json.loads(str(form['jsondata']))
            # Deunicode all strings (Invenio doesn't have unicode
            # support).
            json_data = json_unicode_to_utf8(json_data)
            ajax_request = True
            if json_data.has_key('recID'):
                recid = json_data['recID']
            json_response = {'resultCode': 0, 'ID': json_data['ID']}

        # Authorization.
        user_info = collect_user_info(req)
        if user_info['email'] == 'guest':
            # User is not logged in.
            if not ajax_request:
                # Do not display the introductory recID selection box to guest
                # users (as it used to be with v0.99.0):
                dummy_auth_code, auth_message = acc_authorize_action(req,
                                                                     'runbibedit')
                referer = '/edit/'
                if self.recid:
                    referer = '/%s/%s/edit/' % (CFG_SITE_RECORD, self.recid)
                return page_not_authorized(req=req, referer=referer,
                                           text=auth_message, navtrail=navtrail)
            else:
                # Session has most likely timed out.
                json_response.update({'resultCode': 100})
                return json.dumps(json_response)

        elif self.recid:
            # Handle RESTful calls from logged in users by redirecting to
            # generic URL.
            redirect_to_url(req, '%s/%s/edit/#state=edit&recid=%s&recrev=%s' % (
                    CFG_SITE_SECURE_URL, CFG_SITE_RECORD, self.recid, ""))

        elif recid is not None:
            json_response.update({'recID': recid})
            if json_data['requestType'] == "getRecord":
                # Authorize access to record.
                if not user_can_edit_record_collection(req, recid):
                    json_response.update({'resultCode': 101})
                    return json.dumps(json_response)

        # Handle request.
        if not ajax_request:
            # Show BibEdit start page.
            body, errors, warnings = perform_request_init(uid, argd['ln'], req, __lastupdated__)
            title = 'Record Editor'
            return page(title       = title,
                        body        = body,
                        errors      = errors,
                        warnings    = warnings,
                        uid         = uid,
                        language    = argd['ln'],
                        navtrail    = navtrail,
                        lastupdated = __lastupdated__,
                        req         = req,
                        body_css_classes = ['bibedit'])
        else:
            # Handle AJAX request.
            json_response.update(perform_request_ajax(req, recid, uid,
                                                      json_data))
            return json.dumps(json_response)
コード例 #55
0
ファイル: goto_engine.py プロジェクト: aw-bib/tind-invenio
 def get_json_parameters_from_cli(dummy_option, dummy_opt_str, value, parser):
     try:
         setattr(parser.values, 'parameters', json_unicode_to_utf8(json.loads(value)))
     except Exception, err:
         raise optparse.OptionValueError("Cannot parse as a valid JSON serialization the provided parameters: %s. %s" % (value, err))