-
Notifications
You must be signed in to change notification settings - Fork 655
API endpoint to filter assets by internal name #1998
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
43f70ea
Move serializers to proper file in sponsors app
berinhard 265413a
Minimal config to have the endpoint set up
berinhard ec3e275
Introduce custom query set on generic assets to list all specific imp…
berinhard 376a39f
Refactor to rely on DRF default behavior to serialize bad requests
berinhard 520af9b
Serialize text assets
berinhard 264e8ba
Serialize image value as URL
berinhard 2bdd1d6
Serialize sponsor name within asset information
berinhard ab7da79
Limit reportlab version to one that satisfies dependency but doesn't …
berinhard ebc2227
Also serializes sponsor slug
berinhard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,3 +47,4 @@ num2words==0.5.10 | |
| django-polymorphic==3.0.0 | ||
| sorl-thumbnail==12.7.0 | ||
| docxtpl==0.12.0 | ||
| reportlab==3.6.6 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
|
|
||
| from rest_framework import serializers | ||
|
|
||
| from sponsors.models import GenericAsset | ||
| from sponsors.models.enums import PublisherChoices, LogoPlacementChoices | ||
|
|
||
| class LogoPlacementSerializer(serializers.Serializer): | ||
| publisher = serializers.CharField() | ||
| flight = serializers.CharField() | ||
| sponsor = serializers.CharField() | ||
| sponsor_slug = serializers.CharField() | ||
| description = serializers.CharField() | ||
| logo = serializers.URLField() | ||
| start_date = serializers.DateField() | ||
| end_date = serializers.DateField() | ||
| sponsor_url = serializers.URLField() | ||
| level_name = serializers.CharField() | ||
| level_order = serializers.IntegerField() | ||
|
|
||
|
|
||
| class AssetSerializer(serializers.ModelSerializer): | ||
| content_type = serializers.SerializerMethodField() | ||
| value = serializers.SerializerMethodField() | ||
| sponsor = serializers.SerializerMethodField() | ||
| sponsor_slug = serializers.SerializerMethodField() | ||
|
|
||
| class Meta: | ||
| model = GenericAsset | ||
| fields = ["internal_name", "uuid", "value", "content_type", "sponsor", "sponsor_slug"] | ||
|
|
||
| def _get_sponsor_object(self, asset): | ||
| if asset.from_sponsorship: | ||
| return asset.content_object.sponsor | ||
| else: | ||
| return asset.content_object | ||
|
|
||
| def get_content_type(self, asset): | ||
| return asset.content_type.name.title() | ||
|
|
||
| def get_value(self, asset): | ||
| if not asset.has_value: | ||
| return "" | ||
| return asset.value if not asset.is_file else asset.value.url | ||
|
|
||
| def get_sponsor(self, asset): | ||
| return self._get_sponsor_object(asset).name | ||
|
|
||
| def get_sponsor_slug(self, asset): | ||
| return self._get_sponsor_object(asset).slug | ||
|
|
||
|
|
||
| class FilterLogoPlacementsSerializer(serializers.Serializer): | ||
| publisher = serializers.ChoiceField( | ||
| choices=[(c.value, c.name.replace("_", " ").title()) for c in PublisherChoices], | ||
| required=False, | ||
| ) | ||
| flight = serializers.ChoiceField( | ||
| choices=[(c.value, c.name.replace("_", " ").title()) for c in LogoPlacementChoices], | ||
| required=False, | ||
| ) | ||
|
|
||
| @property | ||
| def by_publisher(self): | ||
| return self.validated_data.get("publisher") | ||
|
|
||
| @property | ||
| def by_flight(self): | ||
| return self.validated_data.get("flight") | ||
|
|
||
| def skip_logo(self, logo): | ||
| if self.by_publisher and self.by_publisher != logo.publisher: | ||
| return True | ||
| if self.by_flight and self.by_flight != logo.logo_place: | ||
| return True | ||
| else: | ||
| return False | ||
|
|
||
|
|
||
| class FilterAssetsSerializer(serializers.Serializer): | ||
| internal_name = serializers.CharField(max_length=128) | ||
| list_empty = serializers.BooleanField(required=False, default=False) | ||
|
|
||
| @property | ||
| def by_internal_name(self): | ||
| return self.validated_data["internal_name"] | ||
|
|
||
| @property | ||
| def accept_empty(self): | ||
| return self.validated_data.get("list_empty", False) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.