diff --git a/app/auth/forms.py b/app/auth/forms.py index dcf98f65..be665bcd 100644 --- a/app/auth/forms.py +++ b/app/auth/forms.py @@ -1,5 +1,5 @@ from flask_wtf import FlaskForm, RecaptchaField -from wtforms import StringField, PasswordField, SubmitField, HiddenField +from wtforms import StringField, PasswordField, SubmitField, HiddenField, BooleanField from wtforms.validators import ValidationError, DataRequired, Email, EqualTo, Length from flask_babel import _, lazy_gettext as _l from app.models import User, Community @@ -8,6 +8,7 @@ from app.models import User, Community class LoginForm(FlaskForm): user_name = StringField(_l('User name'), validators=[DataRequired()]) password = PasswordField(_l('Password'), validators=[DataRequired()]) + low_bandwidth_mode = BooleanField(_l('Low bandwidth mode')) submit = SubmitField(_l('Log In')) diff --git a/app/auth/routes.py b/app/auth/routes.py index 40820307..46a987fc 100644 --- a/app/auth/routes.py +++ b/app/auth/routes.py @@ -62,14 +62,21 @@ def login(): next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('main.index') - return redirect(next_page) + response = make_response(redirect(next_page)) + if form.low_bandwidth_mode.data: + response.set_cookie('low_bandwidth', '1', expires=datetime(year=2099, month=12, day=30)) + else: + response.set_cookie('low_bandwidth', '0', expires=datetime(year=2099, month=12, day=30)) + return response return render_template('auth/login.html', title=_('Login'), form=form) @bp.route('/logout') def logout(): logout_user() - return redirect(url_for('main.index')) + response = make_response(redirect(url_for('main.index'))) + response.set_cookie('low_bandwidth', '0', expires=datetime(year=2099, month=12, day=30)) + return response @bp.route('/register', methods=['GET', 'POST']) diff --git a/app/community/routes.py b/app/community/routes.py index 973bf9df..fbf4815f 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -139,7 +139,7 @@ def show_community(community: Community): is_moderator=is_moderator, is_owner=is_owner, is_admin=is_admin, mods=mod_list, posts=posts, description=description, og_image=og_image, POST_TYPE_IMAGE=POST_TYPE_IMAGE, POST_TYPE_LINK=POST_TYPE_LINK, SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, etag=f"{community.id}_{hash(community.last_active)}", - next_url=next_url, prev_url=prev_url, + next_url=next_url, prev_url=prev_url, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1', rss_feed=f"https://{current_app.config['SERVER_NAME']}/community/{community.link()}/feed", rss_feed_name=f"{community.title} posts on PieFed") @@ -423,7 +423,7 @@ def add_post(actor): form.notify_author.data = True return render_template('community/add_post.html', title=_('Add post to community'), form=form, community=community, - images_disabled=images_disabled, markdown_editor=True) + images_disabled=images_disabled, markdown_editor=True, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1') @bp.route('/community//report', methods=['GET', 'POST']) diff --git a/app/main/routes.py b/app/main/routes.py index d138f80b..31024d0c 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -53,7 +53,7 @@ def index(): active_communities = Community.query.filter_by(banned=False).order_by(desc(Community.last_active)).limit(5).all() return render_template('index.html', posts=posts, active_communities=active_communities, show_post_community=True, - POST_TYPE_IMAGE=POST_TYPE_IMAGE, POST_TYPE_LINK=POST_TYPE_LINK, + POST_TYPE_IMAGE=POST_TYPE_IMAGE, POST_TYPE_LINK=POST_TYPE_LINK, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1', SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, etag=f"home_{hash(str(g.site.last_active))}", next_url=next_url, prev_url=prev_url, rss_feed=f"https://{current_app.config['SERVER_NAME']}/feed", rss_feed_name=f"Posts on " + g.site.name, @@ -93,7 +93,7 @@ def new_posts(): SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, etag=f"home_{hash(str(g.site.last_active))}", next_url=next_url, prev_url=prev_url, rss_feed=f"https://{current_app.config['SERVER_NAME']}/feed", - rss_feed_name=f"Posts on " + g.site.name) + rss_feed_name=f"Posts on " + g.site.name, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1') @bp.route('/top', methods=['HEAD', 'GET', 'POST']) @@ -129,7 +129,7 @@ def top_posts(): SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, etag=f"home_{hash(str(g.site.last_active))}", next_url=next_url, prev_url=prev_url, rss_feed=f"https://{current_app.config['SERVER_NAME']}/feed", - rss_feed_name=f"Posts on " + g.site.name) + rss_feed_name=f"Posts on " + g.site.name, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1') @bp.route('/communities', methods=['GET']) @@ -153,7 +153,8 @@ def list_communities(): return render_template('list_communities.html', communities=communities.order_by(sort_by).all(), search=search_param, title=_('Communities'), SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, - SUBSCRIPTION_OWNER=SUBSCRIPTION_OWNER, topics=topics, topic_id=topic_id, sort_by=sort_by) + SUBSCRIPTION_OWNER=SUBSCRIPTION_OWNER, topics=topics, topic_id=topic_id, sort_by=sort_by, + low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1') @bp.route('/communities/local', methods=['GET']) @@ -162,7 +163,8 @@ def list_local_communities(): sort_by = text('community.' + request.args.get('sort_by') if request.args.get('sort_by') else 'community.post_reply_count desc') communities = Community.query.filter_by(ap_id=None, banned=False) return render_template('list_communities.html', communities=communities.order_by(sort_by).all(), title=_('Local communities'), sort_by=sort_by, - SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER) + SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, + low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1') @bp.route('/communities/subscribed', methods=['GET']) @@ -174,7 +176,8 @@ def list_subscribed_communities(): else: communities = [] return render_template('list_communities.html', communities=communities.order_by(sort_by).all(), title=_('Joined communities'), - SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, sort_by=sort_by) + SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, sort_by=sort_by, + low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1') @bp.route('/donate') diff --git a/app/post/routes.py b/app/post/routes.py index 60535c26..5d743d2d 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -177,7 +177,8 @@ def show_post(post_id: int): canonical=post.ap_id, form=form, replies=replies, THREAD_CUTOFF_DEPTH=constants.THREAD_CUTOFF_DEPTH, description=description, og_image=og_image, POST_TYPE_IMAGE=constants.POST_TYPE_IMAGE, POST_TYPE_LINK=constants.POST_TYPE_LINK, POST_TYPE_ARTICLE=constants.POST_TYPE_ARTICLE, - etag=f"{post.id}_{hash(post.last_active)}", markdown_editor=True) + etag=f"{post.id}_{hash(post.last_active)}", markdown_editor=True, + low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1') @bp.route('/post//', methods=['GET', 'POST']) diff --git a/app/static/structure.css b/app/static/structure.css index 226e4941..316db34a 100644 --- a/app/static/structure.css +++ b/app/static/structure.css @@ -496,6 +496,11 @@ fieldset legend { height: auto; } +.form-check .form-check-input { + position: relative; + top: 4px; +} + .post_reply_form label { display: none; } diff --git a/app/static/structure.scss b/app/static/structure.scss index fe7e10a4..769e8094 100644 --- a/app/static/structure.scss +++ b/app/static/structure.scss @@ -127,6 +127,11 @@ nav, etc which are used site-wide */ } } +.form-check .form-check-input { + position: relative; + top: 4px; +} + .post_reply_form { label { display: none; diff --git a/app/templates/base.html b/app/templates/base.html index 51542d4d..79975c77 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -3,7 +3,7 @@ {% if user.deleted %} [deleted] {% else %} - {% if user.avatar_id %} + {% if user.avatar_id and not low_bandwidth %} Avatar {% endif %} @@ -73,8 +73,7 @@ {% block navbar %}