Пример #1
0
def listOfExcercise():
    query = "SELECT name FROM excercise ORDER BY type DESC, name"
    record = ""
    con = Connection(query,record)
    result = con.fetchAllQuerySQL()
    exc = [r[0] for r in result]
    #exc.append(" ")
    return exc
Пример #2
0
def returnMinDate(user):
    query = "SELECT MIN(dateCreated) FROM lift WHERE user_id = %s"
    record = (user,)
    con = Connection(query,record)
    result = con.fetchOneQuerySQL()
    try:
        return result[0].strftime("%Y-%m-%d")
    except:
        return datetime.now().strftime('%Y-%m-%d')
Пример #3
0
def returnDateLogin(user_id):
    query = "SELECT DISTINCT dateCreated FROM lift WHERE user_id = %s"
    record = (user_id,)
    #result = list(fetchAllQuerySQL(query,record))
    con = Connection(query,record)
    result = con.fetchAllQuerySQL()
    date = [d[0] for d in result]
    dateString = [dt.strftime("%Y-%m-%d") for dt in date]
    return dateString
Пример #4
0
def ifUser(username):
    query = "SELECT user_id FROM user WHERE name = %s"
    record = (username,)
    con = Connection(query,record)
    result = con.fetchOneQuerySQL()
    if result == None:
        return 0
    else:
        return result[0]
Пример #5
0
def checkLoginValid(username,password):
    query = "SELECT password FROM user WHERE name = %s"
    record = (username,)
    con = Connection(query,record)
    result = con.fetchOneQuerySQL()
    
    if result == None:
        return 0
    elif result[0] != password:
        return -1
    else:
        return 1
Пример #6
0
def add_friend():
    """Send a friend request to another user."""

    user_a_id = session["current_user"]["id"]
    #user_b_id = request.form.get("user_b_id")
    user_b_id = request.form['button_for_add']
    print user_b_id
    # Check connection status between user_a and user_b
    is_friends, is_pending = is_friends_or_pending(user_a_id, user_b_id)

    if user_a_id == user_b_id:
        return "You cannot add yourself as a friend."
    elif is_friends:
        return "You are already friends."
    elif is_pending:
        return "Your friend request is pending."
    else:
        requested_connection = Connection(user_a_id=user_a_id,
                                          user_b_id=user_b_id,
                                          status="Requested")
        db.session.add(requested_connection)
        db.session.commit()
        print "User ID %s has sent a friend request to User ID %s" % (
            user_a_id, user_b_id)
        return "Request Sent"
Пример #7
0
def load_connections():
    """Load sample connection."""

    print "Loading connections..."

    Connection.query.delete()

    connect = Connection(pet_id=1,
                         owner_id=1,
                         seeker_id=4,
                         connection_status='Interested')

    connect2 = Connection(pet_id=1,
                          owner_id=1,
                          seeker_id=2,
                          connection_status='Interested')

    db.session.add(connect)
    db.session.add(connect2)

    db.session.commit()
Пример #8
0
def create_connection(user_id_1, user_id_2, connected=True):
    """Creates new Connection"""

    connect_date = datetime.today()
    connection = Connection(user_id_1=user_id_1,
                            user_id_2=user_id_2,
                            connect_date=connect_date,
                            connected=connected)

    db.session.add(connection)
    db.session.commit()

    return connection
Пример #9
0
def add_friend():
    """
    send a friend request
    """

    user_a_id = session["current_user"]["user_id"]
    user_b_id = request.form.get("user_b_id")

    friend_request = Connection(user_a_id=user_a_id,
                                user_b_id=user_b_id,
                                status="Pending")

    session["current_user"]["num_sent_requests"] += 1
    session["current_user"]["num_total_requests"] += 1

    db.session.add(friend_request)
    db.session.commit()
    return "Request Sent"
Пример #10
0
def getLastSession():
    query = "SELECT MAX(id) FROM session"
    record = ""
    con = Connection(query,record)
    user = con.fetchOneQuerySQL()

    query = """
            SELECT user FROM session 
            WHERE id = %s
            """
    record = (user[0],)
    con = Connection(query,record)
    result = con.fetchOneQuerySQL()
    return result[0]
Пример #11
0
def fromExcToAbr(exc):
    query = "SELECT abbreviation FROM excercise WHERE name = %s"
    record = (exc,)
    con = Connection(query,record)
    result = con.fetchOneQuerySQL()
    return result[0]
Пример #12
0
def idFromUser(user):
    query = "SELECT user_id FROM user WHERE name = %s"
    record = (user,)
    con = Connection(query,record)
    result = con.fetchOneQuerySQL()
    return result[0]
Пример #13
0
 def post(self):
     client_id = self.request.get("from")
     logging.getLogger().info("{0} is disconnected".format(client_id))
     con = Connection.get_by_id(int(client_id))
     con.connected = False
     con.put()
Пример #14
0
 def get(self):
     self.tellAll()
     key = Connection(info=self.request.headers.get("User-Agent"), connected=False).put()
     token = channel.create_channel(str(key.id()))
     self.response.write(self.jinja2.render_template("index.html", token=token))
Пример #15
0
 def tellAll(self):
     for con in Connection.query().filter(Connection.connected == True).iter():
         channel.send_message(str(con.key.id()), "Someone JOINED")