Commit 3d514e22 authored by Bengfort's avatar Bengfort
Browse files

simplify code

parent 7294447b
......@@ -85,18 +85,7 @@ class InvitationUpdateView(UpdateView):
fields = ['timeslot']
def get_object(self):
if 'schedule_id' in self.kwargs:
return get_object_or_404(
Invitation,
schedule_id=self.kwargs['schedule_id'],
token=self.kwargs['token'],
)
if 'schedule_uuid' in self.kwargs:
return get_object_or_404(
Invitation,
schedule__uuid=self.kwargs['schedule_uuid'],
token=self.kwargs['token'],
)
return get_object_or_404(Invitation, **self.kwargs)
def get_success_url(self):
return reverse('invitation', args=[self.object.schedule.uuid, self.object.token])
......@@ -157,29 +146,17 @@ class InvitationApiView(View):
raise PermissionDenied
return super().dispatch(request, *args, **kwargs)
def get_invitation_kwargs(self):
if 'schedule_id' in self.kwargs:
return {
'schedule_id': self.kwargs['schedule_id'],
'token': self.kwargs['token']
}
if 'schedule_uuid' in self.kwargs:
return {
'schedule_uuid': self.kwargs['schedule_uuid'],
'token': self.kwargs['token']
}
def get(self, request, *args, **kwargs):
invitation = get_object_or_404(Invitation, **self.get_invitation_kwargs())
invitation = get_object_or_404(Invitation, **kwargs)
return JsonResponse({
'datetime': invitation.timeslot.datetime if invitation.timeslot else None,
})
def put(self, request, *args, **kwargs):
invitation, _ = Invitation.objects.get_or_create(**self.get_invitation_kwargs())
invitation, _ = Invitation.objects.get_or_create(**kwargs)
return HttpResponse(status=204)
def delete(self, request, *args, **kwargs):
invitation = get_object_or_404(Invitation, **self.get_invitation_kwargs())
invitation = get_object_or_404(Invitation, **kwargs)
invitation.delete()
return HttpResponse(status=204)
......@@ -45,7 +45,7 @@ urlpatterns = [
name='invitation-legacy',
),
path(
'invitations/<uuid:schedule_uuid>/<token>/',
'invitations/<uuid:schedule__uuid>/<token>/',
InvitationUpdateView.as_view(),
name='invitation',
),
......@@ -55,7 +55,7 @@ urlpatterns = [
name='api-invitation-legacy',
),
path(
'api/<uuid:schedule_uuid>/<token>/',
'api/<uuid:schedule__uuid>/<token>/',
InvitationApiView.as_view(),
name='api-invitation',
),
......
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