change front_web_view

This commit is contained in:
2025-10-28 10:39:08 +08:00
parent a36d730384
commit 90446cd330
8 changed files with 581 additions and 136 deletions

View File

@@ -16,7 +16,7 @@ from django.utils import timezone
from django.db.models import Count, Q
from django.core.cache import cache
from .models import Website, Article, CrawlTask
from .models import Website, Article, CrawlTask, SiteConfig
from .tasks import crawl_website, crawl_all_websites, cleanup_old_articles
from .distributed_crawler import distributed_crawler
from .task_executor import task_executor
@@ -911,7 +911,36 @@ class CrawlTaskAdmin(admin.ModelAdmin):
# return super().changelist_view(request, extra_context)
#
class SiteConfigAdmin(admin.ModelAdmin):
"""网站配置管理"""
list_display = ['site_title', 'show_title', 'header_background_color', 'header_background_size', 'header_background_position', 'header_height', 'created_at', 'updated_at']
readonly_fields = ['created_at', 'updated_at']
fieldsets = (
('基本信息', {
'fields': ('site_title', 'show_title')
}),
('版头设置', {
'fields': ('header_background_image', 'header_background_color', 'header_background_size', 'header_background_position', 'header_height'),
'description': '上传背景图片后,可以调整图片的显示大小、位置和版头高度'
}),
('时间信息', {
'fields': ('created_at', 'updated_at'),
'classes': ('collapse',)
}),
)
def has_add_permission(self, request):
"""只允许有一个配置实例"""
return not SiteConfig.objects.exists()
def has_delete_permission(self, request, obj=None):
"""不允许删除配置"""
return False
# 注册管理类
admin.site.register(SiteConfig, SiteConfigAdmin)
admin.site.register(Website, WebsiteAdmin)
admin.site.register(Article, ArticleAdmin)
admin.site.register(CrawlTask, CrawlTaskAdmin)

View File

@@ -0,0 +1,28 @@
# Generated by Django 5.1 on 2025-10-28 01:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0004_crawltask_execution_count_and_more'),
]
operations = [
migrations.CreateModel(
name='SiteConfig',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('site_title', models.CharField(default='绿美泉烟绿色课堂', max_length=200, verbose_name='网站标题')),
('header_background_image', models.ImageField(blank=True, null=True, upload_to='site_config/', verbose_name='版头背景图片')),
('header_background_color', models.CharField(default='#667eea', max_length=7, verbose_name='版头背景颜色')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
],
options={
'verbose_name': '网站配置',
'verbose_name_plural': '网站配置',
},
),
]

View File

