Adds ethereum address to device, and adds PATCH
This commit is contained in:
parent
f6af58ef51
commit
dfb518068d
|
@ -382,6 +382,7 @@ class Computer(Device):
|
|||
|
||||
It is a subset of the Linux definition of DMI / DMI decode.
|
||||
"""
|
||||
ethereum_address = Column(CIText(), unique=True, default=None)
|
||||
deposit = Column(Integer, check_range('deposit',min=0,max=100), default=0)
|
||||
owner_address = db.Column(CIText(),
|
||||
db.ForeignKey(User.ethereum_address),
|
||||
|
|
|
@ -122,6 +122,7 @@ class Computer(Device):
|
|||
dump_only=True,
|
||||
collection_class=set,
|
||||
description=m.Computer.privacy.__doc__)
|
||||
ethereum_address = SanitizedStr(validate=f.validate.Length(max=42))
|
||||
deposit = Integer(validate=f.validate.Range(min=0, max=100),
|
||||
description=m.Computer.deposit.__doc__)
|
||||
# author_id = NestedOn(s_user.User,only_query='author_id')
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import datetime
|
||||
|
||||
import marshmallow
|
||||
from flask import current_app as app, render_template, request
|
||||
from flask import current_app as app, render_template, request, Response
|
||||
from flask.json import jsonify
|
||||
from flask_sqlalchemy import Pagination
|
||||
from marshmallow import fields, fields as f, validate as v
|
||||
from marshmallow import fields, fields as f, validate as v, ValidationError
|
||||
from teal import query
|
||||
from teal.cache import cache
|
||||
from teal.resource import View
|
||||
|
@ -15,7 +15,7 @@ from ereuse_devicehub.query import SearchQueryParser, things_response
|
|||
from ereuse_devicehub.resources import search
|
||||
from ereuse_devicehub.resources.action import models as actions
|
||||
from ereuse_devicehub.resources.device import states
|
||||
from ereuse_devicehub.resources.device.models import Device, Manufacturer
|
||||
from ereuse_devicehub.resources.device.models import Device, Manufacturer, Computer
|
||||
from ereuse_devicehub.resources.device.search import DeviceSearch
|
||||
from ereuse_devicehub.resources.lot.models import LotDeviceDescendants
|
||||
from ereuse_devicehub.resources.tag.model import Tag
|
||||
|
@ -92,7 +92,24 @@ class DeviceView(View):
|
|||
description: The device or devices.
|
||||
"""
|
||||
return super().get(id)
|
||||
|
||||
|
||||
def patch(self, id):
|
||||
dev = Device.query.filter_by(id=id).one()
|
||||
if isinstance(dev, Computer):
|
||||
resource_def = app.resources['Computer']
|
||||
# TODO check how to handle the 'actions_one'
|
||||
patch_schema = resource_def.SCHEMA(only=['ethereum_address', 'actions_one'], partial=True)
|
||||
json = request.get_json(schema=patch_schema)
|
||||
# TODO check how to handle the 'actions_one'
|
||||
json.pop('actions_one')
|
||||
if not dev:
|
||||
raise ValueError('Device non existent')
|
||||
for key, value in json.items():
|
||||
setattr(dev,key,value)
|
||||
db.session.commit()
|
||||
return Response(status=204)
|
||||
raise ValueError('Cannot patch a non computer')
|
||||
|
||||
def one(self, id: int):
|
||||
"""Gets one device."""
|
||||
if not request.authorization:
|
||||
|
|
Reference in New Issue