feat: 现代化翻页组件 + 完整项目更新
- 新增 Pagination 通用组件:首页/上一页/页码/下一页/末页导航 - PickModal 和 SwapModal 集成分页功能,每页20项 - 搜索/筛选切换自动回到第1页 - 现代化CSS样式:hover浮起动效、主色高亮、移动端适配 - 新增 dashboard、admin 管理模板 - 菜系(cuisine)模型和迁移 - 构建脚本 build.py 支持 PyInstaller 打包 - 前端资源重新构建
This commit is contained in:
+25
-31
@@ -10,6 +10,7 @@ For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/6.0/ref/settings/
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
@@ -76,54 +77,44 @@ WSGI_APPLICATION = 'config.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.environ.get('DJANGO_DB_PATH', str(BASE_DIR / 'db.sqlite3')),
|
||||
'NAME': os.environ.get(
|
||||
'DJANGO_DB_PATH',
|
||||
str(os.path.join(os.path.dirname(sys.executable), 'db.sqlite3') if getattr(sys, 'frozen', False) else BASE_DIR / 'db.sqlite3')
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
|
||||
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
|
||||
{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},
|
||||
{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/6.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'zh-hans'
|
||||
|
||||
TIME_ZONE = 'Asia/Shanghai'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/6.0/howto/static-files/
|
||||
|
||||
STATIC_URL = os.environ.get('DJANGO_STATIC_URL', '/xx/admin/')
|
||||
STATIC_URL = os.environ.get('DJANGO_STATIC_URL', '/static/')
|
||||
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
||||
STATICFILES_DIRS = [BASE_DIR / 'static']
|
||||
|
||||
# When frozen by PyInstaller, bundled files live in sys._MEIPASS
|
||||
_frozen = getattr(sys, 'frozen', False)
|
||||
if _frozen:
|
||||
_bundled = sys._MEIPASS
|
||||
# In frozen mode, static files are at _MEIPASS/backend/static
|
||||
_be_static = os.path.join(_bundled, 'backend', 'static')
|
||||
if os.path.isdir(_be_static) and _be_static not in [os.path.normpath(d) for d in STATICFILES_DIRS]:
|
||||
STATICFILES_DIRS.append(_be_static)
|
||||
|
||||
CORS_ALLOWED_ORIGINS = [
|
||||
'http://localhost:5173',
|
||||
'http://127.0.0.1:5173',
|
||||
@@ -149,8 +140,8 @@ JAZZMIN_SETTINGS = {
|
||||
'site_title': '学校订餐菜单管理系统',
|
||||
'site_header': '学校订餐菜单生成器',
|
||||
'site_brand': '订餐菜单管理',
|
||||
'site_icon': 'frontend/icon_512.png',
|
||||
'welcome_sign': '欢迎使用学校订餐菜单管理系统',
|
||||
'copyright': '上海外国语大学附属宝山双语学校',
|
||||
'search_model': ['meals.Dish', 'auth.User'],
|
||||
'show_sidebar': True,
|
||||
'navigation_expanded': True,
|
||||
@@ -169,7 +160,6 @@ JAZZMIN_SETTINGS = {
|
||||
'custom_css': None,
|
||||
'custom_js': None,
|
||||
'theme': 'flatly',
|
||||
'dark_mode_theme': 'darkly',
|
||||
'header_classes': 'bg-primary',
|
||||
'order_with_respect_to': ['meals', 'auth'],
|
||||
}
|
||||
@@ -195,6 +185,10 @@ JAZZMIN_UI_TWEAKS = {
|
||||
'sidebar_nav_legacy_style': False,
|
||||
'sidebar_nav_flat_style': False,
|
||||
'theme': 'flatly',
|
||||
'dark_mode_theme': 'darkly',
|
||||
'button_classes': {'primary': 'btn-outline-primary', 'secondary': 'btn-outline-secondary', 'info': 'btn-outline-info', 'warning': 'btn-outline-warning', 'danger': 'btn-outline-danger', 'success': 'btn-outline-success'},
|
||||
}
|
||||
|
||||
|
||||
LOGIN_REDIRECT_URL = '/admin/'
|
||||
LOGOUT_REDIRECT_URL = '/admin/login/'
|
||||
|
||||
|
||||
+54
-16
@@ -1,23 +1,61 @@
|
||||
"""
|
||||
URL configuration for config project.
|
||||
import os
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/6.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
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.contrib import admin
|
||||
from django.urls import include, path
|
||||
from django.http import HttpResponseNotFound
|
||||
from django.urls import include, path, re_path
|
||||
from django.views.generic import RedirectView, TemplateView
|
||||
from django.views.static import serve as static_serve
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from meals.views_spa import spa_serve
|
||||
from meals.views_dashboard import dashboard_api
|
||||
from meals.views_spa import _get_frontend_dir
|
||||
|
||||
|
||||
def _serve_fe_assets(request, path=''):
|
||||
"""Serve built React assets (JS/CSS) from the frontend directory."""
|
||||
fdir = _get_frontend_dir()
|
||||
rel = os.path.join('assets', path)
|
||||
target = os.path.normpath(os.path.join(fdir, rel))
|
||||
if target.startswith(os.path.normpath(fdir)) and os.path.isfile(target):
|
||||
return static_serve(request, rel, document_root=fdir)
|
||||
return HttpResponseNotFound('Not found')
|
||||
|
||||
urlpatterns = [
|
||||
path('', TemplateView.as_view(template_name='index.html'), name='index'),
|
||||
path('app/', spa_serve, name='spa_serve'),
|
||||
path('app/<path:path>', spa_serve, name='spa_serve_path'),
|
||||
re_path(r'^assets/(?P<path>.+)$', _serve_fe_assets, name='fe_assets'),
|
||||
path('admin/', admin.site.urls),
|
||||
path('api/', include('meals.urls')),
|
||||
path('api/dashboard/', dashboard_api, name='dashboard_api'),
|
||||
path('dashboard/', RedirectView.as_view(url='/admin/', permanent=False), name='dashboard_redirect'),
|
||||
]
|
||||
|
||||
# When DEBUG is off (e.g. desktop.py / EXE mode), serve static files directly
|
||||
# so the Django admin and Jazzmin theme load correctly.
|
||||
if not settings.DEBUG:
|
||||
from django.contrib.staticfiles import finders as _sf_finders
|
||||
|
||||
def _serve_static(request, path=''):
|
||||
"""Search all static file roots for the requested path."""
|
||||
for root in _static_roots:
|
||||
target = os.path.normpath(os.path.join(root, path))
|
||||
if target.startswith(root) and os.path.isfile(target):
|
||||
return static_serve(request, path, document_root=root)
|
||||
from django.http import Http404
|
||||
raise Http404
|
||||
|
||||
_static_roots = []
|
||||
for _d in settings.STATICFILES_DIRS:
|
||||
if os.path.isdir(_d):
|
||||
_static_roots.append(os.path.normpath(_d))
|
||||
for _finder in _sf_finders.get_finders():
|
||||
for _path, _storage in _finder.list([]):
|
||||
_loc = getattr(_storage, 'location', None)
|
||||
if _loc and os.path.isdir(_loc):
|
||||
_static_roots.append(os.path.normpath(_loc))
|
||||
urlpatterns += [
|
||||
re_path(r'^static/(?P<path>.+)$', _serve_static),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user