-
Notifications
You must be signed in to change notification settings - Fork 70
Upgrade to Python 3.13 and Django 6 #125
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
Open
delitamakanda
wants to merge
5
commits into
master
Choose a base branch
from
codex/update-project-to-python-1.13-and-django-6
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4a256e4
Upgrade to Python 3.13 and Django 6
delitamakanda 5a3faee
Merge origin/master into PR branch and resolve conflicts
Copilot 23fef1f
downgrade django-embed-video to 1.4.10
Copilot 331ae57
downgrade python3-memcached to 1.51
Copilot f9cf2b9
replace django-taggit-serializer with inline TagListSerializerField a…
Copilot 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
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,84 @@ | ||
| """ | ||
| Custom taggit serializer field and mixin to replace the abandoned | ||
| django-taggit-serializer package. | ||
|
|
||
| Usage | ||
| ----- | ||
| from apps.common.serializers import TaggitSerializer, TagListSerializerField | ||
|
|
||
| class MySerializer(TaggitSerializer, serializers.ModelSerializer): | ||
| tags = TagListSerializerField() | ||
|
|
||
| class Meta: | ||
| model = MyModel | ||
| fields = ('id', 'tags', ...) | ||
| """ | ||
|
|
||
| from rest_framework import serializers | ||
|
|
||
|
|
||
| class TagListSerializerField(serializers.Field): | ||
| """Serializes a django-taggit ``TaggableManager`` as a flat list of tag names.""" | ||
|
|
||
| child = serializers.CharField() | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| kwargs.setdefault("default", list) | ||
| super().__init__(*args, **kwargs) | ||
|
|
||
| def to_internal_value(self, data): | ||
| if isinstance(data, str): | ||
| data = [tag.strip() for tag in data.split(",") if tag.strip()] | ||
| if not isinstance(data, list): | ||
| raise serializers.ValidationError("Expected a list of tag strings.") | ||
| errors = [] | ||
| for item in data: | ||
| try: | ||
| self.child.run_validation(item) | ||
| except serializers.ValidationError as e: | ||
| errors.append(e.detail) | ||
| else: | ||
| errors.append({}) | ||
| if any(errors): | ||
| raise serializers.ValidationError(errors) | ||
| return data | ||
|
|
||
| def to_representation(self, value): | ||
| if not value: | ||
| return [] | ||
| if hasattr(value, "all"): | ||
| return [tag.name for tag in value.all()] | ||
| return list(value) | ||
|
|
||
|
|
||
| class TaggitSerializer(serializers.Serializer): | ||
| """ | ||
| Mixin for ModelSerializer classes that include one or more | ||
| ``TagListSerializerField`` fields backed by a ``TaggableManager``. | ||
|
|
||
| Handles saving tags after the instance is created or updated. | ||
| """ | ||
|
|
||
| def _get_tag_fields(self): | ||
| return { | ||
| field_name: field | ||
| for field_name, field in self.fields.items() | ||
| if isinstance(field, TagListSerializerField) | ||
| } | ||
|
|
||
| def create(self, validated_data): | ||
| tag_fields = self._get_tag_fields() | ||
| tag_data = {name: validated_data.pop(name, []) for name in tag_fields} | ||
| instance = super().create(validated_data) | ||
| for field_name, tags in tag_data.items(): | ||
| getattr(instance, field_name).set(tags) | ||
| return instance | ||
|
|
||
| def update(self, instance, validated_data): | ||
| tag_fields = self._get_tag_fields() | ||
| tag_data = {name: validated_data.pop(name, None) for name in tag_fields} | ||
| instance = super().update(instance, validated_data) | ||
| for field_name, tags in tag_data.items(): | ||
| if tags is not None: | ||
| getattr(instance, field_name).set(tags) | ||
| return instance |
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
Oops, something went wrong.
Oops, something went wrong.
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.
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 settings now declare
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage', but requirements pin the project to Django >=6.0a1. Django 6 removes the legacySTATICFILES_STORAGE/DEFAULT_FILE_STORAGEsettings in favor of theSTORAGESmapping, so keeping this line causes startup/staticfiles initialization to fail and prevents WhiteNoise from being used. Configure theSTORAGES['staticfiles']backend instead to keep the app running on the new Django version.Useful? React with 👍 / 👎.