Skip to content

Instantly share code, notes, and snippets.

@chroto
Created June 9, 2014 20:43
Show Gist options
  • Select an option

  • Save chroto/069b941079eef93d0876 to your computer and use it in GitHub Desktop.

Select an option

Save chroto/069b941079eef93d0876 to your computer and use it in GitHub Desktop.
Behold I am Death, destroyer of worlds
def unpatch_models():
"""unpatch"""
if __backup == {}:
return
for module_to_unpatch in model_mods:
name = module_to_unpatch.__name__
for cls_name in vars(module_to_unpatch).get('__patchable__', []):
setattr(module_to_unpatch,
cls_name,
__backup[name][cls_name])
def patch_models(db):
"""
Warning: Don't try this at home.
"""
logger.debug('Starting Model Patch:')
for model_mod in model_mods:
name = model_mod.__name__
logger.debug('Patching module: %s' % name)
__backup[name] = {}
for cls_name in vars(model_mod).get('__patchable__', []):
__backup[name][cls_name] = getattr(model_mod, cls_name)
setattr(
model_mod,
cls_name,
type(
cls_name,
(db.Model, getattr(model_mod, cls_name)),
{}
)
)
logger.debug('Finished Model Patch.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment