add snapthot and dpp to action EWaste
This commit is contained in:
parent
708dad64aa
commit
9fb2b1c94a
|
@ -841,6 +841,9 @@ class ActionFormMixin(FlaskForm):
|
||||||
if not self._devices:
|
if not self._devices:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if len(devices) > 1 and self.type.data == 'EWaste':
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def generic_validation(self, extra_validators=None):
|
def generic_validation(self, extra_validators=None):
|
||||||
|
|
|
@ -902,6 +902,7 @@ class Snapshot(JoinedWithOneDeviceMixin, ActionWithOneDevice):
|
||||||
from ereuse_devicehub.modules.dpp.models import Dpp, ALGORITHM
|
from ereuse_devicehub.modules.dpp.models import Dpp, ALGORITHM
|
||||||
|
|
||||||
dpp = "{chid}:{phid}".format(chid=self.device.chid, phid=self.phid_dpp)
|
dpp = "{chid}:{phid}".format(chid=self.device.chid, phid=self.phid_dpp)
|
||||||
|
# '54f431688524825f00d6fb786d5211e642e3d4564187f9ad23627ec9d313f17c'
|
||||||
if Dpp.query.filter_by(key=dpp).all():
|
if Dpp.query.filter_by(key=dpp).all():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -1785,11 +1786,50 @@ class EWaste(ActionWithMultipleDevices):
|
||||||
proof = Proof(**d)
|
proof = Proof(**d)
|
||||||
db.session.add(proof)
|
db.session.add(proof)
|
||||||
|
|
||||||
|
self.create_snapshot()
|
||||||
|
|
||||||
def generateDocSig(self):
|
def generateDocSig(self):
|
||||||
if not self.doc:
|
if not self.doc:
|
||||||
return
|
return
|
||||||
return hashlib.sha3_256(self.doc.encode('utf-8')).hexdigest()
|
return hashlib.sha3_256(self.doc.encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
|
def create_snapshot(self):
|
||||||
|
for device in self.devices:
|
||||||
|
dev = device.placeholder.binding
|
||||||
|
hw = self.create_json_hw(dev)
|
||||||
|
phid = hashlib.sha3_256(hw.encode('utf-8')).hexdigest()
|
||||||
|
version = self.last_snap.version
|
||||||
|
software = self.last_snap.software
|
||||||
|
|
||||||
|
snap = Snapshot(
|
||||||
|
author=dev.owner,
|
||||||
|
uuid=uuid4(),
|
||||||
|
device=dev,
|
||||||
|
json_hw = hw,
|
||||||
|
phid_dpp = phid,
|
||||||
|
version = version,
|
||||||
|
software = software
|
||||||
|
)
|
||||||
|
db.session.add(snap)
|
||||||
|
snap.register_passport_dlt()
|
||||||
|
self.snapshot = snap
|
||||||
|
|
||||||
|
def create_json_hw(self, device):
|
||||||
|
hw = self.get_json_hw(device)
|
||||||
|
hw['e-waste'] = True
|
||||||
|
return json.dumps(hw)
|
||||||
|
|
||||||
|
def get_json_hw(self, device):
|
||||||
|
self.last_snap = None
|
||||||
|
try:
|
||||||
|
self.last_snap = device.last_action_of(Snapshot)
|
||||||
|
except Exception:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
if self.last_snap.json_hw:
|
||||||
|
return json.loads(self.last_snap.json_hw)
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
class ToPrepare(ActionWithMultipleDevices):
|
class ToPrepare(ActionWithMultipleDevices):
|
||||||
"""The device has been selected for preparation.
|
"""The device has been selected for preparation.
|
||||||
|
|
|
@ -28,9 +28,9 @@ class LoginView(View):
|
||||||
template_name = 'ereuse_devicehub/user_login.html'
|
template_name = 'ereuse_devicehub/user_login.html'
|
||||||
|
|
||||||
def dispatch_request(self):
|
def dispatch_request(self):
|
||||||
if session.get('_user_id'):
|
# if session.get('_user_id'):
|
||||||
next_url = flask.request.args.get('next')
|
# next_url = flask.request.args.get('next')
|
||||||
return flask.redirect(next_url or flask.url_for('inventory.devicelist'))
|
# return flask.redirect(next_url or flask.url_for('inventory.devicelist'))
|
||||||
|
|
||||||
form = LoginForm()
|
form = LoginForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
|
|
Reference in New Issue