mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
feat: Sortie des calculs des montants totaux de la partie configuration + revue du rendu [#18]
This commit is contained in:
@ -65,57 +65,6 @@ class SpecialityView(APIView):
|
||||
def delete(self, request, _id):
|
||||
return delete_object(Speciality, _id)
|
||||
|
||||
# Vues pour les réductions (Discount)
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class DiscountsView(APIView):
|
||||
def get(self, request):
|
||||
discountsList = Discount.objects.all()
|
||||
discounts_serializer = DiscountSerializer(discountsList, many=True)
|
||||
return JsonResponse(discounts_serializer.data, safe=False)
|
||||
|
||||
def post(self, request):
|
||||
discount_data = JSONParser().parse(request)
|
||||
discount_serializer = DiscountSerializer(data=discount_data)
|
||||
if discount_serializer.is_valid():
|
||||
discount_serializer.save()
|
||||
return JsonResponse(discount_serializer.data, safe=False, status=201)
|
||||
return JsonResponse(discount_serializer.errors, safe=False, status=400)
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class DiscountView(APIView):
|
||||
def get(self, request, _id):
|
||||
try:
|
||||
discount = Discount.objects.get(id=_id)
|
||||
discount_serializer = DiscountSerializer(discount)
|
||||
return JsonResponse(discount_serializer.data, safe=False)
|
||||
except Discount.DoesNotExist:
|
||||
return JsonResponse({'error': 'No object found'}, status=404)
|
||||
|
||||
def post(self, request):
|
||||
discount_data = JSONParser().parse(request)
|
||||
discount_serializer = DiscountSerializer(data=discount_data)
|
||||
if discount_serializer.is_valid():
|
||||
discount_serializer.save()
|
||||
return JsonResponse(discount_serializer.data, safe=False, status=201)
|
||||
return JsonResponse(discount_serializer.errors, safe=False, status=400)
|
||||
|
||||
def put(self, request, _id):
|
||||
discount_data = JSONParser().parse(request)
|
||||
try:
|
||||
discount = Discount.objects.get(id=_id)
|
||||
except Discount.DoesNotExist:
|
||||
return JsonResponse({'error': 'No object found'}, status=404)
|
||||
discount_serializer = DiscountSerializer(discount, data=discount_data, partial=True) # Utilisation de partial=True
|
||||
if discount_serializer.is_valid():
|
||||
discount_serializer.save()
|
||||
return JsonResponse(discount_serializer.data, safe=False)
|
||||
return JsonResponse(discount_serializer.errors, safe=False, status=400)
|
||||
|
||||
def delete(self, request, _id):
|
||||
return delete_object(Discount, _id)
|
||||
|
||||
class TeachersView(APIView):
|
||||
def get(self, request):
|
||||
teachersList=getAllObjects(Teacher)
|
||||
@ -263,7 +212,55 @@ class PlanningView(APIView):
|
||||
return JsonResponse(planning_serializer.errors, safe=False)
|
||||
|
||||
|
||||
# Vues pour les frais (Fee)
|
||||
# Vues pour les réductions (Discount)
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class DiscountsView(APIView):
|
||||
def get(self, request, _filter, *args, **kwargs):
|
||||
|
||||
if _filter not in ['registration', 'tuition']:
|
||||
return JsonResponse({"error": "Invalid type parameter. Must be 'registration' or 'tuition'."}, safe=False, status=400)
|
||||
|
||||
discount_type_value = 0 if _filter == 'registration' else 1
|
||||
discounts = Discount.objects.filter(type=discount_type_value)
|
||||
discounts_serializer = DiscountSerializer(discounts, many=True)
|
||||
|
||||
return JsonResponse(discounts_serializer.data, safe=False, status=200)
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class DiscountView(APIView):
|
||||
def get(self, request, _id):
|
||||
try:
|
||||
discount = Discount.objects.get(id=_id)
|
||||
discount_serializer = DiscountSerializer(discount)
|
||||
return JsonResponse(discount_serializer.data, safe=False)
|
||||
except Discount.DoesNotExist:
|
||||
return JsonResponse({'error': 'No object found'}, status=404)
|
||||
|
||||
def post(self, request):
|
||||
discount_data = JSONParser().parse(request)
|
||||
discount_serializer = DiscountSerializer(data=discount_data)
|
||||
if discount_serializer.is_valid():
|
||||
discount_serializer.save()
|
||||
return JsonResponse(discount_serializer.data, safe=False, status=201)
|
||||
return JsonResponse(discount_serializer.errors, safe=False, status=400)
|
||||
|
||||
def put(self, request, _id):
|
||||
discount_data = JSONParser().parse(request)
|
||||
try:
|
||||
discount = Discount.objects.get(id=_id)
|
||||
except Discount.DoesNotExist:
|
||||
return JsonResponse({'error': 'No object found'}, status=404)
|
||||
discount_serializer = DiscountSerializer(discount, data=discount_data, partial=True) # Utilisation de partial=True
|
||||
if discount_serializer.is_valid():
|
||||
discount_serializer.save()
|
||||
return JsonResponse(discount_serializer.data, safe=False)
|
||||
return JsonResponse(discount_serializer.errors, safe=False, status=400)
|
||||
|
||||
def delete(self, request, _id):
|
||||
return delete_object(Discount, _id)
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class FeesView(APIView):
|
||||
|
||||
Reference in New Issue
Block a user