Now you can upload pics even after the deadline
This commit is contained in:
parent
db97fe0e7e
commit
86ceed6a93
2
ext.py
2
ext.py
|
@ -75,6 +75,8 @@ class Order:
|
||||||
self.is_fursuiter = True if self.ans('is_fursuiter') != 'No' else False
|
self.is_fursuiter = True if self.ans('is_fursuiter') != 'No' else False
|
||||||
self.is_allergic = True if self.ans('is_allergic') != 'No' else False
|
self.is_allergic = True if self.ans('is_allergic') != 'No' else False
|
||||||
self.propic_locked = self.ans('propic_locked')
|
self.propic_locked = self.ans('propic_locked')
|
||||||
|
self.propic_fursuiter = self.ans('propic_fursuiter')
|
||||||
|
self.propic = self.ans('propic')
|
||||||
self.carpooling_message = json.loads(self.ans('carpooling_message')) if self.ans('carpooling_message') else {}
|
self.carpooling_message = json.loads(self.ans('carpooling_message')) if self.ans('carpooling_message') else {}
|
||||||
self.karaoke_songs = json.loads(self.ans('karaoke_songs')) if self.ans('karaoke_songs') else {}
|
self.karaoke_songs = json.loads(self.ans('karaoke_songs')) if self.ans('karaoke_songs') else {}
|
||||||
self.birth_date = self.ans('birth_date')
|
self.birth_date = self.ans('birth_date')
|
||||||
|
|
59
propic.py
59
propic.py
|
@ -19,46 +19,45 @@ async def upload_propic(request, order: Order):
|
||||||
if order.propic_locked:
|
if order.propic_locked:
|
||||||
raise exceptions.BadRequest("You have been limited from further editing the propic.")
|
raise exceptions.BadRequest("You have been limited from further editing the propic.")
|
||||||
|
|
||||||
if time() > PROPIC_DEADLINE:
|
if request.form.get('submit') != 'Upload' and time() > PROPIC_DEADLINE:
|
||||||
raise exceptions.BadRequest("You are beyond the file upload deadline. No more changes are allowed.")
|
raise exceptions.BadRequest("The deadline has passed. You cannot modify the badges at this moment.")
|
||||||
|
|
||||||
if request.form.get('submit') == 'Delete main image':
|
if request.form.get('submit') == 'Delete main image':
|
||||||
await order.edit_answer('propic', None)
|
await order.edit_answer('propic', None)
|
||||||
|
elif request.form.get('submit') == 'Delete fursuit image':
|
||||||
if request.form.get('submit') == 'Delete fursuit image':
|
|
||||||
await order.edit_answer('propic_fursuiter', None)
|
await order.edit_answer('propic_fursuiter', None)
|
||||||
|
else:
|
||||||
|
for fn, body in request.files.items():
|
||||||
|
if fn not in ['propic', 'propic_fursuiter']:
|
||||||
|
continue
|
||||||
|
|
||||||
for fn, body in request.files.items():
|
if not body[0].body: continue
|
||||||
if fn not in ['propic', 'propic_fursuiter']:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not body[0].body: continue
|
h = sha224(body[0].body).hexdigest()[:32]
|
||||||
|
|
||||||
h = sha224(body[0].body).hexdigest()[:32]
|
try:
|
||||||
|
img = Image.open(BytesIO(body[0].body))
|
||||||
|
|
||||||
try:
|
with open(f"res/propic/{fn}_{order.code}_original", "wb") as f:
|
||||||
img = Image.open(BytesIO(body[0].body))
|
f.write(body[0].body)
|
||||||
|
|
||||||
with open(f"res/propic/{fn}_{order.code}_original", "wb") as f:
|
width, height = img.size
|
||||||
f.write(body[0].body)
|
aspect_ratio = width/height
|
||||||
|
if aspect_ratio > 1:
|
||||||
|
crop_amount = (width - height) / 2
|
||||||
|
img = img.crop((crop_amount, 0, width - crop_amount, height))
|
||||||
|
elif aspect_ratio < 1:
|
||||||
|
crop_amount = (height - width) / 2
|
||||||
|
img = img.crop((0, crop_amount, width, height - crop_amount))
|
||||||
|
|
||||||
width, height = img.size
|
img = img.convert('RGB')
|
||||||
aspect_ratio = width/height
|
img.thumbnail((512,512))
|
||||||
if aspect_ratio > 1:
|
img.save(f"res/propic/{fn}_{order.code}_{h}.jpg")
|
||||||
crop_amount = (width - height) / 2
|
except:
|
||||||
img = img.crop((crop_amount, 0, width - crop_amount, height))
|
raise exceptions.BadRequest("The image you uploaded is not valid.")
|
||||||
elif aspect_ratio < 1:
|
else:
|
||||||
crop_amount = (height - width) / 2
|
await order.edit_answer(fn, f"{fn}_{order.code}_{h}.jpg")
|
||||||
img = img.crop((0, crop_amount, width, height - crop_amount))
|
|
||||||
|
|
||||||
img = img.convert('RGB')
|
await order.send_answers()
|
||||||
img.thumbnail((512,512))
|
|
||||||
img.save(f"res/propic/{fn}_{order.code}_{h}.jpg")
|
|
||||||
except:
|
|
||||||
raise exceptions.BadRequest("The image you uploaded is not valid.")
|
|
||||||
else:
|
|
||||||
await order.edit_answer(fn, f"{fn}_{order.code}_{h}.jpg")
|
|
||||||
|
|
||||||
await order.send_answers()
|
|
||||||
|
|
||||||
return redirect("/manage/welcome#badge")
|
return redirect("/manage/welcome#badge")
|
||||||
|
|
Loading…
Reference in New Issue