Skip to content

Commit

Permalink
refactor(apis_metainfo): move clean_uri from get_or_create to get
Browse files Browse the repository at this point in the history
The get_or_create method calls the get method, so it makes sense to put
the url cleaning in the get method itself.
  • Loading branch information
b1rger committed Jan 29, 2024
1 parent 2128001 commit 7f21c81
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions apis_core/apis_metainfo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ class InheritanceForeignKey(models.ForeignKey):


# Uri model
# We use a custom UriManager, so we can override the queryset `get_or_create`
# method. This is useful because we normalize the uri field before saving.
# We use a custom UriManager, so we can override the queryset `get`
# method. This way we can normalize the uri field.


class UriQuerySet(models.query.QuerySet):
def get_or_create(self, defaults=None, **kwargs):
def get(self, *args, **kwargs):
if "uri" in kwargs:
kwargs["uri"] = clean_uri(kwargs["uri"])
return super().get_or_create(defaults, **kwargs)
return super().get(*args, **kwargs)


class UriManager(models.Manager):
Expand Down

0 comments on commit 7f21c81

Please sign in to comment.