]> git.parisson.com Git - teleforma.git/commitdiff
fix Script post save
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 23 Jun 2014 20:58:03 +0000 (22:58 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 23 Jun 2014 20:58:03 +0000 (22:58 +0200)
example/settings.py
teleforma/exam/models.py
teleforma/exam/templates/exam/script_form.html

index 839de6332c730762bbd74206c2fbc78e8d8457cb..3999a8dd6e8b2669f8ffcaa599bb688c2df14c30 100644 (file)
@@ -64,7 +64,7 @@ if not os.path.exists(MEDIA_ROOT):
 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
 # trailing slash if there is a path component (optional in other cases).
 # Examples: "http://media.lawrence.com", "http://example.com/media/"
-MEDIA_URL = 'http://localhost:8040/'
+MEDIA_URL = 'http://wm22.parisson.com:8040/'
 
 # Absolute path to the directory static files should be collected to.
 # Don't put anything in this directory yourself; store your static files
index 5a8c8972a3f660705b29120a13f98188b681c8ac..376eb36a736ea9a15928a2312c08636a0ae60605 100644 (file)
@@ -185,7 +185,7 @@ class Script(BaseResource):
     type = models.ForeignKey(ScriptType, related_name='scripts', verbose_name=_('type'), null=True, on_delete=models.SET_NULL)
     author = models.ForeignKey(User, related_name="author_scripts", verbose_name=_('author'), null=True, blank=True, on_delete=models.SET_NULL)
     corrector = models.ForeignKey(User, related_name="corrector_scripts", verbose_name=_('corrector'), blank=True, null=True, on_delete=models.SET_NULL)
-    file = models.FileField(_('PDF file'), upload_to='corrector_scripts/%Y/%m/%d', blank=True)
+    file = models.FileField(_('PDF file'), upload_to='scripts/%Y/%m/%d', blank=True)
     box_uuid  = models.CharField(_('Box UUID'), max_length='256', blank=True)
     score = models.FloatField(_('score'), blank=True, null=True)
     comments = models.TextField(_('comments'), blank=True)
@@ -267,8 +267,10 @@ class Script(BaseResource):
 
     def save(self, *args, **kwargs):
         #FIXME
-        # if self.status == 2:
-        #     self.submit()
+        if self.status == 2:
+            self.status = 3
+            super(Script, self).save(*args, **kwargs)
+            self.submit()
         if self.status == 4 and self.score:
             self.mark()
         if self.status == 0 and self.reject_reason:
@@ -276,6 +278,13 @@ class Script(BaseResource):
 
         super(Script, self).save(*args, **kwargs)
 
+    def submit(self):
+        self.date_submitted = datetime.datetime.now()
+        self.url = settings.MEDIA_URL + unicode(self.file)
+        self.box_uuid = crocodoc.document.upload(url=self.url)
+        if not self.corrector:
+            self.auto_set_corrector()
+
     def mark(self):
         self.date_marked = datetime.datetime.now()
         context = {}
@@ -314,17 +323,6 @@ def set_file_properties(sender, instance, **kwargs):
                 os.system(command)
                 instance.image = path
 
-def submit_to_box(sender, instance, **kwargs):
-    if instance.file and instance.status == 2:
-        instance.date_submitted = datetime.datetime.now()
-        instance.url = settings.MEDIA_URL + unicode(instance.file)
-        instance.box_uuid = crocodoc.document.upload(url=instance.url)
-        instance.status = 3
-        if not instance.corrector:
-            instance.auto_set_corrector()
-        instance.save()
-
 
-post_save.connect(submit_to_box, sender=Script, dispatch_uid="script_post_save")
-# post_save.connect(set_file_properties, sender=Script, dispatch_uid="script_post_save")
+post_save.connect(set_file_properties, sender=Script, dispatch_uid="script_post_save")
 post_save.connect(set_file_properties, sender=ScriptPage, dispatch_uid="scriptpage_post_save")
index 38ec1616d74066bb7242ca9f19038540132d9b95..1db424877728144d5e07b3bb955fe0dfae21a5f0 100644 (file)
@@ -28,7 +28,7 @@
 </div>
 
 <div class="course_content" id="media_infos" style="font-size: 115%;">
-    <form method="post" id="_ScriptForm" action="">{% csrf_token %}
+    <form method="post" id="_ScriptForm" action="" enctype="multipart/form-data" data-ajax="false">{% csrf_token %}
        <table>
        <tr><td colspan="2">{% for error in form.non_field_errors %}<li class="error">{{ error }}</li>{% endfor %}</td></tr>
        {% for field in form %}
@@ -36,7 +36,6 @@
         {% if not field.html_name in create_fields %}
             <td>{{ field.label_tag.as_hidden }}</td><td>{{ field.as_hidden }}</td>
         {% else %}
-            <tr><td class="error">{{ field.errors }}</td></tr>
             <td>{{ field.label_tag }}:</td><td> {{ field }}</td>
         {% endif %}
         </tr>