Example #1
0
def serve_javascript(request):
    """Serves the JavaScript translations."""
    code = _js_translations.get(request.app)
    if code is None:
        t = request.app.translations
        code = 'Zine.addTranslations(%s)' % dump_json(dict(
            messages=dict((k.id, k.string) for k in t.client_keys),
            plural_expr=t.plural_expr,
            locale=str(t.locale)
        ))
        _js_translations[request.app] = code
    response = zine.application.Response(code, mimetype='application/javascript')
    response.add_etag()
    response.make_conditional(request)
    return response
Example #2
0
def serve_javascript(request):
    """Serves the JavaScript translations."""
    code = _js_translations.get(request.app)
    if code is None:
        t = request.app.translations
        code = "Zine.addTranslations(%s)" % dump_json(
            dict(
                messages=dict((k.id, k.string) for k in t.client_keys), plural_expr=t.plural_expr, locale=str(t.locale)
            )
        )
        _js_translations[request.app] = code
    response = zine.application.Response(code, mimetype="application/javascript")
    response.add_etag()
    response.make_conditional(request)
    return response
Example #3
0
def inject_fish(req, context):
    """This is called before the admin response is rendered. We add the
    fish script and the stylesheet and then we add a new header snippet
    which basically is some HTML code that is added to the <head> section.
    In this header snippet we set the global `$ERIC_THE_FISH_SKIN` variable
    to the selected skin.
    """
    add_script(url_for('eric_the_fish/shared', filename='fish.js'))
    add_link('stylesheet', url_for('eric_the_fish/shared',
                                   filename='fish.css'), 'text/css')

    add_header_snippet('<script type="text/javascript">'
                       '$ERIC_THE_FISH_SKIN = %s;'
                       '</script>' %
                       dump_json(req.app.cfg['eric_the_fish/skin']))
Example #4
0
def inject_fish(req, context):
    """This is called before the admin response is rendered. We add the
    fish script and the stylesheet and then we add a new header snippet
    which basically is some HTML code that is added to the <head> section.
    In this header snippet we set the global `$ERIC_THE_FISH_SKIN` variable
    to the selected skin.
    """
    add_script(url_for('eric_the_fish/shared', filename='fish.js'))
    add_link('stylesheet', url_for('eric_the_fish/shared',
                                   filename='fish.css'), 'text/css')

    add_header_snippet(
        '<script type="text/javascript">'
            '$ERIC_THE_FISH_SKIN = %s;'
        '</script>' % dump_json(req.app.cfg['eric_the_fish/skin'])
    )
Example #5
0
 def _register_user(self, user):
     rv = self.new_dependency(self.z.user)
     self.z('username', text=user.username, parent=rv)
     self.z('email', text=user.email, parent=rv)
     self.z('pw_hash', text=user.pw_hash.encode('base64'), parent=rv)
     self.z('display_name', text=user._display_name, parent=rv)
     self.z('real_name', text=user.real_name, parent=rv)
     self.z('description', text=user.description, parent=rv)
     self.z('www', text=user.www, parent=rv)
     self.z('is_author', text=user.is_author and 'yes' or 'no', parent=rv)
     self.z('extra', text=dump_json(user.extra), parent=rv)
     for participant in self.participants:
         participant.process_user(rv, user)
     privileges = self.z('privileges', parent=rv)
     for privilege in user.own_privileges:
         self.z('privilege', text=privilege.name, parent=privileges)
     self.users[user.id] = rv
Example #6
0
def json_service(req, identifier):
    """Handle a JSON service req."""
    handler = req.app._services.get(identifier)
    if handler is None:
        raise NotFound()

    #! if this event returns a handler it is called instead of the default
    #! handler.  Useful to intercept certain requests.
    for callback in iter_listeners('before-json-service-called'):
        rv = callback(identifier, handler)
        if rv is not None:
            handler = rv
    result = handler(req)

    #! called right after json callback returned some data with the identifier
    #! of the req method and the result object.  Note that events *have*
    #! to return an object, even if it's just changed in place, otherwise the
    #! return value will be `null` (None).
    for callback in iter_listeners('after-json-service-called'):
        result = callback(identifier, result)
    return Response(dump_json(result), mimetype='text/javascript')
