Exemple #1
0
    def post(self):
        action = self.request.get('action', None)
        href = self.request.get('href', None)
        commentID = self.request.get('commentID', None)

        user = self.current_user
        mo = MidautumnObject.get_by_url(href)

        args = None

        if not user:
            args = {'result': 'not_authorized'}
        elif action not in ('create', 'remove'):
            args = {'result': 'unknown_action'}
        elif not href or not commentID:
            args = {'result': 'missing_parameter'}
        elif not mo:
            args = {'result': 'invalid_parameter'}
        else:
            query = user.comment_set
            query.filter('href =', href)
            query.filter('comment_id =', commentID)
            comment = query.get()

            if (action == 'create' and comment) or (action == 'remove' and not comment):
                args = {'result': 'invalid_state'}
            elif action == 'create':
                comment = FacebookComment(owner=user, href=href, comment_id=commentID, object=mo)
                comment.put()

                achievements = []
                achievements.extend(achievement.check_comment(comment))

                args = {'result': 'success',
                        'achievements': achievements,
                        }
            else:
                comment.delete()

                achievements = []
                achievements.extend(achievement.check_comment(owner=user))

                args = {'result': 'success',
                        'achievements': achievements,
                        }

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(json.dumps(args))
Exemple #2
0
    def post(self):
        action = self.request.get('action', None)
        url = self.request.get('url', None)

        user = self.current_user
        mo = MidautumnObject.get_by_url(url)

        args = None

        if not user:
            args = {'result': 'not_authorized'}
        elif action not in ('create', 'remove'):
            args = {'result': 'unknown_action'}
        elif not url:
            args = {'result': 'missing_parameter'}
        elif not mo:
            args = {'result': 'invalid_parameter'}
        else:
            query = user.edge_set
            query.filter('url =', url)
            edge = query.get()
            if not edge:
                edge = FacebookEdge(owner=user, url=url, object=mo)
            if action == 'create':
                edge.connected = True
                edge.created = True
            else:
                edge.connected = False
                edge.removed = True
            edge.put()

            achievements = []
            achievements.extend(achievement.check_like(edge))

            args = {'result': 'success',
                    'achievements': achievements,
                    }

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(json.dumps(args))