Esempio n. 1
0
    def rule_factory(self):
        mapper = mapping.Mapper()

        # add rules
        mapper.add_rule(mapping.Route('/'), _name='default')
        mapper.add_rule(mapping.Route('/(?P<id>\w+)'), _name='r1')
        mapper.add_rule(mapping.Route('/(?P<id>\d+)'), _name='r2')

        return mapper
Esempio n. 2
0
    def __init__(self):
        super().__init__()

        self.mapper.add_rule(mapping.Route('/'), _handler=self.list_posts)
        self.mapper.add_rule(mapping.Route('/post/(?P<id>\d+)'),
                             _handler=self.show_post)
        self.mapper.add_rule(mapping.Route('/compose'), _handler=self.add_post)

        # add the `templates` folder as template source for the `views`
        # component
        self.views.add_path(
            os.path.join(os.path.dirname(__file__), 'templates'))
        self.views.add_default('url_for', self.url_for)

        # try to create the database tables if needed
        models.Post.metadata.create_all(self.db.get_engine())
Esempio n. 3
0
 def setup_mapping(self, add_rule: mapping.Mapper.add_rule, base_path='/'):
     add_rule(mapping.Route(base_path), _handler=self.list_posts)
     add_rule(mapping.Route(''.join((base_path, '(?P<id>\d+)'))),
              _handler=self.show_post)
     add_rule(mapping.Route(''.join((base_path, 'compose'))),
              _handler=self.compose_post)
Esempio n. 4
0
 def rule_factory(self):
     return mapping.Route('/(?P<id>\d+)/(?P<name>\w+)', name='name')
Esempio n. 5
0
 def __init__(self):
     self.mapper.add_rule(mapping.Route('/'), _handler=self.list_posts)
     self.mapper.add_rule(mapping.Route('/post/(?P<id>\d+)'),
                          _handler=self.show_post)
     self.mapper.add_rule(mapping.Route('/compose'), _handler=self.add_post)