forked from rDrama/rDrama
1
0
Fork 0

fix bug with drafts + dont give effortpost notifs to jannies if post doesnt meet requirements

master
Aevann 2024-06-13 22:57:02 +03:00
parent dfdaef6b26
commit 2b46f5c819
5 changed files with 35 additions and 21 deletions

View File

@ -2,6 +2,7 @@ import random
import time
from urllib.parse import urlparse
from flask import g
from bs4 import BeautifulSoup
from sqlalchemy import Column, FetchedValue, ForeignKey
from sqlalchemy.orm import deferred, relationship
@ -432,3 +433,27 @@ class Post(Base):
return v.admin_level >= PERMS['POST_COMMENT_MODERATION']
else:
return v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (v.mods_hole(self.hole)) or self.author_id == v.id
@property
@lazy
def can_be_effortpost(self):
if SITE_NAME == 'WPD':
min_chars = 2000
min_lines = 10
else:
min_chars = 3000
min_lines = 20
if self.body_html.count('<p>') < min_lines:
return False
soup = BeautifulSoup(self.body_html, 'lxml')
tags = soup.html.body.find_all(lambda tag: tag.name in {'p','ul','table'} and tag.text, recursive=False)
post_char_count = 0
for tag in tags:
post_char_count += len(tag.text)
if post_char_count < min_chars:
return False
return True

View File

@ -2043,25 +2043,9 @@ def mark_effortpost(pid, v):
if p.effortpost:
abort(400, "Post is already marked as an effortpost!")
if SITE_NAME == 'WPD':
min_chars = 2000
min_lines = 10
else:
min_chars = 3000
min_lines = 20
if p.body_html.count('<p>') < min_lines:
if not p.can_be_effortpost:
abort(403, "Post is too short!")
soup = BeautifulSoup(p.body_html, 'lxml')
tags = soup.html.body.find_all(lambda tag: tag.name in {'p','ul','table'} and tag.text, recursive=False)
post_char_count = 0
for tag in tags:
post_char_count += len(tag.text)
if post_char_count < min_chars:
abort(403, "Post is too short.")
p.effortpost = True
g.db.add(p)

View File

@ -92,9 +92,11 @@ def publish(pid, v):
execute_snappy(p, v)
if p.effortpost and not (SITE_NAME == 'WPD' and v.truescore < 500):
if p.effortpost and not (SITE_NAME == 'WPD' and v.truescore < 500) and p.can_be_effortpost:
body = f"@{v.username} has requested that {p.textlink} be marked as an effortpost!"
alert_admins(body)
p.effortpost = False
return {"message": "Post has been published successfully!"}
@ -736,10 +738,13 @@ def submit_post(v, hole=None):
generate_thumb = (not p.thumburl and p.url and p.domain != SITE)
gevent.spawn(postprocess_post, p.url, p.body, p.body_html, p.id, generate_thumb, False)
if not p.draft and flag_effortpost and not (SITE_NAME == 'WPD' and v.truescore < 500):
if not p.draft and flag_effortpost and not (SITE_NAME == 'WPD' and v.truescore < 500) and p.can_be_effortpost:
body = f"@{v.username} has requested that {p.textlink} be marked as an effortpost!"
alert_admins(body)
if p.draft and flag_effortpost and not (SITE_NAME == 'WPD' and v.truescore < 500):
p.effortpost = True
if v.client: return p.json
else:
p.voted = 1

View File

@ -96,7 +96,7 @@
<span class="post-flair bg-danger font-weight-bolder mr-1">CHILD WARNING</span>
{% endif %}
{% if p.effortpost %}
{% if p.effortpost and not p.draft %}
<a href="/?effortposts_only=True" class="post-flair effortpost-flair font-weight-bolder mr-1">EFFORTPOST</a>
{% endif %}

View File

@ -95,7 +95,7 @@
<span class="post-flair bg-danger font-weight-bolder mr-1">CHILD WARNING</span>
{% endif %}
{% if p.effortpost %}
{% if p.effortpost and not p.draft %}
<a href="/?effortposts_only=True" class="post-flair effortpost-flair font-weight-bolder mr-1">EFFORTPOST</a>
{% endif %}