def create_authorpage_websearch(self, req, form, ln='en', expire_cache=False): if CFG_WEBAUTHORPROFILE_USE_BIBAUTHORID: if self.person_id < 0: return ("Critical Error. Author identifier should never be smaller than 0!") assert not form.has_key('jsondata'), "Content type should be only text/html." oldest_cache_date = get_person_oldest_date(self.person_id) delay = datetime.now() - oldest_cache_date if delay > RECOMPUTE_ALLOWED_DELAY: recompute_allowed = True if expire_cache: expire_all_cache_for_person(self.person_id) return self.create_authorpage_websearch(req, form, ln, expire_cache=False) else: recompute_allowed = False gboxstatus = self.person_id gpid = self.person_id gNumOfWorkers = 3 # to do: read it from conf file gReqTimeout = 3000 gPageTimeout = 12000 head = '<script type="text/javascript">var gBOX_STATUS = "%s";var gPID = "%s"; var gNumOfWorkers= "%s"; var gReqTimeout= "%s"; var gPageTimeout= "%s";</script>' \ % (gboxstatus, gpid, gNumOfWorkers, gReqTimeout, gPageTimeout) body = webauthorprofile_templates.tmpl_author_page(ln, self.cid, oldest_cache_date, recompute_allowed) return {'head': head, 'body': body}
def create_authorpage_websearch(self, req, form, ln='en', expire_cache=False): if CFG_WEBAUTHORPROFILE_USE_BIBAUTHORID: if self.person_id < 0: return ( "Critical Error. Author identifier should never be smaller than 0!" ) assert not form.has_key( 'jsondata'), "Content type should be only text/html." oldest_cache_date = get_person_oldest_date(self.person_id) delay = datetime.now() - oldest_cache_date if delay > RECOMPUTE_ALLOWED_DELAY: recompute_allowed = True if expire_cache: expire_all_cache_for_person(self.person_id) return self.create_authorpage_websearch(req, form, ln, expire_cache=False) else: recompute_allowed = False gboxstatus = self.person_id gpid = self.person_id gNumOfWorkers = 3 # to do: read it from conf file gReqTimeout = 3000 gPageTimeout = 12000 head = '<script type="text/javascript">var gBOX_STATUS = "%s";var gPID = "%s"; var gNumOfWorkers= "%s"; var gReqTimeout= "%s"; var gPageTimeout= "%s";</script>' \ % (gboxstatus, gpid, gNumOfWorkers, gReqTimeout, gPageTimeout) body = webauthorprofile_templates.tmpl_author_page( ln, self.cid, oldest_cache_date, recompute_allowed) return {'head': head, 'body': body}
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 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))