예제 #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)
예제 #2
0
파일: browseable.py 프로젝트: zeantsoi/drf2
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)
예제 #3
0
파일: basic.py 프로젝트: zeantsoi/drf2
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)
예제 #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
예제 #5
0
파일: browseable.py 프로젝트: zeantsoi/drf2
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)
예제 #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__'
예제 #7
0
파일: basic.py 프로젝트: zeantsoi/drf2
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)        
예제 #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)
예제 #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__'
예제 #10
0
파일: basic.py 프로젝트: zeantsoi/drf2
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)
예제 #11
0
파일: basic.py 프로젝트: zeantsoi/test
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)
예제 #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
예제 #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)
예제 #14
0
 def get(self, request, pk, format=None):
     campaign = self.get_object(pk)
     serializer = CampaignSerializer(campaign)
     return Response(serializer.data)
예제 #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)
예제 #16
0
 def get(self, request, format=None):
     campaigns = Campaign.objects.all()
     serializer = CampaignSerializer(campaigns, many=True)
     return Response(serializer.data)