Rémy HUBSCHER avatar Rémy HUBSCHER committed 5032f60

Update article

Comments (0)

Files changed (1)

src/django-xworkflows.rst

         log_model = ''
         #: Available states.
         states = (
-	    ('init', _(u'Created')),
+        ('init', _(u'Created')),
             ('uploaded', _(u'Uploaded')),
             ('queued', _(u'Queued for previews generation')),
             ('ready', _(u'Ready')),
         )
         #: Available transitions.
         transitions = (
-	    ('upload', 'init', 'uploaded'),
+        ('upload', 'init', 'uploaded'),
             ('queue', 'uploaded', 'queued'),
             ('activate', 'queued', 'ready'),
             # Administration command to restart preview generation
         def __unicode__(self):
             return u'%s' % self.title
 
-    def save(self, *args, **kwargs):
-        flag = self.pk is None
-        if not self.title:
-            self.title = self.file.name
-        doc = super(Document, self).save(*args, **kwargs)
-	if flag:
-   	    doc.upload() # On first save, the document is uploaded to the secure bucket
-	return doc
+        def save(self, *args, **kwargs):
+            flag = self.pk is None
+            if not self.title:
+                self.title = self.file.name
+            super(Document, self).save(*args, **kwargs)
+            if flag:
+                self.upload() # On first save, the document is uploaded to the secure bucket
 
 Maintenant nous avons un models django qui est capable de sauvegarder son état.
 Il faut bien sur mettre à jour la base de données.
     class Document(xwf_models.WorkflowEnabled, models.Model):
         file = models.FileField(verbose_name=_('file'))
         title = models.CharField(_('title'), max_length=100, blank=True)
-	num_pages = models.PositiveIntegerField(editable=False, default=0)
+        num_pages = models.PositiveIntegerField(editable=False, default=0)
 
         state = xwf_models.StateField(DocumentWorkflow)
 
         def __unicode__(self):
             return u'%s' % self.title
 
-    def save(self, *args, **kwargs):
-        if not self.title:
-            self.title = self.file.name
-        return super(Document, self).save(*args, **kwargs)
-
-    def _queue(self):
-        """Send job for async preview generation request."""
-        # Add job to redis queue
-	requests.get(THUMBNAILER_API, params = {
-                'url': self.file.url,
-		'width': [1000, 750, 150],
-		'max_pages': 20,
-                'callback': reverse('vault:thumbnail_callback', self.pk)})
-
-    @xworkflows.transition()
-    def upload(self):
-        """Change the state when the file has been uploaded to the secure bucket."""
-
-    @xworkflows.transition()
-    def queue(self):
-        self._queue()
-
-    @xworkflows.transition()
-    def activate(self, num_pages):
-        self.num_pages = num_pages
-
-    @xworkflows.transition()
-    def reset(self):
-        self._queue()
+        def save(self, *args, **kwargs):
+            flag = self.pk is None
+            if not self.title:
+                self.title = self.file.name
+            super(Document, self).save(*args, **kwargs)
+            if flag:
+                self.upload() # On first save, the document is uploaded to the secure bucket
+        
+        def _queue(self):
+            """Send job for async preview generation request."""
+            # Add job to redis queue
+            requests.get(THUMBNAILER_API, params = {
+                    'url': self.file.url,
+                    'width': [1000, 750, 150],
+                    'max_pages': 20,
+                    'callback': reverse('vault:thumbnail_callback', self.pk)})
+        
+        @xworkflows.transition()
+        def upload(self):
+            """Change the state when the file has been uploaded to the secure bucket."""
+        
+        @xworkflows.transition()
+        def queue(self):
+            self._queue()
+        
+        @xworkflows.transition()
+        def activate(self, num_pages):
+            self.num_pages = num_pages
+        
+        @xworkflows.transition()
+        def reset(self):
+            self._queue()
 
 Il nous reste simplement à réaliser une view qui va nous permettre de
 mettre à jour le nombre de pages lors du callback.
     def thumbnailer_callback(request, pk):
         document = get_object_or_404(Document, pk=pk)
         num_pages = request.POST.get('num_pages', 1)
-	try:
-  	    document.activate(num_pages)
+        try:
+            document.activate(num_pages)
         except InvalidTransitionError, e:
             return HttpResponse(e.message(), status_code=400)
-	return HttpResponse('Document activated')
+        return HttpResponse('Document activated')
 
 Dans nos templates, si nous souhaitons tester si nous devons afficher la preview :
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.