Cleanup and django-admin commands
This commit is contained in:
committed by
Carlos Andrés Rocha
parent
35acbc840e
commit
2c41b94d11
@@ -0,0 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from certificates.models import GeneratedCertificate
|
||||
from certificates.queue import XQueueCertInterface
|
||||
from django.contrib.auth.models import User
|
||||
from student.models import UserProfile
|
||||
import sys
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
help = """
|
||||
Looks for names that have unicode characters
|
||||
and queues them up for a certificate request
|
||||
"""
|
||||
|
||||
def handle(self, *args, **options):
|
||||
course_id = 'BerkeleyX/CS169.1x/2012_Fall'
|
||||
|
||||
enrolled_students = User.objects.filter(
|
||||
courseenrollment__course_id=course_id).prefetch_related(
|
||||
"groups").order_by('username')
|
||||
xq = XQueueCertInterface()
|
||||
print "Looking for unusual names.."
|
||||
for student in enrolled_students:
|
||||
if certificate_status_for_student(
|
||||
student, course_id)['status'] == 'unavailable':
|
||||
continue
|
||||
name = UserProfile.objects.get(user=student).name
|
||||
for c in name:
|
||||
if ord(c) >= 0x200:
|
||||
ret = xq.add_cert(student, course_id)
|
||||
if ret == 'generating':
|
||||
print 'generating for {0}'.format(student)
|
||||
break
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from certificates.models import GeneratedCertificate
|
||||
from certificates.models import certificate_status_for_student
|
||||
from certificates.queue import XQueueCertInterface
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
@@ -13,22 +14,23 @@ class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
||||
course_id = 'BerkeleyX/CS169.1x/2012_Fall'
|
||||
help = """
|
||||
Find all students that have need certificates
|
||||
and put certificate requests on the queue
|
||||
|
||||
enrolled_students = User.objects.filter(
|
||||
This is only for BerkeleyX/CS169.1x/2012_Fall
|
||||
"""
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
||||
course_id = 'BerkeleyX/CS169.1x/2012_Fall'
|
||||
enrolled_students = User.objects.filter(id=444894,
|
||||
courseenrollment__course_id=course_id).prefetch_related(
|
||||
"groups").order_by('username')
|
||||
xq = XQueueCertInterface()
|
||||
|
||||
# TODO (this is for debugging, remove)
|
||||
for c in GeneratedCertificate.objects.all():
|
||||
c.delete()
|
||||
|
||||
count = 0
|
||||
for student in enrolled_students:
|
||||
ret = xq.add_cert(student, course_id)
|
||||
if ret == 'generating':
|
||||
print 'generating for {0}'.format(student)
|
||||
count += 1
|
||||
if count > 10:
|
||||
break
|
||||
if certificate_status_for_student(
|
||||
student, course_id)['status'] == 'unavailable':
|
||||
ret = xq.add_cert(student, course_id)
|
||||
if ret == 'generating':
|
||||
print 'generating for {0}'.format(student)
|
||||
|
||||
@@ -37,6 +37,7 @@ State diagram:
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class CertificateStatuses(object):
|
||||
unavailable = 'unavailable'
|
||||
generating = 'generating'
|
||||
@@ -83,20 +84,23 @@ def certificate_status_for_student(student, course_id):
|
||||
|
||||
deleted - The certificate has been deleted.
|
||||
downloadable - The certificate is available for download.
|
||||
notpassing - The student was graded but is not passing
|
||||
|
||||
If the status is "downloadable", the dictionary also contains
|
||||
"download_url".
|
||||
|
||||
If the student has been graded, the dictionary also contains their grade for the course.
|
||||
If the student has been graded, the dictionary also contains their
|
||||
grade for the course.
|
||||
'''
|
||||
|
||||
try:
|
||||
generated_certificate = GeneratedCertificate.objects.get(
|
||||
user=student, course_id=course_id)
|
||||
d = {'status': generated_certificate.status,
|
||||
'grade' : generated_certificate.grade,}
|
||||
d = {'status': generated_certificate.status}
|
||||
if generated_certificate.grade:
|
||||
d['grade'] = generated_certificate.grade
|
||||
if generated_certificate.status == CertificateStatuses.downloadable:
|
||||
d['download_url'] = generated_certificate.download_url
|
||||
d['download_url'] = generated_certificate.download_url
|
||||
|
||||
return d
|
||||
except GeneratedCertificate.DoesNotExist:
|
||||
|
||||
Reference in New Issue
Block a user