Example #1
0
    def test_container_view(self):
        test_instance = self.test_model()
        a = Div()(test_instance)
        self.assertEqual(a.render(), '<div><p>foo</p><p>bar</p></div>')

        b = Span()(Div()(test_instance))
        self.assertEqual(b.render(),
                         '<span><div><p>foo</p><p>bar</p></div></span>')
Example #2
0
    def test_incomplete(self):
        class Test:
            def __init__(self):
                self.foo = 'foo'
                self.bar = 'bar'

            class HtmlREPR(TempyREPR):
                pass

        with self.assertRaises(IncompleteREPRError):
            a = Span()(Test())
            a.render()
Example #3
0
    def test_nameless_view(self):
        class Test:
            def __init__(self):
                self.foo = 'foo'
                self.bar = 'bar'

            class HtmlREPR(TempyREPR):
                def repr(self):
                    self(Div()(self.foo), Div()(self.bar))

        test_instance = Test()
        a = Span()(test_instance)
        self.assertEqual(a.render(),
                         '<span><div>foo</div><div>bar</div></span>')
Example #4
0
    def test_inside_places(self):
        class Obj:
            foo = 'foo'
            bar = 'bar'

            class TestA(InsideDiv):
                def repr(self):
                    self(self.bar)

            class A(InsideSpan):
                def repr(self):
                    self(self.foo + 'test')

            class Test2(InsideP):
                def repr(self):
                    self(self.bar + 'test')

        inst = Obj()
        self.assertEqual(Span()(A()(inst)).render(),
                         '<span><a>footest</a></span>')

        inst = Obj()
        self.assertEqual(Div()(Div()(inst)).render(),
                         '<div><div>bar</div></div>')

        inst = Obj()
        self.assertEqual(P()(T.CustomTag()(inst)).render(),
                         '<p><customtag>bartest</customtag></p>')
Example #5
0
    def test_root(self):
        class Obj:
            foo = 'foo'
            bar = 'bar'

            class Div(TempyREPR):
                def repr(self):
                    self(self.bar)

            class Pre(TempyREPR):
                def repr(self):
                    self(self.foo + 'test')

        inst = Obj()
        self.assertEqual(Pre()(Span()(A()(inst))).render(),
                         '<pre><span><a>footest</a></span></pre>')
Example #6
0
    def test_after_places(self):
        class Obj:
            foo = 'foo'
            bar = 'bar'

            class TestA(AfterDiv):
                def repr(self):
                    self(self.bar)

            class A(AfterSpan):
                def repr(self):
                    self(self.foo + 'test')

        inst = Obj()
        self.assertEqual(Pre()(Span(), A()(inst)).render(),
                         '<pre><span></span><a>footest</a></pre>')
        self.assertEqual(Pre()(Div(), Div()(inst)).render(),
                         '<pre><div></div><div>bar</div></pre>')
Example #7
0
    def test_near_places(self):
        class Obj:
            foo = 'foo'
            bar = 'bar'

            class TestA(NearDiv):
                def repr(self):
                    self(self.bar)

            class TestB(NearSpan):
                def repr(self):
                    self(self.foo + 'test')

        inst = Obj()
        self.assertEqual(Pre()(Span(), A()(inst)).render(),
                         '<pre><span></span><a>footest</a></pre>')
        self.assertEqual(Pre()(T.Custom()(inst), Div()).render(),
                         '<pre><custom>bar</custom><div></div></pre>')
Example #8
0
 def init(self):
     from pprint import pprint
     pprint(self.__dict__)
     self.head(self.css())
     self.head(
         Meta(charset="utf-8"),
         Meta(
             name="viewport",
             content="width=device-width, initial-scale=1, shrink-to-fit=no"
         ),
         Title()(f'{self.app.config.project_name} - {self.page_title}'))
     self.content_title = Div(
         klass='d-flex justify-content-between flex-wrap '
         'flex-md-nowrap align-items-center pb-2 mb-3 border-bottom')(
             H1(klass='h2')(self.page_title), self.breadcrumb)
     self.content = Div(
         klass=
         'd-flex justify-content-between flex-wrap pb-2 mb-3 flex-md-nowrap'
     )
     self.body(
         Nav(klass='navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0'
             )(A(klass='navbar-brand col-sm-3 col-md-2 mr-0',
                 href='/app')(self.app.config.project_name),
               Input(klass='form-control form-control-dark w-100',
                     typ='text',
                     placeholder='Search',
                     **{'aria-label': 'Search'}),
               Ul(klass='navbar-nav px-3')(Li(klass='nav-item text-nowrap')(
                   A(klass='nav-link', href='/signout')('Sign out')))),
         Div(klass="container-fluid")(Div(klass='row')(Nav(
             klass='col-md-2 d-none d-md-block bg-light sidebar'
         )(Div(klass='sidebar-sticky')(
             Ul(klass='nav flex-column')
             (Li(klass='nav-item')(A(klass='nav-link active', href='/app')(
                 I(klass='fas fa-home'
                   ),
                 ' Dashboard',
                 Span(klass='sr-only')
                 ('(current)')
             )),
              Li(klass=
                 'nav-item sidebar-heading d-flex justify-content-between '
                 'align-items-center px-3 mt-4 mb-1 text-muted')
              (A(klass='nav-link', href='/app/processes')(
                  I(klass="fas fa-chalkboard-teacher"),
                  ' Processes ',
              ),
               A(klass='navbar-toggler collapsed',
                 **{
                     "data-toggle": "collapse",
                     "data-target": "#processesList",
                     "aria-expanded": "false"
                 })(I(klass="fas fa-plus-circle navbar-toggler-icon"))),
              Div(klass="collapse",
                  id="processesList")(Ul(klass="nav flex-column")(
                      Li(klass='nav-item')(A(
                          href=f'/app/processes/{process.name.lower()}',
                          klass='nav-link')(I(
                              klass=f'fas {process.icon}'), ' ' +
                                            process.name.title()))
                      for process in self.app.processes.values()))),
             H6(klass='sidebar-heading d-flex justify-content-between '
                'align-items-center px-3 mt-4 mb-1 text-muted')(
                    Span()('Saved Links')),
         )),
                                                       Main(
                                                           role='main',
                                                           klass=
                                                           'col-md-9 ml-sm-auto col-lg-10 pt-3 px-4'
                                                       )(self.content_title,
                                                         self.content))),
         self.js())
Example #9
0
 def repr(self):
     self(
         Span(klass='personData')(B()('Name: '), self.name),
         Span(klass='personData')(B()('Second Name: '), self.second_name),
         Span(klass='personData')(B()('Birthday: '), self.birth_date.isoformat())
     )