Compare commits

...

2 Commits

Author SHA1 Message Date
Kostanjevec 0339653954 added a fucktion that adds all shared cards to a new user 2022-07-14 22:29:37 +02:00
Kostanjevec 290f8dd266 Removed max_shared option in sttings template. 2022-07-14 21:35:38 +02:00
3 changed files with 28 additions and 7 deletions

11
auth.py
View File

@ -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()

View File

@ -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)

View File

@ -10,8 +10,11 @@ quantity
<input type="number" id="quantity" name="max_new" value= '{{ settings['max_new'] }}' min="0" required="required">
<label for="quantity">Maximum seen cards per session</label>
<input type="number" id="quantity" name="max_due" value='{{ settings['max_due'] }}' min="0" required="required">
<label for="quantity">Maximum shared cards per session</label>
<input type="number" id="quantity" name="max_shared" value='{{ settings['max_shared'] }}' min="0" required="required">
<!--
@TODO napiši to funkcijo, preden se kaže ui za njo
<label for="quantity">Maximum shared cards per session</label>
<input type="number" id="quantity" name="max_shared" value='{{ settings['max_shared'] }}' min="0" required="required">
-->
<input type="submit" value="Save">
</form>
{% endblock %}