-
Notifications
You must be signed in to change notification settings - Fork 158
Add added_between/removed_between filters for content diffs across arbitrary repository versions #7844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add added_between/removed_between filters for content diffs across arbitrary repository versions #7844
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Added optional `added_between` and `removed_between` filters to the content list endpoints. Each | ||
| takes two repository versions (by HREF/PRN) as `base,target` and returns the net set of content | ||
| added or removed going from the base version to the target version, allowing diffs between two | ||
| arbitrary (possibly non-adjacent) repository versions instead of only the single-step difference | ||
| against the immediate predecessor. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,7 +157,7 @@ def get_resource_model(uri): | |
| return match.func.cls.queryset.model | ||
|
|
||
| @staticmethod | ||
| def get_resource(uri, model=None): | ||
| def get_resource(uri, model=None, deferred_fields=None): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to handle the deferring differently (on the model/manager level not the view):
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mdellweg I left a comment on your PR. I'm fine with your changes, but how would you like to proceed so that we don't conflict? |
||
| """ | ||
| Resolve a resource URI/PRN to an instance of the resource. | ||
|
|
||
|
|
@@ -168,6 +168,9 @@ def get_resource(uri, model=None): | |
| uri (str): A resource URI/PRN. | ||
| model (django.models.Model): A model class. If not provided, the method automatically | ||
| determines the used model from the resource URI/PRN. | ||
| deferred_fields (iterable): Optional field names to defer when loading the resource, so | ||
| large columns are not fetched from the database. Field names that do not exist on | ||
| the resolved model are ignored. | ||
|
|
||
| Returns: | ||
| django.models.Model: The resource fetched from the DB. | ||
|
|
@@ -209,7 +212,13 @@ def get_resource(uri, model=None): | |
| kwargs[key] = value | ||
|
|
||
| try: | ||
| return model.objects.get(**kwargs) | ||
| manager = model.objects | ||
| if deferred_fields: | ||
| model_fields = {field.name for field in model._meta.concrete_fields} | ||
| to_defer = [name for name in deferred_fields if name in model_fields] | ||
| if to_defer: | ||
| manager = manager.defer(*to_defer) | ||
| return manager.get(**kwargs) | ||
| except model.MultipleObjectsReturned: | ||
| raise DRFValidationError( | ||
| detail=_("URI {u} matches more than one {m}.").format( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.