]> git.parisson.com Git - teleforma.git/commitdiff
try safier unbind and submit
authorGuillaume Pellerin <yomguy@parisson.com>
Sat, 19 Jul 2014 17:23:56 +0000 (19:23 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Sat, 19 Jul 2014 17:23:56 +0000 (19:23 +0200)
teleforma/exam/models.py
teleforma/exam/templates/exam/script_form.html
teleforma/management/commands/teleforma-exam-submit-scripts.py
teleforma/static/teleforma/css/teleforma.css

index 900f3a40f57c1241d6682244ca0e2a91e7d4299e..747421cf8fc60533ad0051b801d96c635e28a632 100644 (file)
@@ -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):
index 7e3a3593b10ba5d37d53fd78c231f014bfba74e4..eab40b256cf1815eeb7ad222347b34acf28b1ba7 100644 (file)
@@ -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 }}");
 
index 61af613109bc01cec602bf5f0bf376f8f2dad1f6..1f495025c6db3bd1d487b7a8534e4b93ae7f044c 100644 (file)
@@ -38,4 +38,4 @@ class Command(BaseCommand):
             except:
                 logger.logger.error('ERROR')
             logger.logger.info('OK')
-            time.sleep(10)
+            time.sleep(60)
index 3de77178e7027251595eb80aaacc47618517b969..41755657030c6238c7eb58b7ed3fd5e8d3f585f9 100644 (file)
@@ -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;