Repository navigation
Enforce quality checks and type hints, improve quality and typing #73
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 13 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a157711
feat: enable type hints and mypy checking for this repository
bradenmacdonald 1cb67ac
fix: pylint issues
bradenmacdonald 6886014
fix: improve type hints of openedx_learning and fix identified bugs
bradenmacdonald 191cddb
fix: typing issues in tagging code
bradenmacdonald 852b388
fix: typing issues in tagging code
bradenmacdonald 59a80b0
fix: typing issues in tagging code
bradenmacdonald 5729a19
fix: typing issues in tagging code
bradenmacdonald a710cc0
fix: typing issues in tagging code
bradenmacdonald d46f720
chore: update with latest master
bradenmacdonald ca706b2
feat: opt more code into type checking
bradenmacdonald 75b429b
feat: type check the test suite
bradenmacdonald d14b590
chore: add migration to prevent taxonomy description from being null
bradenmacdonald 2079cc0
fix: duplicate module error
bradenmacdonald 826553d
chore: fix some mypy warnings that only appeared on CI
bradenmacdonald 87d5840
feat: add even more type annotations
bradenmacdonald ee19093
fix: PEP8 / pycodestyle issues
bradenmacdonald 6148244
fix: run isort
bradenmacdonald 77b9ff5
fix: invalid descriptions in test fixture
bradenmacdonald 488dac4
fix: failing test cases
bradenmacdonald 57fb09d
fix: address review comments
bradenmacdonald d8e04af
chore: be more explicit about what type error we're ignoring
bradenmacdonald b7f5a84
feat: add a few more missing type annotations
bradenmacdonald 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
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,15 @@ | ||
| [mypy] | ||
| follow_imports = normal | ||
| ignore_missing_imports = False | ||
| allow_untyped_globals = False | ||
| plugins = | ||
| mypy_django_plugin.main, | ||
| mypy_drf_plugin.main | ||
| files = | ||
| openedx_learning, | ||
| openedx_tagging, | ||
| tests | ||
|
|
||
| [mypy.plugins.django-stubs] | ||
| # content_staging only works with CMS; others work with either, so we run mypy with CMS settings. | ||
| django_settings_module = "projects.dev" |
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 |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| """ | ||
| Open edX Learning ("Learning Core") | ||
| """ | ||
| __version__ = "0.1.5" |
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,3 @@ | ||
| """ | ||
| Media server (for dev or low-traffic instances) | ||
| """ |
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 |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| """ | ||
| URLs for the media server application | ||
| """ | ||
| from django.urls import path | ||
|
|
||
| from .views import component_asset | ||
|
|
||
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 |
|---|---|---|
| @@ -1,34 +1,39 @@ | ||
| """ | ||
| Django admin for components models | ||
| """ | ||
| from django.contrib import admin | ||
| from django.template.defaultfilters import filesizeformat | ||
| from django.urls import reverse | ||
| from django.utils.html import format_html | ||
| from django.utils.safestring import SafeText | ||
|
|
||
| from openedx_learning.lib.admin_utils import ReadOnlyModelAdmin | ||
| from .models import ( | ||
| Component, | ||
| ComponentVersion, | ||
| ComponentVersionRawContent, | ||
| ) | ||
| from openedx_learning.lib.admin_utils import ReadOnlyModelAdmin | ||
|
|
||
|
|
||
| class ComponentVersionInline(admin.TabularInline): | ||
| """Inline admin view of ComponentVersion from the Component Admin""" | ||
| model = ComponentVersion | ||
| fields = ["version_num", "created", "title", "format_uuid"] | ||
| readonly_fields = ["version_num", "created", "title", "uuid", "format_uuid"] | ||
| extra = 0 | ||
|
|
||
| @admin.display(description="UUID") | ||
| def format_uuid(self, cv_obj): | ||
| return format_html( | ||
| '<a href="{}">{}</a>', | ||
| reverse("admin:oel_components_componentversion_change", args=(cv_obj.pk,)), | ||
| cv_obj.uuid, | ||
| ) | ||
|
|
||
| format_uuid.short_description = "UUID" | ||
|
|
||
|
|
||
| @admin.register(Component) | ||
| class ComponentAdmin(ReadOnlyModelAdmin): | ||
| """Django admin configuration for Component""" | ||
| list_display = ("key", "uuid", "namespace", "type", "created") | ||
| readonly_fields = [ | ||
| "learning_package", | ||
|
|
@@ -44,6 +49,7 @@ class ComponentAdmin(ReadOnlyModelAdmin): | |
|
|
||
|
|
||
| class RawContentInline(admin.TabularInline): | ||
| """Django admin configuration for RawContent""" | ||
| model = ComponentVersion.raw_contents.through | ||
|
|
||
| def get_queryset(self, request): | ||
|
|
@@ -75,11 +81,11 @@ def get_queryset(self, request): | |
| def rendered_data(self, cvc_obj): | ||
| return content_preview(cvc_obj) | ||
|
|
||
| @admin.display(description="Size") | ||
| def format_size(self, cvc_obj): | ||
| return filesizeformat(cvc_obj.raw_content.size) | ||
|
|
||
| format_size.short_description = "Size" | ||
|
|
||
| @admin.display(description="Key") | ||
| def format_key(self, cvc_obj): | ||
| return format_html( | ||
| '<a href="{}">{}</a>', | ||
|
|
@@ -88,11 +94,10 @@ def format_key(self, cvc_obj): | |
| cvc_obj.key, | ||
| ) | ||
|
|
||
| format_key.short_description = "Key" | ||
|
|
||
|
|
||
| @admin.register(ComponentVersion) | ||
| class ComponentVersionAdmin(ReadOnlyModelAdmin): | ||
| """Django admin configuration for ComponentVersion""" | ||
| readonly_fields = [ | ||
| "component", | ||
| "uuid", | ||
|
|
@@ -120,29 +125,8 @@ def get_queryset(self, request): | |
| ) | ||
|
|
||
|
|
||
| def is_displayable_text(mime_type): | ||
|
Contributor
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. This function was no longer used, after a prior refactor. |
||
| # Our usual text files, including things like text/markdown, text/html | ||
| media_type, media_subtype = mime_type.split("/") | ||
|
|
||
| if media_type == "text": | ||
| return True | ||
|
|
||
| # Our OLX goes here, but so do some other things like | ||
| if media_subtype.endswith("+xml"): | ||
| return True | ||
|
|
||
| # Other application/* types that we know we can display. | ||
| if media_subtype in ["json", "x-subrip"]: | ||
| return True | ||
|
|
||
| # Other formats that are really specific types of JSON | ||
| if media_subtype.endswith("+json"): | ||
| return True | ||
|
|
||
| return False | ||
|
|
||
|
|
||
| def link_for_cvc(cvc_obj: ComponentVersionRawContent): | ||
| def link_for_cvc(cvc_obj: ComponentVersionRawContent) -> str: | ||
| """Get the download URL for the given ComponentVersionRawContent instance""" | ||
| return "/media_server/component_asset/{}/{}/{}/{}".format( | ||
| cvc_obj.raw_content.learning_package.key, | ||
| cvc_obj.component_version.component.key, | ||
|
|
@@ -151,14 +135,20 @@ def link_for_cvc(cvc_obj: ComponentVersionRawContent): | |
| ) | ||
|
|
||
|
|
||
| def format_text_for_admin_display(text): | ||
| def format_text_for_admin_display(text: str) -> SafeText: | ||
| """ | ||
| Get the HTML to display the given plain text (preserving formatting) | ||
| """ | ||
| return format_html( | ||
| '<pre style="white-space: pre-wrap;">\n{}\n</pre>', | ||
| text, | ||
| ) | ||
|
|
||
|
|
||
| def content_preview(cvc_obj: ComponentVersionRawContent): | ||
| def content_preview(cvc_obj: ComponentVersionRawContent) -> SafeText: | ||
| """ | ||
| Get the HTML to display a preview of the given ComponentVersionRawContent | ||
| """ | ||
| raw_content_obj = cvc_obj.raw_content | ||
|
|
||
| if raw_content_obj.mime_type.startswith("image/"): | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.