mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-02 22:36:33 +00:00
Merge branch 'main' into production
This commit is contained in:
commit
8aa920e357
14 changed files with 232 additions and 116 deletions
|
@ -480,12 +480,14 @@ def handle_boost_task(boost_id):
|
|||
instance = models.Status.objects.get(id=boost_id)
|
||||
boosted = instance.boost.boosted_status
|
||||
|
||||
# previous boosts of this status
|
||||
old_versions = models.Boost.objects.filter(
|
||||
boosted_status__id=boosted.id,
|
||||
created_date__lt=instance.created_date,
|
||||
)
|
||||
|
||||
for stream in streams.values():
|
||||
# people who should see the boost (not people who see the original status)
|
||||
audience = stream.get_stores_for_object(instance)
|
||||
stream.remove_object_from_related_stores(boosted, stores=audience)
|
||||
for status in old_versions:
|
||||
|
|
|
@ -38,7 +38,7 @@ class RedisStore(ABC):
|
|||
|
||||
def remove_object_from_related_stores(self, obj, stores=None):
|
||||
"""remove an object from all stores"""
|
||||
stores = stores or self.get_stores_for_object(obj)
|
||||
stores = self.get_stores_for_object(obj) if stores is None else stores
|
||||
pipeline = r.pipeline()
|
||||
for store in stores:
|
||||
pipeline.zrem(store, -1, obj.id)
|
||||
|
|
|
@ -9,26 +9,26 @@
|
|||
|
||||
{% block panel %}
|
||||
|
||||
<div class="columns block has-text-centered">
|
||||
<div class="column is-3">
|
||||
<div class="columns block has-text-centered is-mobile is-multiline">
|
||||
<div class="column is-3-desktop is-6-mobile">
|
||||
<div class="notification">
|
||||
<h3>{% trans "Total users" %}</h3>
|
||||
<p class="title is-5">{{ users|intcomma }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-3">
|
||||
<div class="column is-3-desktop is-6-mobile">
|
||||
<div class="notification">
|
||||
<h3>{% trans "Active this month" %}</h3>
|
||||
<p class="title is-5">{{ active_users|intcomma }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-3">
|
||||
<div class="column is-3-desktop is-6-mobile">
|
||||
<div class="notification">
|
||||
<h3>{% trans "Statuses" %}</h3>
|
||||
<p class="title is-5">{{ statuses|intcomma }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-3">
|
||||
<div class="column is-3-desktop is-6-mobile">
|
||||
<div class="notification">
|
||||
<h3>{% trans "Works" %}</h3>
|
||||
<p class="title is-5">{{ works|intcomma }}</p>
|
||||
|
@ -64,7 +64,7 @@
|
|||
<div class="block content">
|
||||
<h2>{% trans "Instance Activity" %}</h2>
|
||||
|
||||
<form method="get" action="{% url 'settings-dashboard' %}" class="notification has-background-white-bis">
|
||||
<form method="get" action="{% url 'settings-dashboard' %}" class="notification has-background-white-bis scroll-x">
|
||||
<div class="is-flex is-align-items-flex-end">
|
||||
<div class="ml-1 mr-1">
|
||||
<label class="label" for="id_start">
|
||||
|
@ -95,19 +95,31 @@
|
|||
</div>
|
||||
</form>
|
||||
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<h3>{% trans "User signup activity" %}</h3>
|
||||
<div class="columns is-multiline">
|
||||
<div class="column is-half">
|
||||
<h3>{% trans "Total users" %}</h3>
|
||||
<div class="box">
|
||||
<canvas id="user_stats"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="column is-half">
|
||||
<h3>{% trans "User signup activity" %}</h3>
|
||||
<div class="box">
|
||||
<canvas id="register_stats"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-half">
|
||||
<h3>{% trans "Status activity" %}</h3>
|
||||
<div class="box">
|
||||
<canvas id="status_stats"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-half">
|
||||
<h3>{% trans "Works created" %}</h3>
|
||||
<div class="box">
|
||||
<canvas id="works_stats"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -115,6 +127,8 @@
|
|||
|
||||
{% block scripts %}
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.5.1/dist/chart.min.js"></script>
|
||||
{% include 'settings/dashboard/dashboard_user_chart.html' %}
|
||||
{% include 'settings/dashboard/dashboard_status_chart.html' %}
|
||||
{% include 'settings/dashboard/user_chart.html' %}
|
||||
{% include 'settings/dashboard/status_chart.html' %}
|
||||
{% include 'settings/dashboard/registration_chart.html' %}
|
||||
{% include 'settings/dashboard/works_chart.html' %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
{% load i18n %}
|
||||
<script>
|
||||
const status_labels = [{% for label in status_stats.labels %}"{{ label }}",{% endfor %}];
|
||||
const status_data = {
|
||||
labels: status_labels,
|
||||
datasets: [{
|
||||
label: '{% trans "Statuses posted" %}',
|
||||
backgroundColor: 'rgb(255, 99, 132)',
|
||||
borderColor: 'rgb(255, 99, 132)',
|
||||
data: {{ status_stats.total }},
|
||||
}]
|
||||
};
|
||||
// === include 'setup' then 'config' above ===
|
||||
|
||||
const status_config = {
|
||||
type: 'bar',
|
||||
data: status_data,
|
||||
options: {}
|
||||
};
|
||||
|
||||
var statusStats = new Chart(
|
||||
document.getElementById('status_stats'),
|
||||
status_config
|
||||
);
|
||||
</script>
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
{% load i18n %}
|
||||
<script>
|
||||
const labels = [{% for label in user_stats.labels %}"{{ label }}",{% endfor %}];
|
||||
const data = {
|
||||
labels: labels,
|
||||
datasets: [{
|
||||
label: '{% trans "Total" %}',
|
||||
backgroundColor: 'rgb(255, 99, 132)',
|
||||
borderColor: 'rgb(255, 99, 132)',
|
||||
data: {{ user_stats.total }},
|
||||
}, {
|
||||
label: '{% trans "Active this month" %}',
|
||||
backgroundColor: 'rgb(75, 192, 192)',
|
||||
borderColor: 'rgb(75, 192, 192)',
|
||||
data: {{ user_stats.active }},
|
||||
}]
|
||||
};
|
||||
|
||||
const config = {
|
||||
type: 'line',
|
||||
data: data,
|
||||
options: {}
|
||||
};
|
||||
|
||||
var userStats = new Chart(
|
||||
document.getElementById('user_stats'),
|
||||
config
|
||||
);
|
||||
</script>
|
|
@ -0,0 +1,19 @@
|
|||
{% load i18n %}
|
||||
<script>
|
||||
var registerStats = new Chart(
|
||||
document.getElementById('register_stats'),
|
||||
{
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: [{% for label in register_stats.labels %}"{{ label }}",{% endfor %}],
|
||||
datasets: [{
|
||||
label: '{% trans "Registrations" %}',
|
||||
backgroundColor: 'hsl(171, 100%, 41%)',
|
||||
borderColor: 'hsl(171, 100%, 41%)',
|
||||
data: {{ register_stats.total }},
|
||||
}]
|
||||
},
|
||||
options: {}
|
||||
}
|
||||
);
|
||||
</script>
|
21
bookwyrm/templates/settings/dashboard/status_chart.html
Normal file
21
bookwyrm/templates/settings/dashboard/status_chart.html
Normal file
|
@ -0,0 +1,21 @@
|
|||
{% load i18n %}
|
||||
<script>
|
||||
|
||||
var statusStats = new Chart(
|
||||
document.getElementById('status_stats'),
|
||||
{
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: [{% for label in status_stats.labels %}"{{ label }}",{% endfor %}],
|
||||
datasets: [{
|
||||
label: '{% trans "Statuses posted" %}',
|
||||
backgroundColor: 'hsl(141, 71%, 48%)',
|
||||
borderColor: 'hsl(141, 71%, 48%)',
|
||||
data: {{ status_stats.total }},
|
||||
}]
|
||||
},
|
||||
options: {}
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
25
bookwyrm/templates/settings/dashboard/user_chart.html
Normal file
25
bookwyrm/templates/settings/dashboard/user_chart.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
{% load i18n %}
|
||||
<script>
|
||||
|
||||
var userStats = new Chart(
|
||||
document.getElementById('user_stats'),
|
||||
{
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: [{% for label in user_stats.labels %}"{{ label }}",{% endfor %}],
|
||||
datasets: [{
|
||||
label: '{% trans "Total" %}',
|
||||
backgroundColor: 'hsl(217, 71%, 53%)',
|
||||
borderColor: 'hsl(217, 71%, 53%)',
|
||||
data: {{ user_stats.total }},
|
||||
}, {
|
||||
label: '{% trans "Active this month" %}',
|
||||
backgroundColor: 'hsl(171, 100%, 41%)',
|
||||
borderColor: 'hsl(171, 100%, 41%)',
|
||||
data: {{ user_stats.active }},
|
||||
}]
|
||||
},
|
||||
options: {}
|
||||
}
|
||||
);
|
||||
</script>
|
21
bookwyrm/templates/settings/dashboard/works_chart.html
Normal file
21
bookwyrm/templates/settings/dashboard/works_chart.html
Normal file
|
@ -0,0 +1,21 @@
|
|||
{% load i18n %}
|
||||
<script>
|
||||
|
||||
var worksStats = new Chart(
|
||||
document.getElementById('works_stats'),
|
||||
{
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: [{% for label in works_stats.labels %}"{{ label }}",{% endfor %}],
|
||||
datasets: [{
|
||||
label: '{% trans "Works" %}',
|
||||
backgroundColor: 'hsl(204, 86%, 53%)',
|
||||
borderColor: 'hsl(204, 86%, 53%)',
|
||||
data: {{ works_stats.total }},
|
||||
}]
|
||||
},
|
||||
options: {}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
|
|
@ -22,6 +22,16 @@ class Activitystreams(TestCase):
|
|||
local=True,
|
||||
localname="nutria",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
local=False,
|
||||
remote_id="https://example.com/users/rat",
|
||||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
work = models.Work.objects.create(title="test work")
|
||||
self.book = models.Edition.objects.create(title="test book", parent_work=work)
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
|
@ -125,7 +135,7 @@ class Activitystreams(TestCase):
|
|||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
||||
def test_boost_to_another_timeline(self, *_):
|
||||
"""add a boost and deduplicate the boosted status on the timeline"""
|
||||
"""boost from a non-follower doesn't remove original status from feed"""
|
||||
status = models.Status.objects.create(user=self.local_user, content="hi")
|
||||
with patch("bookwyrm.activitystreams.handle_boost_task.delay"):
|
||||
boost = models.Boost.objects.create(
|
||||
|
@ -138,11 +148,32 @@ class Activitystreams(TestCase):
|
|||
activitystreams.handle_boost_task(boost.id)
|
||||
|
||||
self.assertTrue(mock.called)
|
||||
self.assertEqual(mock.call_count, 1)
|
||||
call_args = mock.call_args
|
||||
self.assertEqual(call_args[0][0], status)
|
||||
self.assertEqual(
|
||||
call_args[1]["stores"], ["{:d}-home".format(self.another_user.id)]
|
||||
)
|
||||
self.assertEqual(call_args[1]["stores"], [f"{self.another_user.id}-home"])
|
||||
|
||||
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
||||
def test_boost_to_another_timeline_remote(self, *_):
|
||||
"""boost from a remote non-follower doesn't remove original status from feed"""
|
||||
status = models.Status.objects.create(user=self.local_user, content="hi")
|
||||
with patch("bookwyrm.activitystreams.handle_boost_task.delay"):
|
||||
boost = models.Boost.objects.create(
|
||||
boosted_status=status,
|
||||
user=self.remote_user,
|
||||
)
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores"
|
||||
) as mock:
|
||||
activitystreams.handle_boost_task(boost.id)
|
||||
|
||||
self.assertTrue(mock.called)
|
||||
self.assertEqual(mock.call_count, 1)
|
||||
call_args = mock.call_args
|
||||
self.assertEqual(call_args[0][0], status)
|
||||
self.assertEqual(call_args[1]["stores"], [])
|
||||
|
||||
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
|
||||
|
@ -163,12 +194,8 @@ class Activitystreams(TestCase):
|
|||
self.assertTrue(mock.called)
|
||||
call_args = mock.call_args
|
||||
self.assertEqual(call_args[0][0], status)
|
||||
self.assertTrue(
|
||||
"{:d}-home".format(self.another_user.id) in call_args[1]["stores"]
|
||||
)
|
||||
self.assertTrue(
|
||||
"{:d}-home".format(self.local_user.id) in call_args[1]["stores"]
|
||||
)
|
||||
self.assertTrue(f"{self.another_user.id}-home" in call_args[1]["stores"])
|
||||
self.assertTrue(f"{self.local_user.id}-home" in call_args[1]["stores"])
|
||||
|
||||
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
|
||||
|
@ -188,6 +215,4 @@ class Activitystreams(TestCase):
|
|||
self.assertTrue(mock.called)
|
||||
call_args = mock.call_args
|
||||
self.assertEqual(call_args[0][0], status)
|
||||
self.assertEqual(
|
||||
call_args[1]["stores"], ["{:d}-home".format(self.local_user.id)]
|
||||
)
|
||||
self.assertEqual(call_args[1]["stores"], [f"{self.local_user.id}-home"])
|
||||
|
|
|
@ -25,13 +25,6 @@ class Dashboard(View):
|
|||
"""list of users"""
|
||||
interval = int(request.GET.get("days", 1))
|
||||
now = timezone.now()
|
||||
|
||||
user_queryset = models.User.objects.filter(local=True)
|
||||
user_stats = {"labels": [], "total": [], "active": []}
|
||||
|
||||
status_queryset = models.Status.objects.filter(user__local=True, deleted=False)
|
||||
status_stats = {"labels": [], "total": []}
|
||||
|
||||
start = request.GET.get("start")
|
||||
if start:
|
||||
start = timezone.make_aware(parse(start))
|
||||
|
@ -42,31 +35,55 @@ class Dashboard(View):
|
|||
end = timezone.make_aware(parse(end)) if end else now
|
||||
start = start.replace(hour=0, minute=0, second=0)
|
||||
|
||||
interval_start = start
|
||||
interval_end = interval_start + timedelta(days=interval)
|
||||
while interval_start <= end:
|
||||
print(interval_start, interval_end)
|
||||
interval_queryset = user_queryset.filter(
|
||||
Q(is_active=True) | Q(deactivation_date__gt=interval_end),
|
||||
created_date__lte=interval_end,
|
||||
)
|
||||
user_stats["total"].append(interval_queryset.filter().count())
|
||||
user_stats["active"].append(
|
||||
interval_queryset.filter(
|
||||
last_active_date__gt=interval_end - timedelta(days=31),
|
||||
).count()
|
||||
)
|
||||
user_stats["labels"].append(interval_start.strftime("%b %d"))
|
||||
user_queryset = models.User.objects.filter(local=True)
|
||||
user_chart = Chart(
|
||||
queryset=user_queryset,
|
||||
queries={
|
||||
"total": lambda q, s, e: q.filter(
|
||||
Q(is_active=True) | Q(deactivation_date__gt=e),
|
||||
created_date__lte=e,
|
||||
).count(),
|
||||
"active": lambda q, s, e: q.filter(
|
||||
Q(is_active=True) | Q(deactivation_date__gt=e),
|
||||
created_date__lte=e,
|
||||
)
|
||||
.filter(
|
||||
last_active_date__gt=e - timedelta(days=31),
|
||||
)
|
||||
.count(),
|
||||
},
|
||||
)
|
||||
|
||||
status_stats["total"].append(
|
||||
status_queryset.filter(
|
||||
created_date__gt=interval_start,
|
||||
created_date__lte=interval_end,
|
||||
status_queryset = models.Status.objects.filter(user__local=True, deleted=False)
|
||||
status_chart = Chart(
|
||||
queryset=status_queryset,
|
||||
queries={
|
||||
"total": lambda q, s, e: q.filter(
|
||||
created_date__gt=s,
|
||||
created_date__lte=e,
|
||||
).count()
|
||||
)
|
||||
status_stats["labels"].append(interval_start.strftime("%b %d"))
|
||||
interval_start = interval_end
|
||||
interval_end += timedelta(days=interval)
|
||||
},
|
||||
)
|
||||
|
||||
register_chart = Chart(
|
||||
queryset=user_queryset,
|
||||
queries={
|
||||
"total": lambda q, s, e: q.filter(
|
||||
created_date__gt=s,
|
||||
created_date__lte=e,
|
||||
).count()
|
||||
},
|
||||
)
|
||||
|
||||
works_chart = Chart(
|
||||
queryset=models.Work.objects,
|
||||
queries={
|
||||
"total": lambda q, s, e: q.filter(
|
||||
created_date__gt=s,
|
||||
created_date__lte=e,
|
||||
).count()
|
||||
},
|
||||
)
|
||||
|
||||
data = {
|
||||
"start": start.strftime("%Y-%m-%d"),
|
||||
|
@ -82,7 +99,34 @@ class Dashboard(View):
|
|||
"invite_requests": models.InviteRequest.objects.filter(
|
||||
ignored=False, invite_sent=False
|
||||
).count(),
|
||||
"user_stats": user_stats,
|
||||
"status_stats": status_stats,
|
||||
"user_stats": user_chart.get_chart(start, end, interval),
|
||||
"status_stats": status_chart.get_chart(start, end, interval),
|
||||
"register_stats": register_chart.get_chart(start, end, interval),
|
||||
"works_stats": works_chart.get_chart(start, end, interval),
|
||||
}
|
||||
return TemplateResponse(request, "settings/dashboard/dashboard.html", data)
|
||||
|
||||
|
||||
class Chart:
|
||||
"""Data for a chart"""
|
||||
|
||||
def __init__(self, queryset, queries: dict):
|
||||
self.queryset = queryset
|
||||
self.queries = queries
|
||||
|
||||
def get_chart(self, start, end, interval):
|
||||
"""load the data for the chart given a time scale and interval"""
|
||||
interval_start = start
|
||||
interval_end = interval_start + timedelta(days=interval)
|
||||
|
||||
chart = {k: [] for k in self.queries.keys()}
|
||||
chart["labels"] = []
|
||||
while interval_start <= end:
|
||||
for (name, query) in self.queries.items():
|
||||
chart[name].append(query(self.queryset, interval_start, interval_end))
|
||||
chart["labels"].append(interval_start.strftime("%b %d"))
|
||||
|
||||
interval_start = interval_end
|
||||
interval_end += timedelta(days=interval)
|
||||
|
||||
return chart
|
||||
|
|
|
@ -2118,7 +2118,7 @@ msgstr "Beziehungen"
|
|||
#, fuzzy, python-format
|
||||
#| msgid "Finish \"<em>%(book_title)s</em>\""
|
||||
msgid "Finish \"%(book_title)s\""
|
||||
msgstr "\"<em>%(book_title)s</em>\" abschließen"
|
||||
msgstr "\"<em>%(book_title)s</em>\"zu Ende gelesen"
|
||||
|
||||
#: bookwyrm/templates/reading_progress/start.html:5
|
||||
#, fuzzy, python-format
|
||||
|
|
Binary file not shown.
|
@ -595,11 +595,11 @@ msgstr "Éditeur :"
|
|||
|
||||
#: bookwyrm/templates/book/edit_book.html:185
|
||||
msgid "First published date:"
|
||||
msgstr "Première date de publication :"
|
||||
msgstr "Première date de parution :"
|
||||
|
||||
#: bookwyrm/templates/book/edit_book.html:193
|
||||
msgid "Published date:"
|
||||
msgstr "Date de publication :"
|
||||
msgstr "Date de parution :"
|
||||
|
||||
#: bookwyrm/templates/book/edit_book.html:202
|
||||
msgid "Authors"
|
||||
|
|
Loading…
Reference in a new issue