Exemple #1
0
    def read(self, request):
        if not request.user.is_authenticated():
            return {}
        try:
            profile = MServeProfile.objects.get(user=request.user)
            return profile

        except MServeProfile.DoesNotExist:
            logging.info("PortalProfile Does not exist for this user!")
            mserve_profile = MServeProfile(user=request.user)
            mserve_profile.save()
            return mserve_profile
Exemple #2
0
    def create(self, request):
        if not request.user.is_authenticated():
            response = HttpResponse("Not Authorised.")
            response.status_code = 401
            return response

        try:
            profile = MServeProfile.objects.get(user=request.user)

        except MServeProfile.DoesNotExist:
            logging.info("PortalProfile Does not exist for this user!")
            profile = MServeProfile(user=request.user)
            profile.save()

        srform = ServiceRequestForm(request.POST)
        if srform.is_valid():
            servicerequest = srform.save()
            profile.servicerequests.add(servicerequest)
            profile.save()
            return servicerequest
        else:
            response = rc.BAD_REQUEST
            response.write(srform.as_p())
            return response
Exemple #3
0
    def read(self, request, servicerequestid=None):

        if request.user.is_staff:
            if servicerequestid:
                return ServiceRequest.objects.get(id=servicerequestid)
            else:
                return ServiceRequest.objects.all()
        if not request.user.is_authenticated():
            response = HttpResponse("Not Authorised.")
            response.status_code = 401
            return response
        try:
            profile = MServeProfile.objects.get(user=request.user)

        except MServeProfile.DoesNotExist:
            logging.info("PortalProfile Does not exist for this user!")
            profile = MServeProfile(user=request.user)
            profile.save()

        if servicerequestid:
            return ServiceRequest.objects.filter(
                            profile=profile, id=servicerequestid)
        else:
            return ServiceRequest.objects.filter(profile=profile)