@@ -0,0 +1,28 @@
# Generated by Django 5.1 on 2025-10-28 02:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0005_siteconfig'),
]
operations = [
migrations.AddField(
model_name='siteconfig',
name='header_background_position',
field=models.CharField(choices=[('center', '居中'), ('top', '顶部'), ('bottom', '底部'), ('left', '左侧'), ('right', '右侧'), ('top left', '左上角'), ('top right', '右上角'), ('bottom left', '左下角'), ('bottom right', '右下角')], default='center', max_length=20, verbose_name='背景图片位置'),
),
migrations.AddField(
model_name='siteconfig',
name='header_background_size',
field=models.CharField(choices=[('cover', '覆盖整个区域'), ('contain', '完整显示图片'), ('100% 100%', '拉伸填满'), ('auto', '原始大小')], default='cover', max_length=20, verbose_name='背景图片大小'),
),
migrations.AddField(
model_name='siteconfig',
name='header_height',
field=models.IntegerField(default=200, verbose_name='版头高度(像素)'),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.1 on 2025-10-28 02:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0006_siteconfig_header_background_position_and_more'),
]
operations = [
migrations.AddField(
model_name='siteconfig',
name='show_title',
field=models.BooleanField(default=True, verbose_name='前台显示标题'),
),
]

View File

@@ -3,6 +3,78 @@ from django.utils import timezone
import json
class SiteConfig(models.Model):
"""网站配置模型"""
BACKGROUND_SIZE_CHOICES = [
('cover', '覆盖整个区域'),
('contain', '完整显示图片'),
('100% 100%', '拉伸填满'),
('auto', '原始大小'),
]
BACKGROUND_POSITION_CHOICES = [
('center', '居中'),
('top', '顶部'),
('bottom', '底部'),
('left', '左侧'),
('right', '右侧'),
('top left', '左上角'),
('top right', '右上角'),
('bottom left', '左下角'),
('bottom right', '右下角'),
]
site_title = models.CharField(max_length=200, default="绿美泉烟绿色课堂", verbose_name="网站标题")
show_title = models.BooleanField(default=True, verbose_name="前台显示标题")
header_background_image = models.ImageField(
upload_to='site_config/',
blank=True,
null=True,
verbose_name="版头背景图片"
)
header_background_color = models.CharField(
max_length=7,
default="#667eea",
verbose_name="版头背景颜色"
)
header_background_size = models.CharField(
max_length=20,
choices=BACKGROUND_SIZE_CHOICES,
default='cover',
verbose_name="背景图片大小"
)
header_background_position = models.CharField(
max_length=20,
choices=BACKGROUND_POSITION_CHOICES,
default='center',
verbose_name="背景图片位置"
)
header_height = models.IntegerField(
default=200,
verbose_name="版头高度(像素)"
)
created_at = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
updated_at = models.DateTimeField(auto_now=True, verbose_name="更新时间")
class Meta:
verbose_name = "网站配置"
verbose_name_plural = "网站配置"
def __str__(self):
return f"网站配置 - {self.site_title}"
@classmethod
def get_config(cls):
"""获取网站配置,如果不存在则创建默认配置"""
config, created = cls.objects.get_or_create(
defaults={
'site_title': '绿美泉烟绿色课堂',
'header_background_color': '#667eea'
}
)
return config
class Website(models.Model):
name = models.CharField(max_length=100, unique=True)
base_url = models.URLField()

View File

@@ -2,36 +2,62 @@
<html lang="zh">
<head>
<meta charset="UTF-8"/>
<title>绿色课堂文章列表</title>
<title>{{ site_config.site_title }}</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
line-height: 1.6;
color: #333;
margin: 0 auto;
padding: 20px;
background-color: #f0f8ff; /* 统一背景色调 */
margin: 0;
padding: 0;
background-color: #f0f8ff;
}
.container {
background: white;
padding: 30px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05); /* 添加轻微阴影 */
border-radius: 8px; /* 添加圆角 */
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
border-radius: 8px;
max-width: 1400px;
margin: 0 auto;
}
h1 {
color: #2c3e50;
border-bottom: 2px solid #3498db;
padding-bottom: 10px;
margin-top: 0;
.site-header {
{% if site_config.header_background_image %}
background-image: url('{{ site_config.header_background_image.url }}');
background-size: {{ site_config.header_background_size }};
background-position: {{ site_config.header_background_position }};
background-repeat: no-repeat;
color: white;
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
{% else %}
background: linear-gradient(135deg, {{ site_config.header_background_color }} 0%, #764ba2 100%);
color: white;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
{% endif %}
padding: 50px 30px;
margin-bottom: 30px;
border-radius: 10px;
text-align: center;
min-height: {{ site_config.header_height }}px;
display: flex;
align-items: center;
justify-content: center;
}
.site-title {
color: {% if site_config.header_background_image %}white{% else %}white{% endif %};
font-size: 2.5em;
font-weight: 700;
margin: 0;
text-shadow: {% if site_config.header_background_image %}2px 2px 4px rgba(0,0,0,0.5){% else %}2px 2px 4px rgba(0,0,0,0.3){% endif %};
}
.filters {
margin-bottom: 20px;
padding: 15px;
background-color: #e3f2fd; /* 统一滤镜背景色调 */
background-color: #e3f2fd;
border-radius: 5px;
}
@@ -39,7 +65,7 @@
display: inline-block;
padding: 5px 10px;
margin: 0 5px 5px 0;
background-color: #bbdefb; /* 统一链接背景色调 */
background-color: #bbdefb;
color: #0d47a1;
text-decoration: none;
border-radius: 3px;
@@ -57,7 +83,7 @@
li {
padding: 10px 0;
border-bottom: 1px solid #e0e0e0; /* 统一分隔线颜色 */
border-bottom: 1px solid #e0e0e0;
}
li:last-child {
@@ -65,17 +91,17 @@
}
a {
color: #1976d2; /* 统一链接颜色 */
color: #1976d2;
text-decoration: none;
}
a:hover {
color: #0d47a1; /* 统一悬停颜色 */
color: #0d47a1;
text-decoration: underline;
}
.meta {
color: #78909c; /* 统一元数据颜色 */
color: #78909c;
font-size: 0.9em;
}
@@ -92,7 +118,7 @@
color: white;
text-decoration: none;
border-radius: 4px;
margin: 0 2px; /* 修改:调整页码间距 */
margin: 0 2px;
}
.pagination a:hover {
@@ -104,30 +130,27 @@
color: #7f8c8d;
}
/* 新增:当前页码样式 */
.pagination .current {
background-color: #2980b9;
cursor: default;
}
/* 新增:省略号样式 */
.pagination .ellipsis {
display: inline-block;
padding: 8px 4px;
color: #7f8c8d;
}
/* 新增:搜索框样式 */
.search-form {
margin-bottom: 20px;
padding: 15px;
background-color: #e3f2fd; /* 统一搜索框背景色调 */
background-color: #e3f2fd;
border-radius: 5px;
}
.search-form input[type="text"] {
padding: 8px 12px;
border: 1px solid #bbdefb; /* 统一边框颜色 */
border: 1px solid #bbdefb;
border-radius: 4px;
width: 300px;
margin-right: 10px;
@@ -148,12 +171,11 @@
}
.search-info {
color: #78909c; /* 统一搜索信息颜色 */
color: #78909c;
font-size: 0.9em;
margin-bottom: 10px;
}
/* 新增:左侧筛选栏样式 */
.content-wrapper {
display: flex;
gap: 20px;
@@ -161,7 +183,7 @@
.sidebar {
flex: 0 0 200px;
background-color: #e3f2fd; /* 统一边栏背景色调 */
background-color: #e3f2fd;
border-radius: 5px;
padding: 15px;
}
@@ -186,7 +208,7 @@
display: block;
padding: 8px 10px;
margin: 0 0 5px 0;
background-color: #bbdefb; /* 统一边栏链接背景色调 */
background-color: #bbdefb;
color: #0d47a1;
text-decoration: none;
border-radius: 3px;
@@ -197,18 +219,17 @@
color: white;
}
/* 新增:导出功能样式 */
.export-section {
margin-bottom: 20px;
padding: 15px;
background-color: #e8f5e9; /* 统一导出区域背景色调 */
background-color: #e8f5e9;
border-radius: 5px;
text-align: center;
}
.export-btn {
padding: 10px 20px;
background-color: #4caf50; /* 统一按钮背景色调 */
background-color: #4caf50;
color: white;
border: none;
border-radius: 4px;
@@ -218,24 +239,313 @@
}
.export-btn:hover {
background-color: #388e3c; /* 统一按钮悬停色调 */
background-color: #388e3c;
}
.export-btn:disabled {
background-color: #9e9e9e; /* 统一禁用按钮色调 */
background-color: #9e9e9e;
cursor: not-allowed;
}
.article-checkbox {
margin-right: 10px;
}
.websites-container {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 20px;
}
.website-card {
flex: 1 1 auto;
min-width: 120px;
padding: 10px;
background-color: #e3f2fd;
border-radius: 5px;
text-align: center;
cursor: pointer;
transition: all 0.3s ease;
}
.website-card:hover {
background-color: #bbdefb;
transform: translateY(-2px);
}
.website-card.active {
background-color: #3498db;
color: white;
}
.articles-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-auto-rows: minmax(200px, auto);
gap: 25px;
margin-top: 20px;
}
.article-card {
border-radius: 12px;
overflow: hidden;
box-shadow: 0 4px 15px rgba(0,0,0,0.08);
transition: all 0.3s ease;
background: white;
border: 1px solid #e8e8e8;
display: flex;
flex-direction: column;
}
.article-card.no-image {
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
border: 1px solid #f0f0f0;
min-height: auto;
grid-row: span 1;
}
.article-card.no-image .article-content {
padding: 25px;
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.article-card.no-image h3 {
margin-top: 0;
font-size: 1.3em;
line-height: 1.4;
flex: 1;
}
.article-card:not(.no-image) {
grid-row: span 2;
}
.article-card:not(.no-image) .article-content {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.article-card:hover {
transform: translateY(-8px);
box-shadow: 0 8px 25px rgba(0,0,0,0.15);
border-color: #3498db;
}
.article-image-container {
position: relative;
width: 100%;
height: 280px;
overflow: hidden;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}
.article-image {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.3s ease;
}
.article-card:hover .article-image {
transform: scale(1.05);
}
.article-content {
padding: 20px;
position: relative;
}
.article-card h3 {
margin-top: 0;
margin-bottom: 12px;
color: #2c3e50;
font-size: 20px;
line-height: 1.4;
font-weight: 600;
min-height: 56px;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.article-card h3 a {
color: #2c3e50;
text-decoration: none;
transition: color 0.3s ease;
}
.article-card h3 a:hover {
color: #3498db;
}
.article-meta {
font-size: 0.9em;
color: #78909c;
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 15px;
padding-top: 12px;
border-top: 1px solid #f0f0f0;
}
.article-source {
font-weight: 600;
color: #3498db;
background: #e3f2fd;
padding: 4px 8px;
border-radius: 4px;
font-size: 0.8em;
}
.article-date {
color: #95a5a6;
font-size: 0.85em;
}
.no-image-placeholder {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: 600;
font-size: 16px;
position: relative;
}
.no-image-placeholder::before {
content: "📰";
font-size: 48px;
margin-bottom: 10px;
display: block;
}
.no-image-placeholder span {
position: absolute;
bottom: 15px;
left: 50%;
transform: translateX(-50%);
font-size: 14px;
opacity: 0.9;
}
@media (max-width: 768px) {
.articles-grid {
grid-template-columns: 1fr;
gap: 20px;
}
.article-image-container {
height: 220px;
}
.article-card h3 {
font-size: 18px;
min-height: 50px;
}
.article-content {
padding: 15px;
}
.content-wrapper {
flex-direction: column;
}
.sidebar {
flex: 1;
}
}
.article-summary {
color: #666;
font-size: 0.9em;
line-height: 1.5;
margin-top: 8px;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
.article-card {
animation: fadeInUp 0.6s ease-out;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.article-image {
background-color: #f8f9fa;
background-image: linear-gradient(45deg, transparent 40%, rgba(255,255,255,0.5) 50%, transparent 60%);
background-size: 200% 200%;
animation: shimmer 2s infinite;
}
@keyframes shimmer {
0% {
background-position: -200% -200%;
}
100% {
background-position: 200% 200%;
}
}
.article-checkbox {
position: absolute;
top: 15px;
right: 15px;
width: 18px;
height: 18px;
accent-color: #3498db;
cursor: pointer;
}
.website-card {
position: relative;
overflow: hidden;
}
.website-card::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
transition: left 0.5s;
}
.website-card:hover::before {
left: 100%;
}
</style>
</head>
<body>
<div class="container">
<h1>绿色课堂文章列表</h1>
<div class="site-header">
{% if site_config.show_title %}
<h1 class="site-title">{{ site_config.site_title }}</h1>
{% endif %}
</div>
<!-- 新增:搜索表单 -->
<div class="search-form">
<form method="get">
<input type="text" name="q" placeholder="输入关键词搜索文章..." value="{{ search_query }}">
@@ -246,19 +556,21 @@
</form>
</div>
<div class="content-wrapper">
<!-- 左侧筛选栏 -->
<div class="sidebar">
<div class="filters">
<strong>按网站筛选:</strong>
<a href="{% url 'article_list' %}{% if search_query %}?q={{ search_query }}{% endif %}"
{% if not selected_website %}class="active" {% endif %}>全部</a>
{% for website in websites %}
<a href="?website={{ website.id }}{% if search_query %}&q={{ search_query }}{% endif %}"
{% if selected_website and selected_website.id == website.id %}class="active" {% endif %}>{{ website.name }}</a>
{% endfor %}
<div class="websites-container">
<div class="website-card {% if not selected_website %}active{% endif %}"
onclick="window.location='{% url 'article_list' %}{% if search_query %}?q={{ search_query }}{% endif %}'">
全部
</div>
{% for website in websites %}
<div class="website-card {% if selected_website and selected_website.id == website.id %}active{% endif %}"
onclick="window.location='?website={{ website.id }}{% if search_query %}&q={{ search_query }}{% endif %}'">
{{ website.name }}
</div>
<!-- 修改:按媒体类型筛选 -->
{% endfor %}
</div>
<div class="content-wrapper">
<div class="sidebar">
<div class="filters">
<strong>按媒体类型筛选:</strong>
<a href="?{% if selected_website %}website={{ selected_website.id }}&{% endif %}{% if search_query %}q={{ search_query }}&{% endif %}media_type=all"
@@ -272,9 +584,7 @@
</div>
</div>
<!-- 主内容区域 -->
<div class="main-content">
<!-- 新增:搜索结果信息 -->
{% if search_query %}
<div class="search-info">
搜索 "{{ search_query }}" 找到 {{ page_obj.paginator.count }} 篇文章
@@ -282,32 +592,52 @@
</div>
{% endif %}
<!-- 新增:导出功能 -->
<div class="export-section">
<button id="selectAllBtn" class="export-btn">全选</button>
<button id="deselectAllBtn" class="export-btn">取消全选</button>
<button id="exportJsonBtn" class="export-btn" disabled>导出为JSON</button>
<button id="exportCsvBtn" class="export-btn" disabled>导出为CSV</button>
<!-- 新增:导出为ZIP包按钮 -->
<button id="exportZipBtn" class="export-btn" disabled>导出为ZIP包</button>
<!-- 删除:按类型导出按钮 -->
<!-- <button id="exportTextOnlyBtn" class="export-btn">导出纯文本</button>
<button id="exportWithImagesBtn" class="export-btn">导出含图片</button>
<button id="exportWithVideosBtn" class="export-btn">导出含视频</button> -->
</div>
<ul>
<div class="articles-grid">
{% for article in page_obj %}
<li>
<input type="checkbox" class="article-checkbox" value="{{ article.id }}"
id="article_{{ article.id }}">
<a href="{% url 'article_detail' article.id %}">{{ article.title }}</a>
<div class="meta">({{ article.website.name }} - {{ article.created_at|date:"Y-m-d" }})</div>
</li>
{% empty %}
<li>暂无文章</li>
<div class="article-card {% if not article.media_files %}no-image{% endif %}">
{% if article.media_files %}
{% for media_file in article.media_files|slice:":1" %}
{% if media_file|slice:"-4:" == ".jpg" or media_file|slice:"-5:" == ".jpeg" or media_file|slice:"-4:" == ".png" or media_file|slice:"-4:" == ".gif" %}
<div class="article-image-container">
{% if media_file|slice:":4" == "http" %}
<img src="{{ media_file }}" alt="{{ article.title }}" class="article-image" onerror="this.parentElement.style.display='none';">
{% else %}
<img src="/media/{{ media_file }}" alt="{{ article.title }}" class="article-image" onerror="this.parentElement.style.display='none';">
{% endif %}
</div>
{% endif %}
{% endfor %}
{% endif %}
<div class="article-content">
<input type="checkbox" class="article-checkbox" value="{{ article.id }}" id="article_{{ article.id }}">
<h3><a href="{% url 'article_detail' article.id %}">{{ article.title }}</a></h3>
{% if article.content %}
<div class="article-summary">
{{ article.content|striptags|truncatechars:120 }}
</div>
{% endif %}
<div class="article-meta">
<span class="article-source">{{ article.website.name }}</span>
<span class="article-date">{{ article.created_at|date:"Y-m-d" }}</span>
</div>
</div>
</div>
{% empty %}
<div class="article-card">
<div class="article-content">
<p>暂无文章</p>
</div>
</div>
{% endfor %}
</ul>
</div>
<div class="pagination">
{% if page_obj.has_previous %}
@@ -325,7 +655,6 @@
<span>第 {{ page_obj.number }} 页,共 {{ page_obj.paginator.num_pages }} 页</span>
<!-- 修改:优化页码显示逻辑 -->
{% with page_obj.paginator as paginator %}
{% for num in paginator.page_range %}
{% if page_obj.number == num %}
@@ -369,33 +698,24 @@
</div>
<script>
// 导出功能相关JavaScript
const checkboxes = document.querySelectorAll('.article-checkbox');
const exportJsonBtn = document.getElementById('exportJsonBtn');
const exportCsvBtn = document.getElementById('exportCsvBtn');
const selectAllBtn = document.getElementById('selectAllBtn');
const deselectAllBtn = document.getElementById('deselectAllBtn');
// 新增:获取ZIP导出按钮元素
const exportZipBtn = document.getElementById('exportZipBtn');
// const exportTextOnlyBtn = document.getElementById('exportTextOnlyBtn');
// const exportWithImagesBtn = document.getElementById('exportWithImagesBtn');
// const exportWithVideosBtn = document.getElementById('exportWithVideosBtn');
// 更新导出按钮状态
function updateExportButtons() {
const selectedCount = document.querySelectorAll('.article-checkbox:checked').length;
exportJsonBtn.disabled = selectedCount === 0;
exportCsvBtn.disabled = selectedCount === 0;
exportZipBtn.disabled = selectedCount === 0; // 新增:更新ZIP导出按钮状态
exportZipBtn.disabled = selectedCount === 0;
}
// 为所有复选框添加事件监听器
checkboxes.forEach(checkbox => {
checkbox.addEventListener('change', updateExportButtons);
});
// 全选功能
selectAllBtn.addEventListener('click', () => {
checkboxes.forEach(checkbox => {
checkbox.checked = true;
@@ -403,7 +723,6 @@
updateExportButtons();
});
// 取消全选功能
deselectAllBtn.addEventListener('click', () => {
checkboxes.forEach(checkbox => {
checkbox.checked = false;
@@ -411,12 +730,10 @@
updateExportButtons();
});
// 导出为JSON功能
exportJsonBtn.addEventListener('click', () => {
const selectedArticles = Array.from(document.querySelectorAll('.article-checkbox:checked'))
.map(checkbox => checkbox.value);
// 发送POST请求导出文章
fetch('{% url "export_articles" %}', {
method: 'POST',
headers: {
@@ -449,12 +766,10 @@
});
});
// 导出为CSV功能
exportCsvBtn.addEventListener('click', () => {
const selectedArticles = Array.from(document.querySelectorAll('.article-checkbox:checked'))
.map(checkbox => checkbox.value);
// 发送POST请求导出文章
fetch('{% url "export_articles" %}', {
method: 'POST',
headers: {
@@ -487,12 +802,10 @@
});
});
// 新增:导出为ZIP包功能
exportZipBtn.addEventListener('click', () => {
const selectedArticles = Array.from(document.querySelectorAll('.article-checkbox:checked'))
.map(checkbox => checkbox.value);
// 发送POST请求导出文章为ZIP包
fetch('{% url "export_articles" %}', {
method: 'POST',
headers: {
@@ -501,7 +814,7 @@
},
body: JSON.stringify({
article_ids: selectedArticles,
format: 'zip' // 指定导出格式为ZIP
format: 'zip'
})
})
.then(response => {
@@ -525,55 +838,7 @@
});
});
// exportTextOnlyBtn.addEventListener('click', () => {
// exportByMediaType('text_only');
// });
// exportWithImagesBtn.addEventListener('click', () => {
// exportByMediaType('with_images');
// });
// exportWithVideosBtn.addEventListener('click', () => {
// exportByMediaType('with_videos');
// });
// function exportByMediaType(mediaType) {
// // 发送POST请求按类型导出文章
// fetch('{% url "export_articles_by_type" %}', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// 'X-CSRFToken': '{{ csrf_token }}'
// },
// body: JSON.stringify({
// media_type: mediaType,
// format: 'zip'
// })
// })
// .then(response => {
// if (response.ok) {
// return response.blob();
// }
// throw new Error('导出失败');
// })
// .then(blob => {
// const url = window.URL.createObjectURL(blob);
// const a = document.createElement('a');
// a.href = url;
// a.download = `articles_${mediaType}.zip`;
// document.body.appendChild(a);
// a.click();
// window.URL.revokeObjectURL(url);
// document.body.removeChild(a);
// })
// .catch(error => {
// alert('导出失败: ' + error);
// });
// }
// 初始化导出按钮状态
updateExportButtons();
</script>
</body>
</html>
</html>

View File

@@ -4,7 +4,7 @@ from django.core.paginator import Paginator
from django.http import JsonResponse
from django.views.decorators.http import require_http_methods
from django.core.management import call_command
from .models import Article, Website
from .models import Article, Website, SiteConfig
import threading
from django.http import HttpResponse
import json
@@ -66,11 +66,15 @@ def article_list(request):
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)
# 获取网站配置
site_config = SiteConfig.get_config()
return render(request, 'core/article_list.html', {
'page_obj': page_obj,
'websites': websites,
'selected_website': selected_website,
'search_query': search_query
'search_query': search_query,
'site_config': site_config
})

View File

@@ -40,6 +40,7 @@ outcome==1.3.0.post0
packaging==25.0
parso==0.8.4
pexpect==4.9.0
pillow==12.0.0
pluggy==1.6.0
prompt_toolkit==3.0.51
psycopg2-binary==2.9.10