From 033965395456bdab338cca8e53441eb938ab8720 Mon Sep 17 00:00:00 2001 From: Kostanjevec Date: Thu, 14 Jul 2022 22:29:37 +0200 Subject: [PATCH] added a fucktion that adds all shared cards to a new user --- auth.py | 11 +++++++---- share.py | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/auth.py b/auth.py index 342e729..1cc7803 100644 --- a/auth.py +++ b/auth.py @@ -1,14 +1,11 @@ -import email import functools -import imp from flask import ( Blueprint, flash, g, redirect, render_template, request, session, url_for ) from hashlib import md5 from create_db import User, get_session -from config import CONFIG - +from share import get_all_shared bp = Blueprint('auth', __name__, url_prefix='/auth') @@ -39,6 +36,12 @@ def register(): user = User(username=username, password=md5(password.encode("utf-8")).hexdigest(), email=mail, settings = "") dbsession.add(user) dbsession.commit() + + #Preden zapremo naj user dobi vse shared karte od prej. + user_id = None #TODO get user id + + get_all_shared(user_id) + dbsession.close() diff --git a/share.py b/share.py index c119642..7fe582e 100644 --- a/share.py +++ b/share.py @@ -26,4 +26,19 @@ def share(card, user_id): print("sharing to, ", user.id) new_card = card = Card(title=card.title, interest_rate=-1.0, owner_id=user.id, item_location=card.item_location, last_review=None, share_id=h) dbsession.add(new_card) - dbsession.commit() \ No newline at end of file + dbsession.commit() + + +def get_all_shared(user_id): + """adds all existing shared cards to this users collection""" + print("DODAJAMO VSE KARTE TEMU NOVEMU USERJU") + dbsession = get_session() + + #get all cards with a shared id but make suer they are unique. add them to collection of user + all_shared_cards = dbsession.query(Card).filter(Card.share_id != 0).distinct(Card.share_id).group_by(Card.share_id) + # new_card = card = Card(title=card.title, interest_rate=-1.0, owner_id=user.id, item_location=card.item_location, last_review=None, share_id=h) + for c in all_shared_cards: + new_card = Card(title= c.title, interest_rate=-1.0, owner_id=user_id, item_location=c.item_location, last_review=None, share_id=c.share_id) + dbsession.add(new_card) + dbsession.commit() + print(c.title, c.share_id, c.item_location) \ No newline at end of file