Zine

open source content publishing system


source: zine/services.py @ 1307:160547939d6e

Revision 1307:160547939d6e, 1.4 KB checked in by mitsuhiko, 2 years ago (diff)

Fixed JS for new jQuery version and unbroke some time relevant code for
windows.

Line 
1# -*- coding: utf-8 -*-
2"""
3    zine.services
4    ~~~~~~~~~~~~~
5
6    The builtin (JSON) services.
7
8    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details.
9    :license: BSD, see LICENSE for more details.
10"""
11from werkzeug import abort
12
13from zine.models import Comment, Tag
14from zine.privileges import MODERATE_COMMENTS
15from zine.utils.dates import to_timestamp
16
17
18def do_get_comment(req):
19    comment_id = req.values.get('comment_id')
20    if comment_id is None:
21        abort(404)
22    comment = Comment.query.get(comment_id)
23    if comment is None:
24        abort(404)
25    if comment.blocked and not req.user.has_privilege(MODERATE_COMMENTS):
26        abort(403)
27    if comment.parent is not None:
28        parent_id = comment.parent.id
29    else:
30        parent_id = None
31    email = None
32    if req.user.is_manager:
33        email = comment.email
34    return {
35        'id':           comment.id,
36        'parent':       parent_id,
37        'body':         unicode(comment.body),
38        'author':       comment.author,
39        'email':        email,
40        'pub_date':     to_timestamp(comment.pub_date),
41    }
42
43
44def do_get_taglist(req):
45    return {
46        'tags':         sorted([t.name for t in Tag.query.all()],
47                               key=lambda x: x.lower())
48    }
49
50
51all_services = {
52    'get_comment':          do_get_comment,
53    'get_taglist':          do_get_taglist
54}
Note: See TracBrowser for help on using the repository browser.