You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
1.2 KiB

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from config import CONFIG
from create_db import User, Card, get_session
from hashlib import md5
#@TODO najbrž je treba narediti tako da org card tudi dobi share id in se ostalo, kar to obsega
def share(card, user_id):
dbsession = get_session()
#tu bi lahko naredili nek autoincrement ampak i guess da hash unique idja tudi daje unique share_id, tega potem uporabljamo, da preverimo matche
h = md5(str("utf-8")).hexdigest()
card.share_id = h
owner_card = dbsession.query(Card).filter( ==
owner_card.share_id = h
# all users
users = dbsession.query(User).filter( != user_id).all()
for user in users:
#skip če že ima ta card v db.
existing = dbsession.query(Card).filter(Card.title == card.title,
if existing == []:
print("sharing to, ",
new_card = card = Card(title=card.title, interest_rate=-1.0,, item_location=card.item_location, last_review=None, share_id=h)