Exemple #1
0
    def create(self, request, *args, **kwargs):
        user = request.user
        couple = CoupleController.get_couple(request.user)

        try:
            album_pk = request.DATA.get('album')
            album = PhotoAlbum.objects.get(pk=album_pk)
        except:
            album = None

        image = request.FILES.get('image')

        if image is None:
            return Response({'success': False, 'message': _(u'사진 업로드 실패')}, status=status.HTTP_400_BAD_REQUEST)

        try:
            description = request.DATA.get('description')
            description = sanitize(description)
        except:
            description = None

        photo = Photo.objects.create(
            user=user, couple=couple, album=album, image=image, description=description)

        mission_handler = MissionHandler(user)
        mission_handler.new_cleared_missions()

        return Response({'success': True, 'data': {'photo_pk': photo.pk}}, status=status.HTTP_201_CREATED)
Exemple #2
0
    def create(self, request, *args, **kwargs):
        user = request.user
        couple = CoupleController.get_couple(user)
        receiver = CoupleController.get_partner(couple, user)
        content = request.DATA.get('content')
        content = sanitize(content)
        paper_type = request.DATA.get('paper_type')
        if not paper_type:
            paper_type = Letter.PLAIN
        else:
            try:
                paper_type = int(paper_type)
            except:
                message = _(u'편지지 타입이 올바르지 않습니다.')
                return Response({'success': False, 'message': message}, status=status.HTTP_400_BAD_REQUEST)

        letter = Letter.objects.create(
            user=user, couple=couple, receiver=receiver, content=content, paper_type=paper_type)

        mission_handler = MissionHandler(user)
        mission_handler.new_cleared_missions()

        return Response({'success': True, 'data': {'letter_pk': letter.pk}}, status=status.HTTP_201_CREATED)