def _get_veryfy_my_pubs_list_link_bai(person_id):
    ''' Returns canonical name links. '''
    person_link = person_id
    cid = get_person_redirect_link(person_id)

    if is_valid_canonical_id(cid):
        person_link = cid
    return person_link
def _get_veryfy_my_pubs_list_link_bai(person_id):
    ''' Returns canonical name links. '''
    person_link = person_id
    cid = get_person_redirect_link(person_id)

    if is_valid_canonical_id(cid):
        person_link = cid
    return person_link
    def __init__(self, identifier=None):
        '''
        Constructor of the web interface.

        @param identifier: identifier of an author. Can be one of:
            - an author id: e.g. "14"
            - a canonical id: e.g. "J.R.Ellis.1"
            - a bibrefrec: e.g. "100:1442,155"
        @type identifier: str
        '''
        self.person_id = -1   # -1 is a non valid author identifier
        self.cid = None
        self.original_search_parameter = identifier

        if (not CFG_WEBAUTHORPROFILE_USE_BIBAUTHORID or
            identifier is None or
            not isinstance(identifier, str)):
            return

        # check if it's a canonical id: e.g. "J.R.Ellis.1"
        pid = int(get_person_id_from_canonical_id(identifier))
        if pid >= 0:
            self.person_id = pid
            self.cid = get_person_redirect_link(self.person_id)
            return

        # check if it's an author id: e.g. "14"
        try:
            pid = int(identifier)
            if author_has_papers(pid):
                self.person_id = pid
                cid = get_person_redirect_link(pid)
                # author may not have a canonical id
                if is_valid_canonical_id(cid):
                    self.cid = cid
                return
        except ValueError:
            pass

        # check if it's a bibrefrec: e.g. "100:1442,155"
        if is_valid_bibref(identifier):
            pid = int(get_person_id_from_paper(identifier))
            if pid >= 0:
                self.person_id = pid
                self.cid = get_person_redirect_link(self.person_id)
                return
    def __init__(self, identifier=None):
        '''
        Constructor of the web interface.

        @param identifier: identifier of an author. Can be one of:
            - an author id: e.g. "14"
            - a canonical id: e.g. "J.R.Ellis.1"
            - a bibrefrec: e.g. "100:1442,155"
        @type identifier: str
        '''
        self.person_id = -1  # -1 is a non valid author identifier
        self.cid = None
        self.original_search_parameter = identifier

        self._prepare_render_variables()

        if (not CFG_BIBAUTHORID_ENABLED or identifier is None
                or not isinstance(identifier, str)):
            return

        # check if it's a canonical id: e.g. "J.R.Ellis.1"
        pid = int(get_person_id_from_canonical_id(identifier))
        if pid >= 0:
            self.person_id = pid
            self.cid = get_person_redirect_link(self.person_id)
            return

        # check if it's an author id: e.g. "14"
        try:
            self.person_id = int(identifier)
            cid = get_person_redirect_link(pid)
            # author may not have a canonical id
            if is_valid_canonical_id(cid):
                self.cid = cid
            return
        except ValueError:
            pass

        # check if it's a bibrefrec: e.g. "100:1442,155"
        if is_valid_bibref(identifier):
            pid = int(get_person_id_from_paper(identifier))
            if pid >= 0:
                self.person_id = pid
                self.cid = get_person_redirect_link(self.person_id)
                return
    def __call__(self, req, form):
        '''
        Serves 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
        @rtype: str
        '''
        if not CFG_WEBAUTHORPROFILE_USE_BIBAUTHORID:
            self.person_id = self.original_search_parameter
            return self.index(req, form)

        argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG),
                                   'recid': (int, -1),
                                   'verbose': (int, 0)})

        ln = argd['ln']
        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 self.cid is not None and self.original_search_parameter != self.cid:
            return redirect_to_url(req, '%s/author/profile/%s%s' % (CFG_SITE_URL, self.cid, encoded))

        # author may have only author identifier and not a canonical id
        if self.person_id > -1:
            return self.index(req, form)

        recid = argd['recid']
        if recid > -1:
            possible_authors = search_person_ids_by_name(self.original_search_parameter, limit_to_recid = recid)

            if len(possible_authors) == 1:
                self.person_id = possible_authors[0][0]
                self.cid = get_person_redirect_link(self.person_id)
                redirect_to_url(req, '%s/author/profile/%s%s' % (CFG_SITE_URL, self.cid, encoded))

        encoded = urlencode(url_args)
        if encoded:
            encoded = '&' + encoded

        return redirect_to_url(req, '%s/author/search?q=%s%s' %
                                    (CFG_SITE_URL, self.original_search_parameter, encoded))
    def __call__(self, req, form):
        '''
        Serves 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
        @rtype: str
        '''
        if not CFG_BIBAUTHORID_ENABLED:
            self.person_id = self.original_search_parameter
            return self.index(req, form)

        argd = wash_urlargd(form, {
            'ln': (str, CFG_SITE_LANG),
            'recid': (int, -1),
            'verbose': (int, 0)
        })

        ln = argd['ln']
        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 self.cid is not None and self.original_search_parameter != self.cid:
            return redirect_to_url(
                req,
                '%s/author/profile/%s%s' % (CFG_SITE_URL, self.cid, encoded))

        # author may have only author identifier and not a canonical id
        if self.person_id > -1:
            return self.index(req, form)

        recid = argd['recid']

        if recid > -1:
            possible_authors = get_authors_by_name(
                self.original_search_parameter, limit_to_recid=recid)

            if len(possible_authors) == 1:
                self.person_id = possible_authors.pop()
                self.cid = get_person_redirect_link(self.person_id)
                redirect_to_url(
                    req, '%s/author/profile/%s%s' %
                    (CFG_SITE_URL, self.cid, encoded))

        encoded = urlencode(url_args)
        if encoded:
            encoded = '&' + encoded

        return redirect_to_url(
            req, '%s/author/search?q=%s%s' %
            (CFG_SITE_URL, self.original_search_parameter, encoded))
    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 __init__(self, person_id=None):
        """
        Constructor of the web interface.

        @param person_id: The identifier of a user. Can be one of:
            - a bibref: e.g. "100:1442,155"
            - a person id: e.g. "14"
            - a canonical id: e.g. "Ellis_J_1"
        @type person_id: string

        @return: will return an empty object if the identifier is of wrong type
        @rtype: None (if something is not right)
        """
        self.person_id = None
        self.cid = None
        self.original_search_parameter = person_id

        if not CFG_WEBAUTHORPROFILE_USE_BIBAUTHORID:
            return

        if (not person_id) or (not isinstance(person_id, str)):
            return

        try:
            self.person_id = int(person_id)
            self.cid = get_person_redirect_link(self.person_id)
            return
        except (TypeError, ValueError):
            pass

        try:
            self.person_id = int(get_person_id_from_canonical_id(person_id))
            if self.person_id < 0:
                if is_valid_canonical_id(person_id):
                    self.cid = None
                    return
                else:
                    raise ValueError
            self.cid = get_person_redirect_link(self.person_id)
            return
        except (ValueError, TypeError):
            pass

        fail_bibrecref = False
        if person_id.count(":") and person_id.count(","):
            bibref = person_id
            table, ref, bibrec = None, None, None

            if not bibref.count(":"):
                fail_bibrecref = True

            if not bibref.count(","):
                fail_bibrecref = True

            try:
                table = bibref.split(":")[0]
                ref = bibref.split(":")[1].split(",")[0]
                bibrec = bibref.split(":")[1].split(",")[1]
            except IndexError:
                fail_bibrecref = True
            try:
                table = int(table)
                ref = int(ref)
                bibrec = int(bibrec)
            except (ValueError, TypeError):
                fail_bibrecref = True

            try:
                pid = int(get_person_id_from_paper(person_id))
            except (ValueError, TypeError):
                fail_bibrecref = True

            if not fail_bibrecref:
                self.person_id = pid
                self.cid = self.cid = get_person_redirect_link(self.person_id)
                return

        self.person_id = -1
    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 __init__(self, person_id=None):
        """
        Constructor of the web interface.

        @param person_id: The identifier of a user. Can be one of:
            - a bibref: e.g. "100:1442,155"
            - a person id: e.g. "14"
            - a canonical id: e.g. "Ellis_J_1"
        @type person_id: string

        @return: will return an empty object if the identifier is of wrong type
        @rtype: None (if something is not right)
        """
        self.person_id = None
        self.cid = None
        self.original_search_parameter = person_id

        if not CFG_WEBAUTHORPROFILE_USE_BIBAUTHORID:
            return

        if (not person_id) or (not isinstance(person_id, str)):
            return

        try:
            self.person_id = int(person_id)
            self.cid = get_person_redirect_link(self.person_id)
            return
        except (TypeError, ValueError):
            pass

        try:
            self.person_id = int(get_person_id_from_canonical_id(person_id))
            if self.person_id < 0:
                if is_valid_canonical_id(person_id):
                    self.cid = None
                    return
                else:
                    raise ValueError
            self.cid = get_person_redirect_link(self.person_id)
            return
        except (ValueError, TypeError):
            pass

        fail_bibrecref = False
        if person_id.count(":") and person_id.count(","):
            bibref = person_id
            table, ref, bibrec = None, None, None

            if not bibref.count(":"):
                fail_bibrecref = True

            if not bibref.count(","):
                fail_bibrecref = True

            try:
                table = bibref.split(":")[0]
                ref = bibref.split(":")[1].split(",")[0]
                bibrec = bibref.split(":")[1].split(",")[1]
            except IndexError:
                fail_bibrecref = True
            try:
                table = int(table)
                ref = int(ref)
                bibrec = int(bibrec)
            except (ValueError, TypeError):
                fail_bibrecref = True

            try:
                pid = int(get_person_id_from_paper(person_id))
            except (ValueError, TypeError):
                fail_bibrecref = True

            if not fail_bibrecref:
                self.person_id = pid
                self.cid = self.cid = get_person_redirect_link(self.person_id)
                return

        self.person_id = -1