From 259529411628259a0ce4f96637cc98dd319782f7 Mon Sep 17 00:00:00 2001 From: ngfchl Date: Thu, 2 Apr 2026 19:33:04 +0800 Subject: [PATCH] =?UTF-8?q?update.=20=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/urls.py | 2 + front/views.py | 58 +++++++++++++++++++- server/settings.py | 6 +- static/css/style.css | 9 ++- static/icons/search_23418A.svg | 1 + templates/base.html | 3 +- templates/front/details/article.html | 10 +++- templates/front/details/news.html | 2 +- templates/front/index.html | 4 +- templates/front/list.html | 82 ++++++++++++++++++++-------- 10 files changed, 140 insertions(+), 37 deletions(-) create mode 100644 static/icons/search_23418A.svg diff --git a/front/urls.py b/front/urls.py index b431544..46d3fb4 100644 --- a/front/urls.py +++ b/front/urls.py @@ -7,6 +7,8 @@ app_name = 'front' # 可选,用于命名空间(如 {% url 'main:index' %} urlpatterns = [ path('', views.index, name='index'), path('.html', views.section, name='section'), + path('list/search.html', views.search_list, name='search_list'), + path('list/search/.html', views.search_section_list, name='search_section_list'), path('list/news.html', views.main_news_list, name='news_main'), path('list/.html', views.main_article_list, name='main_list'), path('list//.html', views.sub_article_list, name='sub_list'), diff --git a/front/views.py b/front/views.py index 93e96dd..d66c774 100644 --- a/front/views.py +++ b/front/views.py @@ -206,7 +206,7 @@ def sub_news_list(request, sub: str): logger.info(f"主板块 {main_section} 子板块 {sub_section}") if not sub_section or not main_section: raise Http404("不存在的板块") - news_list = sub_section.news_set.filter(is_published=True).order_by('-created_at')[:21] + news_list = sub_section.news_set.filter(is_published=True).order_by('-created_at') news_list = custom_pagination(news_list, request) context = { @@ -219,6 +219,54 @@ def sub_news_list(request, sub: str): return render(request, 'front/list.html', context=context) +def search_list(request): + sections = MainMenu.objects.filter(parent__visible=True, visible=True, parent__isnull=False, ).all() + articles_qs = Article.objects.filter(is_published=True).all() + q = request.GET.get('q') + if q: + articles_qs = articles_qs.filter( + Q(title__icontains=q) | Q(content__icontains=q) + ) + articles = custom_pagination(articles_qs, request) + main_section = { + 'title': '搜索中心', + 'code': 'search' + } + context = { + 'main_section': main_section, + 'sections': sections, + 'articles': articles, + "q": q, + } + return render(request, 'front/list.html', context=context) + + +def search_section_list(request, sec): + sections = MainMenu.objects.filter(parent__visible=True, visible=True, parent__isnull=False, ).all() + articles_qs = Article.objects.filter(is_published=True).all() + q = request.GET.get('q') + sec = sections.filter(code=sec).first() + if q: + articles_qs = articles_qs.filter( + Q(title__icontains=q) | Q(content__icontains=q) + ) + if sec: + articles_qs = articles_qs.filter(section=sec) + articles = custom_pagination(articles_qs, request) + main_section = { + 'title': '搜索中心', + 'code': 'search' + } + context = { + 'main_section': main_section, + 'sections': sections, + 'articles': articles, + "q": q, + "current_sec": sec, + } + return render(request, 'front/list.html', context=context) + + def main_article_list(request, main): """信息公开""" logger.info(f"正在访问 {main}") @@ -251,11 +299,17 @@ def sub_article_list(request, main: str, sub: str): if not sub_section or not main_section: raise Http404("不存在的板块") articles = sub_section.article_set.filter(is_published=True).order_by('-created_at') + q = request.GET.get('q') + if q: + articles = articles.filter( + Q(title__icontains=q) | Q(content__icontains=q) + ) articles = custom_pagination(articles, request) context = { 'main_section': main_section, 'sub_section': sub_section, 'sections': sections.filter(parent__code=main), - 'articles': articles + 'articles': articles, + "q": q, } return render(request, 'front/list.html', context=context) diff --git a/server/settings.py b/server/settings.py index de3421f..85fc5e1 100644 --- a/server/settings.py +++ b/server/settings.py @@ -214,6 +214,9 @@ STATICFILES_DIRS = ( os.path.join(os.path.join(BASE_DIR, 'static')), ) +MEDIA_URL = '/media/' +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') + # 日志配置 LOGGING = { 'version': 1, # 版本 @@ -293,9 +296,6 @@ CKEDITOR_CONFIGS = { 'width': '100%', }, } -STATIC_URL = '/static/' -MEDIA_URL = '/media/' -MEDIA_ROOT = os.path.join(BASE_DIR, 'media') customColorPalette = [ { diff --git a/static/css/style.css b/static/css/style.css index bf61c73..6d3aca6 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -169,13 +169,16 @@ body { } .search-btn:hover { - background: #1e3a8a; /* 悬停时变为主题色 */ + background: #c62828; /* 悬停时变为主题色 */ color: #fff; /* 图标变白 */ + width: 30px; /* 悬停时稍微变大 */ + height: 30px; /* 悬停时稍微变大 */ } /* 如果使用的是 FontAwesome 等图标库,确保图标大小合适 */ -.search-btn i { - font-size: 18px; +.search-btn img { + width: 16px; + height: 16px; } .user-icons { diff --git a/static/icons/search_23418A.svg b/static/icons/search_23418A.svg new file mode 100644 index 0000000..ae49879 --- /dev/null +++ b/static/icons/search_23418A.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 9015a8c..5ca69f3 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,6 +7,7 @@ {% block title %}{% endblock %}{{ site_info.title }} +
@@ -16,7 +17,7 @@

