Skip to content

Commit

Permalink
Merge branch 'master' into 1470-interview-notes-on-recruitmentpositio…
Browse files Browse the repository at this point in the history
…noverviewpage
  • Loading branch information
Snorre98 authored Nov 14, 2024
2 parents 6094b85 + cc46c23 commit f867d14
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"yzhang.markdown-all-in-one",
"stylelint.vscode-stylelint",
"ms-python.mypy-type-checker",
"visualstudioexptteam.vscodeintellicode"
"visualstudioexptteam.vscodeintellicode",
"ms-vscode-remote.vscode-remote-extensionpack"
]
}
9 changes: 9 additions & 0 deletions backend/samfundet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def event_query(*, query: QueryDict, events: QuerySet[Event] = None) -> QuerySet
return events


def user_query(*, query: QueryDict, users: QuerySet[User] = None) -> QuerySet[User]:
if not users:
users = User.objects.all()
search = query.get('search', None)
if search:
users = users.filter(Q(username__icontains=search) | Q(first_name__icontains=search) | Q(last_name__icontains=search))
return users


def generate_timeslots(start_time: datetime.time, end_time: datetime.time, interval_minutes: int) -> list[str]:
# Convert from datetime.time objects to datetime.datetime
start_datetime = datetime.datetime.combine(datetime.datetime.today(), start_time)
Expand Down
6 changes: 5 additions & 1 deletion backend/samfundet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
REQUESTED_IMPERSONATE_USER,
)

from .utils import event_query, generate_timeslots, get_occupied_timeslots_from_request
from .utils import user_query, event_query, generate_timeslots, get_occupied_timeslots_from_request
from .homepage import homepage
from .models.role import Role, UserOrgRole, UserGangRole, UserGangSectionRole
from .serializers import (
Expand Down Expand Up @@ -492,6 +492,10 @@ class AllUsersView(ListAPIView):
serializer_class = UserSerializer
queryset = User.objects.all()

def get(self, request: Request) -> Response:
users = user_query(query=request.query_params)
return Response(data=UserSerializer(users, many=True).data)


class ImpersonateView(APIView):
permission_classes = [IsAuthenticated] # TODO: Permission check.
Expand Down

0 comments on commit f867d14

Please sign in to comment.