fix(ui): 修复图片路径与缩略显示;审核页展示图+介绍+用户
This commit is contained in:
@@ -29,7 +29,13 @@ def submit(act_id):
|
|||||||
upload_dir = os.path.join(current_app.config["UPLOAD_FOLDER"], "activities")
|
upload_dir = os.path.join(current_app.config["UPLOAD_FOLDER"], "activities")
|
||||||
for idx, f in enumerate(files):
|
for idx, f in enumerate(files):
|
||||||
original, web, thumb, exif = save_image(f, upload_dir)
|
original, web, thumb, exif = save_image(f, upload_dir)
|
||||||
img = SubmissionImage(submission_id=sub.id, original_path=original, web_path=web, thumb_path=thumb, exif_json=exif, order_index=idx)
|
root = current_app.config["UPLOAD_FOLDER"]
|
||||||
|
def rel(p):
|
||||||
|
try:
|
||||||
|
return os.path.relpath(p, root)
|
||||||
|
except Exception:
|
||||||
|
return p
|
||||||
|
img = SubmissionImage(submission_id=sub.id, original_path=rel(original), web_path=rel(web), thumb_path=rel(thumb), exif_json=exif, order_index=idx)
|
||||||
db.session.add(img)
|
db.session.add(img)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("投稿已提交,待审核")
|
flash("投稿已提交,待审核")
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from flask import Blueprint, redirect, url_for, current_app, send_from_directory
|
import os
|
||||||
|
from flask import Blueprint, redirect, url_for, current_app, send_file, abort
|
||||||
|
|
||||||
bp = Blueprint("main", __name__)
|
bp = Blueprint("main", __name__)
|
||||||
|
|
||||||
@@ -8,4 +9,10 @@ def index():
|
|||||||
|
|
||||||
@bp.route("/uploads/<path:filename>")
|
@bp.route("/uploads/<path:filename>")
|
||||||
def uploads(filename):
|
def uploads(filename):
|
||||||
return send_from_directory(current_app.config["UPLOAD_FOLDER"], filename)
|
root = os.path.abspath(current_app.config["UPLOAD_FOLDER"])
|
||||||
|
path = filename
|
||||||
|
if not os.path.isabs(path):
|
||||||
|
path = os.path.abspath(os.path.join(root, filename))
|
||||||
|
if not path.startswith(root):
|
||||||
|
abort(404)
|
||||||
|
return send_file(path)
|
||||||
|
|||||||
@@ -31,7 +31,14 @@ def create():
|
|||||||
upload_dir = os.path.join(current_app.config["UPLOAD_FOLDER"], "posts")
|
upload_dir = os.path.join(current_app.config["UPLOAD_FOLDER"], "posts")
|
||||||
for idx, f in enumerate(files):
|
for idx, f in enumerate(files):
|
||||||
original, web, thumb, exif = save_image(f, upload_dir)
|
original, web, thumb, exif = save_image(f, upload_dir)
|
||||||
img = PostImage(post_id=post.id, original_path=original, web_path=web, thumb_path=thumb, exif_json=exif, order_index=idx)
|
# 存储相对路径,兼容已有绝对路径
|
||||||
|
root = current_app.config["UPLOAD_FOLDER"]
|
||||||
|
def rel(p):
|
||||||
|
try:
|
||||||
|
return os.path.relpath(p, root)
|
||||||
|
except Exception:
|
||||||
|
return p
|
||||||
|
img = PostImage(post_id=post.id, original_path=rel(original), web_path=rel(web), thumb_path=rel(thumb), exif_json=exif, order_index=idx)
|
||||||
db.session.add(img)
|
db.session.add(img)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("作品已提交")
|
flash("作品已提交")
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
{% block title %}作品审核{% endblock %}
|
{% block title %}作品审核{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h3>作品审核</h3>
|
<h3 class="mb-3">作品审核</h3>
|
||||||
<table class="table">
|
<div class="card-grid">
|
||||||
<tr><th>标题</th><th>作者</th><th>操作</th></tr>
|
|
||||||
{% for p in posts %}
|
{% for p in posts %}
|
||||||
<tr>
|
<div class="card">
|
||||||
<td>{{ p.title }}</td>
|
{% set first = p.images[0] if p.images %}
|
||||||
<td>{{ p.user.username }}</td>
|
{% if first %}
|
||||||
<td>
|
<img class="photo-thumb" src="{{ url_for('main.uploads', filename=first.web_path) }}" alt="{{ p.title }}" />
|
||||||
|
{% endif %}
|
||||||
|
<div class="p-3">
|
||||||
|
<div class="mb-2"><strong>{{ p.title }}</strong> · {{ p.user.username }}</div>
|
||||||
|
{% if p.description %}<div class="text-secondary mb-2">{{ p.description }}</div>{% endif %}
|
||||||
<form method="post" action="{{ url_for('admin.approve_post', post_id=p.id) }}" style="display:inline">
|
<form method="post" action="{{ url_for('admin.approve_post', post_id=p.id) }}" style="display:inline">
|
||||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||||
<button class="btn btn-success">通过</button>
|
<button class="btn btn-success">通过</button>
|
||||||
@@ -17,8 +20,8 @@
|
|||||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||||
<button class="btn btn-danger">拒绝</button>
|
<button class="btn btn-danger">拒绝</button>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</div>
|
||||||
</tr>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
{% set first = p.images[0] if p.images %}
|
{% set first = p.images[0] if p.images %}
|
||||||
{% if first %}
|
{% if first %}
|
||||||
<a href="{{ url_for('posts.detail', post_id=p.id) }}">
|
<a href="{{ url_for('posts.detail', post_id=p.id) }}">
|
||||||
<img class="photo-thumb" src="{{ url_for('main.uploads', filename=first.web_path.split('uploads\\')[-1]) }}" alt="{{ p.title }}" />
|
<img class="photo-thumb" src="{{ url_for('main.uploads', filename=first.web_path) }}" alt="{{ p.title }}" />
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="p-3">
|
<div class="p-3">
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
{% set first = p.images[0] if p.images %}
|
{% set first = p.images[0] if p.images %}
|
||||||
{% if first %}
|
{% if first %}
|
||||||
<a href="{{ url_for('posts.detail', post_id=p.id) }}">
|
<a href="{{ url_for('posts.detail', post_id=p.id) }}">
|
||||||
<img class="photo-thumb" src="{{ url_for('main.uploads', filename=first.web_path.split('uploads\\')[-1]) }}" alt="{{ p.title }}" />
|
<img class="photo-thumb" src="{{ url_for('main.uploads', filename=first.web_path) }}" alt="{{ p.title }}" />
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="p-3">
|
<div class="p-3">
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
{% for img in post.images %}
|
{% for img in post.images %}
|
||||||
<div class="col-md-4 mb-2">
|
<div class="col-md-4 mb-2">
|
||||||
<img src="{{ url_for('main.uploads', filename=img.web_path.split('uploads\\')[-1]) }}" class="photo-thumb" />
|
<img src="{{ url_for('main.uploads', filename=img.web_path) }}" class="photo-thumb" />
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user