hashcode insted of hascode

This commit is contained in:
Cayo Puigdefabregas 2021-03-08 13:09:01 +01:00
parent f331128741
commit 2175987c85
3 changed files with 5 additions and 8 deletions

View File

@ -15,7 +15,7 @@ from ereuse_devicehub.resources.agent.models import Organization
from ereuse_devicehub.resources.device.models import Device
from ereuse_devicehub.resources.models import Thing
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']):
@ -134,7 +134,7 @@ class Tag(Thing):
@property
def code(self) -> str:
return hascode.encode(self.internal_id)
return hashcode.encode(self.internal_id)
def delete(self):
"""Deletes the tag.

View File

@ -6,7 +6,7 @@ from teal.resource import View, url_for_resource
from ereuse_devicehub import auth
from ereuse_devicehub.db import db
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.tag import Tag
@ -14,7 +14,7 @@ from ereuse_devicehub.resources.tag import Tag
class TagView(View):
def one(self, code):
"""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
if not tag.device:
raise TagNotLinked(tag.id)

View File

@ -3,7 +3,4 @@ from decouple import config
ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
SECRET = config('TAG_HASH', '')
hascode = Hashids(SECRET, min_length=5, alphabet=ALPHABET)
def hashids(id):
return hascode.encode(id)
hashcode = Hashids(SECRET, min_length=5, alphabet=ALPHABET)