def sys_customers(): global _hasCreated if not _hasCreated: helpers.define_model( "customers", [["code"]], code=helpers.create_field("text", True), # link to sys_multi_tenancy name=helpers.create_field("text", True), contact_info=dict( address=helpers.create_field("text", True), email=helpers.create_field("text", True), ), admin_user=helpers.create_field("text", True), # link to auth_user ) _hasCreated = True ret = applications.get_settings().database.collection("customers") # ret.turn_never_use_schema_on() return ret
def sys_customers(): global _hasCreated if not _hasCreated: helpers.define_model( "customers", [["code"]], code=helpers.create_field("text", True) , # link to sys_multi_tenancy name=helpers.create_field("text", True), contact_info=dict( address=helpers.create_field("text", True), email=helpers.create_field("text", True), ), admin_user=helpers.create_field("text", True),# link to auth_user ) _hasCreated=True ret = applications.get_settings().database.collection("customers") # ret.turn_never_use_schema_on() return ret
def sys_multi_tenancy(): # type: () -> database.collection """ this model is the flection on 'sys_multi_tenancy' in mongodb. Just have 2 fields, no more... :return: """ global _hasCreated if not _hasCreated: helpers.define_model( "sys_multi_tenancy", [ ["code"], ["schema"] ], code= helpers.create_field("text",True), schema= helpers.create_field("text",True), ) _hasCreated=True ret = applications.get_settings().database.collection("sys_multi_tenancy") ret.turn_never_use_schema_on() return ret
def auth_user(): global _hasCreated if not _hasCreated: helpers.define_model( "auth_user", [["username"]], username=helpers.create_field("text", True), first_name=helpers.create_field("text", True), # link to last_name=helpers.create_field("text", True), is_active=helpers.create_field("bool", True), email=helpers.create_field("text", True), is_superuser=helpers.create_field("bool", True), is_staff=helpers.create_field("bool", True), last_login=helpers.create_field("date"), date_joined=helpers.create_field("date")) _hasCreated = True ret = applications.get_settings().database.collection("auth_user") return ret
def sys_multi_tenancy(): # type: () -> database.collection """ this model is the flection on 'sys_multi_tenancy' in mongodb. Just have 2 fields, no more... :return: """ import sys settings = sys.modules["settings"] global _hasCreated if not _hasCreated: helpers.define_model( settings.MULTI_TENANCY_CONFIGURATION["collection"], [["code"], ["schema"]], code=helpers.create_field("text", True), schema=helpers.create_field("text", True), ) _hasCreated = True ret = applications.get_settings().database.collection( settings.MULTI_TENANCY_CONFIGURATION["collection"]) ret.turn_never_use_schema_on() return ret
def auth_user(): global _hasCreated if not _hasCreated: helpers.define_model( "auth_user", [["username"]], username=helpers.create_field("text", True), first_name=helpers.create_field("text", True) , # link to last_name=helpers.create_field("text", True), is_active=helpers.create_field("bool", True), email=helpers.create_field("text", True), is_superuser=helpers.create_field("bool", True), is_staff=helpers.create_field("bool", True), last_login =helpers.create_field("date"), date_joined =helpers.create_field("date") ) _hasCreated=True ret = applications.get_settings().database.collection("auth_user") return ret
user = threading.current_thread().user.username if data.get('created_by',None)==None: data.update({ "created_on":datetime.datetime.now(), "created_on_utc":datetime.datetime.utcnow(), "created_by":user }) def on_before_update(data): user = "******" if hasattr(threading.current_thread(),"user"): user = threading.current_thread().user.username if data.get('modified_by',None)==None: data.update({ "modified_on":datetime.datetime.now(), "modified_on_utc":datetime.datetime.utcnow(), "modified_by":user }) helpers.define_model( "base", [], dict( created_on=helpers.create_field("date",True), created_on_utc=helpers.create_field("date",True), created_by=helpers.create_field("text",True), modified_on=helpers.create_field("date",True), modified_on_utc=helpers.create_field("date",True), modified_by=helpers.create_field("text",True) ) )
"created_on": datetime.datetime.now(), "created_on_utc": datetime.datetime.utcnow(), "created_by": user }) def on_before_update(data): user = "******" if hasattr(threading.current_thread(), "user"): user = threading.current_thread().user.username if data.get('modified_by', None) == None: data.update({ "modified_on": datetime.datetime.now(), "modified_on_utc": datetime.datetime.utcnow(), "modified_by": user }) helpers.define_model( "base_employee", [["code"]], dict(code=helpers.create_field("text", True), description=helpers.create_field("text", False), created_on=helpers.create_field("date", True), created_on_utc=helpers.create_field("date", True), created_by=helpers.create_field("text", True), modified_on=helpers.create_field("date", False), modified_on_utc=helpers.create_field("date", False), modified_by=helpers.create_field("text", False))) helpers.events("base_employee")\ .on_before_insert(on_before_insert)\ .on_before_update(on_before_update)
user = "******" if hasattr(threading.current_thread(), "user"): user = threading.current_thread().user.username if data.get('created_by', None) == None: data.update({ "created_on": datetime.datetime.now(), "created_on_utc": datetime.datetime.utcnow(), "created_by": user }) def on_before_update(data): user = "******" if hasattr(threading.current_thread(), "user"): user = threading.current_thread().user.username if data.get('modified_by', None) == None: data.update({ "modified_on": datetime.datetime.now(), "modified_on_utc": datetime.datetime.utcnow(), "modified_by": user }) helpers.define_model( "base", [], dict(created_on=helpers.create_field("date", True), created_on_utc=helpers.create_field("date", True), created_by=helpers.create_field("text", True), modified_on=helpers.create_field("date", True), modified_on_utc=helpers.create_field("date", True), modified_by=helpers.create_field("text", True)))