def create_authorpage_keywords(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']

                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['boxes_info'].update({
                    'keywords': {
                        'status':
                        kwtuplesStatus,
                        'html_content':
                        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)
    def create_authorpage_keywords(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']

                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['boxes_info'].update({
                    'keywords': {
                        'status':
                        kwtuplesStatus,
                        'html_content':
                        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)
    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))
    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))