list content by domain

This commit is contained in:
rimu 2023-11-29 22:12:55 +13:00
parent e97f3ee4ab
commit ddc747bb76
6 changed files with 109 additions and 1 deletions

View file

@ -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)

View file

@ -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

5
app/domain/__init__.py Normal file
View file

@ -0,0 +1,5 @@
from flask import Blueprint
bp = Blueprint('domain', __name__)
from app.domain import routes

35
app/domain/routes.py Normal file
View file

@ -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/<domain_id>', 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)

View file

@ -0,0 +1,32 @@
{% extends "base.html" %}
{% from 'bootstrap/form.html' import render_form %}
{% block app_content %}
<div class="row">
<div class="col-12 col-md-8 position-relative main_pane">
<nav aria-label="breadcrumb" id="breadcrumb_nav" title="Navigation">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">{{ _('Home') }}</a></li>
<li class="breadcrumb-item"><a href="/domains">{{ _('Domains') }}</a></li>
<li class="breadcrumb-item active">{{ domain.name|shorten }}</li>
</ol>
</nav>
<h1 class="mt-2">{{ domain.name }}</h1>
<div class="post_list">
{% for post in posts %}
{% include 'community/_post_teaser.html' %}
{% else %}
<p>{{ _('No posts in this domain yet.') }}</p>
{% endfor %}
</div>
</div>
<div class="col-12 col-md-4">
</div>
</div>
<div class="row">
</div>
{% endblock %}

View file

@ -0,0 +1,33 @@
{% extends "base.html" %}
{% from 'bootstrap/form.html' import render_form %}
{% block app_content %}
<div class="row">
<div class="col-12 col-md-8 position-relative main_pane">
<nav aria-label="breadcrumb" id="breadcrumb_nav" title="Navigation">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">{{ _('Home') }}</a></li>
<li class="breadcrumb-item active">Domains</li>
</ol>
</nav>
<h1 class="mt-2">{{ _('All known domains') }}</h1>
<div class="post_list">
<ul>
{% for domain in domains %}
<li>
<a href="{{ url_for('domain.show_domain', domain_id=domain.id) }}">{{ domain.name }}</a>
</li>
{% endfor %}
</ul>
</div>
</div>
<div class="col-12 col-md-4">
</div>
</div>
<div class="row">
</div>
{% endblock %}