Ejemplo n.º 1
0
    def get_publications_by_person(self,first="",last="",crs=""):
        """ This functionality should return publications against a person
        This has not been implemented
        Just returns dummy results
        Called from static/grantajax.js
        
        Args:
            first: the first name  - this is not case sensitive.
            last: the last name - this is not case sensitive
            crs: this is the cambridge specific CRSID that is sent to
                LDAP to get full details
            
        Returns:
            html code to embed directly on the page
        """

        searchInfo = "No search performed!"
        # if we have crs, use that
        if(crs != ""):
            try:
                fullName = query.find_full_name_by_crs(crs)
                firstLastName = query.crs_name_to_first_last(fullName)
                first = firstLastName["FirstName"]
                last = firstLastName["LastName"]
                result = query.test_fake_find_publications(first,last)
                searchInfo = "Sources: "
                searchInfo += "<searchterm>crs lookup</searchterm>"
                searchInfo += "<searchterm>GtR</searchterm>"
                searchInfo += " - Search terms: "
                searchInfo += "<searchterm><searchkey>crs</searchkey><searchvalue>"+crs+"</searchvalue></searchterm>"
                searchInfo += " - Looked up: "
                searchInfo += "<searchterm><searchkey>first name</searchkey><searchvalue>"+first+"</searchvalue></searchterm>"
                searchInfo += "<searchterm><searchkey>last name</searchkey><searchvalue>"+last+"</searchvalue></searchterm>"
            except query.NoResultError:
                return "<div class='centrebox'>No results found</div>"
        else:
            # look up researcher by name
            try: 
                result = query.test_fake_find_publications(first,last)
                searchInfo = "Sources: "
                searchInfo += "<searchterm>GtR</searchterm>"
                searchInfo += " - Search terms: "
                if(first!=""):
                    searchInfo += "<searchterm><searchkey>first name</searchkey><searchvalue>"+first+"</searchvalue></searchterm>"
                searchInfo += "<searchterm><searchkey>last name</searchkey><searchvalue>"+last+"</searchvalue></searchterm>"
            except query.NoResultError:
                return "<div class='centrebox'>No results found</div>"
        
        pageHTML = ""
        
        pageHTML += "<div class='groupingbox' ondrop='dropPubOnResultsBox(event)' ondragover='allowDrop(event)'>"
        pageHTML += "<div class='header'>Search Results</div>"
        
        pageHTML += "<div id='pub_search_results'>"
        for publication in result:
            pageHTML += self.get_publication_html(publication,"XXX")
        
        pageHTML += "</div>"
        pageHTML += "</div>"
        
        return pageHTML
Ejemplo n.º 2
0
    def get_grants_by_name(self,first="",last="",crs=""):
        """ Return all Grants from the GTR database based against
        a search based on name of priniciple/co investigator on the grant
        The calls to gtr are configured in the config file.
        
        Called from static/grantajax.js
        
        Args:
            first: the first name  - this is not case sensitive.
            last: the last name - this is not case sensitive
            crs: this is the cambridge specific CRSID that is sent to
                LDAP to get full details
            
        Returns:
            html code to embed directly on the page        
        """
        searchInfo = "No search performed!"
        # if we have crs, use that
        if(crs != ""):
            try:
                fullName = query.find_full_name_by_crs(crs)
                firstLastName = query.crs_name_to_first_last(fullName)
                first = firstLastName["FirstName"]
                last = firstLastName["LastName"]
                result = query.find_grants_by_first_last(first,last,self.allconfig["keys"]["orgname"],self.allconfig["keys"]["orgcode"])
                searchInfo = "Sources: "
                searchInfo += "<searchterm>crs lookup</searchterm>"
                searchInfo += "<searchterm>GtR</searchterm>"
                searchInfo += " - Search terms: "
                searchInfo += "<searchterm><searchkey>crs</searchkey><searchvalue>"+crs+"</searchvalue></searchterm>"
                searchInfo += " - Looked up: "
                searchInfo += "<searchterm><searchkey>first name</searchkey><searchvalue>"+first+"</searchvalue></searchterm>"
                searchInfo += "<searchterm><searchkey>last name</searchkey><searchvalue>"+last+"</searchvalue></searchterm>"
            except query.NoResultError:
                return "<div class='centrebox'>No results found</div>"
        else:
            # look up researcher by name
            try: 
                result = query.find_grants_by_first_last(first,last,self.allconfig["keys"]["orgname"], self.allconfig["keys"]["orgcode"])
                searchInfo = "Sources: "
                searchInfo += "<searchterm>GtR</searchterm>"
                searchInfo += " - Search terms: "
                if(first!=""):
                    searchInfo += "<searchterm><searchkey>first name</searchkey><searchvalue>"+first+"</searchvalue></searchterm>"
                searchInfo += "<searchterm><searchkey>last name</searchkey><searchvalue>"+last+"</searchvalue></searchterm>"
            except query.NoResultError:
                return "<div class='centrebox'>No results found</div>"
        
        pageHTML = ""
        csvResults = ""
        
        # search information
        pageHTML += "<div class='groupingbox'>"
        pageHTML += "<div class='header'>Search Information</div>"
        pageHTML += "<div class='subtext'>"+searchInfo+"</div>"
        pageHTML += "</div>"
       # print(len(result))
        # prepare data for output
        researcherList = set()
        for project in result:
            
            writtenName = project.Researcher.FirstName + " " + project.Researcher.LastName
            
            researcherList.add(writtenName)
            # also create the CSV data
            csvResults += "{0},{1},{2},{3},{4},{5}<br/>".format(project.ProjectName.replace(",",""),project.ProjectFunder,project.GrantReference,project.StartDate,project.EndDate,project.PoundValue)
            
            
        # output
        for researcher in researcherList:
            researcherID = str(hash(researcher))
            
            pageHTML += "<div class='groupingbox'>"
            pageHTML += "<div class='floatingbutton' onclick=selectByResearcher(\""+researcherID+"\")>Add all</div>"
            pageHTML += "<div class='header'>"+researcher+"</div>"
            pageHTML += "<div id='researcher_box_"+researcherID+"'>"
            pageHTML += "<div id='allchosen_"+researcherID+"' hidden='true' class='result result_fake'>All this researcher's grants have been added</div>"
                                
            for project in result:
                # check if it is for this researcher
                writtenName = project.Researcher.FirstName + " " + project.Researcher.LastName
                if(researcherID == str(hash(writtenName))):
                    # add the row
                    pageHTML += self.get_result_row_html(project,researcherID)
            
            pageHTML += "</div>"
            pageHTML += "</div>"

        pageHTML += "<div class='groupingbox'>"
        pageHTML += "<div class='header'>Search for more</div>"
        pageHTML += "<div id='search_by_title_results'></div>"+self.get_titlesearch()
        pageHTML += "</div>" # close the grouping box
        
        pageHTML += "</div>" # close the centerbox
        # csv box
        csvResults = "<div class='csv'>"+csvResults+"</div>"
        return pageHTML + csvResults