Skip to content

Commit

Permalink
Fix return values inside the BaseQueryset
Browse files Browse the repository at this point in the history
  • Loading branch information
adilhussain540 committed Dec 7, 2023
1 parent e3d4781 commit 8b48d3b
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions cookie_consent/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8b48d3b

Please sign in to comment.