Exemple #1
0
 def body(self):
     content = self.content()
     nav = self.nav.render()
     return [
         self.header.render(),
         html.div({'class': 'container-fluid'
                   })(html.div({'class':
                                'row'})(html.div({'class':
                                                  'col-md-2'})(nav),
                                        html.div({'class':
                                                  'col-md-10'})(content)))
     ]
Exemple #2
0
    def content(self):
        results = []
        image_dao = self.dao_factory.get_image_dao()

        # Non logged in users must only see images with 'public'
        if not self.user.has_right(UserRight.USER):
            self.tags.append('public')
            self.ntags = list(filter(lambda x: x != 'public', self.ntags))

        images, count = image_dao.find(self.tags, self.ntags,
                                       self.image_page_size,
                                       self.image_page_size * (self.page - 1))

        self.nav.set_tags_from_images(images)

        row = html.div({'class': 'row'})
        ul = html.ul({'class': 'pagination'})
        row(ul)

        page_count = 1 + int((count - 1) / (self.image_page_size or 1))
        if page_count > 1:
            for x in range(0, page_count):
                page_num = x + 1
                button = markup.button(
                    '%d' % page_num, '/search?' + urlencode({
                        'query': self.query,
                        'page': page_num
                    }))
                ul(button)

                if self.page == page_num:
                    button({'class': 'btn-current'})
                else:
                    button({'class': 'btn-inverse'})

        results.append(row)

        row = html.div({'class': 'row'})
        debug_n = 0
        for image in images:
            debug_n += 1
            row(
                html.div({'class':
                          'col-md-3 image-result debug-%d' % debug_n})(html.a(
                              {'href': '/view?id=%s' % image.id})(html.img({
                                  'src':
                                  '/images/mini/' + image.get_filename(),
                                  'class':
                                  'mini-image'
                              }))))
        results.append(row)

        return results
Exemple #3
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)]
Exemple #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
Exemple #5
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)
Exemple #6
0
    def content(self):
        image_dao = self.dao_factory.get_image_dao()
        image = image_dao.get(self.id)
        if not image:
            raise cherrypy.NotFound()

        self.nav.set_image(image)

        return [
            html.a({'href': '/images/' + image.get_filename()})(html.img({
                'src':
                '/images/' + image.get_filename(),
                'class':
                'image-view'
            })),
            html.div({
                'id': 'summary_display',
                'data-markdown': image.summary
            })
        ]
Exemple #7
0
 def error(self, message):
     return html.div({'class':
                      'alert alert-danger'})(self.icon('times-circle'),
                                             message)
Exemple #8
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'
                            })))))
Exemple #9
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)