Coverage for memberships/mixins.py: 85%
21 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-05-02 14:13 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-05-02 14:13 -0600
1from users.permissions import MemberPanel
2from logs.mixins import LoggingMixin
5class MemberMixin(LoggingMixin):
6 permission_classes = [MemberPanel]
7 model_membership = "membership"
9 @property
10 def memberships(self):
11 """
12 Retrieve user memberships
13 """
14 if self.request: 14 ↛ 17line 14 didn't jump to line 17, because the condition on line 14 was never false
15 return self.request.user.membership_set.all()
16 else:
17 return None
19 @property
20 def model(self):
21 """
22 Retrieve model used in serializer
23 """
24 return self.serializer_class.Meta.model
26 def get_queryset(self):
27 """
28 Get Only Organization Related objects
29 """
30 if self.queryset: 30 ↛ 31line 30 didn't jump to line 31, because the condition on line 30 was never true
31 return self.queryset
32 return self.model.objects.filter(**{self.model_membership + "__in": self.memberships})
34 def get_serializer_context(self):
35 """
36 Add Memberships to serializers context
37 """
38 context = super(MemberMixin, self).get_serializer_context()
39 context.update(
40 {
41 "memberships": self.memberships,
42 }
43 )
44 return context