tidy ups to #289

This commit is contained in:
rimu 2024-08-12 20:23:26 +12:00
parent a06152cf55
commit 935337cbd0
7 changed files with 20 additions and 18 deletions

View file

@ -106,10 +106,8 @@ def create_app(config_class=Config):
from app.tag import bp as tag_bp from app.tag import bp as tag_bp
app.register_blueprint(tag_bp) app.register_blueprint(tag_bp)
# make the dev tools page available if in dev mode from app.dev import bp as dev_bp
if app.config['MODE'] == 'development': app.register_blueprint(dev_bp)
from app.dev import bp as dev_bp
app.register_blueprint(dev_bp)
# send error reports via email # send error reports via email
if app.config['MAIL_SERVER'] and app.config['MAIL_ERRORS']: if app.config['MAIL_SERVER'] and app.config['MAIL_ERRORS']:

View file

@ -1,5 +1,5 @@
import random import random
from flask import request, flash, url_for, current_app, redirect, g from flask import request, flash, url_for, current_app, redirect, g, abort
from flask_login import login_required, current_user from flask_login import login_required, current_user
from flask_babel import _ from flask_babel import _
@ -8,6 +8,7 @@ from app.activitypub.signature import RsaKeys
from app.admin.routes import unsubscribe_everyone_then_delete from app.admin.routes import unsubscribe_everyone_then_delete
from app.dev import bp from app.dev import bp
from app.dev.forms import AddTestCommunities, AddTestTopics, DeleteTestCommunities, DeleteTestTopics from app.dev.forms import AddTestCommunities, AddTestTopics, DeleteTestCommunities, DeleteTestTopics
from app.inoculation import inoculation
from app.models import Site, User, Community, CommunityMember, Language, Topic, utcnow from app.models import Site, User, Community, CommunityMember, Language, Topic, utcnow
from app.utils import render_template, community_membership, moderating_communities, joined_communities, menu_topics, markdown_to_html from app.utils import render_template, community_membership, moderating_communities, joined_communities, menu_topics, markdown_to_html
@ -16,6 +17,8 @@ from app.utils import render_template, community_membership, moderating_communit
@bp.route('/dev/tools', methods=['GET', 'POST']) @bp.route('/dev/tools', methods=['GET', 'POST'])
@login_required @login_required
def tools(): def tools():
if not current_app.debug:
abort(404)
communities_form = AddTestCommunities() communities_form = AddTestCommunities()
topics_form = AddTestTopics() topics_form = AddTestTopics()
delete_communities_form = DeleteTestCommunities() delete_communities_form = DeleteTestCommunities()
@ -177,7 +180,12 @@ def tools():
else: else:
return render_template('dev/tools.html', return render_template('dev/tools.html',
communities_form=communities_form, communities_form=communities_form,
topics_form=topics_form, topics_form=topics_form,
delete_communities_form=delete_communities_form, delete_communities_form=delete_communities_form,
delete_topics_form=delete_topics_form) delete_topics_form=delete_topics_form,
moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id()),
menu_topics=menu_topics(), site=g.site,
inoculation=inoculation[random.randint(0, len(inoculation) - 1)] if g.site.show_inoculation_block else None
)

View file

@ -15,7 +15,7 @@
<a href="{{ url_for('admin.newsletter') }}">{{ _('Newsletter') }}</a> | <a href="{{ url_for('admin.newsletter') }}">{{ _('Newsletter') }}</a> |
<a href="{{ url_for('admin.admin_permissions') }}">{{ _('Permissions') }}</a> | <a href="{{ url_for('admin.admin_permissions') }}">{{ _('Permissions') }}</a> |
<a href="{{ url_for('admin.admin_activities') }}">{{ _('Activities') }}</a> <a href="{{ url_for('admin.admin_activities') }}">{{ _('Activities') }}</a>
{% if current_mode == 'development' %} {% if debug_mode %}
| <a href="{{ url_for('dev.tools') }}">{{ _('Dev Tools') }}</a> | <a href="{{ url_for('dev.tools') }}">{{ _('Dev Tools') }}</a>
{% endif%} {% endif%}
</nav> </nav>

View file

