Ejemplo n.º 1
0
    def content(self):
        elements = []

        if self.failed:
            elements.append(
                markup.error(
                    'Invalid user name or password.  Please try again.'))

        elements.append(
            html.form({
                'action': '/login_post',
                'method': 'post',
                'class': 'form-signin'
            })(html.h2('Log In', {'class': 'form-signin-heading'}),
               markup.text_input('username', placeholder='Username')({
                   'class':
                   'form-control'
               }), markup.password_input('password', placeholder='Password')({
                   'class':
                   'form-control'
               }), markup.submit_button('Log In')({
                   'class':
                   'btn btn-lg btn-inverse btn-block'
               })))

        return elements
Ejemplo n.º 2
0
    def content(self):
        div = html.div({
            'ng-controller': 'ImageController',
            'ng-init': 'init()'
        })
        form = html.form({
            'class': 'form-horizontal',
            'action': '/upload_post',
            'method': 'post',
            'enctype': 'multipart/form-data',
            'ng-submit': 'addTagsFromInput(tag_input)'
        })(html.input({
            'type': 'hidden',
            'name': 'tags',
            'value': '{{tags}}'
        }), html.div({'class': 'form-group'
                      })(html.img(id='upload-preview',
                                  src='/static/images/placeholder.png')),
           html.div({'class': 'form-group'})(html.input(id='image_selector',
                                                        type='file',
                                                        name='image_file')),
           html.div({'class': 'form-group'})(html.input({
               'type':
               'text',
               'placeholder':
               'Enter space-delimited tags',
               'ng-model':
               'tag_input',
               'ng-trim':
               'false',
               'class':
               'tag-input-box'
           })), html.div({'class': 'form-group'})(html.span({
               'ng-repeat':
               'tag in tags',
               'ng-click':
               'deleteTag(tag)',
               'ng-class':
               'getTagClasses(tag)'
           })("{{tag}}")),
           html.div({'class': 'form-group'})(html.textarea(name='summary',
                                                           id='summary_text')({
                                                               'class':
                                                               'summary',
                                                               'ng-model':
                                                               'summary'
                                                           }),
                                             html.div(id='summary_display')),
           html.div({'class': 'form-group'
                     })(markup.submit_button('Upload Image')(disabled=None)))

        return [markup.js('/static/js/image_upload.js'), div(form)]
Ejemplo n.º 3
0
    def content(self):
        container_div = html.div(
            {'ng-controller': 'ChangePasswordController as ctrl'})
        form = html.form(
            {
                'name': 'ctrl.form',
                'action': '/change_password_post',
                'method': 'post',
                'class': 'form-signin'
            }
        )(html.h2('Change Password', {'class': 'form-signin-heading'}),
          markup.password_input('old_password',
                                placeholder='your old password')({
                                    'ng-model':
                                    'ctrl.oldPassword',
                                    'class':
                                    'form-control'
                                }),
          markup.password_input('new_password_A',
                                placeholder='your new password')({
                                    'ng-model':
                                    'ctrl.newPasswordA',
                                    'class':
                                    'form-control'
                                }),
          markup.password_input('new_password_B',
                                placeholder='confirm new password')({
                                    'ng-model':
                                    'ctrl.newPasswordB',
                                    'class':
                                    'form-control'
                                }),
          markup.submit_button('Change Password')({
              'ng-disabled':
              '(!ctrl.newPasswordA.trim()) || (ctrl.newPasswordA != ctrl.newPasswordB)',
              'class':
              'btn btn-lg btn-inverse btn-block'
          }))

        if self.failed:
            container_div(
                markup.error('Old password is incorrect, please try again.'))

        return container_div(form)
Ejemplo n.º 4
0
    def render(self):
        login_elements = []

        if self.user.is_guest():
            login_elements = [
                html.li(html.p({'class': 'navbar-text'})('Not logged in')),
                html.li(
                    html.a('Login', markup.icon('sign-in'),
                           {'href': '/login'}))
            ]
        else:
            login_elements = [
                html.li(
                    html.p({'class': 'navbar-text'
                            })('Logged in as %s' % self.user.username)),
                html.li(
                    html.a('Logout', markup.icon('sign-out'),
                           {'href': '/logout'}))
            ]

        return html.nav({'class': 'navbar navbar-inverse navbar-fixed-top'})(
            html.div({'class': 'container-fluid'
                      })(html.div({'class': 'navbar-header'})(html.button({
                          'type':
                          'button',
                          'class':
                          'navbar-toggle collapsed',
                          'data-toggle':
                          'collapse',
                          'data-target':
                          '#navbar',
                          'aria-expanded':
                          'false',
                          'aria-controls':
                          'navbar'
                      })(html.span({'class': 'sr-only'})('Toggle navigation'),
                         html.span({'class': 'icon-bar'}),
                         html.span({'class': 'icon-bar'}),
                         html.span({
                             'class': 'icon-bar'
                         })), html.a({
                             'class': 'navbar-brand',
                             'href': '/'
                         })(markup.icon('camera-retro'), "Jenna's Photo Box")),
                         html.div({
                             'id': 'navbar',
                             'class': 'navbar-collapse collapse'
                         })(html.ul({'class': 'nav navbar-nav navbar-right'
                                     })(login_elements, [
                                         html.li(
                                             html.a(href=action().href)(
                                                 action().label,
                                                 markup.icon(action().icon)))
                                         for action in Action.values()
                                         if action().is_available(self.user)
                                     ]),
                            html.form({
                                'class': 'navbar-form navbar-right',
                                'action': '/search',
                                'method': 'get'
                            })(html.input({
                                'type': 'text',
                                'name': 'query',
                                'class': 'form-control',
                                'placeholder': 'Search with tags'
                            })))))
Ejemplo n.º 5
0
    def content(self):
        div = html.div({
            'ng-controller': 'ImageController',
            'ng-init': 'init()'
        })

        image_dao = self.dao_factory.get_image_dao()
        image = image_dao.get(self.id)

        if not image.can_edit(self.user):
            raise AccessDenied(
                'User "%s" is not allowed to edit image with id "%s".' %
                (user.username, image.id))

        form = html.form({
            'class': 'form-horizontal',
            'action': '/edit_post',
            'method': 'post',
            'ng-submit': 'addTagsFromInput(tag_input)'
        })(html.input({
            'type': 'hidden',
            'name': 'id',
            'value': image.id
        }), html.input({
            'type': 'hidden',
            'name': 'tags',
            'value': '{{tags}}'
        }),
           html.input({
               'type': 'hidden',
               'id': 'init_tag_list',
               'value': json.dumps(sorted(list(image.tags)))
           }), html.div({'class': 'form-group'
                         })(html.img(id='upload-preview',
                                     src='/images/' + image.get_filename())),
           html.div({'class': 'form-group'})(html.input({
               'type': 'text',
               'placeholder': 'Enter space-delimited tags',
               'ng-model': 'tag_input',
               'ng-trim': 'false'
           })), html.div({'class': 'form-group'})(html.span({
               'ng-repeat':
               'tag in tags',
               'ng-click':
               'deleteTag(tag)',
               'ng-class':
               'getTagClasses(tag)'
           })("{{tag}}")),
           html.div({'class':
                     'form-group'})(html.textarea(name='summary',
                                                  id='summary_text')({
                                                      'class':
                                                      'summary',
                                                      'ng-model':
                                                      'summary',
                                                      'data-textarea-content':
                                                      image.summary
                                                  }),
                                    html.div(id='summary_display')),
           html.div({'class':
                     'form-group'})(markup.submit_button('Edit Image')))

        return div(form)