{{ site_info.title }}

{{ site_info.e_title }}

-

CHANGBAI MOUNTAIN FIRE AND RESCUE BRIGADE

+{#

CHANGBAI MOUNTAIN FIRE AND RESCUE BRIGADE

#}
diff --git a/templates/front/details/article.html b/templates/front/details/article.html index 3e014b8..6ba214d 100644 --- a/templates/front/details/article.html +++ b/templates/front/details/article.html @@ -1,6 +1,6 @@ {% extends 'base.html' %} -{% block title %}{{ article.section.title }} - 长白山消防救援支队{% endblock %} +{% block title %}{{ article.section.title }} - {{ site_info.name }}{% endblock %} {% block content %}
@@ -9,8 +9,12 @@ diff --git a/templates/front/details/news.html b/templates/front/details/news.html index 1915381..c163ba5 100644 --- a/templates/front/details/news.html +++ b/templates/front/details/news.html @@ -1,6 +1,6 @@ {% extends 'base.html' %} -{% block title %}{{ article.section.title }} - 长白山消防救援支队{% endblock %} +{% block title %}{{ article.section.title }} - {{ site_info.name }}{% endblock %} {% block content %}
diff --git a/templates/front/index.html b/templates/front/index.html index 293c5c4..f848b48 100644 --- a/templates/front/index.html +++ b/templates/front/index.html @@ -19,9 +19,9 @@
{{ time_str }}
-
+
- + diff --git a/templates/front/list.html b/templates/front/list.html index 8d1dd2b..8cd6875 100644 --- a/templates/front/list.html +++ b/templates/front/list.html @@ -1,23 +1,34 @@ {% extends 'base.html' %} +{% load static %} {% block title %}{{ main_section.title }} - {% endblock %} {% block content %}
- - +
+ + +
+ + +
+ +
@@ -121,7 +154,8 @@ {% if articles.has_previous %}
  • - 首页 + 首页
  • {% else %}
  • @@ -132,7 +166,8 @@ {% if articles.has_previous %}
  • - 上一页 @@ -154,7 +189,7 @@ {# 显示规则:第1-2页 | 当前页前后各2页 | 最后2页 #} {% if i == 1 or i == 2 or i == articles.paginator.num_pages or i == articles.paginator.num_pages|add:"-1" or i >= articles.number|add:"-2" and i <= articles.number|add:"2" %}
  • - {{ i }} + {{ i }}
  • {% elif i == articles.number|add:"-3" or i == articles.number|add:"3" %} {# 省略号只出现一次 #} @@ -168,7 +203,9 @@ {% if articles.has_next %}
  • - + 下一页
  • @@ -181,7 +218,8 @@ {% if articles.has_next %}
  • - 尾页