Adding a Suggest Topics page

This commit is contained in:
Alan Roberts 2024-08-06 16:25:27 -04:00
parent 5b8d4642ca
commit 99e3ff0391
5 changed files with 81 additions and 1 deletions

View file

@ -34,4 +34,5 @@
<p>{{ _('There are no communities yet.') }}</p>
{% endif -%}
<p><a href="/communities" class="btn btn-primary">{{ _('Explore communities') }}</a></p>
<p><a href="/suggest_topics" class="btn btn-primary">{{ _('Suggest A Topic') }}</a></p>
{% endblock -%}

View file

@ -0,0 +1,22 @@
{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %}
{% extends 'themes/' + theme() + '/base.html' %}
{% else %}
{% extends "base.html" %}
{% endif %} %}
{% set active_child = 'suggest_topics' %}
{% from 'bootstrap/form.html' import render_form %}
{% block app_content %}
<div class="row">
<div class="col col-login mx-auto">
<div class="card mt-5">
<div class="card-body p-6">
<div class="card-title">{{ _('Suggest a topic!') }}</div>
<div class="card-body">
{{ render_form(form) }}
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,22 @@
{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %}
{% extends 'themes/' + theme() + '/base.html' %}
{% else %}
{% extends "base.html" %}
{% endif %} %}
{% from 'bootstrap/form.html' import render_form %}
{% set active_child = 'suggest_topics' %}
{% block app_content %}
<div class="row">
<div class="col col-login mx-auto">
<div class="card mt-5">
<div class="card-body p-6">
<div class="card-title">{{ _('Sorry') }}</div>
<div class="card-body">
<p>{{ _('You have not been using PieFed long enough to be allowed to suggest Topics.') }}</p>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View file

@ -12,3 +12,8 @@ from app import db
class ChooseTopicsForm(FlaskForm):
chosen_topics = MultiCheckboxField(_l('Choose some topics you are interested in'), coerce=int)
submit = SubmitField(_l('Choose'))
class SuggestTopicsForm(FlaskForm):
topic_name = TextAreaField(_l('New Topic Name'), validators=[DataRequired(), Length(min=1, max=100)], render_kw={'placeholder': 'Type a reply here...'})
communities_for_topic = TextAreaField(_l('Suggested Communities'), validators=[DataRequired(), Length(min=1, max=5000)], render_kw={'placeholder': 'Comma seperated list of community suggestions'})
submit = SubmitField(_l('Submit'))

View file

@ -15,8 +15,9 @@ from app.inoculation import inoculation
from app.models import Topic, Community, Post, utcnow, CommunityMember, CommunityJoinRequest, User, \
NotificationSubscription
from app.topic import bp
from app.email import send_email
from app import db, celery, cache
from app.topic.forms import ChooseTopicsForm
from app.topic.forms import ChooseTopicsForm, SuggestTopicsForm
from app.utils import render_template, user_filters_posts, moderating_communities, joined_communities, \
community_membership, blocked_domains, validation_required, mimetype_from_url, blocked_instances, \
communities_banned_from, blocked_users, menu_topics
@ -236,6 +237,35 @@ def topic_notification(topic_id: int):
return render_template('topic/_notification_toggle.html', topic=topic)
@bp.route('/suggest-topics', methods=['GET', 'POST'])
@login_required
def suggest_topics():
form = SuggestTopicsForm()
if current_user.created_recently() or current_user.reputation <= -10 or current_user.banned or not current_user.verified:
return redirect(url_for('topic.suggestion_denied'))
if form.validate_on_submit():
sub = f'New Topic Suggestion from {g.site.name}'
send = f'{g.site.name} <{current_app.config["MAIL_FROM"]}>'
recip = g.site.contact_email
tn = form.topic_name.data
cft = form.communities_for_topic.data
text_body = f'{current_user.user_name} suggested the new Topic "{tn}", containing the communities: {cft}'
html_body = f'<p>{current_user.user_name} suggested the new Topic "{tn}", containing the communities: {cft}</p>'
send_email(sub, send, recip, text_body=text_body, html_body=html_body)
flash(_(f'Thank you for the Topic Suggestion! Your suggestion has been sent to the site administrator(s)'))
return redirect(url_for('main.list_topics'))
else:
return render_template('topic/suggest_topics.html', form=form, title=_('Suggest A Topic!"'),
moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id()),
menu_topics=menu_topics(),
site=g.site)
@bp.route('/topic/suggestion-denied', methods=['GET'])
@login_required
def suggestion_denied():
return render_template('topic/suggestion_denied.html')
def topics_for_form():
topics = Topic.query.filter_by(parent_id=None).order_by(Topic.name).all()