|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
from peewee import *
|
|
|
|
|
from os import path
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
from PIL import Image
|
|
|
|
|
from suchwow import config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -21,6 +23,28 @@ class Post(Model):
|
|
|
|
|
to_discord = BooleanField(default=False)
|
|
|
|
|
approved = BooleanField(default=False)
|
|
|
|
|
|
|
|
|
|
def get_image_path(self, thumbnail=False):
|
|
|
|
|
save_path_base = path.join(config.DATA_FOLDER, "uploads")
|
|
|
|
|
if thumbnail:
|
|
|
|
|
save_path = path.join(save_path_base, self.get_thumbnail_name())
|
|
|
|
|
else:
|
|
|
|
|
save_path = path.join(save_path_base, self.image_name)
|
|
|
|
|
return save_path
|
|
|
|
|
|
|
|
|
|
def save_thumbnail(self):
|
|
|
|
|
try:
|
|
|
|
|
image = Image.open(self.get_image_path())
|
|
|
|
|
image.thumbnail((200,200), Image.ANTIALIAS)
|
|
|
|
|
image.save(self.get_image_path(True), format=image.format, quality=90)
|
|
|
|
|
image.close()
|
|
|
|
|
return True
|
|
|
|
|
except:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def get_thumbnail_name(self):
|
|
|
|
|
s = path.splitext(self.image_name)
|
|
|
|
|
return s[0] + '.thumbnail' + s[1]
|
|
|
|
|
|
|
|
|
|
def show(self):
|
|
|
|
|
return {
|
|
|
|
|
'id': self.id,
|
|
|
|
@ -28,6 +52,9 @@ class Post(Model):
|
|
|
|
|
'text': self.text,
|
|
|
|
|
'submitter': self.submitter,
|
|
|
|
|
'image_name': self.image_name,
|
|
|
|
|
'image_path': self.get_image_path(),
|
|
|
|
|
'thumbnail_name': self.get_thumbnail_name(),
|
|
|
|
|
'thumbnail_path': self.get_image_path(True),
|
|
|
|
|
'readonly': self.readonly,
|
|
|
|
|
'hidden': self.hidden,
|
|
|
|
|
'account_index': self.account_index,
|
|
|
|
|