Exemple #1
0
 def _render_hidden_widgets(self, request):
     r = TemplateIO(html=1)
     for widget in self.widget_order:
         if widget.widget_type == 'hidden':
             r += widget.render(request)
             r += self._render_error(self.error.get(widget.name))
     return r.getvalue()
Exemple #2
0
 def _render_body(self):
     r = TemplateIO(html=True)
     if self.has_errors():
         r += self._render_error_notice()
     r += self._render_widgets()
     r += self._render_submit_widgets()
     return r.getvalue()
Exemple #3
0
 def _q_index(self):
     """
     If directory listings are allowed, generate a simple HTML
     listing of the directory's contents with each item hyperlinked;
     if the item is a subdirectory, place a '/' after it. If not allowed,
     return a page to that effect.
     """
     if self.index_filenames:
         for name in self.index_filenames:
             try:
                 obj = self._q_lookup(name)
             except errors.TraversalError:
                 continue
             if (not isinstance(obj, StaticDirectory)
                     and hasattr(obj, '__call__')):
                 return obj()
     if self.list_directory:
         title = 'Index of %s' % quixote.get_path()
         r = TemplateIO(html=True)
         template = htmltext('<a href="%s">%s</a>%s\n')
         r += htmltext('<pre>')
         r += template % ('..', '..', '')
         files = os.listdir(self.path)
         files.sort()
         for filename in files:
             filepath = os.path.join(self.path, filename)
             marker = os.path.isdir(filepath) and "/" or ""
             r += template % (urllib.parse.quote(filename), filename, marker)
         r += htmltext('</pre>')
         body = r.getvalue()
     else:
         title = 'Directory listing denied'
         body = htmltext('<p>This directory does not allow its contents '
                         'to be listed.</p>')
     return errors.format_page(title, body)
Exemple #4
0
 def _render_start(self, request, action,
                   enctype=None, method='post', name=None):
     r = TemplateIO(html=1)
     r += htmltag('form', enctype=enctype, method=method,
                  action=action, name=name)
     r += self._render_hidden_widgets(request)
     return r.getvalue()
Exemple #5
0
 def _render_submit_buttons(self, request, ncols=3):
     r = TemplateIO(html=1)
     r += htmltext('<tr><td colspan="%d">\n') % ncols
     for button in self.submit_buttons:
         r += button.render(request)
     r += htmltext('</td></tr>')
     return r.getvalue()
Exemple #6
0
 def _q_index(self):
     """
     If directory listings are allowed, generate a simple HTML
     listing of the directory's contents with each item hyperlinked;
     if the item is a subdirectory, place a '/' after it. If not allowed,
     return a page to that effect.
     """
     if self.index_filenames:
         for name in self.index_filenames:
             try:
                 obj = self._q_lookup(name)
             except errors.TraversalError:
                 continue
             if (not isinstance(obj, StaticDirectory)
                     and hasattr(obj, '__call__')):
                 return obj()
     if self.list_directory:
         title = 'Index of %s' % quixote.get_path()
         r = TemplateIO(html=True)
         template = htmltext('<a href="%s">%s</a>%s\n')
         r += htmltext('<pre>')
         r += template % ('..', '..', '')
         files = os.listdir(self.path)
         files.sort()
         for filename in files:
             filepath = os.path.join(self.path, filename)
             marker = os.path.isdir(filepath) and "/" or ""
             r += template % (urllib.quote(filename), filename, marker)
         r += htmltext('</pre>')
         body = r.getvalue()
     else:
         title = 'Directory listing denied'
         body = htmltext('<p>This directory does not allow its contents '
                         'to be listed.</p>')
     return errors.format_page(title, body)
Exemple #7
0
 def _render_start(self):
     r = TemplateIO(html=True)
     r += htmltag('form', method=self.method,
                  enctype=self.enctype, action=self.action,
                  **self.attrs)
     r += self._render_hidden_widgets()
     return r.getvalue()
