123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- from importlib import import_module
- from django.utils import translation
- from misago.core.cache import cache as default_cache
- from misago.core.cachebuster import CACHE_KEY
- def ugettext_lazy(string):
- """
- Custom wrapper that preserves untranslated message on lazy translation
- string object, useful for db entries that should be found by makemessages
- and stored untranslated
- """
- t = translation.ugettext_lazy(string)
- t.message = string
- return t
- def original_message(string):
- try:
- return unicode(string.message)
- except AttributeError:
- return unicode(string)
- def with_core_models(migration, this_migration=None):
- module_name = 'misago.core.migrations.%s' % migration
- migration_module = import_module(module_name)
- core_models = migration_module.Migration.models
- if this_migration:
- core_models.update(this_migration)
- return core_models
- def cachebuster_register_cache(orm, cache):
- orm['core.CacheVersion'].objects.create(cache=cache)
- def cachebuster_unregister_cache(orm, cache):
- try:
- cache = orm['core.CacheVersion'].objects.get(cache=cache)
- cache.delete()
- except orm['core.CacheVersion'].DoesNotExist:
- raise ValueError('Cache "%s" is not registered' % cache)
- def delete_cachebuster_cache():
- default_cache.delete(CACHE_KEY)
|