Example #1
0
    def showWebpage(self, maxlength=50):
        """ return the webpage as a tag """
        url = self.webpage
        if url.startswith("http"):
            title = url.replace("http://", "")
        else:
            title = url
            url = "http://" + url

        if len(title) > maxlength:
            title = title[: maxlength / 2 - 1] + "..." + title[-(maxlength / 2 + 1) :]

        title = FriedUtils.html_quote(title)
        return '<a href="%s">%s</a>' % (url, title)
Example #2
0
 def test_environment_variable_functions(self):
     os.environ['NAME'] = 'Peter'
     self.assertEqual(Utils.getEnvStr('NAME', 'Default'), 'Peter')
     
     self.assertEqual(Utils.getEnvStr('ZAHXSF','Default'), 'Default')
     
     os.environ['AGE'] = '27'
     self.assertEqual(Utils.getEnvInt('AGE', 28), 27)
     self.assertEqual(Utils.getEnvInt('KILOS', 100), 100)
     
     self.assertEqual(Utils.getEnvBool('GAY', False), False)
     os.environ['HAPPY'] = 'Yes'
     self.assertEqual(Utils.getEnvBool('HAPPY', False), True)
Example #3
0
    def doSearch(self, q, by=['title','searchable_text']):
        """ do they actual search """
        
        catalog = self.getCatalog()
        ok_search_keys = ('id','title','searchable_text')
        if FriedUtils.same_type(by, 's'):
            by = [by]

        by = [x for x in by if x in ok_search_keys]

        if not by:
            return []

        try:
            brains = []
            for searchkey in by:
                brains += apply(catalog.searchResults, (), {searchkey:q})

        except Exception, m:
            self.REQUEST.set('SEARCH_ERROR',m)
            LOG("%s.Homepage" % self.ProjectName(), INFO, "doSearch() error",
                error=sys.exc_info())
            return []