mirror of
https://gitlab.com/tildes/tildes.git
synced 2026-04-16 06:18:34 +02:00
TEMP: Add some hacky coronavirus "views"
This adds two links at the top of the home page that go to different "views" - one includes only topics related to the coronavirus, while the other filters out all coronavirus topics. For the purposes of these views, a "coronavirus topic" is one that is either in the ~health.coronavirus group, or has coronaviruses.covid19 tag. This is very hacky and will only work on the main tildes.net site due to hardcoded group name and tag. I'm okay with that.
This commit is contained in:
@@ -516,6 +516,10 @@
|
||||
.toast {
|
||||
color: map-get($theme, "foreground-highlight");
|
||||
background-color: map-get($theme, "background-secondary");
|
||||
|
||||
a {
|
||||
color: map-get($theme, "link");
|
||||
}
|
||||
}
|
||||
|
||||
// Toasts should have colored border + text for dark themes, instead of a
|
||||
|
||||
@@ -121,7 +121,7 @@ def current_listing_base_url(
|
||||
"bookmarks": ("per_page", "type"),
|
||||
"group": ("order", "period", "per_page", "tag", "unfiltered"),
|
||||
"group_search": ("order", "period", "per_page", "q"),
|
||||
"home": ("order", "period", "per_page", "tag", "unfiltered"),
|
||||
"home": ("order", "period", "per_page", "tag", "unfiltered", "view"),
|
||||
"ignored_topics": ("per_page",),
|
||||
"search": ("order", "period", "per_page", "q"),
|
||||
"user": ("order", "per_page", "type"),
|
||||
|
||||
@@ -14,7 +14,25 @@
|
||||
|
||||
{% block header_context_link %}{% endblock %}
|
||||
|
||||
{% block filter_info %}
|
||||
{% if view %}
|
||||
<div class="topic-listing-filter">
|
||||
{% if view == "coronavirus-only" %}
|
||||
Showing only topics related to coronavirus.
|
||||
{% elif view == "coronavirus-filtered" %}
|
||||
Showing only topics <em>not</em> related to coronavirus.
|
||||
{% endif %}
|
||||
|
||||
<a href="/">Back to normal view</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if not view %}
|
||||
<div class="toast toast-minor">Specialized views: <a href="/?view=coronavirus-filtered">No coronavirus topics</a> / <a href="/?view=coronavirus-only">Only coronavirus topics</a></div>
|
||||
{% endif %}
|
||||
|
||||
{% if request.user %}
|
||||
{% if request.user.subscriptions %}
|
||||
{{ super() }}
|
||||
|
||||
@@ -49,6 +49,10 @@
|
||||
<input type="hidden" name="q" value="{{ search }}">
|
||||
{% endif %}
|
||||
|
||||
{% if view is defined %}
|
||||
<input type="hidden" name="view" value="{{ view }}">
|
||||
{% endif %}
|
||||
|
||||
<div class="form-group">
|
||||
<label for="period">from</label>
|
||||
<select id="period" name="period" class="form-select" data-js-time-period-select>
|
||||
|
||||
@@ -15,7 +15,7 @@ from pyramid.renderers import render_to_response
|
||||
from pyramid.request import Request
|
||||
from pyramid.response import Response
|
||||
from pyramid.view import view_config
|
||||
from sqlalchemy import cast, func
|
||||
from sqlalchemy import cast, func, or_
|
||||
from sqlalchemy.orm.session import Session
|
||||
from sqlalchemy.sql.expression import any_, desc, text
|
||||
from sqlalchemy_utils import Ltree
|
||||
@@ -142,6 +142,7 @@ def post_group_topics(
|
||||
@view_config(route_name="home", renderer="home.jinja2")
|
||||
@view_config(route_name="group", renderer="topic_listing.jinja2")
|
||||
@use_kwargs(TopicListingSchema())
|
||||
@use_kwargs({"view": String(missing=None)})
|
||||
def get_group_topics( # noqa
|
||||
request: Request,
|
||||
after: Optional[str],
|
||||
@@ -151,6 +152,7 @@ def get_group_topics( # noqa
|
||||
rank_start: Optional[int],
|
||||
tag: Optional[Ltree],
|
||||
unfiltered: bool,
|
||||
view: Optional[str],
|
||||
**kwargs: Any
|
||||
) -> dict:
|
||||
"""Get a listing of topics in the group."""
|
||||
@@ -159,11 +161,31 @@ def get_group_topics( # noqa
|
||||
|
||||
is_home_page = request.matched_route.name == "home"
|
||||
|
||||
# only allow the special coronavirus views on the home page
|
||||
if not is_home_page:
|
||||
view = None
|
||||
|
||||
if view:
|
||||
coronavirus_group = (
|
||||
request.query(Group)
|
||||
.filter(Group.path == Ltree("health.coronavirus"))
|
||||
.one_or_none()
|
||||
)
|
||||
else:
|
||||
coronavirus_group = None
|
||||
|
||||
if is_home_page:
|
||||
# on the home page, include topics from the user's subscribed groups
|
||||
# (or all groups, if logged-out)
|
||||
if request.user:
|
||||
groups = [sub.group for sub in request.user.subscriptions]
|
||||
|
||||
if (
|
||||
view == "coronavirus-only"
|
||||
and coronavirus_group
|
||||
and coronavirus_group not in groups
|
||||
):
|
||||
groups.append(coronavirus_group)
|
||||
else:
|
||||
groups = [
|
||||
group for group in request.query(Group).all() if group.path != "test"
|
||||
@@ -198,6 +220,20 @@ def get_group_topics( # noqa
|
||||
.apply_sort_option(order)
|
||||
)
|
||||
|
||||
if view and coronavirus_group:
|
||||
if view == "coronavirus-only":
|
||||
query = query.filter( # noqa
|
||||
or_(
|
||||
Topic.group_id == coronavirus_group.group_id,
|
||||
Topic.tags.contains(["coronaviruses.covid19"]), # type: ignore
|
||||
)
|
||||
)
|
||||
elif view == "coronavirus-filtered":
|
||||
query = query.filter(
|
||||
Topic.group_id != coronavirus_group.group_id,
|
||||
~Topic.tags.contains(["coronaviruses.covid19"]), # type: ignore
|
||||
)
|
||||
|
||||
# restrict the time period, if not set to "all time"
|
||||
if period:
|
||||
query = query.inside_time_period(period)
|
||||
@@ -296,6 +332,7 @@ def get_group_topics( # noqa
|
||||
"most_recent_scheduled_topics": most_recent_scheduled_topics,
|
||||
"financial_data": financial_data,
|
||||
"current_time": utc_now(),
|
||||
"view": view,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user