def log_finished(self, request, pk=None, **kwargs):
"""
Create event log with status == "mk42.apps.core.constants.STATUS_FINISHED".
:param request: django request instance.
:type request: django.http.request.HttpRequest.
:param pk: event object primary key.
:type pk: unicode.
:param kwargs: additional args.
:type kwargs: dict.
:return: django rest framework response.
:rtype: rest_framework.response.Response.
"""
obj = self.get_object()
if request.user != obj.group.owner:
# only group owner can change event status
raise PermissionDenied(detail=_("You must be owner of this group to perform this action."))
log = obj.log_finished(**kwargs)
if not log:
# can't create event logs with status == "mk42.apps.core.constants.STATUS_FINISHED"
# if log with status == "mk42.apps.core.constants.STATUS_FINISHED" exist
# if log with status == "mk42.apps.core.constants.STATUS_CANCELED" exist
# or log with status == "mk42.apps.core.constants.STATUS_ONGOING" does not exist
raise PermissionDenied(detail=_("Can't change status to '{status}'.").format(**{"status": dict(obj.STATUS_CHOICES).get(obj.STATUS_FINISHED), }))
return Response({"detail": EventLogSerializer(instance=log, context={"request": request, }).data if log else None, })
评论列表
文章目录