mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-04 07:16:36 +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)
|
instance = models.Status.objects.get(id=boost_id)
|
||||||
boosted = instance.boost.boosted_status
|
boosted = instance.boost.boosted_status
|
||||||
|
|
||||||
|
# previous boosts of this status
|
||||||
old_versions = models.Boost.objects.filter(
|
old_versions = models.Boost.objects.filter(
|
||||||
boosted_status__id=boosted.id,
|
boosted_status__id=boosted.id,
|
||||||
created_date__lt=instance.created_date,
|
created_date__lt=instance.created_date,
|
||||||
)
|
)
|
||||||
|
|
||||||
for stream in streams.values():
|
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)
|
audience = stream.get_stores_for_object(instance)
|
||||||
stream.remove_object_from_related_stores(boosted, stores=audience)
|
stream.remove_object_from_related_stores(boosted, stores=audience)
|
||||||
for status in old_versions:
|
for status in old_versions:
|
||||||
|
|
|
@ -38,7 +38,7 @@ class RedisStore(ABC):
|
||||||
|
|
||||||
def remove_object_from_related_stores(self, obj, stores=None):
|
def remove_object_from_related_stores(self, obj, stores=None):
|
||||||
"""remove an object from all stores"""
|
"""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()
|
pipeline = r.pipeline()
|
||||||
for store in stores:
|
for store in stores:
|
||||||
pipeline.zrem(store, -1, obj.id)
|
pipeline.zrem(store, -1, obj.id)
|
||||||
|
|
|
@ -9,26 +9,26 @@
|
||||||
|
|
||||||
{% block panel %}
|
{% block panel %}
|
||||||
|
|
||||||
<div class="columns block has-text-centered">
|
<div class="columns block has-text-centered is-mobile is-multiline">
|
||||||
<div class="column is-3">
|
<div class="column is-3-desktop is-6-mobile">
|
||||||
<div class="notification">
|
<div class="notification">
|
||||||
<h3>{% trans "Total users" %}</h3>
|
<h3>{% trans "Total users" %}</h3>
|
||||||
<p class="title is-5">{{ users|intcomma }}</p>
|
<p class="title is-5">{{ users|intcomma }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-3">
|
<div class="column is-3-desktop is-6-mobile">
|
||||||
<div class="notification">
|
<div class="notification">
|
||||||
<h3>{% trans "Active this month" %}</h3>
|
<h3>{% trans "Active this month" %}</h3>
|
||||||
<p class="title is-5">{{ active_users|intcomma }}</p>
|
<p class="title is-5">{{ active_users|intcomma }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-3">
|
<div class="column is-3-desktop is-6-mobile">
|
||||||
<div class="notification">
|
<div class="notification">
|
||||||
<h3>{% trans "Statuses" %}</h3>
|
<h3>{% trans "Statuses" %}</h3>
|
||||||
<p class="title is-5">{{ statuses|intcomma }}</p>
|
<p class="title is-5">{{ statuses|intcomma }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-3">
|
<div class="column is-3-desktop is-6-mobile">
|
||||||
<div class="notification">
|
<div class="notification">
|
||||||
<h3>{% trans "Works" %}</h3>
|
<h3>{% trans "Works" %}</h3>
|
||||||
<p class="title is-5">{{ works|intcomma }}</p>
|
<p class="title is-5">{{ works|intcomma }}</p>
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
<div class="block content">
|
<div class="block content">
|
||||||
<h2>{% trans "Instance Activity" %}</h2>
|
<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="is-flex is-align-items-flex-end">
|
||||||
<div class="ml-1 mr-1">
|
<div class="ml-1 mr-1">
|
||||||
<label class="label" for="id_start">
|
<label class="label" for="id_start">
|
||||||
|
@ -95,19 +95,31 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div class="columns">
|
<div class="columns is-multiline">
|
||||||
<div class="column">
|
<div class="column is-half">
|
||||||
<h3>{% trans "User signup activity" %}</h3>
|
<h3>{% trans "Total users" %}</h3>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<canvas id="user_stats"></canvas>
|
<canvas id="user_stats"></canvas>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
<h3>{% trans "Status activity" %}</h3>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<canvas id="status_stats"></canvas>
|
<canvas id="status_stats"></canvas>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="column is-half">
|
||||||
|
<h3>{% trans "Works created" %}</h3>
|
||||||
|
<div class="box">
|
||||||
|
<canvas id="works_stats"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -115,6 +127,8 @@
|
||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.5.1/dist/chart.min.js"></script>
|
<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/user_chart.html' %}
|
||||||
{% include 'settings/dashboard/dashboard_status_chart.html' %}
|
{% include 'settings/dashboard/status_chart.html' %}
|
||||||
|
{% include 'settings/dashboard/registration_chart.html' %}
|
||||||
|
{% include 'settings/dashboard/works_chart.html' %}
|
||||||
{% endblock %}
|
{% 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,
|
local=True,
|
||||||
localname="nutria",
|
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")
|
work = models.Work.objects.create(title="test work")
|
||||||
self.book = models.Edition.objects.create(title="test book", parent_work=work)
|
self.book = models.Edition.objects.create(title="test book", parent_work=work)
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
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.activitystreams.BooksStream.remove_object_from_related_stores")
|
||||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
||||||
def test_boost_to_another_timeline(self, *_):
|
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")
|
status = models.Status.objects.create(user=self.local_user, content="hi")
|
||||||
with patch("bookwyrm.activitystreams.handle_boost_task.delay"):
|
with patch("bookwyrm.activitystreams.handle_boost_task.delay"):
|
||||||
boost = models.Boost.objects.create(
|
boost = models.Boost.objects.create(
|
||||||
|
@ -138,11 +148,32 @@ class Activitystreams(TestCase):
|
||||||
activitystreams.handle_boost_task(boost.id)
|
activitystreams.handle_boost_task(boost.id)
|
||||||
|
|
||||||
self.assertTrue(mock.called)
|
self.assertTrue(mock.called)
|
||||||
|
self.assertEqual(mock.call_count, 1)
|
||||||
call_args = mock.call_args
|
call_args = mock.call_args
|
||||||
self.assertEqual(call_args[0][0], status)
|
self.assertEqual(call_args[0][0], status)
|
||||||
self.assertEqual(
|
self.assertEqual(call_args[1]["stores"], [f"{self.another_user.id}-home"])
|
||||||
call_args[1]["stores"], ["{:d}-home".format(self.another_user.id)]
|
|
||||||
|
@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.LocalStream.remove_object_from_related_stores")
|
||||||
@patch("bookwyrm.activitystreams.BooksStream.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)
|
self.assertTrue(mock.called)
|
||||||
call_args = mock.call_args
|
call_args = mock.call_args
|
||||||
self.assertEqual(call_args[0][0], status)
|
self.assertEqual(call_args[0][0], status)
|
||||||
self.assertTrue(
|
self.assertTrue(f"{self.another_user.id}-home" in call_args[1]["stores"])
|
||||||
"{:d}-home".format(self.another_user.id) in call_args[1]["stores"]
|
self.assertTrue(f"{self.local_user.id}-home" in call_args[1]["stores"])
|
||||||
)
|
|
||||||
self.assertTrue(
|
|
||||||
"{:d}-home".format(self.local_user.id) in call_args[1]["stores"]
|
|
||||||
)
|
|
||||||
|
|
||||||
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
|
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
|
||||||
@patch("bookwyrm.activitystreams.BooksStream.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)
|
self.assertTrue(mock.called)
|
||||||
call_args = mock.call_args
|
call_args = mock.call_args
|
||||||
self.assertEqual(call_args[0][0], status)
|
self.assertEqual(call_args[0][0], status)
|
||||||
self.assertEqual(
|
self.assertEqual(call_args[1]["stores"], [f"{self.local_user.id}-home"])
|
||||||
call_args[1]["stores"], ["{:d}-home".format(self.local_user.id)]
|
|
||||||
)
|
|
||||||
|
|
|
@ -25,13 +25,6 @@ class Dashboard(View):
|
||||||
"""list of users"""
|
"""list of users"""
|
||||||
interval = int(request.GET.get("days", 1))
|
interval = int(request.GET.get("days", 1))
|
||||||
now = timezone.now()
|
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")
|
start = request.GET.get("start")
|
||||||
if start:
|
if start:
|
||||||
start = timezone.make_aware(parse(start))
|
start = timezone.make_aware(parse(start))
|
||||||
|
@ -42,31 +35,55 @@ class Dashboard(View):
|
||||||
end = timezone.make_aware(parse(end)) if end else now
|
end = timezone.make_aware(parse(end)) if end else now
|
||||||
start = start.replace(hour=0, minute=0, second=0)
|
start = start.replace(hour=0, minute=0, second=0)
|
||||||
|
|
||||||
interval_start = start
|
user_queryset = models.User.objects.filter(local=True)
|
||||||
interval_end = interval_start + timedelta(days=interval)
|
user_chart = Chart(
|
||||||
while interval_start <= end:
|
queryset=user_queryset,
|
||||||
print(interval_start, interval_end)
|
queries={
|
||||||
interval_queryset = user_queryset.filter(
|
"total": lambda q, s, e: q.filter(
|
||||||
Q(is_active=True) | Q(deactivation_date__gt=interval_end),
|
Q(is_active=True) | Q(deactivation_date__gt=e),
|
||||||
created_date__lte=interval_end,
|
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,
|
||||||
)
|
)
|
||||||
user_stats["total"].append(interval_queryset.filter().count())
|
.filter(
|
||||||
user_stats["active"].append(
|
last_active_date__gt=e - timedelta(days=31),
|
||||||
interval_queryset.filter(
|
)
|
||||||
last_active_date__gt=interval_end - timedelta(days=31),
|
.count(),
|
||||||
).count()
|
},
|
||||||
)
|
)
|
||||||
user_stats["labels"].append(interval_start.strftime("%b %d"))
|
|
||||||
|
|
||||||
status_stats["total"].append(
|
status_queryset = models.Status.objects.filter(user__local=True, deleted=False)
|
||||||
status_queryset.filter(
|
status_chart = Chart(
|
||||||
created_date__gt=interval_start,
|
queryset=status_queryset,
|
||||||
created_date__lte=interval_end,
|
queries={
|
||||||
|
"total": lambda q, s, e: q.filter(
|
||||||
|
created_date__gt=s,
|
||||||
|
created_date__lte=e,
|
||||||
).count()
|
).count()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
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()
|
||||||
|
},
|
||||||
)
|
)
|
||||||
status_stats["labels"].append(interval_start.strftime("%b %d"))
|
|
||||||
interval_start = interval_end
|
|
||||||
interval_end += timedelta(days=interval)
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"start": start.strftime("%Y-%m-%d"),
|
"start": start.strftime("%Y-%m-%d"),
|
||||||
|
@ -82,7 +99,34 @@ class Dashboard(View):
|
||||||
"invite_requests": models.InviteRequest.objects.filter(
|
"invite_requests": models.InviteRequest.objects.filter(
|
||||||
ignored=False, invite_sent=False
|
ignored=False, invite_sent=False
|
||||||
).count(),
|
).count(),
|
||||||
"user_stats": user_stats,
|
"user_stats": user_chart.get_chart(start, end, interval),
|
||||||
"status_stats": status_stats,
|
"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)
|
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
|
#, fuzzy, python-format
|
||||||
#| msgid "Finish \"<em>%(book_title)s</em>\""
|
#| msgid "Finish \"<em>%(book_title)s</em>\""
|
||||||
msgid "Finish \"%(book_title)s\""
|
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
|
#: bookwyrm/templates/reading_progress/start.html:5
|
||||||
#, fuzzy, python-format
|
#, fuzzy, python-format
|
||||||
|
|
Binary file not shown.
|
@ -595,11 +595,11 @@ msgstr "Éditeur :"
|
||||||
|
|
||||||
#: bookwyrm/templates/book/edit_book.html:185
|
#: bookwyrm/templates/book/edit_book.html:185
|
||||||
msgid "First published date:"
|
msgid "First published date:"
|
||||||
msgstr "Première date de publication :"
|
msgstr "Première date de parution :"
|
||||||
|
|
||||||
#: bookwyrm/templates/book/edit_book.html:193
|
#: bookwyrm/templates/book/edit_book.html:193
|
||||||
msgid "Published date:"
|
msgid "Published date:"
|
||||||
msgstr "Date de publication :"
|
msgstr "Date de parution :"
|
||||||
|
|
||||||
#: bookwyrm/templates/book/edit_book.html:202
|
#: bookwyrm/templates/book/edit_book.html:202
|
||||||
msgid "Authors"
|
msgid "Authors"
|
||||||
|
|
Loading…
Reference in a new issue