def _get_pubs_bai(person_id):
    '''
    Person's publication list.
    @param person_id: int person id
    '''
    full_pubs = get_papers_by_person_id(person_id, -1)
    pubs = [int(row[0]) for row in full_pubs]
    return pubs
def _get_pubs_bai(person_id):
    '''
    Person's publication list.
    @param person_id: int person id
    '''
    full_pubs = get_papers_by_person_id(person_id, -1)
    pubs = [int(row[0]) for row in full_pubs]
    return pubs
    def __call__(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: Parameters sent via GET or POST request
        @type form: dict

        @return: a full page formatted in HTML
        @return: string
        '''
        argd = wash_urlargd(form,
                    {'ln': (str, CFG_SITE_LANG),
                     'verbose': (int, 0),
                     'recid': (int, -1)
                     })
        recid = argd['recid']

        if not CFG_WEBAUTHORPROFILE_USE_BIBAUTHORID:
            return self.index(req, form)

        if self.cid:
            return redirect_to_url(req, '%s/author/%s/' % (CFG_SITE_URL, self.cid))
        elif self.person_id and self.person_id >= 0:
            return redirect_to_url(req, '%s/author/%s/' % (CFG_SITE_URL, self.person_id))

        elif self.person_id and recid > -1:
            #we got something different from person_id, canonical name or bibrefrec pair.
            #try to figure out a personid
            argd = wash_urlargd(form,
                                {'ln': (str, CFG_SITE_LANG),
                                 'verbose': (int, 0),
                                 'recid': (int, -1)
                                 })
            recid = argd['recid']
            if not recid:
                return redirect_to_url(req, "%s/person/search?q=%s" %
                    (CFG_SITE_URL, self.original_search_parameter))
                # req.write("Not enough search parameters %s"%
                #    str(self.original_search_parameter))

            nquery = self.original_search_parameter
            sorted_results = search_person_ids_by_name(nquery)
            test_results = None
            authors = []

            for results in sorted_results:
                pid = results[0]
                authorpapers = get_papers_by_person_id(pid, -1)
                authorpapers = sorted(authorpapers, key=itemgetter(0),
                                      reverse=True)

                if (recid and
                    not (str(recid) in [row[0] for row in authorpapers])):
                    continue

                authors.append([results[0], results[1],
                                authorpapers[0:4]])

            test_results = authors
            if len(test_results) == 1:
                self.person_id = test_results[0][0]
                self.cid = get_person_redirect_link(self.person_id)
                if self.cid and self.person_id > -1:
                    redirect_to_url(req, '%s/author/%s/' % (CFG_SITE_URL, self.cid))
                elif self.person_id > -1:
                    redirect_to_url(req, '%s/author/%s/' % (CFG_SITE_URL, self.person_id))
                else:
                    return redirect_to_url(req, "%s/person/search?q=%s" %
                    (CFG_SITE_URL, self.original_search_parameter))
                    #req.write("Could not determine personID from bibrec. What to do here? %s"%
                    #str(self.original_search_parameter))
            else:
                return redirect_to_url(req, "%s/person/search?q=%s" %
                    (CFG_SITE_URL, self.original_search_parameter))
                #req.write("Could not determine personID from bibrec. What to do here 2? %s"%
                #   (str(self.original_search_parameter),str(recid)))

        else:
            return redirect_to_url(req, "%s/person/search?q=%s" %
                    (CFG_SITE_URL, self.original_search_parameter))
    def __call__(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: Parameters sent via GET or POST request
        @type form: dict

        @return: a full page formatted in HTML
        @return: string
        '''
        argd = wash_urlargd(form,
                    {'ln': (str, CFG_SITE_LANG),
                     'verbose': (int, 0),
                     'recid': (int, -1)
                     })
        recid = argd['recid']

        if not CFG_WEBAUTHORPROFILE_USE_BIBAUTHORID:
            return self.index(req, form)

        if self.cid:
            return redirect_to_url(req, '%s/author/%s/' % (CFG_SITE_URL, self.cid))
        elif self.person_id and self.person_id >= 0:
            return redirect_to_url(req, '%s/author/%s/' % (CFG_SITE_URL, self.person_id))

        elif self.person_id and recid > -1:
            #we got something different from person_id, canonical name or bibrefrec pair.
            #try to figure out a personid
            argd = wash_urlargd(form,
                                {'ln': (str, CFG_SITE_LANG),
                                 'verbose': (int, 0),
                                 'recid': (int, -1)
                                 })
            recid = argd['recid']
            if not recid:
                return redirect_to_url(req, "%s/person/search?q=%s" %
                    (CFG_SITE_URL, self.original_search_parameter))
                # req.write("Not enough search parameters %s"%
                #    str(self.original_search_parameter))

            nquery = self.original_search_parameter
            sorted_results = search_person_ids_by_name(nquery)
            test_results = None
            authors = []

            for results in sorted_results:
                pid = results[0]
                authorpapers = get_papers_by_person_id(pid, -1)
                authorpapers = sorted(authorpapers, key=itemgetter(0),
                                      reverse=True)

                if (recid and
                    not (str(recid) in [row[0] for row in authorpapers])):
                    continue

                authors.append([results[0], results[1],
                                authorpapers[0:4]])

            test_results = authors
            if len(test_results) == 1:
                self.person_id = test_results[0][0]
                self.cid = get_person_redirect_link(self.person_id)
                if self.cid and self.person_id > -1:
                    redirect_to_url(req, '%s/author/%s/' % (CFG_SITE_URL, self.cid))
                elif self.person_id > -1:
                    redirect_to_url(req, '%s/author/%s/' % (CFG_SITE_URL, self.person_id))
                else:
                    return redirect_to_url(req, "%s/person/search?q=%s" %
                    (CFG_SITE_URL, self.original_search_parameter))
                    #req.write("Could not determine personID from bibrec. What to do here? %s"%
                    #str(self.original_search_parameter))
            else:
                return redirect_to_url(req, "%s/person/search?q=%s" %
                    (CFG_SITE_URL, self.original_search_parameter))
                #req.write("Could not determine personID from bibrec. What to do here 2? %s"%
                #   (str(self.original_search_parameter),str(recid)))

        else:
            return redirect_to_url(req, "%s/person/search?q=%s" %
                    (CFG_SITE_URL, self.original_search_parameter))