Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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__'
Exemplo n.º 7
0
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)        
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
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__'
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
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
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
 def get(self, request, pk, format=None):
     campaign = self.get_object(pk)
     serializer = CampaignSerializer(campaign)
     return Response(serializer.data)
Exemplo n.º 15
0
 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)
Exemplo n.º 16
0
 def get(self, request, format=None):
     campaigns = Campaign.objects.all()
     serializer = CampaignSerializer(campaigns, many=True)
     return Response(serializer.data)