예제 #1
0
    def get(self, short_url):
        token = self.get_secure_cookie("token")
        query = Shortening.select().where(Shortening.short_url == short_url)
        if query.exists():
            shortening = query.get().id

            logs = list(Logs.select().where((Logs.user == token) & (Logs.shortening == shortening)).dicts())
            data = json.dumps(logs, default=json_serial)
        else:
            self.set_status(400)
            data = json.dumps({'error': 'Unable to found given url'})

        self.set_header('Content-Type', 'application/json')
        self.write(data)
예제 #2
0
    def get(self, short_url):
        query = Shortening.select().where(Shortening.short_url == short_url)
        if query.exists():
            shortening = query.get()

            l = Logs(user=shortening.user, shortening=shortening, ip=self.request.remote_ip)
            l.save()
            full_short_url = BASE_URL+"/"+shortening.short_url
            data = json.dumps({'short_url': full_short_url, 'long_url': shortening.long_url})
        else:
            self.set_status(400)
            data = json.dumps({'error': 'Unable to found given url'})
        self.set_header('Content-Type', 'application/json')
        self.write(data)
예제 #3
0
    def get(self, short_url):
        token = self.get_secure_cookie("token")
        query = Shortening.select().where(Shortening.short_url == short_url)
        if query.exists():
            shortening = query.get()
            logs = list(Logs.select().where((Logs.user == token) & (Logs.shortening == shortening.id)).dicts())
            shortening_dict = model_to_dict(shortening)
            shortening_dict['short_url'] = BASE_URL+"/"+shortening.short_url
            shortening_dict['access_count'] = len(logs)
            data = json.dumps(shortening_dict, default=json_serial)
        else:
            self.set_status(400)
            data = json.dumps({'error': 'Unable to found given url'})

        self.set_header('Content-Type', 'application/json')
        self.write(data)
예제 #4
0
 def get(self):
     user_id = self.get_secure_cookie("token")
     shortenings = list(Shortening.select().where(Shortening.user == User.get(id=user_id)).dicts())
     data = json.dumps(shortenings, default=json_serial)
     self.set_header('Content-Type', 'application/json')
     self.write(data)