Repository navigation
feat: add locale URL routing for admin and chat static files with tests #8296
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| from django.test import SimpleTestCase | ||
|
|
||
| from maxkb.urls import pro | ||
|
|
||
|
|
||
| class LocaleUrlTests(SimpleTestCase): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
| pro() | ||
|
|
||
| def test_admin_locale_index_is_served_from_static_path(self): | ||
| response = self.client.get("/static/admin/locales/index.json") | ||
|
|
||
| self.assertEqual(response.status_code, 200) | ||
|
|
||
| def test_chat_locale_index_is_served_from_static_path(self): | ||
| response = self.client.get("/static/chat/locales/index.json") | ||
|
|
||
| self.assertEqual(response.status_code, 200) | ||
|
Contributor
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. Code ReviewPotential Issues
Optimization / Style Suggestions
def test_locale_index_is_served_from_static_path(self):
for path in ("admin/locales/index.json", "chat/locales/index.json"):
with self.subTest(path=path):
response = self.client.get(f"{settings.STATIC_URL}{path}")
self.assertEqual(response.status_code, 200)
self.assertIn("application/json", response["Content-Type"])
from django.contrib.staticfiles import finders
self.assertIsNotNone(finders.find("admin/locales/index.json"))which is faster and doesn't depend on the static server handler. SummaryThe biggest risks are (a) |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,23 @@ def pro(): | |
| name="doc_chat", | ||
| ), | ||
| ) | ||
| # 暴露运行时生成的 UI 语言包 | ||
| urlpatterns.append( | ||
| re_path( | ||
| r"^static/admin/locales/(?P<path>.*)$", | ||
| static.serve, | ||
| {"document_root": os.path.join(settings.STATIC_ROOT, "admin", "locales")}, | ||
| name="admin_locales", | ||
| ), | ||
| ) | ||
| urlpatterns.append( | ||
| re_path( | ||
| r"^static/chat/locales/(?P<path>.*)$", | ||
| static.serve, | ||
| {"document_root": os.path.join(settings.STATIC_ROOT, "chat", "locales")}, | ||
| name="chat_locales", | ||
| ), | ||
| ) | ||
| # 暴露ui静态资源 | ||
| urlpatterns.append( | ||
| re_path( | ||
|
Contributor
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. Here's my review of the added code: Issues1. Using 2. Path traversal risk 3. Overlapping/suboptimal routing 4. Redundant 5. No caching / no conditional GET tuning Optimization suggestions
Minor
|
||
|
|
||
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 code you provided doesn't contain any actual code — it's just a diff header (
@@ -0,0 +1 @@) followed by an empty added line. There's nothing to review for irregularities, bugs, or optimizations.If you intended to paste the code, please resend it in full (without diff markers, or with the complete diff including context lines), and I'll review it.