Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def add_to_log(game, field, user, id_user, field_opponent, opponent):
    """add note to collection Logs 
    
    Arguments:
    - `game`:
    - `field`:
    - `user`:
    """
    note = Logs(game=game,
                snapshot=field,
                snapshot_opponent=field_opponent,
                move_user=user,
                move_user_id = id_user,
                opponent=opponent,
                time=datetime.datetime.now())
    note.save(cascade=True)