added a fucktion that adds all shared cards to a new user
parent
290f8dd266
commit
0339653954
11
auth.py
11
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()
|
||||
|
||||
|
||||
|
|
17
share.py
17
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()
|
||||
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)
|
Loading…
Reference in New Issue