Commit 00ae822f by John Jarvis

Cleanup

parent 6b31db25
...@@ -16,14 +16,16 @@ on the course overview page. ...@@ -16,14 +16,16 @@ on the course overview page.
''' '''
class CertificateStatuses(object): class CertificateStatuses(object):
unavailable='unavailable' unavailable = 'unavailable'
generating='generating' generating = 'generating'
regenerating='regenerating' regenerating = 'regenerating'
deleting='deleting' deleting = 'deleting'
deleted='deleted' deleted = 'deleted'
downloadable='downloadable' downloadable = 'downloadable'
error='error' error = 'error'
class GeneratedCertificate(models.Model): class GeneratedCertificate(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User)
...@@ -37,7 +39,8 @@ class GeneratedCertificate(models.Model): ...@@ -37,7 +39,8 @@ class GeneratedCertificate(models.Model):
status = models.CharField(max_length=32, default='unavailable') status = models.CharField(max_length=32, default='unavailable')
class Meta: class Meta:
unique_together= (('user', 'course_id'),) unique_together = (('user', 'course_id'),)
def certificate_status_for_student(student, course_id): def certificate_status_for_student(student, course_id):
''' '''
......
from django.utils.simplejson import dumps
from django.core.management.base import BaseCommand, CommandError
from certificates.models import GeneratedCertificate from certificates.models import GeneratedCertificate
from certificates.models import certificate_status_for_student from certificates.models import certificate_status_for_student
from certificates.models import CertificateStatuses as status from certificates.models import CertificateStatuses as status
from courseware import grades, courses from courseware import grades, courses
from django.contrib.auth.models import User
from django.test.client import RequestFactory from django.test.client import RequestFactory
from capa.xqueue_interface import XQueueInterface from capa.xqueue_interface import XQueueInterface
from capa.xqueue_interface import make_xheader, make_hashkey from capa.xqueue_interface import make_xheader, make_hashkey
from django.conf import settings from django.conf import settings
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
from student.models import UserProfile from student.models import UserProfile
from django.conf import settings
import json import json
import random import random
import logging
class XQueueCertInterface(object):
log = logging.getLogger("mitx.certificates") class XQueueCertInterface(object):
def __init__(self, request=None): def __init__(self, request=None):
...@@ -36,14 +30,12 @@ class XQueueCertInterface(object): ...@@ -36,14 +30,12 @@ class XQueueCertInterface(object):
else: else:
self.request = request self.request = request
self.xqueue_interface = XQueueInterface( self.xqueue_interface = XQueueInterface(
settings.XQUEUE_INTERFACE['url'], settings.XQUEUE_INTERFACE['url'],
settings.XQUEUE_INTERFACE['django_auth'], settings.XQUEUE_INTERFACE['django_auth'],
requests_auth, requests_auth,
) )
def regen_cert(self, student, course_id): def regen_cert(self, student, course_id):
""" """
...@@ -86,15 +78,16 @@ class XQueueCertInterface(object): ...@@ -86,15 +78,16 @@ class XQueueCertInterface(object):
'name': profile.name, 'name': profile.name,
} }
key = cert.key key = cert.key
xheader = make_xheader('http://sandbox-jrjarvis-001.m.edx.org/certificate', key, 'test-pull') # TODO - this needs to be read from settings
xheader = make_xheader(
'http://sandbox-jrjarvis-001.m.edx.org/certificate',
key, 'test-pull')
(error, msg) = self.xqueue_interface.send_to_queue(header=xheader, (error, msg) = self.xqueue_interface.send_to_queue(header=xheader,
body=json.dumps(contents)) body=json.dumps(contents))
return cert_status return cert_status
def remove_cert(self, student, course_id): def remove_cert(self, student, course_id):
""" """
...@@ -121,7 +114,6 @@ class XQueueCertInterface(object): ...@@ -121,7 +114,6 @@ class XQueueCertInterface(object):
cert = GeneratedCertificate.objects.get( cert = GeneratedCertificate.objects.get(
user=student, course_id=course_id) user=student, course_id=course_id)
username = cert.user.username
cert.status = status.deleting cert.status = status.deleting
cert.save() cert.save()
...@@ -132,15 +124,16 @@ class XQueueCertInterface(object): ...@@ -132,15 +124,16 @@ class XQueueCertInterface(object):
'username': cert.user.username, 'username': cert.user.username,
} }
key = cert.key key = cert.key
xheader = make_xheader('http://sandbox-jrjarvis-001.m.edx.org/certificate', key, 'test-pull') # TODO - this needs to be read from settings
xheader = make_xheader(
'http://sandbox-jrjarvis-001.m.edx.org/certificate',
key, 'test-pull')
(error, msg) = self.xqueue_interface.send_to_queue(header=xheader, (error, msg) = self.xqueue_interface.send_to_queue(header=xheader,
body=json.dumps(contents)) body=json.dumps(contents))
return cert_status return cert_status
def add_cert_to_queue(self, student, course_id): def add_cert_to_queue(self, student, course_id):
""" """
...@@ -169,7 +162,6 @@ class XQueueCertInterface(object): ...@@ -169,7 +162,6 @@ class XQueueCertInterface(object):
cert_status = certificate_status_for_student( cert_status = certificate_status_for_student(
student, course_id)['status'] student, course_id)['status']
if cert_status in VALID_STATUSES: if cert_status in VALID_STATUSES:
# grade the student # grade the student
course = courses.get_course_by_id(course_id) course = courses.get_course_by_id(course_id)
...@@ -195,10 +187,13 @@ class XQueueCertInterface(object): ...@@ -195,10 +187,13 @@ class XQueueCertInterface(object):
'course_id': course_id, 'course_id': course_id,
'name': profile.name, 'name': profile.name,
} }
xheader = make_xheader('http://sandbox-jrjarvis-001.m.edx.org/update_certificate?{0}'.format(key), key, 'test-pull') # TODO - this needs to be read from settings
xheader = make_xheader(
'http://sandbox-jrjarvis-001.m.edx.org/'
'update_certificate?{0}'.format(key), key, 'test-pull')
(error, msg) = self.xqueue_interface.send_to_queue( (error, msg) = self.xqueue_interface.send_to_queue(
header=xheader, body=json.dumps(contents)) header=xheader, body=json.dumps(contents))
if error: if error:
log.critical('Unable to send message') raise Exception('Unable to send queue message')
return cert_status return cert_status
...@@ -6,6 +6,7 @@ import json ...@@ -6,6 +6,7 @@ import json
log = logging.getLogger("mitx.certificates") log = logging.getLogger("mitx.certificates")
@csrf_exempt @csrf_exempt
def update_certificate(request): def update_certificate(request):
""" """
...@@ -42,5 +43,3 @@ def update_certificate(request): ...@@ -42,5 +43,3 @@ def update_certificate(request):
cert.save() cert.save()
return HttpResponse(json.dumps({'return_code': 0}), return HttpResponse(json.dumps({'return_code': 0}),
mimetype='application/json') mimetype='application/json')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment