Skip to content

Commit

Permalink
Fix(backend): Cleanup project structure and settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
onegreyonewhite committed Dec 20, 2024
1 parent 3a3eede commit a6ee5f1
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 71 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,6 @@ module = [
"pywebpush.*",
"authlib.*",
"uvloop.*",
"htmlmin.*",
]
ignore_missing_imports = true
4 changes: 2 additions & 2 deletions requirements-rtd.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-rrequirements.txt
-rrequirements-doc.txt
-rrequirements-rpc.txt
django~=5.1.3
django~=5.1.4
httpx>=0.27.0
typing-extensions
sphinx-intl~=2.2.0
sphinx-intl~=2.3.1
orjson==3.9.13
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ormsgpack~=1.7.0
pyyaml~=6.0.2

# web server
uvicorn~=0.32.1
uvicorn~=0.34.0
fastapi-slim~=0.115.6
aiofiles~=24.1.0

Expand Down
2 changes: 1 addition & 1 deletion test_src/test_proj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@

GUI_VIEWS[r'^gui/$'] = r'^csrf_disable_gui/$'
GUI_VIEWS[r'^csrf_disable_gui/$'] = {
'BACKEND': 'vstutils.gui.views.SWView',
'BACKEND': 'vstutils.gui.views.TermsView',
'CSRF_ENABLE': False
}
GUI_VIEWS['login'] = {
Expand Down
22 changes: 15 additions & 7 deletions vstutils/gui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,30 @@
from django.http.response import Http404
from django.contrib.auth.decorators import login_required
from django.views.generic import TemplateView
from django.template.response import TemplateResponse
from django.template.response import TemplateResponse as BaseTemplateResponse
from django.conf import settings
from django.urls import reverse_lazy
from htmlmin.minify import html_minify
from jsmin import jsmin

from ..utils import lazy_translate as __


class TemplateResponse(BaseTemplateResponse):
minify_response = True

@property
def rendered_content(self):
content = super().rendered_content
if self.minify_response and 'text/html' in self.headers.get('Content-Type', ''):
return html_minify(content)
return content


class BaseView(TemplateView):
login_required = False
minify_response = True
response_class = TemplateResponse

def dispatch(self, request, *args, **kwargs):
response = super().dispatch(request, *args, **kwargs)
Expand All @@ -30,11 +43,6 @@ def as_view(cls, *args, **kwargs):
return cls.login_required and login_required(view, login_url=reverse_lazy('login')) or view # type: ignore


class OfflineView(BaseView):
login_required = False
template_name = "gui/offline.html"


class JSMinTemplateResponse(TemplateResponse):
@property
def rendered_content(self):
Expand All @@ -50,7 +58,7 @@ class SWView(BaseView):
response_class = JSMinTemplateResponse


class BaseAgreementsView(TemplateView):
class BaseAgreementsView(BaseView):
template_name = 'registration/base_agreements.html'
title_message = __('Terms')
path_in_settings: str
Expand Down
9 changes: 0 additions & 9 deletions vstutils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,6 @@ def secret_key(secret_file, default='*sg17)9wa_e+4$n%7n7r_(kqwlsc^^xdoc3&px$hs)s
MIDDLEWARE: _t.List[_t.Text] = [
'vstutils.middleware.ExecuteTimeHeadersMiddleware',
'vstutils.middleware.FrontendChangesNotifications',
'htmlmin.middleware.HtmlMinifyMiddleware',
'htmlmin.middleware.MarkRequestMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'vstutils.middleware.LangMiddleware',
Expand Down Expand Up @@ -1349,12 +1347,6 @@ def parse_db(params):
'name': 'service_worker'
}
},
"OFFLINE": {
"BACKEND": 'vstutils.gui.views.OfflineView',
"OPTIONS": {
'name': 'offline_gui'
}
},
"TERMS": {
"BACKEND": 'vstutils.gui.views.TermsView',
"OPTIONS": {
Expand All @@ -1371,7 +1363,6 @@ def parse_db(params):

GUI_VIEWS: _t.Dict[_t.Text, _t.Union[_t.Text, _t.Dict]] = {
'service-worker.js': 'SERVICE_WORKER',
'offline.html': 'OFFLINE',
}

def get_accounts_views_mapping():
Expand Down
2 changes: 0 additions & 2 deletions vstutils/templates/gui/manifest.json

This file was deleted.

49 changes: 0 additions & 49 deletions vstutils/templates/gui/offline.html

This file was deleted.

0 comments on commit a6ee5f1

Please sign in to comment.