X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/01e93f28b2829fd3924a3b6021a201c1b6ed3d72..f3dfeeeb263ea9456b21e07b84dc7a01d2d17b98:/forum/models/base.py?ds=sidebyside diff --git a/forum/models/base.py b/forum/models/base.py index 33bf0c8..9c328c5 100644 --- a/forum/models/base.py +++ b/forum/models/base.py @@ -83,7 +83,8 @@ class CachedQuerySet(models.query.QuerySet): obj.cache() else: obj = self.obj_from_datadict(obj) - obj.reset_original_state() + + obj.reset_original_state() return obj @@ -171,19 +172,25 @@ class CachedQuerySet(models.query.QuerySet): if to_return: for row in to_return: if hasattr(row, 'leaf'): - yield row.leaf - else: - yield row + row = row.leaf - def _get_query_hash(self): - return md5(unicode(self.query).encode("utf-8")).hexdigest() + row.reset_original_state() + yield row + def _get_query_hash(self): + try: + return md5(unicode(self.query).encode("utf-8")).hexdigest() + except: + try: + return md5(self.query).hexdigest() + except: + return md5(str(self.query)).hexdigest() class CachedManager(models.Manager): use_for_related_fields = True - def get_query_set(self): + def get_queryset(self): return CachedQuerySet(self.model) def get_or_create(self, *args, **kwargs): @@ -219,7 +226,7 @@ class DenormalizedField(object): cls.add_to_class("reset_%s_cache" % name, reset_cache) -class BaseMetaClass(models.Model.__metaclass__): +class BaseMetaClass(type(models.Model)): to_denormalize = [] def __new__(cls, *args, **kwargs):