fixing automatic confirmation

This commit is contained in:
Cayo Puigdefabregas 2021-06-07 17:12:30 +02:00
parent 6546332fe5
commit e9a09ec2ae
1 changed files with 27 additions and 26 deletions

View File

@ -29,14 +29,14 @@ class TradeView():
def __init__(self, data, resource_def, schema):
self.schema = schema
a = resource_def.schema.load(data)
a.pop('user_to_email', '')
a.pop('user_from_email', '')
self.trade = Trade(**a)
self.data = resource_def.schema.load(data)
self.data.pop('user_to_email', '')
self.data.pop('user_from_email', '')
self.create_phantom_account()
self.trade = Trade(**self.data)
db.session.add(self.trade)
self.create_automatic_trade()
self.create_confirmations()
self.create_automatic_trade()
def post(self):
db.session().final_flush()
@ -82,36 +82,40 @@ class TradeView():
The same if exist to but not from
"""
if self.trade.user_from and self.trade.user_to:
user_from = self.data.get('user_from')
user_to = self.data.get('user_to')
code = self.data.get('code')
if user_from and user_to:
return
if self.trade.confirm:
if self.data['confirm']:
return
if self.trade.user_from and not self.trade.user_to:
assert g.user == self.trade.user_from
email = "{}_{}@dhub.com".format(str(self.trade.user_from.id), self.trade.code)
if user_from and not user_to:
assert g.user == user_from
email = "{}_{}@dhub.com".format(str(user_from.id), code)
users = User.query.filter_by(email=email)
if users.first():
user = users.first()
self.trade.user_to = user
self.data['user_to'] = user
return
user = User(email=email, password='', active=False, phantom=True)
db.session.add(user)
self.trade.user_to = user
self.data['user_to'] = user
if not self.trade.user_from and self.trade.user_to:
email = "{}_{}@dhub.com".format(str(self.trade.user_to.id), self.trade.code)
if not user_from and user_to:
email = "{}_{}@dhub.com".format(str(user_to.id), code)
users = User.query.filter_by(email=email)
if users.first():
user = users.first()
self.trade.user_from = user
self.data['user_from'] = user
return
user = User(email=email, password='', active=False, phantom=True)
db.session.add(user)
self.trade.user_from = user
self.data['user_from'] = user
def create_automatic_trade(self) -> None:
# not do nothing if it's neccesary confirmation explicity
@ -120,10 +124,7 @@ class TradeView():
# Change the owner for every devices
for dev in self.trade.devices:
dev.owner = self.trade.user_to
if hasattr(dev, 'components'):
for c in dev.components:
c.owner = self.trade.user_to
dev.change_owner(self.trade.user_to)
class ConfirmMixin():