From 6d168bde9f5c3e07ca6d36edb4100ce2daaad359 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Sat, 19 Jul 2014 19:23:56 +0200 Subject: [PATCH] try safier unbind and submit --- teleforma/exam/models.py | 67 +++++++++++-------- .../exam/templates/exam/script_form.html | 2 +- .../commands/teleforma-exam-submit-scripts.py | 2 +- teleforma/static/teleforma/css/teleforma.css | 3 + 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/teleforma/exam/models.py b/teleforma/exam/models.py index 900f3a40..747421cf 100644 --- a/teleforma/exam/models.py +++ b/teleforma/exam/models.py @@ -67,6 +67,7 @@ REJECT_REASON = (('unreadable', _('unreadable')), ('bad framing', _('bad framing')), ('incomplete', _('incomplete')), ('wrong course', _('wrong course')), + ('wrong format', _('wrong format')), ) cache_path = settings.MEDIA_ROOT + 'cache/' @@ -302,44 +303,56 @@ class Script(BaseResource): self.save() def submit(self): - import crocodoc - crocodoc.api_token = settings.BOX_API_TOKEN - self.date_submitted = datetime.datetime.now() + # self.url = 'http://teleforma.parisson.com/media/scripts/2014/06/24/Gstreamer_monitoring_Pipleline.pdf' self.url = settings.MEDIA_URL + unicode(self.file) - self.box_uuid = crocodoc.document.upload(url=self.url) - - i = 0 - n = 30 - s = 6 - - while True: - statuses = crocodoc.document.status([self.box_uuid,]) - if (len(statuses) != 0): - if (statuses[0].get('error') == None): - if statuses[0]['status'] == 'DONE': - if not self.corrector: - self.auto_set_corrector() - self.status = 3 - self.save() - break + + if '.jpg' in self.file.path or '.JPG' in self.file.path \ + or '.png' in self.file.path or '.PNG' in self.file.path: + self.reject_reason = 'wrong format' + self.reject() + + self.save() + + if not self.box_uuid and not self.reject_reason: + self.box_uuid = crocodoc.document.upload(url=self.url) + + i = 0 + n = 50 + s = 6 + t = 0 + + while True: + i += 1 + statuses = crocodoc.document.status([self.box_uuid,]) + if (len(statuses) != 0): + if (statuses[0].get('error') == None): + if statuses[0]['status'] == 'DONE': + t = 1 + break + else: + time.sleep(s) + if i == n: + break else: + print 'File upload failed :(' + print ' Error Message: ' + statuses[0]['error'] time.sleep(s) if i == n: break else: - print 'File upload failed :(' - print ' Error Message: ' + statuses[0]['error'] + print 'failed :(' + print ' Statuses were not returned.' time.sleep(s) if i == n: break - else: - print 'failed :(' - print ' Statuses were not returned.' - time.sleep(s) - if i == n: - break + + if not self.corrector and t == 1: + self.auto_set_corrector() + self.status = 3 + + self.save() def mark(self): diff --git a/teleforma/exam/templates/exam/script_form.html b/teleforma/exam/templates/exam/script_form.html index 7e3a3593..eab40b25 100644 --- a/teleforma/exam/templates/exam/script_form.html +++ b/teleforma/exam/templates/exam/script_form.html @@ -11,7 +11,7 @@ var b2 = $('#submit_button'); b2.unbind('click').click(function() { $(window).unbind('beforeunload'); - b2.unbind('click'); + // b2.unbind('click'); $('#id_status').val("2"); $('#id_period').val("{{ period.id }}"); diff --git a/teleforma/management/commands/teleforma-exam-submit-scripts.py b/teleforma/management/commands/teleforma-exam-submit-scripts.py index 61af6131..1f495025 100644 --- a/teleforma/management/commands/teleforma-exam-submit-scripts.py +++ b/teleforma/management/commands/teleforma-exam-submit-scripts.py @@ -38,4 +38,4 @@ class Command(BaseCommand): except: logger.logger.error('ERROR') logger.logger.info('OK') - time.sleep(10) + time.sleep(60) diff --git a/teleforma/static/teleforma/css/teleforma.css b/teleforma/static/teleforma/css/teleforma.css index 3de77178..41755657 100644 --- a/teleforma/static/teleforma/css/teleforma.css +++ b/teleforma/static/teleforma/css/teleforma.css @@ -1254,6 +1254,9 @@ a.image-link { .icon_speaker{ background-image: url('/static/telemeta/images/text-speak.png'); } +.icon_wait{ + background-image: url('/static/telemeta/images/wait.gif'); +} .icon_rss,.icon_rss:hover{ background: url('/static/telemeta/images/feed-icon-14x14.png') no-repeat; background-position: 0ex .8ex; -- 2.39.5