def task_completed(request, id): try: if request.method == "POST" and request.is_ajax(): proposal = get_object_or_404(Proposal, pk=id) proposal.task.job_status = 'Completed' proposal.user.profile.total_job_done += 1 proposal.status = 'completed' proposal.task.save() proposal.user.profile.save() proposal.save() # calculate success rate and overall profile rating user = request.user user.profile.success_rate = user.profile.calculate_success_rate() user.profile.rating = user.profile.calculate_rating() user.profile.save() notification_handler(request.user, proposal.task.user, Notification.TASK_COMPLETED, target=proposal.task) return JsonResponse({"success": True, "msg": "Job Completed."}) else: raise Http404("Invalid request") except Exception as e: raise Http404(str(e))
def post_reviews(request, id): try: if request.method == "POST" and request.is_ajax(): proposal = get_object_or_404(Proposal, pk=id) if not request.user.tasks.filter(proposals=proposal).exists(): return JsonResponse({ "success": False, 'errors': "You are not permitted to perform this action." }) budget = request.POST.get('onBudget') time = request.POST.get('onTime') rating = request.POST.get('rating') comment = request.POST.get('comment') proposal.onBudget = True if budget == "yes" else False proposal.onTime = True if time == "yes" else False proposal.rating = rating proposal.comment = comment proposal.save() notification_handler(request.user, proposal.user, Notification.POST_REVIEW, target=proposal.task) return JsonResponse({"success": True, 'msg': "Review submitted"}) else: raise Http404("Invalid request") except Exception as e: raise Http404(str(e))
def cancel_task(request, id): try: if request.method == "POST" and request.is_ajax(): proposal = get_object_or_404(Proposal, pk=id) proposal.task.job_status = "Pending" proposal.status = "cancelled" proposal.task.save() proposal.save() # calculate success rate and overall profile rating user = request.user user.profile.success_rate = user.profile.calculate_success_rate() user.profile.rating = user.profile.calculate_rating() user.profile.save() notification_handler(request.user, proposal.task.user, Notification.TASK_CANCELLED, target=proposal.task) return JsonResponse({"success": True, "msg": "Job cancelled."}) else: raise Http404("Invalid request") except Exception as e: raise Http404(str(e))
def update(self, request, *args, **kwargs): instance = self.get_object() task = instance.task if task.user != self.request.user: return Response( {"detail": "You are not permitted to perform this action."}, status=403) if task.proposals.filter(status="accepted").exists(): return Response( { "detail": "Sorry your are not assign this job to multiple user." }, status=403) if task.proposals.filter(status='completed').exists(): return Response({"detail": "Your job is completed"}, status=403) instance.user.profile.total_hired += 1 instance.task.job_status = 'In Progress' instance.status = "accepted" instance.user.profile.save() instance.task.save() instance.save() notification_handler(self.request.user, instance.user, Notification.ACCEPT_OFFER, target=instance) return Response({"detail": "Proposal accepted"}, status=200)
def accept_proposal(request, id): try: proposal = get_object_or_404(Proposal, pk=id) if proposal.task.user != request.user and request.is_ajax(): return JsonResponse({ "success": False, "errors": "You are not permitted to perform this action." }) task = proposal.task if task.proposals.filter( status='accepted').exists() and request.is_ajax(): return JsonResponse({ "success": False, "errors": "Sorry your are not assign this job to multiple user." }) if task.proposals.filter( status='completed').exists() and request.is_ajax(): return JsonResponse({ "success": False, "errors": "Your job is completed" }) if request.method == "POST" and request.is_ajax(): proposal.user.profile.total_hired += 1 proposal.task.job_status = 'In Progress' proposal.status = "accepted" proposal.user.profile.save() proposal.task.save() proposal.save() notification_handler(request.user, proposal.user, Notification.ACCEPT_OFFER, target=proposal) return JsonResponse({ "success": True, "msg": "Proposal accepted.", "url": redirect('my_tasks').url }) if request.method == "POST" and not request.is_ajax(): raise Http404("Invalid request.") return HttpResponseBadRequest() except Exception as e: raise Http404(str(e))
def update(self, request, *args, **kwargs): instance = self.get_object() if instance.task.user != self.request.user: return Response( {"detail": "You are not permitted to perform this action."}, status=403) serializer = self.get_serializer(instance, data=request.data) if serializer.is_valid(): serializer.save() notification_handler(self.request.user, instance.user, Notification.POST_REVIEW, target=instance.task) return Response(serializer.data, status=200) else: return Response(serializer.errors, status=400)
def update(self, request, *args, **kwargs): instance = self.get_object() if instance.status != "accepted": return Response( {"detail": "your proposal has not been accepted yet."}, status=403) instance.task.job_status = "Pending" instance.status = "cancelled" instance.task.save() instance.save() calculate_profile_rating(self.request.user) notification_handler(self.request.user, instance.task.user, Notification.TASK_CANCELLED, target=instance.task) return Response({"detail": "Job cancelled"}, status=200)
def update(self, request, *args, **kwargs): instance = self.get_object() if instance.status != "accepted": return Response( {"detail": "your proposal has not been accepted yet."}, status=403) instance.task.job_status = 'Completed' instance.user.profile.total_job_done += 1 instance.status = 'completed' instance.task.save() instance.user.profile.save() instance.save() calculate_profile_rating(self.request.user) notification_handler(self.request.user, instance.task.user, Notification.TASK_COMPLETED, target=instance.task) return Response({"detail": "Job Completed"}, status=200)