Commit 20c4cd3f authored by Robert's avatar Robert

Move url and view from conversations to associations module, show conversations AND content

parent e9abdd90
Pipeline #1810 passed with stage
in 2 minutes and 41 seconds
......@@ -2,6 +2,7 @@ import django.utils.timezone
from django.contrib.contenttypes import models as contenttypes
from django.db import models
from django.db.models import Max, Min
from django.db.models.functions import Coalesce, Greatest
from grouprise.features.content import models as content
from grouprise.features.conversations import models as conversations
......@@ -79,3 +80,15 @@ class Association(models.QuerySet):
qs = qs.annotate(last_activity=Max('conversation__contributions__time_created'))
qs = qs.order_by('-last_activity')
return qs
def ordered_user_associations(self, user):
qs = self
qs = qs.can_view(user, container='conversation')
qs = qs.annotate(last_answer=Max('conversation__contributions__time_created'))
qs = qs.annotate(last_comment=Max('content__contributions__time_created'))
qs = qs.annotate(first_version=Min('content__versions__time_created'))
qs = qs.annotate(last_activity=Coalesce(
'last_answer',
Greatest('first_version', Coalesce('last_comment', 'first_version'))))
qs = qs.order_by('-last_activity')
return qs
......@@ -22,3 +22,5 @@ def is_long_standing_group_member(user, association):
add_perm('associations.delete',
is_authenticated & (is_creator | is_long_standing_group_member))
add_perm('associations.list_activity', is_authenticated)
from django.urls import path
from django.conf.urls import url
from . import views
from grouprise.features.associations.views import ActivityView, Delete
urlpatterns = [
path('stadt/activity', ActivityView.as_view(), name='activity'),
url(
r'^(?P<entity_slug>[\w.@+-]+)/(?P<association_slug>[\w-]+)/delete/$',
views.Delete.as_view(),
Delete.as_view(),
name='delete-association',
),
]
import django
from django.http import Http404
from django.http import Http404, HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.utils.timezone import now
from django.views.generic import ListView
import grouprise.core
from grouprise.core.views import PermissionMixin
from grouprise.features.associations.models import Association
from grouprise.features.gestalten.models import Gestalt
from grouprise.features.groups.models import Group
......@@ -32,6 +35,24 @@ class AssociationMixin:
entity_type=entity.content_type, entity_id=entity.id, slug=association_slug)
class ActivityView(PermissionMixin, ListView):
model = Association
permission_required = 'associations.list_activity'
template_name = 'associations/list_activity.html'
paginate_by = 10
def get_content(self):
return Association.objects.can_view(self.request.user)
def get_queryset(self):
return super().get_queryset().ordered_user_associations(self.request.user)
def post(self, *args, **kwargs):
self.request.user.gestalt.activity_bookmark_time = now()
self.request.user.gestalt.save()
return HttpResponseRedirect(reverse('activity'))
class Delete(
AssociationMixin, grouprise.core.views.PermissionMixin, django.views.generic.UpdateView):
permission_required = 'associations.delete'
......
......@@ -24,10 +24,6 @@ rules.add_perm(
'conversations.create_group_conversation_by_email',
memberships.is_member_of)
rules.add_perm(
'conversations.list',
rules.always_allow)
rules.add_perm(
'conversations.list_group',
memberships.is_member_of)
......
......@@ -7,11 +7,6 @@ urlpatterns = [
views.CreateAbuseConversation.as_view(),
name='abuse'),
urls.url(
r'^stadt/conversations/$',
views.Conversations.as_view(),
name='conversations'),
urls.url(
r'^stadt/conversations/(?P<association_pk>[0-9]+)/$',
views.Conversation.as_view(),
......
from django import shortcuts, urls
from django.contrib.messages import views as messages
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.utils.timezone import now
from django.views import generic
from django.views.generic import ListView
import grouprise.core.views
import grouprise.features.contributions.forms
import grouprise.features.contributions.view_mixins
from grouprise.features.gestalten.models import Gestalt
from grouprise.core.views import PermissionMixin
from grouprise.features.associations import models as associations
from grouprise.features.associations.models import Association
from grouprise.features.gestalten.models import Gestalt
from grouprise.features.groups import models as groups
from grouprise.features.groups.models import Group
from . import forms
......@@ -30,34 +30,22 @@ class Conversation(
form_class = grouprise.features.contributions.forms.Text
class Conversations(grouprise.core.views.PermissionMixin, generic.ListView):
model = associations.Association
permission_required = 'conversations.list'
template_name = 'conversations/list.html'
class GroupConversations(PermissionMixin, ListView):
permission_required = 'conversations.list_group'
model = Association
template_name = 'conversations/list_group.html'
paginate_by = 10
def get_content(self):
return associations.Association.objects.can_view(self.request.user)
def get_queryset(self):
return super().get_queryset().ordered_user_conversations(self.request.user)
def post(self, *args, **kwargs):
self.request.user.gestalt.activity_bookmark_time = now()
self.request.user.gestalt.save()
return HttpResponseRedirect(reverse('conversations'))
class GroupConversations(Conversations):
permission_required = 'conversations.list_group'
template_name = 'conversations/list_group.html'
return Association.objects.can_view(self.request.user)
def get_permission_object(self):
self.group = shortcuts.get_object_or_404(groups.Group, pk=self.kwargs['group_pk'])
return self.group
def get_queryset(self):
return super().get_queryset().filter_group_containers().filter(entity_id=self.group.id)
return super().get_queryset().ordered_user_conversations(self.request.user) \
.filter_group_containers().filter(entity_id=self.group.id)
class CreateConversation(
......
......@@ -45,7 +45,7 @@
<div class="dock-content-inner">
<ol class="nav-vertical">
<li>
<a href="{% url 'conversations' %}" class="nav-menu-item">
<a href="{% url 'activity' %}" class="nav-menu-item">
<i class="sg sg-fw sg-conversations"></i>
<span class="nav-menu-item-label">
Gespräche
......
......@@ -36,7 +36,7 @@
<ul>
{% if user.is_authenticated %}
<li><a href="{{ user.gestalt|url_for_user:user }}">Deine Seite</a></li>
<li><a href="{% url 'conversations' %}">Deine Gespräche</a></li>
<li><a href="{% url 'activity' %}">Dich betreffende Aktivität</a></li>
<li class="separator"></li>
<li><a href="{% url 'settings' %}">Einstellungen</a></li>
<li class="separator"></li>
......
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