Compare commits
2 Commits
12a76158ed
...
5cbf25f929
Author | SHA1 | Date | |
---|---|---|---|
5cbf25f929 | |||
93f1ae75ff |
@ -5,8 +5,9 @@ import sys, datetime
|
||||
|
||||
Group = Blueprint('Group', __name__)
|
||||
|
||||
@Group.route("/groups/index", methods=['GET'])
|
||||
@Group.route("/groups", methods=['GET'])
|
||||
def index():
|
||||
current_user.join_group(1000)
|
||||
groups = current_user.get_groups()
|
||||
return render_template('groups.html', groups=groups)
|
||||
|
||||
|
@ -66,10 +66,10 @@ class User(tuple, UserMixin):
|
||||
|
||||
def get_groups(self):
|
||||
cur = conn.cursor()
|
||||
sql_call = f"""
|
||||
SELECT groups.* FROM users_groups JOIN groups ON users_groups.group_id = groups.group_id WHERE users_groups.user_id = {self.user_id}
|
||||
sql_call = """
|
||||
SELECT groups.* FROM users_groups JOIN groups ON users_groups.group_id = groups.group_id WHERE users_groups.user_id = %s
|
||||
"""
|
||||
cur.execute(sql_call)
|
||||
cur.execute(sql_call, (self.user_id,))
|
||||
groups = cur.fetchall()
|
||||
result = []
|
||||
for group_data in groups:
|
||||
@ -77,6 +77,25 @@ class User(tuple, UserMixin):
|
||||
cur.close()
|
||||
return result
|
||||
|
||||
def leave_group(self, group_id):
|
||||
# TODO: Tjek om brugeren må forlade gruppen
|
||||
cur = conn.cursor()
|
||||
sql_call = """
|
||||
DELETE FROM users_groups WHERE user_id = %s AND group_id = %s
|
||||
"""
|
||||
cur.execute(sql_call, (self.user_id, group_id))
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
||||
def join_group(self, group_id):
|
||||
cur = conn.cursor()
|
||||
sql_call = """
|
||||
INSERT INTO users_groups VALUES (%s, %s)
|
||||
"""
|
||||
cur.execute(sql_call, (self.user_id, group_id))
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
||||
|
||||
def insert_users(user_id, first_name, last_name, password, email, adresse, role):
|
||||
cur = conn.cursor()
|
||||
|
Reference in New Issue
Block a user