def one(self, id): """Gets the device from the tag.""" if request.authorization: return self.one_authorization(id) tag = Tag.from_an_id(id).one() # type: Tag if not tag.device: raise TagNotLinked(tag.id) if not request.authorization: return redirect( location=url_for_resource(Device, tag.device.devicehub_id)) return app.resources[Device.t].schema.jsonify(tag.device.devicehub_id)
def get_device_from_tag(id: str): """Gets the device by passing a tag id. Example: /tags/23/device. :raise MultipleTagsPerId: More than one tag per Id. Please, use the /tags/<organization>/<id>/device URL to disambiguate. """ # todo this could be more efficient by Device.query... join with tag device = Tag.query.filter_by(id=id).one().device if not request.authorization: return redirect(location=url_for_resource(Device, device.devicehub_id)) if device is None: raise TagNotLinked(id) return app.resources[Device.t].schema.jsonify(device)
def url(self) -> urlutils.URL: """The URL where to GET this device.""" # todo this url only works for printable internal tags return urlutils.URL(url_for_resource(Tag, item_id=self.id))
def url(self) -> urlutils.URL: """The URL where to GET this event.""" return urlutils.URL(url_for_resource(Lot, item_id=self.id))
def url(self) -> urlutils.URL: """The URL where to GET this action.""" return urlutils.URL(url_for_resource(Deliverynote, item_id=self.id))
def url(self) -> urlutils.URL: """The URL where to GET this device.""" return urlutils.URL(url_for_resource(Device, item_id=self.id))
def test_url_for_resource(app: Teal): with app.test_request_context(): # Note we need a test_request_context or flask won't know # which base_url to use. assert url_for_resource('Computer') == '/computers/' assert url_for_resource('Computer', 24) == '/computers/24'