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