try execute create_code
This commit is contained in:
parent
269550270f
commit
41cadcc0b3
|
@ -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()}')
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Reference in New Issue