Example #7
0
def json_service(req, identifier):
    """Handle a JSON service req."""
    handler = req.app._services.get(identifier)
    if handler is None:
        raise NotFound()

    #! if this event returns a handler it is called instead of the default
    #! handler.  Useful to intercept certain requests.
    for callback in iter_listeners('before-json-service-called'):
        rv = callback(identifier, handler)
        if rv is not None:
            handler = rv
    result = handler(req)

    #! called right after json callback returned some data with the identifier
    #! of the req method and the result object.  Note that events *have*
    #! to return an object, even if it's just changed in place, otherwise the
    #! return value will be `null` (None).
    for callback in iter_listeners('after-json-service-called'):
        result = callback(identifier, result)
    return Response(dump_json(result), mimetype='text/javascript')
Example #8
0
    def _dump_post(self, post):
        url = url_for(post, _external=True)
        entry = self.atom('entry', {'{%s}base' % XML_NS: url})
        self.atom('title', text=post.title, type='text', parent=entry)
        self.atom('id', text=post.uid, parent=entry)
        self.atom('updated',
                  text=format_iso8601(post.last_update),
                  parent=entry)
        self.atom('published',
                  text=format_iso8601(post.pub_date),
                  parent=entry)
        self.atom('link', href=url, parent=entry)

        author = self.atom('author', parent=entry)
        author.attrib[self.z.dependency] = self.users[post.author.id] \
                                                .attrib['dependency']
        self.atom('name', text=post.author.display_name, parent=author)
        self.atom('email', text=post.author.email, parent=author)

        self.z('slug', text=post.slug, parent=entry)
        self.z('comments_enabled',
               text=post.comments_enabled and 'yes' or 'no',
               parent=entry)
        self.z('pings_enabled',
               text=post.pings_enabled and 'yes' or 'no',
               parent=entry)
        self.z('status', text=str(post.status), parent=entry)
        self.z('content_type', text=str(post.content_type), parent=entry)
        self.z('extra', text=dump_json(post.extra), parent=entry)

        self.atom('content', type='text', text=post.text, parent=entry)
        self.atom('content',
                  type='html',
                  text=post.body.to_html(),
                  parent=entry)
        if post.intro:
            self.atom('summary',
                      type='html',
                      text=post.intro.to_html(),
                      parent=entry)

        for category in post.categories:
            attrib = dict(term=category.slug, scheme=ZINE_CATEGORY_URI)
            if category.slug != category.name:
                attrib['label'] = category.name
            element = self.atom('category', attrib=attrib, parent=entry)
            if category.description:
                self.zine.description(category.description, parent=element)

        for tag in post.tags:
            attrib = dict(term=tag.slug, scheme=ZINE_TAG_URI)
            if tag.slug != tag.name:
                attrib['label'] = tag.name
            self.atom('category', attrib=attrib, parent=entry)

        self.z('parser_data',
               text=dump_parser_data(post.parser_data).encode('base64'),
               parent=entry)

        for c in post.comments:
            comment = self.z('comment', parent=entry)
            comment.attrib['id'] = str(c.id)
            author = self.z('author', parent=comment)
            self.z('name', text=c.author, parent=author)
            self.z('email', text=c.email, parent=author)
            self.z('uri', text=c.www, parent=author)
            if c.user is not None:
                author.attrib['dependency'] = self.users[c.user.id] \
                                                  .attrib['dependency']
            self.z('published',
                   text=format_iso8601(c.pub_date),
                   parent=comment)
            self.z('blocked', text=c.blocked and 'yes' or 'no', parent=comment)
            self.z('is_pingback',
                   text=c.is_pingback and 'yes' or 'no',
                   parent=comment)
            self.z('status', text=str(c.status), parent=comment),
            self.z('blocked_msg',
                   text=str(c.blocked_msg or ''),
                   parent=comment)
            self.z('parent',
                   text=c.parent_id is not None and str(c.parent_id) or '',
                   parent=comment)
            self.z('submitter_ip', text=c.submitter_ip, parent=comment)
            self.z('content',
                   type='html',
                   text=c.body.to_html(),
                   parent=comment)
            self.z('content', type='text', text=c.text, parent=comment)
            self.z('parser_data',
                   text=dump_parser_data(c.parser_data).encode('base64'),
                   parent=comment)

        for participant in self.participants:
            participant.process_post(entry, post)
        return entry
Example #9
0
 def process_bind_param(self, value, dialect):
     if value is None:
         return None
     else:
         return dump_json(value)
Example #10
0
 def taglist(self):
     """Return all available tags as a JSON-encoded list."""
     tags = [t.name for t in Tag.query.all()]
     return dump_json(tags)