|
|
@ -2,14 +2,14 @@ import io
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
from flask import (Blueprint, abort, current_app, flash, redirect,
|
|
|
|
from flask import (Blueprint, abort, current_app, flash, redirect,
|
|
|
|
render_template, request, send_from_directory, url_for)
|
|
|
|
render_template, request, send_from_directory, url_for, session, jsonify)
|
|
|
|
from flask_login import current_user, login_required
|
|
|
|
from flask_login import current_user, login_required
|
|
|
|
from PIL import Image
|
|
|
|
from PIL import Image
|
|
|
|
from sqlalchemy import func
|
|
|
|
from sqlalchemy import func
|
|
|
|
from sqlalchemy.orm import aliased
|
|
|
|
from sqlalchemy.orm import aliased
|
|
|
|
|
|
|
|
|
|
|
|
from yadc import db
|
|
|
|
from yadc import db
|
|
|
|
from yadc.forms import UploadForm, CommentForm#, EditCommentForm
|
|
|
|
from yadc.forms import UploadForm, CommentForm, PostForm
|
|
|
|
from yadc.models import FILETYPE, RATING, Post, Tag, Comment
|
|
|
|
from yadc.models import FILETYPE, RATING, Post, Tag, Comment
|
|
|
|
from yadc.utils import query_replace
|
|
|
|
from yadc.utils import query_replace
|
|
|
|
|
|
|
|
|
|
|
@ -33,7 +33,9 @@ def posts(page):
|
|
|
|
|
|
|
|
|
|
|
|
# PARSING ARGUMENTS
|
|
|
|
# PARSING ARGUMENTS
|
|
|
|
f_tags = request.args.get('tags', '').split()
|
|
|
|
f_tags = request.args.get('tags', '').split()
|
|
|
|
m_ratings = RATING.matched(request.args.get('rating'))
|
|
|
|
# m_ratings = RATING.matched(request.args.get('rating'))
|
|
|
|
|
|
|
|
f_rating = {r.name : r for r in RATING}.get(request.args.get('rating'), RATING.safe)
|
|
|
|
|
|
|
|
m_ratings = f_rating.matched
|
|
|
|
|
|
|
|
|
|
|
|
posts_query = Post.query
|
|
|
|
posts_query = Post.query
|
|
|
|
if f_tags:
|
|
|
|
if f_tags:
|
|
|
@ -45,6 +47,8 @@ def posts(page):
|
|
|
|
|
|
|
|
|
|
|
|
# flash(f_tags)
|
|
|
|
# flash(f_tags)
|
|
|
|
# flash(m_ratings)
|
|
|
|
# flash(m_ratings)
|
|
|
|
|
|
|
|
# session['index_settings'] = dict(tags=f_tags, rating=f_rating)
|
|
|
|
|
|
|
|
session['index_settings'] = dict(tags=request.args.get('tags', ''), rating=f_rating.name)
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('post/index.html', posts=posts, tags=tags)
|
|
|
|
return render_template('post/index.html', posts=posts, tags=tags)
|
|
|
|
|
|
|
|
|
|
|
@ -60,7 +64,7 @@ def post_show(id):
|
|
|
|
for comment in post.comments:
|
|
|
|
for comment in post.comments:
|
|
|
|
comment.editform = CommentForm(id=comment.id, content=comment.content)
|
|
|
|
comment.editform = CommentForm(id=comment.id, content=comment.content)
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('post/post.html', post=post, tags=post.tags, comments=post.comments, comment_form=CommentForm(post_id=post.id))
|
|
|
|
return render_template('post/post.html', post=post, tags=post.tags, comments=post.comments, editform=PostForm(id=post.id), comment_form=CommentForm(post_id=post.id))
|
|
|
|
|
|
|
|
|
|
|
|
from yadc.bp import manage
|
|
|
|
from yadc.bp import manage
|
|
|
|
@bp.route('/comment', methods=['POST'])
|
|
|
|
@bp.route('/comment', methods=['POST'])
|
|
|
@ -110,3 +114,81 @@ def upload():
|
|
|
|
return redirect(url_for('.posts'))
|
|
|
|
return redirect(url_for('.posts'))
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('post/upload.html', form=form)
|
|
|
|
return render_template('post/upload.html', form=form)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/tags')
|
|
|
|
|
|
|
|
def tag_autocomplete():
|
|
|
|
|
|
|
|
query = request.args.get('q', '')
|
|
|
|
|
|
|
|
if query != '':
|
|
|
|
|
|
|
|
tags = Tag.query.filter(Tag.content.like("%{}%".format(query))).limit(15).all()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return jsonify([{"id": t.id, "content": t.content, "content_deser": t.content_deser, "category": {"id": t.category.value, "name": t.category.name}} for t in tags])
|
|
|
|
|
|
|
|
return jsonify()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# A TRY TO MAKE A DANBOORU COMPATIBLE API
|
|
|
|
|
|
|
|
# import json
|
|
|
|
|
|
|
|
@bp.route('/index.json')
|
|
|
|
|
|
|
|
def post_index():
|
|
|
|
|
|
|
|
# return jsonify(json.load(open('index.json', 'r')))
|
|
|
|
|
|
|
|
# return jsonify(json.load(open('test.json', 'r')))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
f_tags = request.args.get('tags', '').split()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# rating = None
|
|
|
|
|
|
|
|
for t in f_tags:
|
|
|
|
|
|
|
|
if t.startswith('rating:') or t.startswith('-rating:'):
|
|
|
|
|
|
|
|
f_tags.remove(t)
|
|
|
|
|
|
|
|
# rating = t.split(':')[1]
|
|
|
|
|
|
|
|
# f_rating = {r.name : r for r in RATING}.get(rating, RATING.safe)
|
|
|
|
|
|
|
|
# m_ratings = f_rating.matched
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
posts_query = Post.query
|
|
|
|
|
|
|
|
if f_tags:
|
|
|
|
|
|
|
|
posts_query = posts_query.join(Post.tags).group_by(Post.id).filter(Tag.content.in_(f_tags)).having(func.count(Post.id)==len(f_tags))
|
|
|
|
|
|
|
|
# posts_query = posts_query.filter(Post.rating.in_(m_ratings)).order_by(Post.created.desc())
|
|
|
|
|
|
|
|
posts_query = posts_query.order_by(Post.created.desc())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
posts = posts_query.paginate(int(request.args.get('page', 0))+1, int(request.args.get('limit') or current_app.config.get('POSTS_PER_PAGE')))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return jsonify([dict(
|
|
|
|
|
|
|
|
id=p.id,
|
|
|
|
|
|
|
|
tags=" ".join([t.content for t in p.tags]),
|
|
|
|
|
|
|
|
created_at=int(p.created.timestamp()),
|
|
|
|
|
|
|
|
creator_id=p.author_id,
|
|
|
|
|
|
|
|
source=p.source,
|
|
|
|
|
|
|
|
md5=p.md5,
|
|
|
|
|
|
|
|
file_size=p.filesize,
|
|
|
|
|
|
|
|
file_url=p.url(path=p.image_url, endpoint='img'),
|
|
|
|
|
|
|
|
preview_url=p.url(path=p.image_url, endpoint='thumb'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preview_width=0,
|
|
|
|
|
|
|
|
preview_height=0,
|
|
|
|
|
|
|
|
actual_preview_width=0,
|
|
|
|
|
|
|
|
actual_preview_height=0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sample_url=p.url(path=p.image_url, endpoint='sample'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sample_width=0,
|
|
|
|
|
|
|
|
sample_height=0,
|
|
|
|
|
|
|
|
sample_file_size=0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jpeg_url=p.url(path=p.image_url, endpoint='img') if p.filetype is FILETYPE.jpeg else p.url(path=p.image_url, endpoint='jpeg'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jpeg_width=0,
|
|
|
|
|
|
|
|
jpeg_height=0,
|
|
|
|
|
|
|
|
jpeg_file_size=0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rating=str(p.rating.name)[:1],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
has_children=False,
|
|
|
|
|
|
|
|
parent_id=None,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
status=p.status.name,
|
|
|
|
|
|
|
|
width=p.width,
|
|
|
|
|
|
|
|
height=p.height,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
is_held=False,
|
|
|
|
|
|
|
|
frames_pending_string='',
|
|
|
|
|
|
|
|
frames_pending=[],
|
|
|
|
|
|
|
|
frames_string='',
|
|
|
|
|
|
|
|
frames=[]
|
|
|
|
|
|
|
|
) for p in posts.items])
|