This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/scripts/sharelot.py
Cayo Puigdefabregas e365c366f4 share lot structure
2023-04-26 18:25:03 +02:00

31 lines
729 B
Python

import sys
import uuid
from decouple import config
from ereuse_devicehub.db import db
from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.resources.lot.models import Lot, ShareLot
from ereuse_devicehub.resources.user.models import User
def main():
# import pdb; pdb.set_trace()
schema = config('DB_SCHEMA')
app = Devicehub(inventory=schema)
app.app_context().push()
email = sys.argv[1]
lot_id = sys.argv[2]
id = uuid.uuid4()
user = User.query.filter_by(email=email).first()
lot = Lot.query.filter_by(id=lot_id).first()
share_lot = ShareLot(id=id, lot=lot, user_to=user)
db.session.add(share_lot)
db.session.commit()
if __name__ == '__main__':
main()