Exemplo n.º 1
0
 def patch(self, request, format=None):
     if request.user.is_authenticated() and is_manager(request):
         user_id = request.user.id
         reward_id = request.POST['id']
         reward = Reward.objects.get(id=reward_id)
         reward_serializer = RewardSerializer(reward, data=request.data)
         if reward_serializer.is_valid():
             reward_serializer.save()
             return Response(reward_serializer.data)
     return Response(reward_serializer.errors,
                     status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
 def post(self, request, format=None):
     if request.user.is_authenticated() and is_manager(request):
         user_id = request.user.id
         user_profile = Profile.objects.get(user_id=user_id)
         org_id = user_profile.organization_id
         serializer = RewardSerializer(data=request.data,
                                       context={'org_id': org_id})
         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
class StuffSerializer(serializers.ModelSerializer):
    rewards = RewardSerializer(many=True)
    firm = FirmSerializer()

    class Meta:
        model = Stuff
        fields = '__all__'
Exemplo n.º 4
0
class OrderCreateSerializer(serializers.ModelSerializer):
    user = UserSerializer(required=False)
    reward = RewardSerializer(required=False)
    card = CardSerialiser(required=False)

    class Meta:
        model = Order
        fields = '__all__'
Exemplo n.º 5
0
class OrderSerializer(serializers.ModelSerializer):
    user = UserSerializer()
    reward = RewardSerializer()
    card = CardSerialiser()

    class Meta:
        model = Order
        fields = '__all__'
Exemplo n.º 6
0
 def get(self, request, format=None):
     if request.user.is_authenticated() and is_manager(request):
         uid = request.user.id
         user_profile = Profile.objects.get(user_id=uid)
         org_id = user_profile.organization_id
         rewards = Reward.objects.filter(
             organization_id=org_id).order_by('id')
         serializer = RewardSerializer(rewards, many=True)
         return Response(serializer.data)
     return Response(status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 7
0
class FacilitySerializer(serializers.ModelSerializer):
    followings = UserSerializer(many=True)
    facility_rewards = RewardSerializer(many=True)

    class Meta:
        model = Facility
        fields = [
            'name', 'facility_rewards', 'description', 'address1', 'address2',
            'address3', 'facility_type', 'homepage', 'imgurl', 'created_at',
            'followings'
        ]
Exemplo n.º 8
0
 def get(self, request, format=None):
     if request.user.is_authenticated and not is_manager(request):
         user_id = request.user.id
         rewards_id = Employee_Rewards.objects.filter(
             employee_id=user_id).values('reward_id')
         if rewards_id:
             rewards = Reward.objects.filter(
                 id__in=rewards_id).order_by('id')
             serializers = RewardSerializer(rewards, many=True)
             return Response(serializers.data)
         return Response(status=status.HTTP_200_OK)
     return Response(status=status.HTTP_200_OK)