Example #1
0
 def button(self, label, action, lefticon=None, righticon=None):
     button = html.a(href=action)({'class': 'btn btn-inverse'})
     if lefticon is not None:
         button(self.icon(lefticon))
     button(label)
     if righticon is not None:
         button(self.icon(righticon))
     return button
Example #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
Example #3
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
            })
        ]
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 link(self, title, href):
     return html.a(title, href=href)
Example #6
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'
                            })))))