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

@ -40,7 +40,9 @@ def manage_posts(page):
id=post.id,
rating=post.rating.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)
@ -131,9 +133,13 @@ def modify_post():
elif form.edit.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.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()
tags = Tag.query.filter(Tag.content.in_(f_tags)).all()
el.tags = tags

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

@ -1,5 +1,5 @@
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 werkzeug.utils import cached_property
@ -169,6 +169,12 @@ class PostForm(EditForm):
validators=[optional()])
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()
approve = SubmitField('Approve')

@ -192,8 +192,9 @@ class Post(TimestampMixin, db.Model):
tags = db.relationship('Tag', secondary=post_tags, backref=db.backref('posts'))
# 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_id = db.Column(db.Integer, db.ForeignKey('post.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):
# super().__init__(**kwargs)
@ -247,7 +248,7 @@ class Post(TimestampMixin, db.Model):
@property
def image_files(self):
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),
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"),

File diff suppressed because one or more lines are too long

@ -37,12 +37,12 @@
<!--<span class="user fa fa-user"></span>-->
<div class="user_dropdown">
{% 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>
{% else %}
<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('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%}
</div>
</div>
@ -61,7 +61,7 @@
{% endif %}
{% endwith %}
<div class="main-wrap">
<div class="main-wrap{%block sidepanel%}{%endblock%}">
{% block content %}{% endblock %}
</div>

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

@ -10,9 +10,7 @@
{% if post.is_approved %}
<div class="approver">Approved by: {{ post.approver.username }}</div>
{% endif %}
{% if not post.is_approved %}
{% else %}
<div class="status">Status: {{ post.status.name.capitalize() }}</div>
{% endif %}
@ -20,8 +18,21 @@
<div class="source">Source: <a href="{{ post.source }}">{{ post.source }}</a></div>
<div class="size">File size: {{ post.filesize_human }}</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 %}
<div class="png"><a href="{{ post.url(path=post.file_uri) }}">Original PNG file</a></div>
{% endif %}
@ -39,11 +50,14 @@
{{ editform.referer() }}
{{ editform.source }}
<div class="row">
{{ editform.parent.label }}
{{ editform.parent }}
</div>
{{ render_tag_input(editform.tags, {'alt-selblock': 'section.sidepanel article.tags .tags-inpage'}) }}
{{ editform.edit() }}
{{ editform.approve() }}
{{ editform.edit() }}{{ editform.approve() }}
</form>
</div>
</article>
@ -104,7 +118,7 @@
{% if current_user.is_authenticated %}
<h3>Reply</h3>
<div class="comment-form">
<div class="comment-form baseform">
<form action="{{ url_for('post.comment') }}" method="post">
{{ comment_form.csrf_token }}
{{ comment_form.post_id() }}

Loading…
Cancel
Save