event.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:mk42 作者: Peer-Lab 项目源码 文件源码
def log_canceled(self, request, pk=None, **kwargs):
        """
        Create event log with status == "mk42.apps.core.constants.STATUS_CANCELED".

        :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_canceled(**kwargs)

        if not log:
            # can't create event logs with status == "mk42.apps.core.constants.STATUS_CANCELED"
            # if log with status == "mk42.apps.core.constants.STATUS_PENDING" does not exist
            # or log with status == "mk42.apps.core.constants.STATUS_ONGOING" exist
            raise PermissionDenied(detail=_("Can't change status to '{status}'.").format(**{"status": dict(obj.STATUS_CHOICES).get(obj.STATUS_CANCELED), }))

        return Response({"detail": EventLogSerializer(instance=log, context={"request": request, }).data if log else None, })
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号