1
1
Fork 0

Minor changes

preparing for editing
user settings
dev
Jan Kužílek 5 years ago
parent 70dba62cae
commit cf21dc2917

@ -24,6 +24,8 @@ python-magic = "*"
flask-mail = "*" flask-mail = "*"
sqlalchemy-utc = "*" sqlalchemy-utc = "*"
flask-admin = "*" flask-admin = "*"
sqlalchemy-utils = "*"
werkzeug = "==0.16.1"
[requires] [requires]
python_version = "3.8" python_version = "3.8"

21
Pipfile.lock generated

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "4aa69f03ba5d5f31ea39beeefc97e9a9b61946c3275fb53e58897aa33c9ffc1c" "sha256": "90470384a8160ec4176abf18d39b07271e755ae437ead34f7b70d914c514d709"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -18,9 +18,9 @@
"default": { "default": {
"alembic": { "alembic": {
"hashes": [ "hashes": [
"sha256:d412982920653db6e5a44bfd13b1d0db5685cbaaccaf226195749c706e1e862a" "sha256:2df2519a5b002f881517693b95626905a39c5faf4b5a1f94de4f1441095d1d26"
], ],
"version": "==1.3.3" "version": "==1.4.0"
}, },
"blinker": { "blinker": {
"hashes": [ "hashes": [
@ -97,11 +97,11 @@
}, },
"flask-wtf": { "flask-wtf": {
"hashes": [ "hashes": [
"sha256:5d14d55cfd35f613d99ee7cba0fc3fbbe63ba02f544d349158c14ca15561cc36", "sha256:57b3faf6fe5d6168bda0c36b0df1d05770f8e205e18332d0376ddb954d17aef2",
"sha256:d9a9e366b32dcbb98ef17228e76be15702cd2600675668bca23f63a7947fd5ac" "sha256:d417e3a0008b5ba583da1763e4db0f55a1269d9dd91dcc3eb3c026d3c5dbd720"
], ],
"index": "pypi", "index": "pypi",
"version": "==0.14.2" "version": "==0.14.3"
}, },
"itsdangerous": { "itsdangerous": {
"hashes": [ "hashes": [
@ -281,6 +281,13 @@
"index": "pypi", "index": "pypi",
"version": "==0.10.0" "version": "==0.10.0"
}, },
"sqlalchemy-utils": {
"hashes": [
"sha256:4e637c88bf3ac5f99b7d72342092a1f636bea1287b2e3e17d441b0413771f86e"
],
"index": "pypi",
"version": "==0.36.1"
},
"webassets": { "webassets": {
"hashes": [ "hashes": [
"sha256:167132337677c8cedc9705090f6d48da3fb262c8e0b2773b29f3352f050181cd", "sha256:167132337677c8cedc9705090f6d48da3fb262c8e0b2773b29f3352f050181cd",
@ -293,6 +300,7 @@
"sha256:1e0dedc2acb1f46827daa2e399c1485c8fa17c0d8e70b6b875b4e7f54bf408d2", "sha256:1e0dedc2acb1f46827daa2e399c1485c8fa17c0d8e70b6b875b4e7f54bf408d2",
"sha256:b353856d37dec59d6511359f97f6a4b2468442e454bd1c98298ddce53cac1f04" "sha256:b353856d37dec59d6511359f97f6a4b2468442e454bd1c98298ddce53cac1f04"
], ],
"index": "pypi",
"version": "==0.16.1" "version": "==0.16.1"
}, },
"wtforms": { "wtforms": {
@ -469,6 +477,7 @@
"sha256:1e0dedc2acb1f46827daa2e399c1485c8fa17c0d8e70b6b875b4e7f54bf408d2", "sha256:1e0dedc2acb1f46827daa2e399c1485c8fa17c0d8e70b6b875b4e7f54bf408d2",
"sha256:b353856d37dec59d6511359f97f6a4b2468442e454bd1c98298ddce53cac1f04" "sha256:b353856d37dec59d6511359f97f6a4b2468442e454bd1c98298ddce53cac1f04"
], ],
"index": "pypi",
"version": "==0.16.1" "version": "==0.16.1"
}, },
"wrapt": { "wrapt": {

@ -56,7 +56,11 @@ def create_app():
app.register_blueprint(post.bp, url_prefix='/post') app.register_blueprint(post.bp, url_prefix='/post')
app.register_blueprint(auth.bp, url_prefix='/user') app.register_blueprint(auth.bp, url_prefix='/user')
login.login_view = 'auth.login' login.login_view = 'auth.login'
from yadc import utils
@app.context_processor
def utility_processor():
return dict(utils=utils)
#assets.url = app.static_url_path #assets.url = app.static_url_path
scss = AssetsBundle('default.scss', filters='libsass', output='all.css') scss = AssetsBundle('default.scss', filters='libsass', output='all.css')

@ -63,7 +63,7 @@ def posts(page):
# flash(posts.items) # flash(posts.items)
# flash(tags) # flash(tags)
return render_template('index.html', posts=posts.items, tags=tags, pagination=posts, query_replace=query_replace) return render_template('index.html', posts=posts.items, tags=tags, pagination=posts)
@bp.route('/show/<id>') @bp.route('/show/<id>')
def post_show(id): def post_show(id):

@ -4,7 +4,7 @@ import os
from datetime import datetime from datetime import datetime
from flask import current_app, url_for from flask import current_app, url_for
from flask_login import UserMixin, login_user, logout_user from flask_login import UserMixin, login_user, logout_user, current_user
from PIL import Image from PIL import Image
from sqlalchemy_utc import UtcDateTime, utcnow from sqlalchemy_utc import UtcDateTime, utcnow
from werkzeug.security import check_password_hash, generate_password_hash from werkzeug.security import check_password_hash, generate_password_hash
@ -61,6 +61,10 @@ class User(UserMixin, TimestampMixin, db.Model):
user_status = db.Column(db.Enum(USER_STATUS), default=USER_STATUS.active, nullable=False) user_status = db.Column(db.Enum(USER_STATUS), default=USER_STATUS.active, nullable=False)
last_login = db.Column(UtcDateTime) last_login = db.Column(UtcDateTime)
ban_status = None
ban_until = None
ban_reason = None
#authored_posts = db.relationship('Post', back_populates='author') #authored_posts = db.relationship('Post', back_populates='author')
#approved_posts = db.relationship('Post', back_populates='approver') #approved_posts = db.relationship('Post', back_populates='approver')
@ -93,6 +97,14 @@ class User(UserMixin, TimestampMixin, db.Model):
def load_user(id): def load_user(id):
return User.query.get(int(id)) return User.query.get(int(id))
class UserPreferences(db.Model):
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
user = db.relationship('User', backref=db.backref('profile', uselist=False))
rating = db.Column(db.Enum(RATING), default=RATING.safe, nullable=False)
tag_blacklist = None
post_tags = db.Table('post_tags', db.metadata, post_tags = db.Table('post_tags', db.metadata,
db.Column('post_id', db.Integer, db.ForeignKey('post.id')), db.Column('post_id', db.Integer, db.ForeignKey('post.id')),
db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')) db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'))
@ -184,6 +196,11 @@ class Post(TimestampMixin, db.Model):
def is_approved(self): def is_approved(self):
return self.status is POST_STATUS.active return self.status is POST_STATUS.active
@property
def can_edit(self):
author = current_user == self.author
moderator = current_user.is_moderator
return author or moderator
class Tag(TimestampMixin, db.Model): class Tag(TimestampMixin, db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
@ -208,4 +225,10 @@ class Comment(TimestampMixin, db.Model):
user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
user = db.relationship('User', backref=db.backref('comments', lazy=True)) user = db.relationship('User', backref=db.backref('comments', lazy=True))
@property
def can_edit(self):
author = current_user == self.user
moderator = current_user.is_moderator
return author or moderator
# THINK ABOUT LAZY LOADING # THINK ABOUT LAZY LOADING

@ -403,7 +403,7 @@ header {
} }
> .comment_container { > .comment_container {
margin-left: 10px; padding: 0 10px;
article { overflow: hidden; } article { overflow: hidden; }
h4 { h4 {
@ -418,6 +418,11 @@ header {
color: red; color: red;
} }
} }
.head {
display: flex;
justify-content: space-between;
}
} }
> .form > form { > .form > form {

@ -18,12 +18,12 @@
{% macro render_pagination(endpoint) %} {% macro render_pagination(endpoint) %}
<div class="pagin"> <div class="pagin">
{% if pagination.has_prev %} {% if pagination.has_prev %}
<a href="{{ query_replace({}, url_for(endpoint, page=pagination.prev_num)) }}"><span class="fa fa-chevron-left"></span></a> <a href="{{ utils.query_replace({}, url_for(endpoint, page=pagination.prev_num)) }}"><span class="fa fa-chevron-left"></span></a>
{% endif %} {% endif %}
{% for page in pagination.iter_pages(left_edge=1, left_current=1, right_current=2, right_edge=1) %} {% for page in pagination.iter_pages(left_edge=1, left_current=1, right_current=2, right_edge=1) %}
{% if page %} {% if page %}
{% if page != pagination.page %} {% if page != pagination.page %}
<a href="{{ query_replace({}, url_for(endpoint, page=page)) }}">{{ page }}</a> <a href="{{ utils.query_replace({}, url_for(endpoint, page=page)) }}">{{ page }}</a>
{% else %} {% else %}
<a><strong>{{ page }}</strong></a> <a><strong>{{ page }}</strong></a>
{% endif %} {% endif %}
@ -32,7 +32,7 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if pagination.has_next %} {% if pagination.has_next %}
<a href="{{ query_replace({}, url_for(endpoint, page=pagination.next_num)) }}"><span class="fa fa-chevron-right"></span></a> <a href="{{ utils.query_replace({}, url_for(endpoint, page=pagination.next_num)) }}"><span class="fa fa-chevron-right"></span></a>
{% endif %} {% endif %}
</div> </div>
{% endmacro %} {% endmacro %}
@ -48,7 +48,12 @@
<div class="comment_container"> <div class="comment_container">
{% for comment in comments %} {% for comment in comments %}
<article> <article>
<h4>{{ comment.user.username }}</h4> <div class="head">
<h4>{{ comment.user.username }}</h4>
{% if comment.can_edit %}
<span class="controls">edit</span>
{% endif %}
</div>
{% if not comment.deleted %} {% if not comment.deleted %}
<p>{{ comment.content }}</p> <p>{{ comment.content }}</p>
{% else %} {% else %}
@ -60,4 +65,11 @@
<p>No comments so far.</p> <p>No comments so far.</p>
{% endif %} {% endif %}
</div> </div>
{% endmacro %}
{% macro render_post_edit() %}
<article class="edit">
<h3>Edit</h3>
<a href="">edit?</a>
</article>
{% endmacro %} {% endmacro %}

@ -1,5 +1,5 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% from '_includes.html' import render_tags, render_comments with context %} {% from '_includes.html' import render_tags, render_comments, render_post_edit with context %}
{% from "_formhelpers.html" import errors %} {% from "_formhelpers.html" import errors %}
{% block content %} {% block content %}
@ -27,6 +27,9 @@
</article> </article>
{{ render_tags() }} {{ render_tags() }}
{% if post.can_edit %}
{{ render_post_edit() }}
{% endif %}
</section> </section>
<section class="post_single"> <section class="post_single">
<div class="image"> <div class="image">

Loading…
Cancel
Save