Example #1
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)]
Example #2
0
 def password_input(self, name, placeholder=None):
     password_element = html.input(type='password', name=name, id=name)({
         'class':
         'password-input'
     })
     if placeholder is not None:
         password_element(placeholder=placeholder)
     return password_element
Example #3
0
 def text_input(self, name, value=None, placeholder=None):
     input_element = html.input(type='text', name=name, id=name)({
         'class':
         'text-input'
     })
     if value is not None:
         input_element(value=value)
     if placeholder is not None:
         input_element(placeholder=placeholder)
     return input_element
Example #4
0
    def render(self):
        container = html.div({'class': 'left-nav'})

        if self.tags:
            container({
                'ng-controller': 'ImageController',
                'ng-init': 'init()'
            })

            container(
                html.input({
                    'id': 'init_tag_list',
                    'type': 'hidden',
                    'value': json.dumps(self.tags)
                }))

        row = html.div({'class': 'row image-controls'})
        user = self.auth.get_user()
        if self.image and user:
            user_tag = 'user:%s' % user.username
            if self.image.can_edit(user):
                row(
                    markup.button('Edit',
                                  '/edit?' + urlencode({'id': self.image.id}),
                                  lefticon='pencil-square-o'))
                container(row)

        if self.tags:
            row = html.div({'class': 'row', 'ng-show': 'tags.length > 0'})
            container(row)

            row(
                html.a({
                    'ng-repeat': 'tag in tags',
                    'ng-href': '/search?query={{tag}}'
                })(html.span({'ng-class': 'getTagClasses(tag)'}, '{{tag}}')))

        return container
Example #5
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'
                            })))))
Example #6
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)