Commit c8bf672f authored by Robert's avatar Robert

Move activity code to associations module

parent 20c4cd3f
Pipeline #1811 passed with stage
in 2 minutes and 42 seconds
......@@ -94,6 +94,7 @@ TEMPLATES = [
# grouprise core
'grouprise.core.context_processors.settings',
# grouprise features
'grouprise.features.associations.context_processors.activity',
'grouprise.features.groups.context_processors.groups',
'grouprise.features.stadt.context_processors.page_meta',
],
......
from grouprise.features.associations.models import Association
def activity(request):
num_activity = None
if request.user.is_authenticated:
num_activity = len(Association.objects.active_ordered_user_associations(request.user))
return {'num_activity': num_activity}
......@@ -92,3 +92,9 @@ class Association(models.QuerySet):
Greatest('first_version', Coalesce('last_comment', 'first_version'))))
qs = qs.order_by('-last_activity')
return qs
def active_ordered_user_associations(self, user):
qs = self
qs = qs.ordered_user_associations(user)
qs = qs.filter(last_activity__gte=user.gestalt.activity_bookmark_time)
return qs
{% extends 'stadt/stadt.html' %}
{% block title %}Gespräche - {{ GROUPRISE_SITE_NAME }}{% endblock %}
{% block title %}Gespräche - {{ block.super }}{% endblock %}
{% block menu %}{% with menu='conversation' %}{{ block.super }}{% endwith %}{% endblock %}
{% block heading_title %}
{% include 'core/_heading.html' with title='Gespräche' icon='sg-comments' %}
{% include 'core/_heading.html' with title='Aktivität' icon='sg-comments' %}
{% endblock %}
{% block sidebar %}
......
from django import template
from django.db.models import Max
from grouprise.features.associations.models import Association
register = template.Library()
@register.filter
def unread(association, gestalt):
last_activity = association.container.contributions.aggregate(Max('time_created'))
last_activity = last_activity['time_created__max']
return last_activity >= gestalt.activity_bookmark_time
return Association.objects.active_ordered_user_associations(gestalt.user) \
.filter(pk=association.pk).exists()
......@@ -48,7 +48,7 @@
<a href="{% url 'activity' %}" class="nav-menu-item">
<i class="sg sg-fw sg-conversations"></i>
<span class="nav-menu-item-label">
Gespräche
Aktivität
{% if num_activity %}
({{ num_activity }})
{% endif %}
......
from grouprise.features.associations.models import Association
from grouprise.features.content.models import Content
from grouprise.features.contributions.models import Contribution
from grouprise.features.gestalten.models import Gestalt
......@@ -6,14 +5,8 @@ from grouprise.features.groups.models import Group
def page_meta(request):
num_activity = None
if request.user.is_authenticated:
num_activity = Association.objects.ordered_user_conversations(request.user) \
.filter(last_activity__gte=request.user.gestalt.activity_bookmark_time) \
.count()
return {
'num_groups': Group.objects.count(),
'num_gestalten': Gestalt.objects.count(),
'num_contributions': Contribution.objects.count() + Content.objects.count(),
'num_activity': num_activity,
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment