Ejemplo n.º 1
0
    def handler(self):
        # get fields
        self._articlesList = self.get_articles()
        if self._articlesList:
            # format all paragraphs
            self._articlesList[0]['description'] = helpers.paragraph_filter(
                self._articlesList[0]['description']
            )

            self.projectDict = self._articlesList[0]
            self.loggedContext = {
                'title': self.projectDict.get('title')
                ,'description': self.projectDict.get('description')
                ,'salir': True
                ,'classification': self.projectDict.get('classification')
                ,'country': self.projectDict.get('country')
                ,'state': self.projectDict.get('state')
                ,'city': self.projectDict.get('city')
                ,'autor': self.projectDict.get('autor')
                ,'colaborators': self.projectDict.get('colaborators')
                ,'project_date': self.projectDict.get('project_date')
            }
            self.loggedTemplatePath = 'applications/home/views/article.html'
            self.unloggedTemplatePath = self.loggedTemplatePath
            self.unloggedContext = self.loggedContext.copy()
            self.unloggedContext['salir'] = False
            self.logged(
                context=self.loggedContext
                ,templatePath=self.loggedTemplatePath
            )
            self.unlogged(
                context=self.unloggedContext
                ,templatePath=self.unloggedTemplatePath
            )
        # launch 404 error if url is not found
        else:
            self.loggedContext = {
                'url': self.clientModel.url
                ,'title': '404 No encontrado'
                ,'salir': True}
            self.loggedTemplatePath = 'applications/error/error404.html'
            self.unloggedTemplatePath = self.loggedTemplatePath
            self.unloggedContext = self.loggedContext.copy()
            self.unloggedContext['salir'] = False
            self.response.set_status(404)
            self.logged(
                context=self.loggedContext
                ,templatePath=self.loggedTemplatePath
            )
            self.unlogged(
                context=self.unloggedContext
                ,templatePath=self.unloggedTemplatePath
            )
Ejemplo n.º 2
0
 def test_paragraph_filter(self):
     expectedValues = (
         ("a", "<p>a</p>"),
         ("\na", "<p>a</p>"),
         ("\r\r\na", "<p>a</p>"),
         ("a\n", "<p>a</p>"),
         ("a\n\r", "<p>a</p>"),
         ("\na\n", "<p>a</p>"),
         ("\ra", "<p>a</p>"),
         ("a\r", "<p>a</p>"),
         ("\ra\r", "<p>a</p>"),
         ("\na\r", "<p>a</p>"),
         ("\ra\n", "<p>a</p>"),
         ("a\nb", "<p>a</p><p>b</p>"),
         ("a\rb", "<p>a</p><p>b</p>"),
         ("a\n\nb", "<p>a</p><p>b</p>"),
         ("a\r\rb", "<p>a</p><p>b</p>"),
         ("a\n\rb", "<p>a</p><p>b</p>"),
         ("a\r\nb", "<p>a</p><p>b</p>"),
     )
     for unformatText, expected in expectedValues:
         obtained = helpers.paragraph_filter(unformatText)
         self.assertEqual(obtained, expected)