def submission_approve(request): project_id = request.POST.get("project_id") print project_id # update submission status submission = get_object_or_404(Submission, pk=project_id) print submission submission.approved = True submission.save() # clear relevant notification try: notification = get_object_or_404(Notification, label=submission.project.name, type=1) print notification notification.delete() except Http404: pass info(request, _("Submission approved")) event = {"time": datetime.now(), "project_id": int(submission.project.id), "message": _("Submission approved")} create_log(event) # generate PDF html2pdf( request.build_absolute_uri(submission.get_pdf_url()), "D:/workspace/greenbuilding/media/submission/", project_id ) return HttpResponse(json.dumps("OK"), content_type="application/json")
def project_selection(request, project_id): user = get_object_or_404(User, pk=request.user.pk) project = get_object_or_404(Project, pk=project_id) if request.method == "POST": print request.POST.get("user") thumbs_up = request.POST.get("thumbsUp") user_id = request.session["_auth_user_id"] print user_id vote_status = _("Thumbs Up") try: selection = get_object_or_404(Selection, user_id=user_id, project_id=project_id) except Http404: selection = Selection() selection.user = user selection.project = project if thumbs_up == "true": selection.passed = True else: selection.passed = False vote_status = _("Thumbs Down") selection.date = datetime.utcnow() selection.save() event = { "time": datetime.now(), "project_id": int(project_id), "message": u"{} ".format(user.username) + _("Expert has voted") + u":{}".format(vote_status), } create_log(event) query_set = Selection.objects.filter(pk=selection.id) data = serializers.serialize("json", query_set) print data return HttpResponse(data, content_type="application/json") # return HttpResponse(json.dumps(selection), content_type="application/json") else: selections = Selection.objects.filter(project_id=project_id) print selections print user.has_perm("enterprise.approve_submission") print user.has_perm("enterprise.add_submission") return render( request, "project_selection.html", {"selections": selections, "project": project, "project_id": project_id} )
def submission_commit(request): project_id = request.POST.get("project_id") print project_id submission = get_object_or_404(Submission, pk=project_id) project = submission.project.name messages = "OK" try: notification = get_object_or_404(Notification, label=project, type=1) print notification messages = _("Submission already committed.") except Http404: n = Notification(label=project, type=1, project_url=submission.get_absolute_url()) n.save() event = {"time": datetime.now(), "project_id": int(project_id), "message": _("Submission is committed now")} create_log(event) return HttpResponse(json.dumps(messages), content_type="application/json")
def create_submission(request, template="create_project.html"): project_id = request.GET.get("project_id") print "create submission for project:{}".format(project_id) form = SubmissionForm(request.POST or None) if project_id is not None: project = get_object_or_404(Project, pk=project_id) form = SubmissionForm(request.POST or None, initial={"project": project}) if request.method == "POST" and form.is_valid(): new_submission = form.save() print new_submission if project_id is None: project_id = new_submission.project.id event = {"time": datetime.now(), "project_id": int(project_id), "message": _("Create Submission")} create_log(event) return redirect("enterprise.submissions") context = {"form": form, "title": _("Create Submission")} return render(request, template, context)
def review_commit(request): project_id = request.POST.get("project_id") print project_id review = get_object_or_404(ApplicationReview, pk=project_id) project = review.project.name messages = "OK" try: notification = get_object_or_404(Notification, label=project, type=2) print notification messages = _("ApplicationReview already committed.") except Http404: n = Notification(label=project, type=2, project_url=review.get_absolute_url()) n.save() event = { "time": datetime.now(), "project_id": int(review.project.id), "message": _("ApplicationReview is committed now"), } create_log(event) return HttpResponse(json.dumps(messages), content_type="application/json")
def review_deny(request, project_id): # project_id = request.POST.get('project_id') reason = request.POST.get("reason") print project_id review = get_object_or_404(ApplicationReview, pk=project_id) review.approved = False review.save() try: notification = get_object_or_404(Notification, label=review.project.name, type=1) notification.delete() except Http404: pass info(request, _("ApplicatonReview denied")) event = { "time": datetime.now(), "project_id": int(review.project.id), "message": _("ApplicatonReview denied") + u":{}".format(reason), } create_log(event) return HttpResponse(json.dumps("OK"), content_type="application/json")
def review_approve(request, project_id): # project_id = request.POST.get('project_id') print project_id # update review status review = get_object_or_404(ApplicationReview, pk=project_id) print review review.approved = True review.save() try: # clear relevant notification notification = get_object_or_404(Notification, label=review.project.name, type=2) notification.delete() except Http404: pass info(request, _("ApplicatonReview approved")) event = {"time": datetime.now(), "project_id": int(review.project.id), "message": _("ApplicatonReview approved")} create_log(event) # generate PDF html2pdf(request.build_absolute_uri(review.get_pdf_url()), "D:/workspace/greenbuilding/media/review/", project_id) return HttpResponse(json.dumps("OK"), content_type="application/json")
def create_review(request, template="create_project.html"): project_id = request.GET.get("project_id") print "create application review for project:{}".format(project_id) project = None if project_id is not None: project = get_object_or_404(Project, pk=project_id) if request.method == "POST": # Must pass request.FILES to ModelForm so it can handle file upload form = ReviewForm(request.POST, request.FILES, initial={"project": project}) new_review = form.save() print new_review if project_id is None: project_id = new_review.project.id event = {"time": datetime.now(), "project_id": int(project_id), "message": _("Create ApplicationReview")} create_log(event) return redirect("enterprise.reviews") else: form = ReviewForm(initial={"project": project}) context = {"form": form, "title": _("Create ApplicationReview")} return render(request, template, context)
def submission_deny(request): project_id = request.POST.get("project_id") reason = request.POST.get("reason") print project_id submission = get_object_or_404(Submission, pk=project_id) submission.approved = False submission.save() try: notification = get_object_or_404(Notification, label=submission.project.name, type=1) notification.delete() except Http404: pass info(request, _("Submission denied")) event = { "time": datetime.now(), "project_id": int(submission.project.id), "message": _("Submission denied") + u":{}".format(reason), } create_log(event) return HttpResponse(json.dumps("OK"), content_type="application/json")
def create_log(bid): body = json.loads(request.data) if not is_valid(body, [("timestamp", int), ("challenger_hp", int), ("opponent_hp", int), ("action", str)]): return failure_response("Provide a proper request of the form {timestamp: number, " "challenger_hp: number, opponent_hp: number, action: string}", 400) log = dao.create_log( timestamp=body.get("timestamp"), challenger_hp=body.get("challenger_hp"), opponent_hp=body.get("opponent_hp"), action=body.get("action"), bid=bid ) if log is None: return failure_response("The provided battle does not exist!") return success_response(log.serialize(), 201)