Ejemplo n.º 1
0
 def post(self, request, *args, **kwargs):
     category_id = self.request.query_params.get('category')
     category = Category.objects.filter(id=category_id)
     if category.exists() and len(
             category) == 1 and category[0].user == self.request.user:
         request.data['category'] = category_id
         request.data['user'] = self.request.user.pk
         results = self._save(request, *args, **kwargs)
         if results:
             return Response(results, status=status.HTTP_201_CREATED)
         raise ServerException("URL이 존재하지 않습니다.")
     raise ServerException('카테고리가 존재하지 않거나 해당 카테고리에 대한 권한이 존재하지 않습니다.')
Ejemplo n.º 2
0
    def move(self, instance, new_order):
        queryset = self.get_queryset()
        user = instance.user

        if new_order < 1 or self.get_my_last_order(user) < new_order:
            raise ServerException("잘못된 order 입니다.")

        with transaction.atomic():
            if instance.order > new_order:
                queryset.filter(
                    user=user,
                    order__lt=instance.order,
                    order__gte=new_order
                    # ).exclude(
                    #     pk=obj.pk
                ).update(
                    order=F('order') + 1
                )
            else:
                queryset.filter(
                    user=user,
                    order__lte=new_order,
                    order__gt=instance.order
                    # ).exclude(
                    #     pk=obj.pk
                ).update(
                    order=F('order') - 1
                )
            instance.order = new_order
            instance.save()
        return instance
Ejemplo n.º 3
0
 def reformat_string_to_datetime(time):
     try:
         _datetime = datetime.strptime(
             f"{time['year']}-{time['month']}-{time['day']} {time['hour']}:{time['minute']}",
             '%Y-%m-%d %H:%M')
     except Exception as e:
         raise ServerException('예약시간 형식이 올바르지 않습니다.')
     else:
         return _datetime
Ejemplo n.º 4
0
 def post(self, request):
     refresh_token = request.data.get('refresh')
     try:
         token = RefreshToken(refresh_token)
     except Exception:
         raise ServerException('유효하지 않은 Refresh 토큰입니다.')
     token.blacklist()
     logout(self.request)
     return Response({
         'logout': True,
         'message': '해당 Refresh 토큰은 이제 사용할 수 없습니다.'
     })
Ejemplo n.º 5
0
    def update(self, instance, validated_data):
        email = validated_data.get('email', None)
        password = validated_data.pop('password', None)

        if email is not None and validated_data['email'] != instance.email:
            from server.exceptions import ServerException
            raise ServerException("이메일은 수정할 수 없습니다.")

        for (key, value) in validated_data.items():
            setattr(instance, key, value)

        if password is not None:
            instance.set_password(password)

        instance.save()

        return instance
Ejemplo n.º 6
0
 def create(self, validated_data):
     current_time = datetime.now(timezone(timedelta(hours=9)))
     if validated_data['reserved_time'] < current_time:
         raise ServerException('예약시간이 올바르지 않습니다.')
     return super().create(validated_data)
Ejemplo n.º 7
0
 def update(self, instance, validated_data):
     if validated_data.get('path'):
         raise ServerException('URL은 수정할 수 없습니다.')
     return super().update(instance, validated_data)
Ejemplo n.º 8
0
 def put(self, request, *args, **kwargs):
     raise ServerException('PUT Method는 허용되지 않습니다.')