1
1
Fork 0

Parent post relation + minor form styles,

image creating bugfix
dev
Jan Kužílek 5 years ago
parent e596ee6ff1
commit 7d40d8f2c0

@ -0,0 +1,31 @@
"""parent child relations
Revision ID: 4b6c6a23c639
Revises: 71386dc42f9b
Create Date: 2020-03-18 16:17:09.512280
"""
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utc
# revision identifiers, used by Alembic.
revision = '4b6c6a23c639'
down_revision = '71386dc42f9b'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('post', sa.Column('parent_id', sa.Integer(), nullable=True))
op.create_foreign_key(None, 'post', 'post', ['parent_id'], ['id'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'post', type_='foreignkey')
op.drop_column('post', 'parent_id')
# ### end Alembic commands ###

@ -64,6 +64,10 @@ h4 {
margin-top: .4em; margin-top: .4em;
} }
.oneline-space {
height: 1em;
}
.comment-form { .comment-form {
margin-left: 10px; margin-left: 10px;
@ -105,7 +109,7 @@ input[type=text], input[type=password], textarea {
display: block; display: block;
padding: .5em; padding: .5em;
margin: .3em 0; // margin: .3em 0;
} }
input[type=text], input[type=password] { input[type=text], input[type=password] {
@ -130,7 +134,6 @@ input[type=submit] {
color: inherit; color: inherit;
padding: .4em 1.8em; padding: .4em 1.8em;
} }
@ -149,21 +152,27 @@ label {
} }
input[type=submit] { input[type=submit] {
margin: .2em 0; margin: .2em;
} }
form > input, form > div { form > input, form > textarea, form > div {
margin: .8em 0; margin: .8em 0;
} }
div.row { div.row {
padding: .2em; // padding: .2em;
display: flex; display: flex;
align-items: center; align-items: center;
&.stretch { &.stretch {
justify-content: space-between; justify-content: space-between;
} }
label {
padding: 0;
margin-left: .2em;
margin-right: .6em;
}
} }
ul { ul {
padding: 0; padding: 0;
@ -191,9 +200,10 @@ label {
width: 100%; width: 100%;
position: relative; position: relative;
// input[type=text] { input[type=text] {
// width: 100%; // width: 100%;
// } margin: .3em 0;
}
> .suggest-dropdown { > .suggest-dropdown {
display: flex; display: flex;
@ -243,12 +253,12 @@ label {
flex-grow: 1; flex-grow: 1;
flex-basis: 100%; flex-basis: 100%;
word-break: break-all; // word-break: break-all;
word-wrap: break-word; // overflow-wrap: anywhere;
} }
.tag-right { .tag-icon, .tag-right {
align-self: center;
} }
.count { .count {
font-size: .8em; font-size: .8em;

@ -40,7 +40,9 @@ def manage_posts(page):
id=post.id, id=post.id,
rating=post.rating.name, rating=post.rating.name,
status=post.status.name, status=post.status.name,
source=post.source) source=post.source,
parent=post.parent_id
)
return render_template('manage/posts.html', posts=posts, elements=posts.items) return render_template('manage/posts.html', posts=posts, elements=posts.items)
@ -131,9 +133,13 @@ def modify_post():
elif form.edit.data: elif form.edit.data:
if form.rating.raw_data and form.rating.data: el.rating = form.rating.data if form.rating.raw_data and form.rating.data: el.rating = form.rating.data
if form.status.raw_data and form.status.data: el.status = form.status.data if form.status.raw_data and form.status.data: el.status = form.status.data
if form.source.raw_data and form.source.data: el.source = form.source.data if form.source.raw_data: el.source = form.source.data
if form.tags.raw_data and form.tags.raw_data: if form.parent.raw_data:
el.parent_id = form.parent.data
# el.parent = Post.query.get(form.parent.data)
if form.tags.raw_data and form.tags.data:
f_tags = form.tags.data.split() f_tags = form.tags.data.split()
tags = Tag.query.filter(Tag.content.in_(f_tags)).all() tags = Tag.query.filter(Tag.content.in_(f_tags)).all()
el.tags = tags el.tags = tags

@ -85,6 +85,7 @@ def post_show(id):
id=post.id, id=post.id,
referer=post_show.__name__, referer=post_show.__name__,
source=post.source, source=post.source,
parent=post.parent_id,
tags=' '.join(t.content for t in post.tags), tags=' '.join(t.content for t in post.tags),
rating=post.rating, rating=post.rating,
status=post.status status=post.status

@ -1,5 +1,5 @@
from wtforms import Form from wtforms import Form
from wtforms import StringField, PasswordField, BooleanField, SubmitField, FileField, MultipleFileField, ValidationError, RadioField, TextAreaField, HiddenField, SelectField from wtforms import StringField, PasswordField, BooleanField, SubmitField, FileField, MultipleFileField, ValidationError, RadioField, TextAreaField, HiddenField, SelectField, IntegerField
from wtforms.validators import DataRequired, InputRequired, Email, EqualTo, AnyOf, optional, StopValidation, URL from wtforms.validators import DataRequired, InputRequired, Email, EqualTo, AnyOf, optional, StopValidation, URL
from werkzeug.utils import cached_property from werkzeug.utils import cached_property
@ -169,6 +169,12 @@ class PostForm(EditForm):
validators=[optional()]) validators=[optional()])
source = StringField('Source', validators=[optional(), URL()], render_kw=dict(placeholder='Source URL', autocomplete='off')) source = StringField('Source', validators=[optional(), URL()], render_kw=dict(placeholder='Source URL', autocomplete='off'))
parent = IntegerField('Parent', validators=[optional()], render_kw=dict(placeholder='Parent ID', autocomplete='off'))
def validate_parent(form, field):
if not Post.query.get(field.data):
raise ValidationError('Enter valid parent post.')
referer = HiddenField() referer = HiddenField()
approve = SubmitField('Approve') approve = SubmitField('Approve')

@ -192,8 +192,9 @@ class Post(TimestampMixin, db.Model):
tags = db.relationship('Tag', secondary=post_tags, backref=db.backref('posts')) tags = db.relationship('Tag', secondary=post_tags, backref=db.backref('posts'))
# parent_id = db.Column(db.Integer, db.ForeignKey('post.id')) parent_id = db.Column(db.Integer, db.ForeignKey('post.id'))
# parent = db.relationship('Post', backref=db.backref('children', lazy=True), foreign_keys=[parent_id]) parent = db.relationship('Post', backref=db.backref('children', lazy=True), remote_side=[id])
# children = db.relationship('Post', back_populates='parent')
# def __init__(self, **kwargs): # def __init__(self, **kwargs):
# super().__init__(**kwargs) # super().__init__(**kwargs)
@ -247,7 +248,7 @@ class Post(TimestampMixin, db.Model):
@property @property
def image_files(self): def image_files(self):
return dict( return dict(
image=os.path.join(current_app.config.get('POST_UPLOADS'), IMAGE_STORE.image.value, f"{path}.{self.filetype.file_ext}"), image=os.path.join(current_app.config.get('POST_UPLOADS'), IMAGE_STORE.image.value, f"{self.md5}.{self.filetype.file_ext}"),
jpeg=(os.path.join(current_app.config.get('POST_UPLOADS'), IMAGE_STORE.jpeg.value, f"{self.md5}.jpg") if not self.filetype.is_jpeg else None), jpeg=(os.path.join(current_app.config.get('POST_UPLOADS'), IMAGE_STORE.jpeg.value, f"{self.md5}.jpg") if not self.filetype.is_jpeg else None),
sample=os.path.join(current_app.config.get('POST_UPLOADS'), IMAGE_STORE.sample.value, f"{self.md5}.jpg"), sample=os.path.join(current_app.config.get('POST_UPLOADS'), IMAGE_STORE.sample.value, f"{self.md5}.jpg"),
thumb_big=os.path.join(current_app.config.get('POST_UPLOADS'), IMAGE_STORE.thumb_big.value, f"{self.md5}.jpg"), thumb_big=os.path.join(current_app.config.get('POST_UPLOADS'), IMAGE_STORE.thumb_big.value, f"{self.md5}.jpg"),

File diff suppressed because one or more lines are too long

@ -37,12 +37,12 @@
<!--<span class="user fa fa-user"></span>--> <!--<span class="user fa fa-user"></span>-->
<div class="user_dropdown"> <div class="user_dropdown">
{% if current_user.is_anonymous %} {% if current_user.is_anonymous %}
<a href="{{ url_for('auth.login', next=url_for('post.posts', **utils.session_rating()) ) }}">Login</a> <a href="{{ url_for('auth.login', next=request.path ) }}">Login</a>
<a href="{{ url_for('auth.register') }}">Register</a> <a href="{{ url_for('auth.register') }}">Register</a>
{% else %} {% else %}
<a href="{{ url_for('user.profile', username=current_user.username).replace('%40','@') }}">Profile</a> <a href="{{ url_for('user.profile', username=current_user.username).replace('%40','@') }}">Profile</a>
<a href="{{ url_for('user.settings') }}">Settings</a> <a href="{{ url_for('user.settings') }}">Settings</a>
<a href="{{ url_for('auth.logout', next=url_for('post.posts', **utils.session_rating()) ) }}">Log out</a> <a href="{{ url_for('auth.logout', next=request.path ) }}">Log out</a>
{% endif%} {% endif%}
</div> </div>
</div> </div>
@ -61,7 +61,7 @@
{% endif %} {% endif %}
{% endwith %} {% endwith %}
<div class="main-wrap"> <div class="main-wrap{%block sidepanel%}{%endblock%}">
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </div>

@ -17,6 +17,7 @@
<th>Rating</th> <th>Rating</th>
<th>Status</th> <th>Status</th>
<th>Source</th> <th>Source</th>
<th>Parent</th>
{% endblock %} {% endblock %}
{% block fields %} {% block fields %}
@ -39,4 +40,8 @@
{% call genfield(element.editform.source) %} {% call genfield(element.editform.source) %}
{{ element.source }} {{ element.source }}
{% endcall %} {% endcall %}
{% call genfield(element.editform.parent) %}
{{ element.parent_id or '' }}
{% endcall %}
{% endblock %} {% endblock %}

@ -10,9 +10,7 @@
{% if post.is_approved %} {% if post.is_approved %}
<div class="approver">Approved by: {{ post.approver.username }}</div> <div class="approver">Approved by: {{ post.approver.username }}</div>
{% endif %} {% else %}
{% if not post.is_approved %}
<div class="status">Status: {{ post.status.name.capitalize() }}</div> <div class="status">Status: {{ post.status.name.capitalize() }}</div>
{% endif %} {% endif %}
@ -20,8 +18,21 @@
<div class="source">Source: <a href="{{ post.source }}">{{ post.source }}</a></div> <div class="source">Source: <a href="{{ post.source }}">{{ post.source }}</a></div>
<div class="size">File size: {{ post.filesize_human }}</div> <div class="size">File size: {{ post.filesize_human }}</div>
<div class="resolution">Image res: {{ post.image_resolution }}</div> <div class="resolution">Image res: {{ post.image_resolution }}</div>
<div class="jpeg"><a href="{{ post.url(path=post.file_uri, endpoint='jpeg') }}">Enlarge image</a></div>
{% if post.parent %}
<div class="parent"><a href="{{ url_for('post.post_show', id=post.parent_id) }}">Parent post #{{post.parent_id}}</a></div>
{% endif %}
{% if post.children %}
<div class="children">
Children:
{% for child in post.children %}
<a href="{{ url_for('post.post_show', id=child.id) }}">#{{child.id}}</a>
{% endfor%}
</div>
{% endif %}
<div class="oneline-space"></div>
<div class="jpeg"><a href="{{ post.url(path=post.file_uri, endpoint='jpeg') }}">Enlarge image</a></div>
{% if not post.filetype.is_jpeg %} {% if not post.filetype.is_jpeg %}
<div class="png"><a href="{{ post.url(path=post.file_uri) }}">Original PNG file</a></div> <div class="png"><a href="{{ post.url(path=post.file_uri) }}">Original PNG file</a></div>
{% endif %} {% endif %}
@ -39,11 +50,14 @@
{{ editform.referer() }} {{ editform.referer() }}
{{ editform.source }} {{ editform.source }}
<div class="row">
{{ editform.parent.label }}
{{ editform.parent }}
</div>
{{ render_tag_input(editform.tags, {'alt-selblock': 'section.sidepanel article.tags .tags-inpage'}) }} {{ render_tag_input(editform.tags, {'alt-selblock': 'section.sidepanel article.tags .tags-inpage'}) }}
{{ editform.edit() }} {{ editform.edit() }}{{ editform.approve() }}
{{ editform.approve() }}
</form> </form>
</div> </div>
</article> </article>
@ -104,7 +118,7 @@
{% if current_user.is_authenticated %} {% if current_user.is_authenticated %}
<h3>Reply</h3> <h3>Reply</h3>
<div class="comment-form"> <div class="comment-form baseform">
<form action="{{ url_for('post.comment') }}" method="post"> <form action="{{ url_for('post.comment') }}" method="post">
{{ comment_form.csrf_token }} {{ comment_form.csrf_token }}
{{ comment_form.post_id() }} {{ comment_form.post_id() }}

Loading…
Cancel
Save