Beispiel #1
0
 def to_dict(self, obj, user_key_to_desc):
     d = super(JSComments, self).to_dict(obj, user_key_to_desc)
     user_key = db.resolve_post_uid(obj.parent_post(), obj.user)
     if user_key:
         d['user'] = user_key_to_desc.get(db.decode_key(user_key), user_key)
     else:
         d['user'] = '******'
     return d
Beispiel #2
0
    def delete(self, key=None):
        assert_editor(self)

        if not key:
            log.error('missing key')
            self.abort(httplib.BAD_REQUEST)

        try:
            key = db.decode_key(key)
        except TypeError as err:
            log.error('bad key %s', err)
            self.abort(httplib.BAD_REQUEST)

        self.delete_related_objects(key)

        key.delete()
        self.respond({'ok': True})
Beispiel #3
0
    def post(self, key=None):
        assert_editor(self)
        if not key:
            log.error('missing key')
            self.abort(httplib.BAD_REQUEST)

        try:
            data = json.loads(self.request.body)
        except (ValueError, TypeError) as err:
            log.error('bad comment - %s', err)
            self.abort(httplib.BAD_REQUEST)

        created = data.get('created', None)
        if created:
            created = edit_str2dt(created)

        euser = None
        user = data.get('user', None)
        for u in edit_users():
            if db.encode_key(u) == user:
                euser = u.get()
                break
        if not euser:
            log.error('bad user (not edit user) - %s', user)
            self.abort(httplib.BAD_REQUEST)

        post = db.decode_key(key).get()
        try:
            comment = db.Comment.create(
                post,
                euser,
                data['content'],
                data['role'],
                data['role_text'],
                created,
            )
        except KeyError as err:
            log.error('missing field - %s', err)
            self.abort(httplib.BAD_REQUEST)

        self.gen_votes(comment, euser, data)
        self.respond({'ok': True, 'key': db.encode_key(comment.key)})
Beispiel #4
0
    def get(self, key=None):
        user = users.get_current_user()
        if not user:
            url = users.create_login_url(self.request.uri)
            self.redirect(url)
            return

        assert_editor(self, user)

        # FIXME: Check that user is admin
        template = get_template(self.template)
        logout = users.create_logout_url(self.request.uri)
        obj = None
        if key:
            obj = db.decode_key(key).get()
        self.response.write(template.render(
            user=user,
            edit_users=list(k.get() for k in edit_users()),
            logout=logout,
            obj=obj,
            channels=[c.to_dict() for c in db.Channel.iter_all()],
        ))
Beispiel #5
0
 def query(self, key):
     key = db.decode_key(key)
     return db.Comment.query(ancestor=key).order(-db.Comment.created)