def get_serializer(self, *args, **kwargs): kwargs['context'] = self.get_serializer_context() if is_user_a_tenant(self.request, raise_exception=False): kwargs['exclude_fields'] = ('having',) return TenantMealSerializer(*args, **kwargs) else: return TenantMealSerializer(*args, **kwargs)
def get_queryset(self): owner = is_user_a_owner(self.request, raise_exception=False) if owner: return TenantMeal.objects.filter(house__owner=owner) tenant = is_user_a_tenant(self.request, raise_exception=False) if tenant: return TenantMeal.objects.filter(house=tenant.current_booking.space.house)
def get_queryset(self): # returns all the check-ins of every current booking of spaces where space house owner = logged in owner owner = is_user_a_owner(self.request, raise_exception=False) if owner: return TenantLateCheckin.objects.filter(current_booking__space__house__owner=owner) # returns all the check-ins of logged in tenant tenant = is_user_a_tenant(self.request, raise_exception=True) if tenant: return TenantLateCheckin.objects.filter(current_booking=tenant.current_booking)
def has_permission(self, request, view): if not request.user.is_authenticated: return False tenant = is_user_a_tenant(request, raise_exception=False) # print("tenant is ", tenant) if tenant: return True else: return False
def create(self, request, *args, **kwargs): tenant = is_user_a_tenant(request, raise_exception=False) booking = get_object_or_404(Booking, tenant=tenant, moved_out=False) serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) self.perform_create(serializer=serializer, booking=booking) headers = self.get_success_headers(serializer.data) return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
def get_queryset(self): tenant = is_user_a_tenant(self.request, raise_exception=True) query_filter_params = { 'paid': 'paid', 'due_date__lte': 'due_date__lte', 'due_date__gte': 'due_date__gte', 'amount__lte': 'amount__lte', 'amount__gte': 'amount__gte' } extra_kwargs = get_filter_extra_kwargs(query_filter_params, self.request) return BillSplit.objects.filter(tenant=tenant, **extra_kwargs)
def tenant_accept_meal(request): tenant = is_user_a_tenant(request, raise_exception=True) required = ('meal',) if not all(request.data.get(field) for field in required): return Response({'error': "Incomplete fields provided!"}, status=status.HTTP_400_BAD_REQUEST) if tenant.current_booking.space.house.meals.filter(id=request.data['meal']): TenantMeal.objects.get(id=request.data['meal']).accepted_by.add(tenant) return Response({'status': 'success', 'message': 'Meal Accepted'}, status=status.HTTP_202_ACCEPTED) else: return Response({'status': 'error', 'message': "meal does not exist"}, status=status.HTTP_202_ACCEPTED)
def get_object(self): tenant = is_user_a_tenant(request=self.request, raise_exception=True) return get_object_or_404(TenantLateCheckin, current_booking__tenant=tenant, pk=self.kwargs.get('pk'))