Beispiel #1
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 #2
0
    def post(self, ignored=None):
        assert_editor(self)

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

        channel = data.get('channel', [])
        if channel:
            channels = [channel]
        else:
            channel = db.Channel.query().get()
            if channel:
                channels = [db.encode_key(channel.key)]

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

        try:
            post = db.Post.create(
                user,
                data['content'],
                data['theme'],
                data['background'],
                channels,
                data['role'],
                data['role_text'],
                created=created,
            )
        except KeyError as err:
            log.error('missing field - %s', err)
            self.abort(httplib.BAD_REQUEST)

        self.gen_votes(post, user, data)
        self.respond({'ok': True, 'key': db.encode_key(post.key)})