|
|
@ -141,7 +141,8 @@ class Post(TimestampMixin, db.Model):
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def image_url(self):
|
|
|
|
def image_url(self):
|
|
|
|
# filename = "{}.{}".format('maybe_later_generated_cute_filename', 'jpg' if self.filetype is FILETYPE.jpeg else 'png')
|
|
|
|
# filename = "{}.{}".format('maybe_later_generated_cute_filename', 'jpg' if self.filetype is FILETYPE.jpeg else 'png')
|
|
|
|
filename = 'maybe_later_generated_cute_filename'
|
|
|
|
# filename = 'maybe_later_generated_cute_filename'
|
|
|
|
|
|
|
|
filename = "{} - {} {}".format(current_app.config.get('INSTANCE_NAME'), self.id, " ".join(tag.content for tag in self.tags))
|
|
|
|
return os.path.join(self.md5, filename)
|
|
|
|
return os.path.join(self.md5, filename)
|
|
|
|
|
|
|
|
|
|
|
|
def url(self, path, endpoint='img'):
|
|
|
|
def url(self, path, endpoint='img'):
|
|
|
@ -170,6 +171,18 @@ 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 filesize_human(self):
|
|
|
|
|
|
|
|
#https://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size
|
|
|
|
|
|
|
|
def sizeof_fmt(num, suffix='B'):
|
|
|
|
|
|
|
|
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
|
|
|
|
|
|
|
|
if abs(num) < 1024.0:
|
|
|
|
|
|
|
|
return "%3.1f%s%s" % (num, unit, suffix)
|
|
|
|
|
|
|
|
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):
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|