Exemple #8
0
def listkeywords(base, kwlist, bigletter=False):
    kwlist.sort()

    r = TemplateIO(html=True)
    
    if not kwlist:
        return r

    if len(kwlist) > 10:
        divide = 'p'
    else:
        divide = 'span'

    char = None

    kwlist.sort()

    for k in kwlist:
        if k[0] != char:
            if char:
                r += H('</%s>\n' % divide) 
            r += H('<%s class="emphasize %s">\n' % (divide, bigletter and 'bigletter' or ''))
            char = k[0]
        r += H('  <a class="kw" href="%s%s/">%s</a>\n') % (base, k, k)
    if char:
        r += H('</%s>\n' % divide) 

    return r.getvalue()
Exemple #9
0
 def _render_finish(self):
     r = TemplateIO(html=True)
     r += htmltext('</form><br class="quixoteform" />')
     code = get_request().response.javascript_code
     if code:
         r += self._render_javascript(code)
     return r.getvalue()
Exemple #10
0
 def _render_body(self):
     r = TemplateIO(html=True)
     if self.has_errors():
         r += self._render_error_notice()
     r += self._render_widgets()
     r += self._render_submit_widgets()
     return r.getvalue()
Exemple #11
0
 def _render_start(self):
     r = TemplateIO(html=True)
     r += htmltag('form', name=self.name, method=self.method,
                  enctype=self.enctype, action=self.action_url,
                  **self.attrs)
     r += self._render_hidden_widgets()
     return r.getvalue()
Exemple #12
0
 def _render_finish(self):
     r = TemplateIO(html=True)
     r += htmltext('</form><br class="quixoteform" />')
     code = get_request().response.javascript_code
     if code:
         r += self._render_javascript(code)
     return r.getvalue()
Exemple #13
0
 def _render_submit_widgets(self):
     r = TemplateIO(html=True)
     if self.submit_widgets:
         r += htmltext('<div class="submit">')
         for widget in self.submit_widgets:
             r += widget.render()
         r += htmltext('</div><br class="submit" />')
     return r.getvalue()
Exemple #14
0
 def _render_submit_widgets(self):
     r = TemplateIO(html=True)
     if self.submit_widgets:
         r += htmltext('<div class="submit">')
         for widget in self.submit_widgets:
             r += widget.render()
         r += htmltext('</div><br class="submit" />')
     return r.getvalue()
Exemple #15
0
    def editdetails(self, request, p):
        form = form2.Form(name='editdetails')

        form.add(form2.StringWidget, name='title', size=50,
                 value=p.title or '', title='Title')
        form.add(form2.StringWidget, name='keywords', size=40,
                 value=', '.join([ k.word for k in p.keywords]),
                 title='Keywords')
        form.add(form2.StringWidget, name='description', size=50,
                 value=p.description, title='Description')
# FIXME form layout
#        form.add(form2.TextWidget, name='description', cols=50, rows=10,
#                 value=p.description, title='Description')

        form.add(form2.SingleSelectWidget, name='owner', value=p.ownerID, title='Picture owner',
                 options=imagestore.form.userOptList())
        form.add(form2.SingleSelectWidget, name='visibility',
                 value=p.visibility, title='Visibility',
                 options=[ s for s in ['public', 'restricted', 'private']])

        (prev,next) = request.session.get_results_neighbours(p.id)

        if next is not None:
            form.add_submit('submit-next', H('Update picture and go to next >>'))
        else:
            form.add_submit('submit', 'Update picture details')
        form.add_reset('reset', 'Revert changes')

        if not form.is_submitted() or form.has_errors():
            from image_page import detail_table
            
            self.image.set_prevnext(request, p.id,
                                    urlfn=lambda pic, size, s=self.image: s.edit.path(pic))
            
            ret = TemplateIO(html=True)
            
            ret += page.pre(request, 'Edit details', 'editdetails', trail=False)
            ret += page.menupane(request)
            ret += self.image.view_rotate_link(request, p, wantedit=True)
            ret += detail_table(p)
            ret += form.render()
            ret += page.post()

            ret = ret.getvalue()
        else:
            keywords = form['keywords']
            keywords = imagestore.form.splitKeywords(keywords)

            p.setKeywords(keywords)

            p.visibility = form['visibility']

            if form.get_submit() == 'submit-next' and next:
                ret = quixote.redirect(self.image.edit.path(db.Picture.get(next)))
            else:
                ret = quixote.redirect(request.get_path())

        return ret
