migrationutils.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from importlib import import_module
  2. from django.utils import translation
  3. from misago.core.cache import cache as default_cache
  4. from misago.core.cachebuster import CACHE_KEY
  5. def ugettext_lazy(string):
  6. """
  7. Custom wrapper that preserves untranslated message on lazy translation
  8. string object, useful for db entries that should be found by makemessages
  9. and stored untranslated
  10. """
  11. t = translation.ugettext_lazy(string)
  12. t.message = string
  13. return t
  14. def with_core_models(migration, this_migration=None):
  15. module_name = 'misago.core.migrations.%s' % migration
  16. migration_module = import_module(module_name)
  17. core_models = migration_module.Migration.models
  18. if this_migration:
  19. core_models.update(this_migration)
  20. return core_models
  21. def cachebuster_register_cache(orm, cache):
  22. orm['core.CacheVersion'].objects.create(cache=cache)
  23. def cachebuster_unregister_cache(orm, cache):
  24. try:
  25. cache = orm['core.CacheVersion'].objects.get(cache=cache)
  26. cache.delete()
  27. except orm['core.CacheVersion'].DoesNotExist:
  28. raise ValueError('Cache "%s" is not registered' % cache)
  29. def delete_cachebuster_cache():
  30. default_cache.delete(CACHE_KEY)