예제 #1
0
    def post(self):
        vote_id         = self.request.get('vote_id', None)
        how             = self.request.get('how', None)
        why             = self.request.get('why', None)
        
        result = { 'status': 'failed' }
        followup = doFollowup(vote_id, how, why)
        if followup:
            result = {
                'status'    : 'success',
            }

        jsonResponse(self, result)
예제 #2
0
    def post(self):
        number          = self.request.get('number', None)
        method          = self.request.get('method', None)
        pick            = self.request.get('pick', None)
        submit          = self.request.get('submit', None)
        showed_random   = self.request.get('random', None)
        
        ip = self.request.remote_addr
        
        result = { 'status': 'failed' }
        vote = doVote(number, method, pick, submit, showed_random, ip)
        if vote:
            result = {
                'status'    : 'success',
                'vote_id'   : str(vote.key())
            }

        jsonResponse(self, result)
예제 #3
0
    def get(self):

        skeleton_key = self.request.get("skeleton", None)

        if settings.THROTTLE_API and skeleton_key != settings.SKELETON_KEY:
            ip = str(self.request.remote_addr)
            throttle = memcache.get(ip)
            if throttle:
                throttle = throttle - datetime.now()
                jsonResponse(self, {
                    'status': 'throttled',
                    'remaining': throttle.seconds
                })
                return
            else:
                throttle = datetime.now() + timedelta(
                    seconds=settings.THROTTLE_LIFE)
                memcache.set(ip, throttle, settings.THROTTLE_LIFE)

        method = self.request.get("method", None)
        number = self.request.get("number", None)
        random_text = self.request.get("random_text", None)

        cursor = self.request.get("cursor", None)

        showed_random = None
        if random_text:
            if random_text == 'visible':
                showed_random = True
            elif random_text == 'hidden':
                showed_random = False
            else:
                self.error(400)
                return

        q = Vote.all()

        if method:
            if method in OPTIONS:
                q.filter("method =", method)
            else:
                self.error(400)
                return

        if number is not None:
            try:
                number = int(number)
            except:
                self.error(400)
                return
            else:
                q.filter("number =", number)

        if showed_random is not None:
            q.filter("showed_random =", showed_random)

        if cursor:
            try:
                q.with_cursor(cursor)
            except:
                self.error(400)
                return

        data = None
        cached_data = None
        LIMIT = 1000

        key = "%s-%s-%s-%s-%s" % (settings.VERSION, method, number,
                                  random_text, cursor)

        if settings.CACHE:
            cached_data = memcache.get(key)

        if not cached_data:
            data = q.fetch(LIMIT)
            next_cursor = q.cursor() if len(data) == LIMIT else None

            result = {
                "objects": [
                    vote.toJSON(full=(skeleton_key is not None))
                    for vote in data
                ],
                "next_cursor":
                next_cursor
            }
            if settings.CACHE and not skeleton_key:
                memcache.set(key, result, settings.CACHE_LIFE)
        else:
            result = cached_data

        jsonResponse(self, result)
예제 #4
0
 def get(self):
     jsonResponse(self, assembleData())
예제 #5
0
    def get(self):

        skeleton_key = self.request.get("skeleton", None)

        if settings.THROTTLE_API and skeleton_key != settings.SKELETON_KEY:
            ip = str(self.request.remote_addr)
            throttle = memcache.get(ip)
            if throttle:
                throttle = throttle - datetime.now()
                jsonResponse(self, {
                    'status': 'throttled',
                    'remaining': throttle.seconds
                })
                return
            else:
                throttle = datetime.now() + timedelta(seconds=settings.THROTTLE_LIFE)
                memcache.set(ip, throttle, settings.THROTTLE_LIFE)

        method          = self.request.get("method", None)
        number          = self.request.get("number", None)
        random_text     = self.request.get("random_text", None)

        cursor = self.request.get("cursor", None)

        showed_random = None
        if random_text:
            if random_text == 'visible':
                showed_random = True
            elif random_text == 'hidden':
                showed_random = False
            else:
                self.error(400)
                return

        q = Vote.all()

        if method:
            if method in OPTIONS:
                q.filter("method =", method)
            else:
                self.error(400)
                return
        
        if number is not None:
            try:
                number = int(number)
            except:
                self.error(400)
                return
            else:
                q.filter("number =", number)
        
        if showed_random is not None:
            q.filter("showed_random =", showed_random)

        if cursor:
            try:
                q.with_cursor(cursor)
            except:
                self.error(400)
                return
        
        data = None
        cached_data = None
        LIMIT = 1000

        key = "%s-%s-%s-%s-%s" % (settings.VERSION, method, number, random_text, cursor)

        if settings.CACHE:
            cached_data = memcache.get(key)
        
        if not cached_data:
            data = q.fetch(LIMIT)
            next_cursor = q.cursor() if len(data) == LIMIT else None

            result = {
                "objects"       : [vote.toJSON(full=(skeleton_key is not None)) for vote in data],
                "next_cursor"   : next_cursor
            }
            if settings.CACHE and not skeleton_key:
                memcache.set(key, result, settings.CACHE_LIFE)
        else:
            result = cached_data

        jsonResponse(self, result)
예제 #6
0
 def get(self):
     jsonResponse(self, assembleData())