示例#1
0
文件: main.py 项目: ronhuang/adieu
    def get(self):
        pagename = None
        args = None

        if self.current_user:
            # load initial set of data
            query = MidautumnObject.all()
            query.order('-pubtime')

            objects = []
            results = query.fetch(10)
            for obj in results:
                objects.append(obj.to_dict(current_user=self.current_user))

            pagename = 'home.html'
            args = {'objects': objects,
                    'cursor': query.cursor(),
                    'more': len(objects) >= 10,
                    'profile': self.current_user.profile,
                    }
        else:
            pagename = 'register.html'
            args = None

        dirname = os.path.dirname(__file__)
        path = os.path.join(dirname, 'view', pagename)
        self.response.out.write(template.render(path, args))
示例#2
0
文件: api.py 项目: ronhuang/adieu
    def get(self, key):
        mo = MidautumnObject.get_by_id(int(key))

        args = None

        if not mo:
            args = {'result': 'not_exist', 'key': key}
        else:
            args = {'result': 'success',
                    'objects': [mo.to_dict(current_user=self.current_user),]}

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(json.dumps(args))
示例#3
0
文件: api.py 项目: ronhuang/adieu
    def post(self):
        title = self.request.get('title')
        timestamp = self.request.get('timestamp')

        user = self.current_user
        query = db.GqlQuery("SELECT * FROM MidautumnObject WHERE title = :1", title)
        mo = query.get()

        args = None

        if not user:
            args = {'result': 'not_authorized'}
        elif mo:
            args = {'result': 'duplicated', 'objects': [mo.to_dict(details=True, current_user=user),]}
        else:
            mo = MidautumnObject(title=title, owner=user)
            mo.put()

            # fetch all objects after the timestamp
            # should include the one just posted
            query = MidautumnObject.all()
            query.filter('pubtime >', datetime.utcfromtimestamp(float(timestamp)))
            query.order('-pubtime')

            objects = []
            for obj in query:
                objects.append(obj.to_dict(current_user=user))

            # check achievements
            achievements = []
            achievements.extend(achievement.check_post(mo))

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

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(json.dumps(args))
示例#4
0
文件: api.py 项目: ronhuang/adieu
    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))
示例#5
0
文件: main.py 项目: ronhuang/adieu
    def get(self):
        args = {}
        pagename = 'objects.html'

        query = MidautumnObject.all()
        query.order('pubtime')
        objects = []
        for obj in query:
            objects.append(obj.to_dict(details=True))
        args['objects'] = objects

        # current user related info
        if self.current_user:
            args['profile'] = self.current_user.profile

        dirname = os.path.dirname(__file__)
        path = os.path.join(dirname, 'view', pagename)
        self.response.out.write(template.render(path, args))
示例#6
0
文件: api.py 项目: ronhuang/adieu
    def post(self, key):
        user = self.current_user

        mo = MidautumnObject.get_by_id(int(key))

        args = None

        if not user:
            args = {'result': 'not_authorized'}
        elif not mo:
            args = {'result': 'not_exist', 'key': key}
        elif mo.owner.id != user.id:
            args = {'result': 'not_authorized'}
        else:
            mo.delete()
            args = {'result': 'success', 'key': key}

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(json.dumps(args))
示例#7
0
文件: main.py 项目: ronhuang/adieu
    def get(self, key):
        pagename = None
        args = None

        mo = MidautumnObject.get_by_id(int(key))
        if mo == None:
            pagename = "object_not_found.html"
            args = {}
        else:
            pagename = "object.html"
            args = mo.to_dict(details=True)

        # current user related info
        if self.current_user:
            args['profile'] = self.current_user.profile

        dirname = os.path.dirname(__file__)
        path = os.path.join(dirname, 'view', pagename)
        self.response.out.write(template.render(path, args))
示例#8
0
文件: api.py 项目: ronhuang/adieu
    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))
示例#9
0
文件: api.py 项目: ronhuang/adieu
    def get(self):
        cursor = self.request.get('cursor', None)

        args = None

        # load initial set of data
        query = MidautumnObject.all()
        query.order('-pubtime')
        if cursor:
            query.with_cursor(cursor)

        objects = []
        results = query.fetch(10)
        for obj in results:
            objects.append(obj.to_dict(current_user=self.current_user))

        args = {'result': 'success',
                'objects': objects,
                'cursor': query.cursor(),
                'more': len(objects) >= 10,
                }

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