Exemple #16
0
    def render(self, depth=0):
        r = TemplateIO(html=True)

        pfx = _p(depth)
        r += H("%s<div %s>") % (pfx, self.tags())
        self.renderitems(r, depth + 1, None)
        r += H("\n%s</div>\n") % pfx

        return r.getvalue()
Exemple #17
0
 def render_content(self):
     r = TemplateIO(html=True)
     add_element_widget = self.get_widget('add_element')
     for widget in self.get_widgets():
         if widget is add_element_widget:
             continue
         r += widget.render()
     r += add_element_widget.render()
     return r.getvalue()
Exemple #18
0
        def upload(self, request):
            form = self.upload_form(request)

            if form.get_submit() != 'upload':
                r = TemplateIO(html=True)

                r += page.pre(request, 'Upload pictures', 'upload')
                r += page.menupane(request)
                r += form.render()

                #r += H(request.dump_html())

                r += page.post()

                return r.getvalue()
            else:
                user = request.session.getuser()
                start = calendar.int_day.rounddown(gmt())
                end = calendar.int_day.roundup(gmt())
                upload = db.Upload.select(AND(db.Upload.q.import_time >= start,
                                              db.Upload.q.import_time < end,
                                              db.Upload.q.userID == user.id,
                                              db.Upload.q.collectionID == self.collection.db.id))

                assert upload.count() == 0 or upload.count() == 1, \
                       'Should be only one Upload per day per user'

                if upload.count() == 1:
                    u = upload[0]
                else:
                    u = db.Upload(user=user, collection=self.collection.db)

                c = int(form['camera'])

                if c == -2:
                    camera = None                    # new camera            
                elif c == -1:
                    camera = None                    # guess
                else:
                    camera = db.Camera.get(c)

                numfiles = int(form['numfiles'])

                keywords = form['keywords']
                if keywords is not None:
                    keywords = splitKeywords(keywords)

                print 'self.collection.db=%s' % self.collection.db

                request.response.buffered=False
                upload = self.do_upload(request,
                                        [ (f.fp, f.base_filename)
                                          for f in [ form['file.%d' % n]
                                                     for n in range(numfiles) ]
                                          if f is not None],
                                        user, camera, keywords, form['visibility'], u)
                return quixote.http_response.Stream(upload)
Exemple #19
0
 def render_content(self):
     r = TemplateIO(html=True)
     add_element_widget = self.get_widget('add_element')
     for widget in self.get_widgets():
         if widget is add_element_widget:
             continue
         r += widget.render()
     r += add_element_widget.render()
     return r.getvalue()
Exemple #20
0
 def render(self):
     """() -> HTML text
     Render a form as HTML.
     """
     r = TemplateIO(html=True)
     r += self._render_start()
     r += self._render_body()
     r += self._render_finish()
     return r.getvalue()
Exemple #21
0
 def render(self):
     """() -> HTML text
     Render a form as HTML.
     """
     r = TemplateIO(html=True)
     r += self._render_start()
     r += self._render_body()
     r += self._render_finish()
     return r.getvalue()
Exemple #22
0
 def _render_body(self, request):
     r = TemplateIO(html=1)
     r += htmltext('<table>')
     r += self._render_error_notice(request)
     r += self._render_required_notice(request)
     r += self._render_visible_widgets(request)
     r += self._render_submit_buttons(request)
     r += htmltext('</table>')
     return r.getvalue()
Exemple #23
0
    def render():
        ret = TemplateIO(html=True)

        ret += page.pre(request, 'User administration', 'editusers')
        ret += page.menupane(request)
        ret += H('<h1>User administration</h1>\n')
        ret += userform.render()
        ret += page.post()

        return ret.getvalue()
Exemple #24
0
 def _render_header(self, title):
     r = TemplateIO(html=True)
     r += htmltext('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 '
                   'Transitional//EN" '
                   '"http://www.w3.org/TR/REC-html40/loose.dtd">')
     r += htmltext('<html>')
     r += htmltext('<head><title>%s</title></head>') % title
     r += htmltext('<body>')
     r += htmltext("<h1>%s</h1>") % title
     return r.getvalue()
