From 41cadcc0b39758d9b232b6f6e2fc8ea453e5802e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 4 Mar 2021 10:19:31 +0100 Subject: [PATCH] try execute create_code --- .../versions/8cb91ad1cc40_add_code_to_device.py | 10 ++++++++-- ereuse_devicehub/resources/device/models.py | 14 ++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ereuse_devicehub/migrations/versions/8cb91ad1cc40_add_code_to_device.py b/ereuse_devicehub/migrations/versions/8cb91ad1cc40_add_code_to_device.py index 44d7c39a..3e9b2828 100644 --- a/ereuse_devicehub/migrations/versions/8cb91ad1cc40_add_code_to_device.py +++ b/ereuse_devicehub/migrations/versions/8cb91ad1cc40_add_code_to_device.py @@ -5,10 +5,11 @@ Revises: eca457d8b2a4 Create Date: 2021-03-03 10:39:19.331027 """ +import citext +import sqlalchemy as sa from alembic import op from alembic import context -import sqlalchemy as sa -import citext +from ereuse_devicehub.resources.device.utils import Hashids # revision identifiers, used by Alembic. @@ -25,8 +26,13 @@ def get_inv(): return INV +def create_code(context): + _id = context.get_current_parameters()['id'] + return Hashids(_id) + def upgrade(): op.add_column('device', sa.Column('code', citext.CIText(), + default=create_code, nullable=True), schema=f'{get_inv()}') diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index f9c7db13..492b5004 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -1029,10 +1029,12 @@ class Manufacturer(db.Model): listener_reset_field_updated_in_actual_time(Device) -def create_code(mapper, connection, thing_obj): - """ This function create the code for every device.""" - thing_obj.code = Hashids(thing_obj.id) +# def create_code(mapper, connection, thing_obj): + # """ This function create the code for every device.""" + # thing_obj.code = Hashids(thing_obj.id) -def listener_reset_field_updated_in_actual_time(thing_obj): - """ This function launch a event than listen like a signal when some device is create.""" - event.listen(thing_obj, 'after_create', create_code, propagate=True) +# def listener_create_code(thing_obj): + # """ This function launch a event than listen like a signal when some device is create.""" + # event.listen(thing_obj, 'before_create', create_code) + +# listener_create_code(Device)