|
|
@ -1,10 +1,16 @@
|
|
|
|
import enum
|
|
|
|
import enum
|
|
|
|
|
|
|
|
import hashlib
|
|
|
|
|
|
|
|
import os
|
|
|
|
from datetime import datetime
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy_utc import UtcDateTime, utcnow
|
|
|
|
|
|
|
|
# from sqlalchemy.sql.functions import now as current_timestamp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from yadc import db, login
|
|
|
|
from flask import current_app, url_for
|
|
|
|
|
|
|
|
from flask_login import UserMixin, login_user, logout_user
|
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
from sqlalchemy_utc import UtcDateTime, utcnow
|
|
|
|
|
|
|
|
from werkzeug.security import check_password_hash, generate_password_hash
|
|
|
|
|
|
|
|
from werkzeug.utils import cached_property
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from yadc import db, login, utils
|
|
|
|
|
|
|
|
|
|
|
|
class OP_LEVEL(enum.Enum):
|
|
|
|
class OP_LEVEL(enum.Enum):
|
|
|
|
user = 0
|
|
|
|
user = 0
|
|
|
@ -42,9 +48,6 @@ class TimestampMixin(object):
|
|
|
|
created = db.Column(UtcDateTime, nullable=False, default=utcnow())
|
|
|
|
created = db.Column(UtcDateTime, nullable=False, default=utcnow())
|
|
|
|
updated = db.Column(UtcDateTime, nullable=False, onupdate=utcnow(), default=utcnow())
|
|
|
|
updated = db.Column(UtcDateTime, nullable=False, onupdate=utcnow(), default=utcnow())
|
|
|
|
|
|
|
|
|
|
|
|
from flask_login import UserMixin, login_user, logout_user
|
|
|
|
|
|
|
|
from werkzeug.security import check_password_hash, generate_password_hash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class User(UserMixin, TimestampMixin, db.Model):
|
|
|
|
class User(UserMixin, TimestampMixin, db.Model):
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
username = db.Column(db.String(128), unique=True, nullable=False)
|
|
|
|
username = db.Column(db.String(128), unique=True, nullable=False)
|
|
|
@ -90,13 +93,6 @@ post_tags = db.Table('post_tags', db.metadata,
|
|
|
|
db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'))
|
|
|
|
db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
import hashlib
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from werkzeug.utils import cached_property
|
|
|
|
|
|
|
|
from flask import current_app, url_for
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Post(TimestampMixin, db.Model):
|
|
|
|
class Post(TimestampMixin, db.Model):
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
md5 = db.Column(db.String(32), unique=True, nullable=False)
|
|
|
|
md5 = db.Column(db.String(32), unique=True, nullable=False)
|
|
|
@ -171,17 +167,17 @@ class Post(TimestampMixin, db.Model):
|
|
|
|
jpeg_filename = "{}.{}".format(self.md5, 'jpg')
|
|
|
|
jpeg_filename = "{}.{}".format(self.md5, 'jpg')
|
|
|
|
return os.path.join(current_app.instance_path, 'post', 'thumb', jpeg_filename)
|
|
|
|
return os.path.join(current_app.instance_path, 'post', 'thumb', jpeg_filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
|
|
|
|
def image_resolution(self):
|
|
|
|
|
|
|
|
return "{}x{}".format(self.width, self.height)
|
|
|
|
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
@cached_property
|
|
|
|
def filesize_human(self):
|
|
|
|
def filesize_human(self):
|
|
|
|
#https://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size
|
|
|
|
return utils.sizeof_fmt(self.filesize)
|
|
|
|
def sizeof_fmt(num, suffix='B'):
|
|
|
|
|
|
|
|
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
|
|
|
|
@property
|
|
|
|
if abs(num) < 1024.0:
|
|
|
|
def is_approved(self):
|
|
|
|
return "%3.1f%s%s" % (num, unit, suffix)
|
|
|
|
return self.status is POST_STATUS.active
|
|
|
|
num /= 1024.0
|
|
|
|
|
|
|
|
return "%.1f%s%s" % (num, 'Yi', suffix)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sizeof_fmt(self.filesize)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Tag(TimestampMixin, db.Model):
|
|
|
|
class Tag(TimestampMixin, db.Model):
|
|
|
|