Exemple #25
0
 def __call__(self, request):
     r = TemplateIO(html=0)
     file_name = request.get_path()[1:]  # drop leading '/'
     r += header(get_title_from_path(file_name))
     body = StaticFile.__call__(self, request)
     if isinstance(body, Stream):
         for hunk in body:
             r += hunk
     else:
         r += body
     r += footer()
     return r.getvalue()
Exemple #26
0
def newuser(request):
    user = admin.login_user(quiet=True)

    if not ((user and user.mayAdmin) or
            config.get('users', 'unpriv_newuser')):
        raise AccessError('You may not create a new user')

    form = form2.Form()
    
    form.add(form2.StringWidget, 'username', title='User name')
    form.add(form2.StringWidget, 'fullname', title='Full name')
    form.add(form2.StringWidget, 'email', title='email address')
    form.add(form2.PasswordWidget, 'pass1', title='Password')
    form.add(form2.PasswordWidget, 'pass2', title='Password verify')
    form.add_submit('create', 'Create user')
    
    ret = None
    
    if form.is_submitted():
        username = form['username'].strip()
        if db.User.select(db.User.q.username == username).count() != 0:
            form.get_widget('username').set_error(H("Username '%s' already in use") % username)
        if form['pass1'] != form['pass2']:
            form.get_widget('pass1').set_error('Passwords do not match')
        fullname = form['fullname'].strip()
        if fullname == '':
            form.get_widget('fullname').set_error('Full name not set')
        email = form['email'].strip()
        if email == '':
            form.get_widget('email').set_error('Missing or bad email address')
            
        if not form.has_errors():
            u = db.User(username=username, fullname=fullname,
                        password=form['pass1'],
                        email=email,
                        mayAdmin=False,
                        mayViewall=False,
                        mayUpload=False,
                        mayComment=config.get('users', 'mayComment'),
                        mayRate=config.get('users', 'mayRate'))
            ret = quixote.redirect(path(u))

    if ret is None:
        r = TemplateIO(html=True)
        
        r += page.pre(request, 'New User', 'newuser')
        r += page.menupane(request)
        r += form.render()
        r += page.post()

        ret =  r.getvalue()

    return ret
Exemple #27
0
 def __call__(self, request):
     r = TemplateIO(html=0)
     file_name = request.get_path()[1:]     # drop leading '/'
     r += header(get_title_from_path(file_name))
     body = StaticFile.__call__(self, request)
     if isinstance(body, Stream):
         for hunk in body:
             r += hunk
     else:
         r += body
     r += footer()
     return r.getvalue()
Exemple #28
0
    def render(self, depth=0):
        r = TemplateIO(html=True)

        if self.heading:
            if isinstance(self.heading, MenuItem):
                r += self.heading.render(depth)
            else:
                r += str(self.heading)

        self.renderitems(r, depth, self.tags())

        return r.getvalue()
Exemple #29
0
 def render_content(self):
     r = TemplateIO(html=True)
     for widget in self.get_widgets():
         if widget.get_title():
             classnames = '%s widget' % widget.__class__.__name__
             r += H('<td title="%s" class="%s">') % (widget.get_hint(), classnames)
             r += widget.render_content()
             r += widget.render_error(widget.get_error())
             r += H('</td>')
         else:
             r += widget.render_content()
     return r.getvalue()
Exemple #30
0
 def render(self, request, action_url):
     # render(request : HTTPRequest,
     #           action_url : string)
     #    -> HTML text
     #
     # Render a form as HTML.
     assert type(action_url) in (StringType, htmltext)
     r = TemplateIO(html=1)
     r += self._render_start(request, action_url,
                             enctype=self.enctype, method=self.method)
     r += self._render_body(request)
     r += self._render_finish(request)
     return r.getvalue()
