mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
list content by domain
This commit is contained in:
parent
e97f3ee4ab
commit
ddc747bb76
6 changed files with 109 additions and 1 deletions
|
@ -65,6 +65,9 @@ def create_app(config_class=Config):
|
||||||
from app.user import bp as user_bp
|
from app.user import bp as user_bp
|
||||||
app.register_blueprint(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'):
|
def get_resource_as_string(name, charset='utf-8'):
|
||||||
with app.open_resource(name) as f:
|
with app.open_resource(name) as f:
|
||||||
return f.read().decode(charset)
|
return f.read().decode(charset)
|
||||||
|
|
|
@ -92,7 +92,7 @@ def show_community(community: Community):
|
||||||
if current_user.is_anonymous or current_user.ignore_bots:
|
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()
|
posts = community.posts.filter(Post.from_bot == False).order_by(desc(Post.last_active)).all()
|
||||||
else:
|
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
|
description = shorten_string(community.description, 150) if community.description else None
|
||||||
og_image = community.image.source_url if community.image_id else None
|
og_image = community.image.source_url if community.image_id else None
|
||||||
|
|
5
app/domain/__init__.py
Normal file
5
app/domain/__init__.py
Normal 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
35
app/domain/routes.py
Normal 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)
|
32
app/templates/domain/domain.html
Normal file
32
app/templates/domain/domain.html
Normal 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 %}
|
33
app/templates/domain/domains.html
Normal file
33
app/templates/domain/domains.html
Normal 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 %}
|
Loading…
Reference in a new issue