work to get the routes aligned and working

This commit is contained in:
Alan Roberts 2024-08-12 19:36:25 -04:00 committed by JollyDevelopment
parent 932e662369
commit de7c8c9d4c
4 changed files with 21 additions and 23 deletions

View file

@ -33,7 +33,7 @@ from app.models import Community, CommunityMember, Post, Site, User, utcnow, Dom
@bp.route('/', methods=['HEAD', 'GET', 'POST'])
@bp.route('/home', methods=['GET', 'POST'])
@bp.route('/home/<sort>', methods=['GET', 'POST'])
# @bp.route('/home/<sort>', methods=['GET', 'POST'])
@bp.route('/home/<sort>/<view_filter>', methods=['GET', 'POST'])
@cache.cached(make_cache_key=make_cache_key)
def index(sort=None, view_filter=None):
@ -41,11 +41,8 @@ def index(sort=None, view_filter=None):
'Accept', ''):
return activitypub_application()
# view_filter = request.view_args['view_filter'] if request.view_args['view_filter'] else None
# view_filter_list = list(request.view_args)
# view_filter = view_filter_list
if 'sort' in request.view_args:
view_filter = request.view_args['sort']
if 'view_filter' in request.view_args:
view_filter = request.view_args['view_filter']
return CachedResponse(
@ -55,13 +52,14 @@ def index(sort=None, view_filter=None):
@bp.route('/popular', methods=['GET'])
@bp.route('/popular/<sort>', methods=['GET'])
# @bp.route('/popular/<sort>', methods=['GET'])
@bp.route('/popular/<sort>/<view_filter>', methods=['GET', 'POST'])
@cache.cached(timeout=5, make_cache_key=make_cache_key)
def popular(sort=None, view_filter=None):
# view_filter = request.view_args['view_filter'] if request.view_args['view_filter'] else None
if 'sort' in request.view_args:
view_filter = request.view_args['sort']
if 'view_filter' in request.view_args:
view_filter = request.view_args['view_filter']
return CachedResponse(
response=home_page('popular', sort, view_filter),
timeout=50 if current_user.is_anonymous else 5,
@ -69,13 +67,14 @@ def popular(sort=None, view_filter=None):
@bp.route('/all', methods=['GET'])
@bp.route('/all/<sort>', methods=['GET'])
# @bp.route('/all/<sort>', methods=['GET'])
@bp.route('/all/<sort>/<view_filter>', methods=['GET', 'POST'])
@cache.cached(timeout=5, make_cache_key=make_cache_key)
def all_posts(sort=None, view_filter=None):
# view_filter = request.view_args['view_filter'] if request.view_args['view_filter'] else None
if 'sort' in request.view_args:
view_filter = request.view_args['sort']
if 'view_filter' in request.view_args:
view_filter = request.view_args['view_filter']
return CachedResponse(
response=home_page('all', sort, view_filter),
timeout=50 if current_user.is_anonymous else 5,
@ -89,7 +88,6 @@ def home_page(type, sort, view_filter):
sort = current_user.default_sort if current_user.is_authenticated else 'hot'
if view_filter is None:
# view_filter = current_user.default_view_filter if current_user.is_authenticated else 'all'
view_filter = 'all'
# If nothing has changed since their last visit, return HTTP 304

View file

@ -1,14 +1,14 @@
<div class="btn-group mt-1 mb-2">
<a href="/{{ type }}/hot" class="btn {{ 'btn-primary' if sort == 'hot' else 'btn-outline-secondary' }}" rel="nofollow noindex">
<a href="/{{ type }}/hot/{{ view_filter }}" class="btn {{ 'btn-primary' if sort == 'hot' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Hot') }}
</a>
<a href="/{{ type }}/top" class="btn {{ 'btn-primary' if sort == 'top' else 'btn-outline-secondary' }}" rel="nofollow noindex">
<a href="/{{ type }}/top/{{ view_filter }}" class="btn {{ 'btn-primary' if sort == 'top' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Top') }}
</a>
<a href="/{{ type }}/new" class="btn {{ 'btn-primary' if sort == 'new' else 'btn-outline-secondary' }}" rel="nofollow noindex">
<a href="/{{ type }}/new/{{ view_filter }}" class="btn {{ 'btn-primary' if sort == 'new' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('New') }}
</a>
<a href="/{{ type }}/active" class="btn {{ 'btn-primary' if sort == 'active' else 'btn-outline-secondary' }}" rel="nofollow noindex">
<a href="/{{ type }}/active/{{ view_filter }}" class="btn {{ 'btn-primary' if sort == 'active' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Active') }}
</a>
</div>

View file

@ -1,11 +1,11 @@
<div class="btn-group mt-1 mb-2" style="float: right;">
<a href="/{{ type }}/subscribed" class="btn {{ 'btn-primary' if view_filter == 'subscribed' else 'btn-outline-secondary' }}" rel="nofollow noindex">
<a href="/{{ type }}/{{ sort }}/subscribed" class="btn {{ 'btn-primary' if view_filter == 'subscribed' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Subscribed') }}
</a>
<a href="/{{ type }}/local" class="btn {{ 'btn-primary' if view_filter == 'local' else 'btn-outline-secondary' }}" rel="nofollow noindex">
<a href="/{{ type }}/{{ sort }}/local" class="btn {{ 'btn-primary' if view_filter == 'local' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('Local') }}
</a>
<a href="/{{ type }}/all" class="btn {{ 'btn-primary' if view_filter == 'all' else 'btn-outline-secondary' }}" rel="nofollow noindex">
<a href="/{{ type }}/{{ sort }}/all" class="btn {{ 'btn-primary' if view_filter == 'all' else 'btn-outline-secondary' }}" rel="nofollow noindex">
{{ _('All') }}
</a>
</div>

View file

@ -169,7 +169,7 @@ def gibberish(length: int = 10) -> str:
# used by @cache.cached() for home page and post caching
def make_cache_key(sort=None, post_id=None):
def make_cache_key(sort=None, post_id=None, view_filter=None):
if current_user.is_anonymous:
return f'{request.url}_{sort}_{post_id}_anon_{request.headers.get("Accept")}_{request.headers.get("Accept-Language")}' # The Accept header differentiates between activitypub requests and everything else
else: