Skip to content

Commit

Permalink
Merge pull request #126 from CMSTrackerDPG/#125
Browse files Browse the repository at this point in the history
  • Loading branch information
nothingface0 authored Apr 25, 2022
2 parents 41a3f55 + 7d51b95 commit ee80424
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions certifier/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ def promoteToReference(request, run_number, reco):
"""
try:
runReconstruction = RunReconstruction.objects.get(
run__run_number=run_number, reconstruction=reco)
run__run_number=run_number, reconstruction=reco
)
except RunReconstruction.DoesNotExist as run_reco_does_not_exist:
raise Http404(
f"The run {run_number} doesn't exist") from run_reco_does_not_exist
f"The run {run_number} doesn't exist"
) from run_reco_does_not_exist

if request.method == "POST":
runReconstruction.promote_to_reference()
return HttpResponseRedirect("/shiftleader/")

return render(request, "certifier/promote.html",
{"runReconstruction": runReconstruction})
return render(
request, "certifier/promote.html", {"runReconstruction": runReconstruction}
)


@login_required
Expand Down Expand Up @@ -77,21 +80,18 @@ def certify(request, run_number, reco=None):
runreconstruction__run__run_number=run_number,
runreconstruction__reconstruction=reco,
)
if request.user != TrackerCertification.user:
if request.user != certification.user:
print(request.user, certification.user.username)
msg = f"Reconstruction {run_number} {reco} is already certified by another user"
logger.warning(msg)
return render(
request,
"certifier/http_error.html",
context={
"error_num": 400,
"message": msg
},
context={"error_num": 400, "message": msg},
)
except TrackerCertification.DoesNotExist as e:
# Means that this specific certification does not exist yet
logger.debug(
f"Certification for {run_number} {reco} does not exist yet")
logger.debug(f"Certification for {run_number} {reco} does not exist yet")

# From openruns colored boxes
if request.META.get("HTTP_X_REQUESTED_WITH") == "XMLHttpRequest":
Expand Down Expand Up @@ -135,11 +135,11 @@ def certify(request, run_number, reco=None):
# print(request)
except (IndexError, ConnectionError) as e:
context = {"message": "Run {} does not exist".format(run_number)}
logger.error(e)
logger.error(f"{context['message']} ({repr(e)})")
return render(request, "certifier/404.html", context)
except Exception as e:
context = {"message": e}
logger.exception(e)
logger.exception(repr(e))
return render(request, "certifier/404.html", context)

if not reco:
Expand All @@ -149,10 +149,12 @@ def certify(request, run_number, reco=None):
if request.method == "POST":
try:
runReconstruction = RunReconstruction.objects.get(
run__run_number=run_number, reconstruction=reco)
run__run_number=run_number, reconstruction=reco
)
except RunReconstruction.DoesNotExist:
runReconstruction = RunReconstruction.objects.create(
run=run, reconstruction=reco)
run=run, reconstruction=reco
)

try:
dataset = Dataset.objects.get(dataset=dataset)
Expand All @@ -171,7 +173,8 @@ def certify(request, run_number, reco=None):
# redirect to a new URL:
try:
trackerCertification = TrackerCertification.objects.get(
runreconstruction=runReconstruction)
runreconstruction=runReconstruction
)
except TrackerCertification.DoesNotExist:
formToSave = form.save(commit=False)
formToSave.runreconstruction = runReconstruction
Expand Down

0 comments on commit ee80424

Please sign in to comment.