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)
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)
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)
def index(self, req, form): ''' Serve the main person page. Will use the object's person id to get a person's information. @param req: apache request object @type req: apache request object @param form: POST/GET variables of the request @type form: dict @return: a full page formatted in HTML @return: str ''' webapi.session_bareinit(req) session = webapi.get_session(req) pinfo = session['personinfo'] ulevel = pinfo['ulevel'] argd = wash_urlargd( form, { 'ln': (str, CFG_SITE_LANG), 'recompute': (int, 0), 'verbose': (int, 0), 'trial': (str, None) }) ln = argd['ln'] debug = "verbose" in argd and argd["verbose"] > 0 # Create Page Markup and Menu try: int(self.person_id) except ValueError: cname = self.person_id else: cname = webapi.get_canonical_id_from_person_id(self.person_id) menu = WebProfileMenu(str(cname), "profile", ln, self._is_profile_owner(pinfo['pid']), self._is_admin(pinfo)) profile_page = WebProfilePage( "profile", webapi.get_longest_name_from_pid(self.person_id)) profile_page.add_profile_menu(menu) if 'form_email' in pinfo: gFormEmail = pinfo['form_email'] else: gFormEmail = "" profile_page.add_bootstrapped_data( json.dumps({ "backbone": """ (function(ticketbox) { var app = ticketbox.app; app.userops.set(%s); app.bodyModel.set({userLevel: "%s"}); })(ticketbox);""" % (WebInterfaceAuthorTicketHandling.bootstrap_status( pinfo, "user"), ulevel), "other": "var gUserLevel = '%s'; var gFormEmail = '%s';" % (ulevel, gFormEmail) })) if debug: profile_page.add_debug_info(pinfo) last_computed = str(self.last_computed()) context = { 'person_id': self.person_id, 'last_computed': last_computed, 'citation_fine_print_link': "%s/help/citation-metrics" % CFG_BASE_URL, 'search_form_url': "%s/author/search" % CFG_BASE_URL, 'possible_to_recompute': self._possible_to_recompute(pinfo) } verbose = argd['verbose'] url_args = dict() if ln != CFG_SITE_LANG: url_args['ln'] = ln if verbose: url_args['verbose'] = str(verbose) encoded = urlencode(url_args) if encoded: encoded = '&' + encoded if CFG_BIBAUTHORID_ENABLED: if self.person_id < 0: return redirect_to_url( req, '%s/author/search?q=%s%s' % (CFG_SITE_URL, self.original_search_parameter, encoded)) else: self.person_id = self.original_search_parameter profile_page.menu = None assert not form.has_key( 'jsondata'), "Content type should be only text/html." full_name = webapi.get_longest_name_from_pid(self.person_id) page_title = '%s - Profile' % full_name if argd['recompute'] and req.get_method() == 'POST': expire_all_cache_for_person(self.person_id) context['last_computed'] = str( datetime.now().replace(microsecond=0)) history_log_visit(req, 'profile', pid=self.person_id) meta = profile_page.get_head() context["visible"] = AID_VISIBILITY context["element_width"] = self.render_width_dict body = profile_page.get_wrapped_body("profile_page", context) return page(title=page_title, metaheaderadd=meta.encode('utf-8'), body=body.encode('utf-8'), req=req, language=ln, show_title_p=False)
def index(self, req, form): ''' Serve the main person page. Will use the object's person id to get a person's information. @param req: apache request object @type req: apache request object @param form: POST/GET variables of the request @type form: dict @return: a full page formatted in HTML @return: str ''' webapi.session_bareinit(req) session = webapi.get_session(req) pinfo = session['personinfo'] ulevel = pinfo['ulevel'] argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG), 'recompute': (int, 0), 'verbose': (int, 0)}) ln = argd['ln'] debug = "verbose" in argd and argd["verbose"] > 0 # Create Page Markup and Menu cname = webapi.get_canonical_id_from_person_id(self.person_id) menu = WebProfileMenu(str(cname), "profile", ln, self._is_profile_owner(pinfo['pid']), self._is_admin(pinfo)) profile_page = WebProfilePage("profile", webapi.get_longest_name_from_pid(self.person_id)) profile_page.add_profile_menu(menu) gboxstatus = self.person_id gpid = self.person_id gNumOfWorkers = 3 # to do: read it from conf file gReqTimeout = 5000 gPageTimeout = 120000 profile_page.add_bootstrapped_data(json.dumps({ "other": "var gBOX_STATUS = '%s';var gPID = '%s'; var gNumOfWorkers= '%s'; var gReqTimeout= '%s'; var gPageTimeout= '%s';" % (gboxstatus, gpid, gNumOfWorkers, gReqTimeout, gPageTimeout), "backbone": """ (function(ticketbox) { var app = ticketbox.app; app.userops.set(%s); app.bodyModel.set({userLevel: "%s"}); })(ticketbox);""" % (WebInterfaceAuthorTicketHandling.bootstrap_status(pinfo, "user"), ulevel) })) if debug: profile_page.add_debug_info(pinfo) verbose = argd['verbose'] url_args = dict() if ln != CFG_SITE_LANG: url_args['ln'] = ln if verbose: url_args['verbose'] = str(verbose) encoded = urlencode(url_args) if encoded: encoded = '&' + encoded if CFG_WEBAUTHORPROFILE_USE_BIBAUTHORID: if self.person_id < 0: return redirect_to_url(req, '%s/author/search?q=%s%s' % (CFG_SITE_URL, self.original_search_parameter, encoded)) else: self.person_id = self.original_search_parameter assert not form.has_key('jsondata'), "Content type should be only text/html." title_message = 'Author Publication Profile Page' expire_cache = False if argd['recompute'] and req.get_method() == 'POST': expire_cache = True content = self.create_authorpage_websearch(req, form, ln, expire_cache) history_log_visit(req, 'profile', pid = self.person_id) if isinstance(content, dict): meta = profile_page.get_head() + content['head'] body = profile_page.get_wrapped_body(content['body']) return page(title=title_message, metaheaderadd=meta.encode('utf-8'), body=body.encode('utf-8'), req=req, language=ln, show_title_p=False) else: return page(title=title_message, metaheaderadd="", body="Error, no content returned!".encode('utf-8'), req=req, language=ln, show_title_p=False)
def index(self, req, form): ''' Serve the main person page. Will use the object's person id to get a person's information. @param req: apache request object @type req: apache request object @param form: POST/GET variables of the request @type form: dict @return: a full page formatted in HTML @return: str ''' webapi.session_bareinit(req) session = webapi.get_session(req) pinfo = session['personinfo'] ulevel = pinfo['ulevel'] argd = wash_urlargd(form, { 'ln': (str, CFG_SITE_LANG), 'recompute': (int, 0), 'verbose': (int, 0) }) ln = argd['ln'] debug = "verbose" in argd and argd["verbose"] > 0 # Create Page Markup and Menu cname = webapi.get_canonical_id_from_person_id(self.person_id) menu = WebProfileMenu(str(cname), "profile", ln, self._is_profile_owner(pinfo['pid']), self._is_admin(pinfo)) profile_page = WebProfilePage( "profile", webapi.get_longest_name_from_pid(self.person_id)) profile_page.add_profile_menu(menu) gboxstatus = self.person_id gpid = self.person_id gNumOfWorkers = 3 # to do: read it from conf file gReqTimeout = 5000 gPageTimeout = 120000 profile_page.add_bootstrapped_data( json.dumps({ "other": "var gBOX_STATUS = '%s';var gPID = '%s'; var gNumOfWorkers= '%s'; var gReqTimeout= '%s'; var gPageTimeout= '%s';" % (gboxstatus, gpid, gNumOfWorkers, gReqTimeout, gPageTimeout), "backbone": """ (function(ticketbox) { var app = ticketbox.app; app.userops.set(%s); app.bodyModel.set({userLevel: "%s"}); })(ticketbox);""" % (WebInterfaceAuthorTicketHandling.bootstrap_status( pinfo, "user"), ulevel) })) if debug: profile_page.add_debug_info(pinfo) verbose = argd['verbose'] url_args = dict() if ln != CFG_SITE_LANG: url_args['ln'] = ln if verbose: url_args['verbose'] = str(verbose) encoded = urlencode(url_args) if encoded: encoded = '&' + encoded if CFG_WEBAUTHORPROFILE_USE_BIBAUTHORID: if self.person_id < 0: return redirect_to_url( req, '%s/author/search?q=%s%s' % (CFG_SITE_URL, self.original_search_parameter, encoded)) else: self.person_id = self.original_search_parameter assert not form.has_key( 'jsondata'), "Content type should be only text/html." title_message = 'Author Publication Profile Page' expire_cache = False if argd['recompute'] and req.get_method() == 'POST': expire_cache = True content = self.create_authorpage_websearch(req, form, ln, expire_cache) history_log_visit(req, 'profile', pid=self.person_id) if isinstance(content, dict): meta = profile_page.get_head() + content['head'] body = profile_page.get_wrapped_body(content['body']) return page(title=title_message, metaheaderadd=meta.encode('utf-8'), body=body.encode('utf-8'), req=req, language=ln, show_title_p=False) else: return page(title=title_message, metaheaderadd="", body="Error, no content returned!".encode('utf-8'), req=req, language=ln, show_title_p=False)