Exemple #31
0
    def render(self):
        r = TemplateIO(html=True)
        classnames = '%s widget' % self.__class__.__name__
        r += H('<table class="%s">\n') % classnames
        r += H('<thead>\n<tr>')
        for t in self.get_widgets()[0].column_titles():
            r += H('<td>%s</td>') % t
        r += self.render_title(self.get_title())
        r += H('</tr>\n</thead>\n')
        r += H('<tbody>\n')
        r += self.render_content()
        r += H('</table>\n')

        return r.getvalue()
Exemple #32
0
 def render(self):
     r = TemplateIO(html=True)
     classnames = '%s widget' % self.__class__.__name__
     r += htmltext('<div class="%s">') % classnames
     r += self.render_title(self.get_title())
     r += htmltext('<div class="content">')
     r += self.render_content()
     r += self.render_hint(self.get_hint())
     r += self.render_error(self.get_error())
     r += htmltext('</div>')
     r += htmltext('</div>')
     if self.render_br:
         r += htmltext('<br class="%s" />') % classnames
     r += htmltext('\n')
     return r.getvalue()
Exemple #33
0
 def render_content(self):
     r = TemplateIO(html=True)
     for name in self.element_names:
         if name in ('add_element', 'added_elements'):
             continue
         key_widget = self.get_widget(name + 'key')
         value_widget = self.get_widget(name + 'value')
         r += htmltext('%s<div class="widget">: </div>%s') % (
             key_widget.render(), value_widget.render())
         if self.render_br:
             r += htmltext('<br clear="left" class="widget" />')
         r += htmltext('\n')
     r += self.get_widget('add_element').render()
     r += self.get_widget('added_elements').render()
     return r.getvalue()
Exemple #34
0
 def render(self):
     r = TemplateIO(html=True)
     classnames = '%s widget' % self.__class__.__name__
     r += htmltext('<div class="%s">') % classnames
     r += self.render_title(self.get_title())
     r += htmltext('<div class="content">')
     r += self.render_content()
     r += self.render_hint(self.get_hint())
     r += self.render_error(self.get_error())
     r += htmltext('</div>')
     r += htmltext('</div>')
     if self.render_br:
         r += htmltext('<br class="%s" />') % classnames
     r += htmltext('\n')
     return r.getvalue()
Exemple #35
0
    def render(self):
        if self._parsed and (self.get('skip') == 'skip' or not self.has_changed()):
            return self.get_widget('skip').render()

        r = TemplateIO(html=True)

        classnames = '%s widget' % self.__class__.__name__
        if self['delete']:
            classnames += ' deleted'
        r += H('<tr title="%s" class="%s">') % (self.get_hint(), classnames)
        r += H('<td><a href="%s">%d</a></td>') % (path(self.user), self.user.id)
        r += self.render_content()
        r += H('</tr>\n')
            
        return r.getvalue()
Exemple #36
0
 def _render_widget_row(self, request, widget):
     if widget.widget_type == 'hidden':
         return ''
     title = self.title[widget.name] or ''
     if self.required.get(widget.name):
         title = title + htmltext('&nbsp;*')
     r = TemplateIO(html=1)
     r += htmltext('<tr><th colspan="3" align="left">')
     r += title
     r += htmltext('</th></tr>' '<tr><td>&nbsp;&nbsp;</td><td>')
     r += widget.render(request)
     r += htmltext('</td><td>')
     r += self._render_error(self.error.get(widget.name))
     r += self._render_hint(self.hint.get(widget.name))
     r += htmltext('</td></tr>')
     return r.getvalue()
Exemple #37
0
 def render_content(self):
     r = TemplateIO(html=True)
     for name in self.element_names:
         if name in ('add_element', 'added_elements'):
             continue
         key_widget = self.get_widget(name + 'key')
         value_widget = self.get_widget(name + 'value')
         r += htmltext('%s<div class="widget">: </div>%s') % (
             key_widget.render(),
             value_widget.render())
         if self.render_br:
             r += htmltext('<br clear="left" class="widget" />')
         r += htmltext('\n')
     r += self.get_widget('add_element').render()
     r += self.get_widget('added_elements').render()
     return r.getvalue()
