Skip to content
Snippets Groups Projects
Commit d82e1daa authored by robinwilliam.hundt's avatar robinwilliam.hundt
Browse files

Deleted custom_annotations

parent 83153212
No related branches found
No related tags found
1 merge request!15Refactor
Pipeline #
from django.contrib.auth.decorators import user_passes_test
"""I collect custom decorators here that I use for the simple premission system
Currently the following options are available
- group_required
- in_groups
"""
def in_groups(user, group_list):
return bool(user.groups.filter(name__in=group_list)) # or user.is_superuser
def group_required(*group_names):
"""Requires user membership in at least one of the groups passed in. Should
only be used in annotations
"""
def _in_groups(u):
if u.is_authenticated():
return in_groups(u, group_names)
return user_passes_test(_in_groups)
......@@ -46,7 +46,7 @@ def get_annotated_tutor_list():
Returns:
TYPE: the annotated QuerySet
"""
return User.objects\
return get_user_model().objects\
.filter(groups__name='Tutors')\
.annotate(Count('feedback_list'))\
.order_by('-feedback_list__count')
......
......@@ -8,6 +8,7 @@ from core.serializers import (FeedbackSerializer, StudentSerializer,
log = logging.getLogger(__name__)
class StudentApiView(RetrieveAPIView):
permission_classes = (IsStudent,)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment