Updating view for different certificate statuses, error
This commit is contained in:
committed by
Carlos Andrés Rocha
parent
5529eecb85
commit
0481cf995f
@@ -1,10 +1,11 @@
|
||||
import logging
|
||||
from certificates.models import GeneratedCertificate
|
||||
from certificates.models import CertificateStatuses as status
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.http import HttpResponse
|
||||
import json
|
||||
|
||||
log = logging.getLogger("mitx.certificates")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@@ -12,6 +13,10 @@ def update_certificate(request):
|
||||
"""
|
||||
Will update GeneratedCertificate for a new certificate or
|
||||
modify an existing certificate entry.
|
||||
|
||||
See models.py for a state diagram of certificate states
|
||||
|
||||
This view should only ever be accessed by the xqueue server
|
||||
"""
|
||||
|
||||
if request.method == "POST":
|
||||
@@ -26,7 +31,7 @@ def update_certificate(request):
|
||||
key=xqueue_header['lms_key'])
|
||||
|
||||
except GeneratedCertificate.DoesNotExist:
|
||||
log.critical('Unable to lookup certificate\n'
|
||||
logger.critical('Unable to lookup certificate\n'
|
||||
'xqueue_body: {0}\n'
|
||||
'xqueue_header: {1}'.format(
|
||||
xqueue_body, xqueue_header))
|
||||
@@ -36,10 +41,23 @@ def update_certificate(request):
|
||||
'content': 'unable to lookup key'}),
|
||||
mimetype='application/json')
|
||||
|
||||
cert.download_uuid = xqueue_body['download_uuid']
|
||||
cert.verify_uuid = xqueue_body['download_uuid']
|
||||
cert.download_url = xqueue_body['url']
|
||||
cert.status = 'downloadable'
|
||||
if 'error' in xqueue_body:
|
||||
cert.status = status.error
|
||||
else:
|
||||
if cert.state in [status.generating, status.regenerating]:
|
||||
cert.download_uuid = xqueue_body['download_uuid']
|
||||
cert.verify_uuid = xqueue_body['verify_uuid']
|
||||
cert.download_url = xqueue_body['url']
|
||||
cert.status = status.downloadable
|
||||
elif cert.state in [status.deleting]:
|
||||
cert.status = status.deleted
|
||||
else:
|
||||
logger.critical('Invalid state for cert update: {0}'.format(
|
||||
cert.state))
|
||||
return HttpResponse(json.dumps({
|
||||
'return_code': 1,
|
||||
'content': 'invalid cert state'}),
|
||||
mimetype='application/json')
|
||||
cert.save()
|
||||
return HttpResponse(json.dumps({'return_code': 0}),
|
||||
mimetype='application/json')
|
||||
|
||||
Reference in New Issue
Block a user