Exemple #38
0
 def _render_widget_row(self, request, widget):
     if widget.widget_type == 'hidden':
         return ''
     title = self.title[widget.name] or ''
     if self.required.get(widget.name):
         title = title + htmltext('&nbsp;*')
     r = TemplateIO(html=1)
     r += htmltext('<tr><th colspan="3" align="left">')
     r += title
     r += htmltext('</th></tr>'
                   '<tr><td>&nbsp;&nbsp;</td><td>')
     r += widget.render(request)
     r += htmltext('</td><td>')
     r += self._render_error(self.error.get(widget.name))
     r += self._render_hint(self.hint.get(widget.name))
     r += htmltext('</td></tr>')
     return r.getvalue()
Exemple #39
0
def dump_request(request=None):
    if request is None:
        request = quixote.get_request()
    """Dump an HTTPRequest object as HTML."""
    row_fmt = htmltext('<tr><th>%s</th><td>%s</td></tr>')
    r = TemplateIO(html=True)
    r += htmltext('<h3>form</h3>' '<table>')
    for k, v in request.form.items():
        r += row_fmt % (k, v)
    r += htmltext('</table>' '<h3>cookies</h3>' '<table>')
    for k, v in request.cookies.items():
        r += row_fmt % (k, v)
    r += htmltext('</table>' '<h3>environ</h3>' '<table>')
    for k, v in request.environ.items():
        r += row_fmt % (k, v)
    r += htmltext('</table>')
    return r.getvalue()
Exemple #40
0
    def render_links(self, depth=0):
        r = TemplateIO(html=True)

        if self.first:
            r += self.first.render_link(depth)

        if self.prev:
            r += self.prev.render_link(depth)
        elif len(self.request.session.breadcrumbs) > 1:
            r += H('%s<link rel="prev" href="%s">\n') % ('  '*depth,
                                                         self.request.session.breadcrumbs[-2][1])
            
        if self.next:
            r += self.next.render_link(depth)

        if self.last:
            r += self.last.render_link(depth)

        return r.getvalue()
Exemple #41
0
 def render_options(self, depth=0):
     r = TemplateIO(html=True)
         
     if self.options:
         pfx = '  '*depth
         r += H('%s<span class="options">\n') % pfx
         for url,link,title,selected,extra in self.options:
             t = title and (H('title="%s"') % title) or ''
             if extra is None:
                 extra = {}
             r += H('%(pfx)s  <a %(title)s class="%(sel)s" href="%(url)s" %(extra)s>%(link)s</a>\n') % {
                 'pfx': pfx,
                 'title': t,
                 'sel': selected and 'selected' or '',
                 'url': url,
                 'link': link,
                 'extra': page.join_extra(extra)
                 }
         r += H('%s</span>\n') % pfx
     return r.getvalue()
Exemple #42
0
    def _q_index(self, request):
        r = TemplateIO(html=True)

        kw = db.Keyword.select(db.Keyword.q.collectionID == self.col.db.id,
                               orderBy=db.Keyword.q.word)

        r += page.pre(request, 'Keyword search', 'search', brieftitle='keywords')
        r += page.menupane(request)

        r += H('<div class="title-box kwlist">\n')
        r += H('<h2>%s</h2>\n') % page.plural(kw.count(), 'keyword')

        # XXX filter only keywords with (visible) pictures associated with them
        # (and perhaps weight by use)
        r += listkeywords('kw/', [ k.word for k in kw ], True)
        r += H('</div>\n')

        r += page.post();

        return r.getvalue()
Exemple #43
0
 def _render_finish(self, request):
     r = TemplateIO(html=1)
     r += htmltext('</form>')
     r += self._render_javascript(request)
     return r.getvalue()
Exemple #44
0
 def _render_visible_widgets(self, request):
     r = TemplateIO(html=1)
     for widget in self.widget_order:
         r += self._render_widget_row(request, widget)
     return r.getvalue()
Exemple #45
0
 def _render_hidden_widgets(self):
     r = TemplateIO(html=True)
     for widget in self.hidden_widgets:
         r += widget.render()
     return r.getvalue()
Exemple #46
0
 def render_content(self):
     r = TemplateIO(html=True)
     for widget in self.get_widgets():
         r += widget.render()
     return r.getvalue()