optimizing context data generation for group listing page and group page
@@ -1831,14 +1831,21 @@ class FindGroupsView(TemplateView):
if self.request.user.is_authenticated():
u = User.objects.get(pk=self.request.user.id)
- groups = Group.objects.filter(gaccess__active=True).exclude(name="Hydroshare Author")
+ groups = Group.objects.filter(gaccess__active=True).exclude(
+ name="Hydroshare Author").select_related('gaccess')
for g in groups:
- g.is_user_member = u in g.gaccess.members
+ g.members = g.gaccess.members
+ g.is_user_member = u in g.members
+ g.join_request = None
+ if g.is_user_member:
+ g.join_request_waiting_owner_action = False
+ g.join_request_waiting_user_action = False
+ else:
g.join_request_waiting_owner_action = g.gaccess.group_membership_requests.filter(
request_from=u).exists()
g.join_request_waiting_user_action = g.gaccess.group_membership_requests.filter(
invitation_to=u).exists()
- g.join_request = None
+
if g.join_request_waiting_owner_action or g.join_request_waiting_user_action:
g.join_request = g.gaccess.group_membership_requests.filter(request_from=u).first() or \
g.gaccess.group_membership_requests.filter(invitation_to=u).first()
@@ -1852,6 +1859,8 @@ class FindGroupsView(TemplateView):
(Q(gaccess__discoverable=True) |
Q(gaccess__public=True))).exclude(name="Hydroshare Author")
+ for g in groups:
+ g.members = g.gaccess.members
return {
'groups': groups
}
@@ -1915,11 +1924,12 @@ class GroupView(TemplateView):
group_resources = sorted(group_resources, key=lambda x: x.date_granted, reverse=True)
if self.request.user.is_authenticated():
+ group_members = g.gaccess.members
u = User.objects.get(pk=self.request.user.id)
u.is_group_owner = u.uaccess.owns_group(g)
u.is_group_editor = g in u.uaccess.edit_groups
u.is_group_viewer = g in u.uaccess.view_groups or g.gaccess.public or g.gaccess.discoverable
- u.is_group_member = u in g.gaccess.members
+ u.is_group_member = u in group_members
g.join_request_waiting_owner_action = g.gaccess.group_membership_requests.filter(request_from=u).exists()
g.join_request_waiting_user_action = g.gaccess.group_membership_requests.filter(invitation_to=u).exists()
@@ -1932,7 +1942,7 @@ class GroupView(TemplateView):
Q(invitation_to=None) | Q(invitation_to__is_active=True)
)
- if u not in g.gaccess.members:
+ if u not in group_members:
group_resources = [r for r in group_resources if r.raccess.public or r.raccess.discoverable]
return {
