From ddc747bb76568eee53f1bc023c8b13c311d5f6e0 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Wed, 29 Nov 2023 22:12:55 +1300 Subject: [PATCH] list content by domain --- app/__init__.py | 3 +++ app/community/routes.py | 2 +- app/domain/__init__.py | 5 +++++ app/domain/routes.py | 35 +++++++++++++++++++++++++++++++ app/templates/domain/domain.html | 32 ++++++++++++++++++++++++++++ app/templates/domain/domains.html | 33 +++++++++++++++++++++++++++++ 6 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 app/domain/__init__.py create mode 100644 app/domain/routes.py create mode 100644 app/templates/domain/domain.html create mode 100644 app/templates/domain/domains.html diff --git a/app/__init__.py b/app/__init__.py index d28a7f4e..19687551 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -65,6 +65,9 @@ def create_app(config_class=Config): from app.user import bp as user_bp app.register_blueprint(user_bp) + from app.domain import bp as domain_bp + app.register_blueprint(domain_bp) + def get_resource_as_string(name, charset='utf-8'): with app.open_resource(name) as f: return f.read().decode(charset) diff --git a/app/community/routes.py b/app/community/routes.py index 0d36b40a..2b225a60 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -92,7 +92,7 @@ def show_community(community: Community): if current_user.is_anonymous or current_user.ignore_bots: posts = community.posts.filter(Post.from_bot == False).order_by(desc(Post.last_active)).all() else: - posts = community.posts.order_by(desc(Post.last_active)) + posts = community.posts.order_by(desc(Post.last_active)).all() description = shorten_string(community.description, 150) if community.description else None og_image = community.image.source_url if community.image_id else None diff --git a/app/domain/__init__.py b/app/domain/__init__.py new file mode 100644 index 00000000..043d6b0a --- /dev/null +++ b/app/domain/__init__.py @@ -0,0 +1,5 @@ +from flask import Blueprint + +bp = Blueprint('domain', __name__) + +from app.domain import routes diff --git a/app/domain/routes.py b/app/domain/routes.py new file mode 100644 index 00000000..d19b2fe2 --- /dev/null +++ b/app/domain/routes.py @@ -0,0 +1,35 @@ +from flask import redirect, url_for, flash, request, make_response, session, Markup, current_app, abort +from flask_login import login_user, logout_user, current_user, login_required +from flask_babel import _ + +from app import db, constants +from app.models import Post, Domain +from app.domain import bp +from app.utils import get_setting, render_template +from sqlalchemy import desc + + +@bp.route('/d/', methods=['GET']) +def show_domain(domain_id): + if '.' in domain_id: + domain = Domain.query.filter_by(name=domain_id, banned=False).first() + else: + domain = Domain.query.get_or_404(domain_id) + if domain.banned: + domain = None + if domain: + if current_user.is_anonymous or current_user.ignore_bots: + posts = Post.query.filter(Post.from_bot == False, Post.domain_id == domain.id).order_by(desc(Post.last_active)).all() + else: + posts = Post.query.filter(Post.domain_id == domain.id).order_by(desc(Post.last_active)).all() + return render_template('domain/domain.html', domain=domain, title=domain.name, posts=posts, + POST_TYPE_IMAGE=constants.POST_TYPE_IMAGE, POST_TYPE_LINK=constants.POST_TYPE_LINK) + else: + abort(404) + + +@bp.route('/domains', methods=['GET']) +def domains(): + domains = Domain.query.filter_by(banned=False).order_by(Domain.name).all() + + return render_template('domain/domains.html', title='All known domains', domains=domains) \ No newline at end of file diff --git a/app/templates/domain/domain.html b/app/templates/domain/domain.html new file mode 100644 index 00000000..e50a2f74 --- /dev/null +++ b/app/templates/domain/domain.html @@ -0,0 +1,32 @@ +{% extends "base.html" %} +{% from 'bootstrap/form.html' import render_form %} + +{% block app_content %} +
+
+ +

{{ domain.name }}

+
+ {% for post in posts %} + {% include 'community/_post_teaser.html' %} + {% else %} +

{{ _('No posts in this domain yet.') }}

+ {% endfor %} +
+
+ +
+ +
+
+
+ + +
+{% endblock %} diff --git a/app/templates/domain/domains.html b/app/templates/domain/domains.html new file mode 100644 index 00000000..763cdb73 --- /dev/null +++ b/app/templates/domain/domains.html @@ -0,0 +1,33 @@ +{% extends "base.html" %} +{% from 'bootstrap/form.html' import render_form %} + +{% block app_content %} +
+
+ +

{{ _('All known domains') }}

+
+ +
+
+ +
+ +
+
+
+ + +
+{% endblock %}