A few hashtag fixups

This commit is contained in:
Andrew Godwin 2022-11-28 22:14:52 -07:00
parent 1ad9bfcb06
commit 0bced8fe17
5 changed files with 28 additions and 5 deletions

View file

@ -8,6 +8,7 @@ from django.db import models
from django.utils import timezone from django.utils import timezone
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from core.html import strip_html
from core.models import Config from core.models import Config
from stator.models import State, StateField, StateGraph, StatorModel from stator.models import State, StateField, StateGraph, StatorModel
@ -174,7 +175,7 @@ class Hashtag(StatorModel):
Return a parsed and sanitized of hashtags found in content without Return a parsed and sanitized of hashtags found in content without
leading '#'. leading '#'.
""" """
hashtag_hits = cls.hashtag_regex.findall(content) hashtag_hits = cls.hashtag_regex.findall(strip_html(content))
hashtags = sorted({tag[1].lower() for tag in hashtag_hits}) hashtags = sorted({tag[1].lower() for tag in hashtag_hits})
return list(hashtags) return list(hashtags)

View file

@ -77,6 +77,17 @@ class PostStates(StateGraph):
class PostQuerySet(models.QuerySet): class PostQuerySet(models.QuerySet):
def public(self, include_replies: bool = False):
query = self.filter(
visibility__in=[
Post.Visibilities.public,
Post.Visibilities.local_only,
],
)
if not include_replies:
return query.filter(in_reply_to__isnull=True)
return query
def local_public(self, include_replies: bool = False): def local_public(self, include_replies: bool = False):
query = self.filter( query = self.filter(
visibility__in=[ visibility__in=[
@ -104,6 +115,9 @@ class PostManager(models.Manager):
def get_queryset(self): def get_queryset(self):
return PostQuerySet(self.model, using=self._db) return PostQuerySet(self.model, using=self._db)
def public(self, include_replies: bool = False):
return self.get_queryset().public(include_replies=include_replies)
def local_public(self, include_replies: bool = False): def local_public(self, include_replies: bool = False):
return self.get_queryset().local_public(include_replies=include_replies) return self.get_queryset().local_public(include_replies=include_replies)

View file

@ -80,7 +80,7 @@ class Tag(ListView):
def get_queryset(self): def get_queryset(self):
return ( return (
Post.objects.local_public() Post.objects.public()
.tagged_with(self.hashtag) .tagged_with(self.hashtag)
.select_related("author") .select_related("author")
.prefetch_related("attachments") .prefetch_related("attachments")

View file

@ -92,6 +92,7 @@ td a {
--color-text-duller: #5f6983; --color-text-duller: #5f6983;
--color-text-dull: #99a; --color-text-dull: #99a;
--color-text-main: #fff; --color-text-main: #fff;
--color-text-link: rgb(176, 194, 206);
--color-input-border: #000; --color-input-border: #000;
--color-input-border-active: #444b5d; --color-input-border-active: #444b5d;
@ -451,6 +452,7 @@ form .field .label-input {
form .field.stats { form .field.stats {
width: 100%; width: 100%;
} }
form .field.stats table { form .field.stats table {
width: 50%; width: 50%;
} }
@ -907,11 +909,14 @@ table.metadata td.name {
width: 16px; width: 16px;
} }
.post a.hashtag, .post.mini a.hashtag { .post a.hashtag,
.post.mini a.hashtag {
text-decoration: none; text-decoration: none;
color: var(--color-text-link);
} }
.post a.hashtag:hover, .post.mini a.hashtag:hover { .post a.hashtag:hover,
.post.mini a.hashtag:hover {
text-decoration: underline; text-decoration: underline;
} }

View file

@ -6,9 +6,12 @@
<a href="{% url "notifications" %}" {% if current_page == "notifications" %}class="selected"{% endif %} title="Notifications"> <a href="{% url "notifications" %}" {% if current_page == "notifications" %}class="selected"{% endif %} title="Notifications">
<i class="fa-solid fa-at"></i> Notifications <i class="fa-solid fa-at"></i> Notifications
</a> </a>
{% comment %}
Not sure we want to show this quite yet
<a href="{% url "explore" %}" {% if current_page == "explore" %}class="selected"{% endif %} title="Explore"> <a href="{% url "explore" %}" {% if current_page == "explore" %}class="selected"{% endif %} title="Explore">
<i class="fa-solid fa-hashtag"></i> Explore <i class="fa-solid fa-hashtag"></i> Explore
</a> </a>
{% endcomment %}
<a href="{% url "local" %}" {% if current_page == "local" %}class="selected"{% endif %} title="Local"> <a href="{% url "local" %}" {% if current_page == "local" %}class="selected"{% endif %} title="Local">
<i class="fa-solid fa-city"></i> Local <i class="fa-solid fa-city"></i> Local
</a> </a>
@ -30,7 +33,7 @@
<a href="{% url "settings" %}" {% if top_section == "settings" %}class="selected"{% endif %} title="Settings"> <a href="{% url "settings" %}" {% if top_section == "settings" %}class="selected"{% endif %} title="Settings">
<i class="fa-solid fa-gear"></i> Settings <i class="fa-solid fa-gear"></i> Settings
</a> </a>
{% else %} {% else %}
<a href="{% url "local" %}" {% if current_page == "local" %}class="selected"{% endif %} title="Local Posts"> <a href="{% url "local" %}" {% if current_page == "local" %}class="selected"{% endif %} title="Local Posts">
<i class="fa-solid fa-city"></i> Local Posts <i class="fa-solid fa-city"></i> Local Posts
</a> </a>