-
Notifications
You must be signed in to change notification settings - Fork 11
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
Minor fixes for tagging django admin [FC-0036] #114
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
@@ -1,10 +1,44 @@ | ||
""" | ||
Tagging app admin | ||
""" | ||
from __future__ import annotations | ||
|
||
from django.contrib import admin | ||
|
||
from .models import ObjectTag, Tag, Taxonomy | ||
|
||
admin.site.register(Taxonomy) | ||
admin.site.register(Tag) | ||
admin.site.register(ObjectTag) | ||
|
||
|
||
@admin.register(Tag) | ||
class TagAdmin(admin.ModelAdmin): | ||
""" | ||
Admin definition for Tag model | ||
""" | ||
autocomplete_fields = ["parent"] | ||
search_fields = ["value", "external_id"] | ||
list_display = ["__str__", "taxonomy", "external_id"] | ||
list_filter = ["taxonomy"] | ||
|
||
def has_add_permission(self, request): | ||
""" | ||
Don't create Tags using the django admin. Use the API or UI. | ||
""" | ||
return False | ||
|
||
|
||
@admin.register(ObjectTag) | ||
class ObjectTagAdmin(admin.ModelAdmin): | ||
""" | ||
Admin definition for ObjectTag model | ||
""" | ||
fields = ["object_id", "taxonomy", "tag", "_value"] | ||
autocomplete_fields = ["tag"] | ||
list_display = ["object_id", "name", "value"] | ||
readonly_fields = ["object_id"] | ||
|
||
def has_add_permission(self, request): | ||
""" | ||
Don't create ObjectTags using the django admin. Use the API or UI. | ||
""" | ||
return False |
36 changes: 36 additions & 0 deletions
36
openedx_tagging/core/tagging/migrations/0014_minor_fixes.py
This file contains 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,36 @@ | ||
# Generated by Django 3.2.22 on 2023-11-08 22:37 | ||
|
||
from django.db import migrations, models | ||
|
||
import openedx_learning.lib.fields | ||
|
||
|
||
def fix_language_taxonomy(apps, schema_editor): | ||
""" | ||
Ensure that the language taxonomy has the correct taxonomy_class. Some | ||
previous versions of this app's migration history allowed it to be created | ||
without the right taxonomy_class. | ||
""" | ||
Taxonomy = apps.get_model("oel_tagging", "Taxonomy") | ||
correct_class = "openedx_tagging.core.tagging.models.system_defined.LanguageTaxonomy" | ||
lang_taxonomy = Taxonomy.objects.get(pk=-1) | ||
if lang_taxonomy._taxonomy_class != correct_class: | ||
lang_taxonomy._taxonomy_class = correct_class | ||
lang_taxonomy.save(update_fields=["_taxonomy_class"]) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('oel_tagging', '0013_tag_parent_blank'), | ||
] | ||
|
||
operations = [ | ||
# Allow taxonomy_class to be blank: | ||
migrations.AlterField( | ||
model_name='taxonomy', | ||
name='_taxonomy_class', | ||
field=models.CharField(blank=True, help_text='Taxonomy subclass used to instantiate this instance; must be a fully-qualified module and class name. If the module/class cannot be imported, an error is logged and the base Taxonomy class is used instead.', max_length=255, null=True), | ||
), | ||
migrations.RunPython(fix_language_taxonomy, None), | ||
] |
This file contains 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 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 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.
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.
Thanks for this fix - looks good! 👍🏻