adding hashcode
This commit is contained in:
parent
3a4410a4ce
commit
06dfb9e31e
|
@ -10,9 +10,7 @@ import sqlalchemy as sa
|
|||
from alembic import op
|
||||
from alembic import context
|
||||
|
||||
from ereuse_devicehub.db import db
|
||||
from ereuse_devicehub.resources.device.utils import hashids
|
||||
from ereuse_devicehub.resources.device.models import Device
|
||||
from ereuse_devicehub.resources.device.utils import hashcode
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
|
@ -34,7 +32,7 @@ def upgrade_data():
|
|||
devices = con.execute(f"select id from {get_inv()}.device")
|
||||
for d in devices:
|
||||
id_dev = d.id
|
||||
code = hashids(d.id)
|
||||
code = hashcode(d.id)
|
||||
sql = f"update {get_inv()}.device set code='{code}' where id={id_dev};"
|
||||
con.execute(sql)
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ from teal.marshmallow import ValidationError
|
|||
from teal.resource import url_for_resource
|
||||
|
||||
from ereuse_devicehub.db import db
|
||||
from ereuse_devicehub.resources.device.utils import hashids
|
||||
from ereuse_devicehub.resources.device.utils import hashcode
|
||||
from ereuse_devicehub.resources.enums import BatteryTechnology, CameraFacing, ComputerChassis, \
|
||||
DataStorageInterface, DisplayTech, PrinterTechnology, RamFormat, RamInterface, Severity, TransferState
|
||||
from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing, listener_reset_field_updated_in_actual_time
|
||||
|
@ -39,7 +39,7 @@ def create_code(context):
|
|||
_id = Device.query.order_by(Device.id.desc()).first() or 1
|
||||
if not _id == 1:
|
||||
_id = _id.id + 1
|
||||
return hashids(_id)
|
||||
return hashcode.encode(_id)
|
||||
|
||||
|
||||
class Device(Thing):
|
||||
|
|
6
ereuse_devicehub/resources/utils.py
Normal file
6
ereuse_devicehub/resources/utils.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from hashids import Hashids
|
||||
from decouple import config
|
||||
|
||||
ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
SECRET = config('TAG_HASH', '')
|
||||
hashcode = Hashids(SECRET, min_length=5, alphabet=ALPHABET)
|
Reference in a new issue