Conversation
|
Hello @dralley! Thanks for updating the PR.
Comment last updated on December 14, 2018 at 19:58 Hours UTC |
| @@ -247,6 +247,20 @@ def content(self): | |||
| ) | |||
| return Content.objects.filter(version_memberships__in=relationships) | |||
|
|
|||
| @property | |||
| def content_by_type(self): | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not actually sure this function (content_by_type) is necessary or even particularly useful, I may remove it before merging. It seemed like an obvious thing to have at first but I realized that I can't think of anywhere it would actually be used. Generic code doesn't usually need to touch the content-specific fields, so it can just use Content objects. Plugin code already knows what concrete models exist so it can just manage those directly also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the added() and removed() methods be made properties, to match content? Or should we make content a method? The latter would provide maximal flexibility in terms of being able to add functionality later on in the form of kwargs.
f8b232a
to
51e216d
Compare
| @@ -247,6 +249,62 @@ def content(self): | |||
| ) | |||
| return Content.objects.filter(version_memberships__in=relationships) | |||
|
|
|||
| @property | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 3 properties are probably temporary, pending a better solution. This is ugly but it was fairly simple for an initial implementation.
If anyone has suggestions on how to do this in a way that better respects separation of responsibilities, please let me know :) It probably isn't something we want to leave in the model layer.
| _content_href = NestedIdentityField( | ||
| view_name='versions-content', | ||
| lookup_field='number', parent_lookup_kwargs={'repository_pk': 'repository__pk'}, | ||
| _content = serializers.DictField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these names OK or should we go back to what they were before?
Different variants:
- "added_content"
- "content_added_hrefs"
- "added_content_hrefs"
- "added_hrefs"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the "added_content" and "removed_content".
| @@ -244,35 +177,6 @@ class Meta: | |||
| class Meta: | |||
| fields = ModelSerializer.Meta.fields + ('type',) | |||
|
|
|||
| def to_representation(self, instance): | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed since we're no longer trying to serialize generic Content objects as their detail counterparts. Yay!
| _removed_href = NestedIdentityField( | ||
| view_name='versions-removed-content', | ||
| lookup_field='number', parent_lookup_kwargs={'repository_pk': 'repository__pk'}, | ||
| _content_removed = serializers.DictField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume the permanent solution to the aforementioned separation of concerns issue will be to make custom field types with the same logic as the properties, but I haven't done this yet and want to field suggestions first. This way was more straightforwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that custom fields would be appropriate here.
| @@ -1,10 +1,16 @@ | |||
| from .base import AsyncRemoveMixin, AsyncUpdateMixin, BaseFilterSet, NamedModelViewSet # noqa | |||
| # These need to be imported prior to ContentViewSet - do not shuffle this by alphabetical order | |||
| from .custom_filters import ( # noqa | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I struggled a little bit with circular imports here -- should we just move these to viewsets.content since they're only used in that one place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a problem with moving them there.
| @@ -60,3 +63,101 @@ class IsoDateTimeFilter(DateTimeFilter): | |||
| def __init__(self, *args, **kwargs): | |||
| kwargs.setdefault('help_text', _('ISO 8601 formatted dates are supported')) | |||
| super().__init__(*args, **kwargs) | |||
|
|
|||
|
|
|||
| class RepoVersionHrefFilter(Filter): | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I rename this to "BaseRepoVersionHrefFilter" since it's meant to be subclassed and not used directly?
I don't much like the naming of these, generally. Naming suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current name seems fine. The not implemented on filter() will let a developer know not to use it directly.
| @@ -110,13 +110,13 @@ def test_02_sync_content(self): | |||
|
|
|||
| self.assertIsNotNone(repo['_latest_version_href']) | |||
|
|
|||
| content = get_content(repo) | |||
| content = get_file_content(repo) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned on the pulp_file PR, we could just always do get_content(repo)['file'] instead. Open to changing this if QE would prefer it that way.
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
Required PR: pulp/pulp#3774 Required PR: pulp/pulp-smash#1154 [noissue]
These are the API changes from the single-table-content work that were discussed.