From: Guillaume Pellerin Date: Wed, 2 Jul 2014 09:03:32 +0000 (+0200) Subject: add command for submit all scripts X-Git-Tag: 1.1~448 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=087622332f40ddec0caf2460ca834c56cfa5c71d;p=teleforma.git add command for submit all scripts --- diff --git a/teleforma/exam/models.py b/teleforma/exam/models.py index 98b8e109..f062af4d 100644 --- a/teleforma/exam/models.py +++ b/teleforma/exam/models.py @@ -281,10 +281,22 @@ class Script(BaseResource): def submit(self): self.date_submitted = datetime.datetime.now() self.url = settings.MEDIA_URL + unicode(self.file) - try: - self.box_uuid = crocodoc.document.upload(url=self.url) - except: - pass + self.box_uuid = crocodoc.document.upload(url=self.url) + while True: + statuses = crocodoc.document.status([self.box_uuid,]) + if (len(statuses) != 0): + if (statuses[0].get('error') == None): + if statuses[0]['status'] == 'DONE': + break + else: + time.sleep(1) + else: + print ' File #1 failed :(' + print ' Error Message: ' + statuses[0]['error'] + else: + print 'failed :(' + print ' Statuses were not returned.' + if not self.corrector: self.auto_set_corrector() diff --git a/teleforma/management/commands/teleforma-exam-submit-scripts.py b/teleforma/management/commands/teleforma-exam-submit-scripts.py new file mode 100644 index 00000000..1d752cb6 --- /dev/null +++ b/teleforma/management/commands/teleforma-exam-submit-scripts.py @@ -0,0 +1,19 @@ +from optparse import make_option +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth.models import User +from django.template.defaultfilters import slugify +from telemeta.models import * +from telemeta.util.unaccent import unaccent +from teleforma.exam.models import * +import logging +import codecs + + +class Command(BaseCommand): + help = "submit all script to Box View" + + def handle(self, *args, **options): + for script in Script.bojects.all() + script.submit() + script.save() \ No newline at end of file