def put(self, request, pk, format=None): campaign = self.get_object(pk) serializer = CampaignSerializer(campaign, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def campaign_list(request): """ List all campaigns, or create a new campaign. """ if request.method == 'GET': campaigns = Campaign.objects.all() serializer = CampaignSerializer(campaigns, many=True) return Response(serializer.data) elif request.method == 'POST': serializer = CampaignSerializer(data=request.DATA) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def campaign_list(request): """ List all campaigns, or create a new campaign. """ if request.method == 'GET': campaigns = Campaign.objects.all() serializer = CampaignSerializer(campaigns, many=True) return JSONResponse(serializer.data) elif request.method == 'POST': data = JSONParser().parse(request) serializer = CampaignSerializer(data=data) if serializer.is_valid(): serializer.save() return JSONResponse(serializer.data, status=201) return JSONResponse(serializer.errors, status=400)
class ReportOrderSerializer(serializers.ModelSerializer): sale_rep = MeSerializer() packages = PackageSerializer(many=True) campaign = CampaignSerializer() contacts = ContactSerializer() income = serializers.SerializerMethodField() class Meta: model = models.Order fields = '__all__' def get_income(self, instance): return 1
def campaign_detail(request, pk): """ Retrieve, update, or delete a campaign. """ try: campaign = Campaign.objects.get(pk=pk) except Campaign.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': serializer = CampaignSerializer(campaign) return Response(serializer.data) elif request.method == 'PUT': serializer = CampaignSerializer(campaign, data=request.DATA) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) elif request.method == 'DELETE': campaign.delete() return Response(status=status.HTTP_204_NO_CONTENT)
class OrderSaleRepChartSerializer(serializers.ModelSerializer): contacts = ContactSerializer() sale_rep = MeSerializer() packages = PackageSerializer(many=True) campaign = CampaignSerializer() step_details = StepDetailWithoutOrderSerializer(many=True) history = OrderHistorySerializer(many=True) licenses = LicenseSerializer(many=True) lifetime_licenses = LifetimeLicenseSerializer(many=True) # order_packages = Order class Meta: model = models.Order fields = '__all__'
def campaign_detail(request, pk): """ Retrieve, update, or delete a campaign. """ try: campaign = Campaign.objects.get(pk=pk) except Campaign.DoesNotExist: return HttpResponse(status=404) if request.method == 'GET': serializer = CampaignSerializer(campaign) return JSONResponse(serializer.data) elif request.method == 'PUT': data = JSONParser().parse(request) serializer = CampaignSerializer(campaign, data=data) if serializer.is_valid(): serializer.save() return JSONResponse(serializer.data) return JSONResponse(serializer.errors, status=400) elif request.method == 'DELETE': campaign.delete() return HttpResponse(status=204)
def campaign_list(request): """ List all campaigns, or create a new campaign. """ if request.method == 'GET': campaigns = Campaign.objects.all() serializer = CampaignSerializer(campaigns, many=True) return Response(serializer.data) elif request.method == 'POST': serializer = CampaignSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
class OrderChartSerializer(serializers.ModelSerializer): contacts = ContactSerializer() sale_rep = MeSerializer() packages = PackageSerializer(many=True) campaign = CampaignSerializer() step_details = StepDetailWithoutOrderSerializer(many=True) history = OrderHistorySerializer(many=True) licenses = LicenseSerializer(many=True) lifetime_licenses = LifetimeLicenseSerializer(many=True) amount = serializers.IntegerField(required=False) month_group = serializers.IntegerField() # order_packages = Order class Meta: model = models.Order fields = '__all__'
def campaign_detail(request, pk): try: campaign = Campaign.objects.get(pk=pk) except Campaign.DoesNotExist: return HttpResponse(status=404) if request.method == 'GET': serializer = CampaignSerializer(campaign) return JSONResponse(serializer.data) elif request.method == 'PUT': data = JSONParser().parse(request) serializer = CampaignSerializer(campaign, data=data) if serializer.is_valid(): serializer.save() return JSONResponse(serializer.data) return JSONResponse(serializer.errors, status=400) elif request.method == 'DELETE': campaign.delete() return HttpResponse(status=204)
class OrderSerializer(serializers.ModelSerializer): contacts = ContactSerializer() sale_rep = MeSerializer() packages = PackageSerializer(many=True) campaign = CampaignSerializer() step_details = StepDetailWithoutOrderSerializer(many=True) history = OrderHistorySerializer(many=True) all_histories = serializers.SerializerMethodField() licenses = LicenseSerializer(many=True) lifetime_licenses = LifetimeLicenseSerializer(many=True) # order_packages = Order class Meta: model = models.Order fields = '__all__' def get_all_histories(self, instance): cur_contact = instance.contacts histories = models.OrderHistory.objects.filter( order__contacts=cur_contact) serializer = OrderHistorySerializer(histories, many=True) return serializer.data
def campaign_detail(request, pk): """ Retrieve, update or delete a campaign instance. """ try: campaign = Campaign.objects.get(pk=pk) except Campaign.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': serializer = CampaignSerializer(campaign) return Response(serializer.data) elif request.method == 'PUT': serializer = CampaignSerializer(campaign, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) elif request.method == 'DELETE': campaign.delete() return Response(status=status.HTTP_204_NO_CONTENT)
def get(self, request, pk, format=None): campaign = self.get_object(pk) serializer = CampaignSerializer(campaign) return Response(serializer.data)
def post(self, request, format=None): serializer = CampaignSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, format=None): campaigns = Campaign.objects.all() serializer = CampaignSerializer(campaigns, many=True) return Response(serializer.data)