hashcode insted of hascode
This commit is contained in:
parent
f331128741
commit
2175987c85
|
@ -15,7 +15,7 @@ from ereuse_devicehub.resources.agent.models import Organization
|
||||||
from ereuse_devicehub.resources.device.models import Device
|
from ereuse_devicehub.resources.device.models import Device
|
||||||
from ereuse_devicehub.resources.models import Thing
|
from ereuse_devicehub.resources.models import Thing
|
||||||
from ereuse_devicehub.resources.user.models import User
|
from ereuse_devicehub.resources.user.models import User
|
||||||
from ereuse_devicehub.resources.utils import hascode
|
from ereuse_devicehub.resources.utils import hashcode
|
||||||
|
|
||||||
|
|
||||||
class Tags(Set['Tag']):
|
class Tags(Set['Tag']):
|
||||||
|
@ -134,7 +134,7 @@ class Tag(Thing):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code(self) -> str:
|
def code(self) -> str:
|
||||||
return hascode.encode(self.internal_id)
|
return hashcode.encode(self.internal_id)
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
"""Deletes the tag.
|
"""Deletes the tag.
|
||||||
|
|
|
@ -6,7 +6,7 @@ from teal.resource import View, url_for_resource
|
||||||
from ereuse_devicehub import auth
|
from ereuse_devicehub import auth
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.query import things_response
|
from ereuse_devicehub.query import things_response
|
||||||
from ereuse_devicehub.resources.utils import hascode
|
from ereuse_devicehub.resources.utils import hashcode
|
||||||
from ereuse_devicehub.resources.device.models import Device
|
from ereuse_devicehub.resources.device.models import Device
|
||||||
from ereuse_devicehub.resources.tag import Tag
|
from ereuse_devicehub.resources.tag import Tag
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ from ereuse_devicehub.resources.tag import Tag
|
||||||
class TagView(View):
|
class TagView(View):
|
||||||
def one(self, code):
|
def one(self, code):
|
||||||
"""Gets the device from the named tag, /tags/namedtag."""
|
"""Gets the device from the named tag, /tags/namedtag."""
|
||||||
internal_id = hascode.decode(code.upper()) or -1
|
internal_id = hashcode.decode(code.upper()) or -1
|
||||||
tag = Tag.query.filter_by(internal_id=internal_id).one() # type: Tag
|
tag = Tag.query.filter_by(internal_id=internal_id).one() # type: Tag
|
||||||
if not tag.device:
|
if not tag.device:
|
||||||
raise TagNotLinked(tag.id)
|
raise TagNotLinked(tag.id)
|
||||||
|
|
|
@ -3,7 +3,4 @@ from decouple import config
|
||||||
|
|
||||||
ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
SECRET = config('TAG_HASH', '')
|
SECRET = config('TAG_HASH', '')
|
||||||
hascode = Hashids(SECRET, min_length=5, alphabet=ALPHABET)
|
hashcode = Hashids(SECRET, min_length=5, alphabet=ALPHABET)
|
||||||
|
|
||||||
def hashids(id):
|
|
||||||
return hascode.encode(id)
|
|
||||||
|
|
Reference in New Issue