diff options
| author | Bobby <[email protected]> | 2024-10-15 18:18:42 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-10-15 18:18:42 -0400 |
| commit | 226d3a1112e52073f8557d396cd80533ed8bce53 (patch) | |
| tree | 80dbf0a90789429d28e4c28cd4e2617cc43b4475 | |
| parent | a010777be6b23f8875f175f78af09b7539709b2d (diff) | |
| download | thatcomputerscientist-226d3a1112e52073f8557d396cd80533ed8bce53.tar.xz thatcomputerscientist-226d3a1112e52073f8557d396cd80533ed8bce53.zip | |
starting something fresh
| -rw-r--r-- | apps/core/__init__.py | 0 | ||||
| -rw-r--r-- | apps/core/admin.py | 3 | ||||
| -rw-r--r-- | apps/core/apps.py | 6 | ||||
| -rw-r--r-- | apps/core/migrations/__init__.py | 0 | ||||
| -rw-r--r-- | apps/core/models.py | 3 | ||||
| -rw-r--r-- | apps/core/tests.py | 3 | ||||
| -rw-r--r-- | apps/core/urls.py | 8 | ||||
| -rw-r--r-- | apps/core/views.py | 8 | ||||
| -rw-r--r-- | middleware/i18nmiddleware.py | 5 | ||||
| -rw-r--r-- | templates/en/core/home.html | 1 | ||||
| -rw-r--r-- | thatcomputerscientist/settings.py | 6 | ||||
| -rw-r--r-- | thatcomputerscientist/urls.py | 36 | ||||
| -rw-r--r-- | thatcomputerscientist/utils.py | 8 |
13 files changed, 64 insertions, 23 deletions
diff --git a/apps/core/__init__.py b/apps/core/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/apps/core/__init__.py diff --git a/apps/core/admin.py b/apps/core/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/apps/core/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/apps/core/apps.py b/apps/core/apps.py new file mode 100644 index 00000000..ab0051ed --- /dev/null +++ b/apps/core/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class CoreConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "apps.core" diff --git a/apps/core/migrations/__init__.py b/apps/core/migrations/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/apps/core/migrations/__init__.py diff --git a/apps/core/models.py b/apps/core/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/apps/core/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/apps/core/tests.py b/apps/core/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/apps/core/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/apps/core/urls.py b/apps/core/urls.py new file mode 100644 index 00000000..8612977a --- /dev/null +++ b/apps/core/urls.py @@ -0,0 +1,8 @@ +from django.urls import path + +from . import views + +app_name = "blog" +urlpatterns = [ + path("", views.home, name="home"), +] diff --git a/apps/core/views.py b/apps/core/views.py new file mode 100644 index 00000000..359a1c86 --- /dev/null +++ b/apps/core/views.py @@ -0,0 +1,8 @@ +from django.shortcuts import render +from thatcomputerscientist.utils import i18npatterns + + +def home(request): + LANGUAGE_CODE = i18npatterns(request.LANGUAGE_CODE) + + return render(request, f"{LANGUAGE_CODE}/core/home.html") diff --git a/middleware/i18nmiddleware.py b/middleware/i18nmiddleware.py index 4014ca46..b0e7e077 100644 --- a/middleware/i18nmiddleware.py +++ b/middleware/i18nmiddleware.py @@ -1,4 +1,3 @@ -from django.utils.translation import activate from django.utils.deprecation import MiddlewareMixin @@ -6,9 +5,9 @@ class I18NMiddleware(MiddlewareMixin): def process_request(self, request): language = request.COOKIES.get("site_language") if language: - activate(language) + request.LANGUAGE_CODE = language else: - activate("en") + request.LANGUAGE_CODE = "en" request.LANGUAGE_CODE = language def process_response(self, request, response): diff --git a/templates/en/core/home.html b/templates/en/core/home.html new file mode 100644 index 00000000..6319fc44 --- /dev/null +++ b/templates/en/core/home.html @@ -0,0 +1 @@ +welcome to core diff --git a/thatcomputerscientist/settings.py b/thatcomputerscientist/settings.py index b92136ce..9cd7daf3 100644 --- a/thatcomputerscientist/settings.py +++ b/thatcomputerscientist/settings.py @@ -75,6 +75,7 @@ INSTALLED_APPS = [ "sslserver", "thatcomputerscientist", "haystack", + "apps.core", "blog.apps.BlogConfig", "users", "userpages", @@ -228,11 +229,6 @@ USE_I18N = True USE_TZ = True -LANGUAGES = ( - ("en", _("English")), - ("ja", _("Japanese")) -) - # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.0/howto/static-files/ diff --git a/thatcomputerscientist/urls.py b/thatcomputerscientist/urls.py index 32d9a06c..c2d442a3 100644 --- a/thatcomputerscientist/urls.py +++ b/thatcomputerscientist/urls.py @@ -13,33 +13,39 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + from django.conf import settings from django.conf.urls.static import static from django.contrib import admin from django.contrib.sitemaps.views import sitemap from django.urls import include, path -from .sitemaps import (CategorySitemap, GithubSitemap, PostSitemap, - StaticViewSitemap, TagSitemap) +from .sitemaps import ( + CategorySitemap, + GithubSitemap, + PostSitemap, + StaticViewSitemap, + TagSitemap, +) sitemaps = { - 'posts': PostSitemap, - 'categories': CategorySitemap, - 'tags': TagSitemap, - 'static': StaticViewSitemap, - 'github': GithubSitemap, + "posts": PostSitemap, + "categories": CategorySitemap, + "tags": TagSitemap, + "static": StaticViewSitemap, + "github": GithubSitemap, } -handler404 = 'thatcomputerscientist.error_handler.custom_404' +handler404 = "thatcomputerscientist.error_handler.custom_404" urlpatterns = [ - path('', include('blog.urls', namespace='blog')), - path('users', include('users.urls', namespace='users')), - path('blog-admin', include('blog_admin.urls', namespace='blog-admin')), - path('repositories', include(('dev_status.urls', 'dev_status'), namespace='dev_status')), - path('ignis', include(('ignis.urls', 'ignis'), namespace='ignis')), - path('admin/', admin.site.urls), - path('sitemap.xml', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'), + path("", include("apps.core.urls", namespace="core")), + # path('users', include('users.urls', namespace='users')), + # path('blog-admin', include('blog_admin.urls', namespace='blog-admin')), + # path('repositories', include(('dev_status.urls', 'dev_status'), namespace='dev_status')), + # path('ignis', include(('ignis.urls', 'ignis'), namespace='ignis')), + # path('admin/', admin.site.urls), + # path('sitemap.xml', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'), ] urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/thatcomputerscientist/utils.py b/thatcomputerscientist/utils.py new file mode 100644 index 00000000..c9f43a02 --- /dev/null +++ b/thatcomputerscientist/utils.py @@ -0,0 +1,8 @@ +def i18npatterns(LANGUAGE_CODE): + DEFAULT_LANGUAGE = "en" + SUPPORTED_LANGUAGES = ["en", "ja"] + + if LANGUAGE_CODE in SUPPORTED_LANGUAGES: + return LANGUAGE_CODE + + return DEFAULT_LANGUAGE |
