From 8b48d3b7e51c01bb5530f378057f28b140f0a3ac Mon Sep 17 00:00:00 2001 From: adilhussain540 Date: Thu, 7 Dec 2023 14:25:30 +0500 Subject: [PATCH] Fix return values inside the BaseQueryset --- cookie_consent/models.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/cookie_consent/models.py b/cookie_consent/models.py index c454ba2..19f2483 100644 --- a/cookie_consent/models.py +++ b/cookie_consent/models.py @@ -19,6 +19,15 @@ ) +def clear_cache_after(func): + def wrapper(*args, **kwargs): + return_value = func(*args, **kwargs) + delete_cache() + return return_value + + return wrapper + + class CookieGroupDict(TypedDict): varname: str name: str @@ -30,13 +39,13 @@ class CookieGroupDict(TypedDict): class BaseQueryset(models.query.QuerySet): + @clear_cache_after def delete(self): - super().delete() - delete_cache() + return super().delete() - def update(self, *args, **kwargs): - super().update(*args, **kwargs) - delete_cache() + @clear_cache_after + def update(self, **kwargs): + return super().update(**kwargs) class CookieGroup(models.Model): @@ -74,13 +83,13 @@ def get_version(self) -> str: except IndexError: return "" + @clear_cache_after def delete(self, *args, **kwargs): super(CookieGroup, self).delete(*args, **kwargs) - delete_cache() + @clear_cache_after def save(self, *args, **kwargs): super(CookieGroup, self).save(*args, **kwargs) - delete_cache() def for_json(self) -> CookieGroupDict: return { @@ -121,13 +130,13 @@ def varname(self): def get_version(self): return self.created.isoformat() + @clear_cache_after def delete(self, *args, **kwargs): super(Cookie, self).delete(*args, **kwargs) - delete_cache() + @clear_cache_after def save(self, *args, **kwargs): super(Cookie, self).save(*args, **kwargs) - delete_cache() ACTION_ACCEPTED = 1