@ -211,7 +211,7 @@
<li><a class="dropdown-item{{ ' active' if active_child == 'admin_newsletter' }}" href="{{ url_for('admin.newsletter') }}">{{ _('Newsletter') }}</a></li> <li><a class="dropdown-item{{ ' active' if active_child == 'admin_newsletter' }}" href="{{ url_for('admin.newsletter') }}">{{ _('Newsletter') }}</a></li>
<li><a class="dropdown-item{{ ' active' if active_child == 'admin_activities' }}" href="{{ url_for('admin.admin_activities') }}">{{ _('Activities') }}</a></li> <li><a class="dropdown-item{{ ' active' if active_child == 'admin_activities' }}" href="{{ url_for('admin.admin_activities') }}">{{ _('Activities') }}</a></li>
<li><a class="dropdown-item{{ ' active' if active_child == 'admin_permissions' }}" href="{{ url_for('admin.admin_permissions') }}">{{ _('Permissions') }}</a></li> <li><a class="dropdown-item{{ ' active' if active_child == 'admin_permissions' }}" href="{{ url_for('admin.admin_permissions') }}">{{ _('Permissions') }}</a></li>
{% if current_mode == 'development' %} {% if debug_mode %}
<li><a class="dropdown-item{{ ' active' if active_child == 'dev_tools' }}" href="{{ url_for('dev.tools') }}">{{ _('Dev Tools') }}</a></li> <li><a class="dropdown-item{{ ' active' if active_child == 'dev_tools' }}" href="{{ url_for('dev.tools') }}">{{ _('Dev Tools') }}</a></li>
{% endif %} {% endif %}
</ul> </ul>

View file

@ -7,6 +7,8 @@
{% set active_child = 'dev_tools' %} {% set active_child = 'dev_tools' %}
{% block app_content %} {% block app_content %}
<h1>{{ _('Dev Tools') }}</h1>
<p>{{ _('Use these buttons to quickly generate some testing topics and communities to use during development.') }}</p>
<div class="row"> <div class="row">
<div class="col col-login mx-auto"> <div class="col col-login mx-auto">
<div class="card mt-5"> <div class="card mt-5">

View file

@ -34,7 +34,6 @@ import re
from moviepy.editor import VideoFileClip from moviepy.editor import VideoFileClip
from PIL import Image, ImageOps from PIL import Image, ImageOps
from app.email import send_welcome_email
from app.models import Settings, Domain, Instance, BannedInstances, User, Community, DomainBlock, ActivityPubLog, IpBan, \ from app.models import Settings, Domain, Instance, BannedInstances, User, Community, DomainBlock, ActivityPubLog, IpBan, \
Site, Post, PostReply, utcnow, Filter, CommunityMember, InstanceBlock, CommunityBan, Topic, UserBlock, Language, \ Site, Post, PostReply, utcnow, Filter, CommunityMember, InstanceBlock, CommunityBan, Topic, UserBlock, Language, \
File, ModLog File, ModLog
@ -42,11 +41,6 @@ from app.models import Settings, Domain, Instance, BannedInstances, User, Commun
# Flask's render_template function, with support for themes added # Flask's render_template function, with support for themes added
def render_template(template_name: str, **context) -> Response: def render_template(template_name: str, **context) -> Response:
# add current_mode to context
# if mode is 'development' this will enable the dev tools link in the admin drop down
current_mode = current_app.config['MODE']
context['current_mode'] = current_mode
theme = current_theme() theme = current_theme()
if theme != '' and os.path.exists(f'app/templates/themes/{theme}/{template_name}'): if theme != '' and os.path.exists(f'app/templates/themes/{theme}/{template_name}'):
content = flask.render_template(f'themes/{theme}/{template_name}', **context) content = flask.render_template(f'themes/{theme}/{template_name}', **context)

View file

@ -23,7 +23,7 @@ cli.register(app)
def app_context_processor(): def app_context_processor():
def getmtime(filename): def getmtime(filename):
return os.path.getmtime('app/static/' + filename) return os.path.getmtime('app/static/' + filename)
return dict(getmtime=getmtime, instance_domain=current_app.config['SERVER_NAME'], return dict(getmtime=getmtime, instance_domain=current_app.config['SERVER_NAME'], debug_mode=current_app.debug,
POST_TYPE_LINK=POST_TYPE_LINK, POST_TYPE_IMAGE=POST_TYPE_IMAGE, POST_TYPE_LINK=POST_TYPE_LINK, POST_TYPE_IMAGE=POST_TYPE_IMAGE,
POST_TYPE_ARTICLE=POST_TYPE_ARTICLE, POST_TYPE_VIDEO=POST_TYPE_VIDEO, POST_TYPE_POLL=POST_TYPE_POLL, POST_TYPE_ARTICLE=POST_TYPE_ARTICLE, POST_TYPE_VIDEO=POST_TYPE_VIDEO, POST_TYPE_POLL=POST_TYPE_POLL,
SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER,