diff --git a/app/email.py b/app/email.py index 7ff7b5d1..c4d3a156 100644 --- a/app/email.py +++ b/app/email.py @@ -39,6 +39,18 @@ def send_welcome_email(user, application_required): html_body=render_template('email/welcome.html', user=user, application_required=application_required)) +def send_topic_suggestion(communities_for_topic, user, recipients, subject, topic_name): + send_email(subject, + sender=f'{g.site.name} <{current_app.config["MAIL_FROM"]}>', + recipients=recipients, + text_body=render_template('email/suggested_topic.txt', site_name=g.site.name, + current_user_name=user.user_name, topic_name=topic_name, + communities_for_topic=communities_for_topic), + html_body=render_template('email/suggested_topic.html', site_name=g.site.name, + current_user_name=user.user_name, topic_name=topic_name, + communities_for_topic=communities_for_topic, + domain=current_app.config['SERVER_NAME'])) + @celery.task def send_async_email(subject, sender, recipients, text_body, html_body, reply_to): if 'ngrok.app' in sender: # for local development diff --git a/app/templates/list_topics.html b/app/templates/list_topics.html index 6954176b..ec070865 100644 --- a/app/templates/list_topics.html +++ b/app/templates/list_topics.html @@ -7,32 +7,34 @@ {% set active_child = 'list_topics' -%} {% block app_content -%} -{% if len(topics) > 0 -%} - {% macro render_topic(topic, depth) -%} -
  • - {% if depth == 0 -%}{% endif -%} - {{ topic['topic'].name }} - {% if depth == 0 -%}{% endif -%} - {% if topic['children'] -%} - + + {% else -%} +

    {{ _('There are no communities yet.') }}

    + {% endif -%} +

    {{ _('Explore communities') }}

    + {% if current_user.is_authenticated and current_user.trustworthy() -%} +

    {{ _('Suggest a topic') }}

    + {% endif -%} {% endblock -%} diff --git a/app/templates/topic/suggest_topics.html b/app/templates/topic/suggest_topics.html index ac3e54a4..c7262e8a 100644 --- a/app/templates/topic/suggest_topics.html +++ b/app/templates/topic/suggest_topics.html @@ -11,7 +11,7 @@
    -
    {{ _('Suggest a topic!') }}
    +
    {{ _('Suggest a topic') }}
    {{ render_form(form) }}
    diff --git a/app/topic/forms.py b/app/topic/forms.py index 72ba5633..c7620497 100644 --- a/app/topic/forms.py +++ b/app/topic/forms.py @@ -1,19 +1,18 @@ -from flask import request -from flask_login import current_user from flask_wtf import FlaskForm from wtforms import StringField, SubmitField, TextAreaField, BooleanField, HiddenField, SelectField, FileField from wtforms.validators import ValidationError, DataRequired, Email, EqualTo, Length, Optional from flask_babel import _, lazy_gettext as _l from app.utils import MultiCheckboxField -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': 'New Topic name here...'}) - communities_for_topic = TextAreaField(_l('Suggested Communities'), validators=[DataRequired(), Length(min=1, max=5000)], render_kw={'placeholder': 'Comma seperated list of community suggestions'}) + topic_name = TextAreaField(_l('New topic name'), validators=[DataRequired(), Length(min=1, max=100)], + render_kw={'placeholder': _l('New topic name here...')}) + communities_for_topic = TextAreaField(_l('Suggested communities'), validators=[Optional(), Length(max=5000)], + render_kw={'placeholder': _l('Comma seperated list of community suggestions')}) submit = SubmitField(_l('Submit')) diff --git a/app/topic/routes.py b/app/topic/routes.py index 7d215fb8..7017ba83 100644 --- a/app/topic/routes.py +++ b/app/topic/routes.py @@ -16,7 +16,7 @@ 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.email import send_email, send_topic_suggestion from app import db, celery, cache from app.topic.forms import ChooseTopicsForm, SuggestTopicsForm from app.utils import render_template, user_filters_posts, moderating_communities, joined_communities, \ @@ -238,38 +238,29 @@ def topic_notification(topic_id: int): return render_template('topic/_notification_toggle.html', topic=topic) -@bp.route('/suggest-topics', methods=['GET', 'POST']) + +@bp.route('/topics/new', 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: + if not current_user.trustworthy(): return redirect(url_for('topic.suggestion_denied')) if form.validate_on_submit(): - subject = f'New Topic Suggestion from {g.site.name}' - sender = f'{g.site.name} <{current_app.config["MAIL_FROM"]}>' + subject = f'New topic suggestion from {g.site.name}' recipients = g.site.contact_email topic_name = form.topic_name.data communities_for_topic = form.communities_for_topic.data - send_email(subject, - sender, - recipients, - text_body=flask_render_template('email/suggested_topic.txt', site_name=g.site.name, - current_user_name=current_user.user_name, topic_name=topic_name, - communities_for_topic=communities_for_topic), - html_body=flask_render_template('email/suggested_topic.html', site_name=g.site.name, - current_user_name=current_user.user_name, topic_name=topic_name, - communities_for_topic=communities_for_topic, - domain=current_app.config['SERVER_NAME']) - ) - flash(_(f'Thank you for the Topic Suggestion! Your suggestion has been sent to the site administrator(s)')) + send_topic_suggestion(communities_for_topic, current_user, recipients, subject, topic_name) + flash(_(f'Thank you for the topic suggestion, it 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!"'), + 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():