2023-08-10 21:13:37 +12:00
|
|
|
from datetime import datetime
|
|
|
|
|
2023-09-05 20:25:02 +12:00
|
|
|
from app import db
|
2023-07-28 16:22:12 +12:00
|
|
|
from app.main import bp
|
2023-10-02 22:16:44 +13:00
|
|
|
from flask import g, session, flash, request
|
2023-07-28 16:22:12 +12:00
|
|
|
from flask_moment import moment
|
2023-08-26 15:41:11 +12:00
|
|
|
from flask_login import current_user
|
2023-07-28 16:22:12 +12:00
|
|
|
from flask_babel import _, get_locale
|
2023-09-05 20:25:02 +12:00
|
|
|
from sqlalchemy import select
|
|
|
|
from sqlalchemy_searchable import search
|
2023-10-02 22:16:44 +13:00
|
|
|
from app.utils import render_template, get_setting, gibberish
|
2023-07-28 16:22:12 +12:00
|
|
|
|
2023-09-05 20:25:02 +12:00
|
|
|
from app.models import Community, CommunityMember
|
2023-08-22 21:24:11 +12:00
|
|
|
|
2023-07-28 16:22:12 +12:00
|
|
|
|
|
|
|
@bp.route('/', methods=['GET', 'POST'])
|
|
|
|
@bp.route('/index', methods=['GET', 'POST'])
|
|
|
|
def index():
|
2023-08-26 15:41:11 +12:00
|
|
|
if hasattr(current_user, 'verified') and current_user.verified is False:
|
|
|
|
flash(_('Please click the link in your email inbox to verify your account.'), 'warning')
|
|
|
|
return render_template('index.html')
|
2023-08-22 21:24:11 +12:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/communities', methods=['GET'])
|
|
|
|
def list_communities():
|
2023-09-05 20:25:02 +12:00
|
|
|
search_param = request.args.get('search', '')
|
|
|
|
if search_param == '':
|
|
|
|
communities = Community.query.all()
|
|
|
|
else:
|
|
|
|
query = search(select(Community), search_param, sort=True)
|
|
|
|
communities = db.session.scalars(query).all()
|
|
|
|
|
|
|
|
return render_template('list_communities.html', communities=communities, search=search_param)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/communities/local', methods=['GET'])
|
|
|
|
def list_local_communities():
|
|
|
|
communities = Community.query.filter_by(ap_id=None).all()
|
|
|
|
return render_template('list_communities.html', communities=communities)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/communities/subscribed', methods=['GET'])
|
|
|
|
def list_subscribed_communities():
|
|
|
|
communities = Community.query.join(CommunityMember).filter(CommunityMember.user_id == current_user.id).all()
|
2023-08-29 22:01:06 +12:00
|
|
|
return render_template('list_communities.html', communities=communities)
|