Commits

H3n0xek committed 0513b66

QueueDraft repair

Comments (0)

Files changed (1)

diario_extviews/views.py

         return queryset.filter(author=user)
   
 
-def QueueDraft(RedirectView):
-    queryset = EntryStatus.objects.filter(status=STATUS_DRAFT)    
-
-    def get_redirect_url(self, **kwargs):
-        return reverse('list-drafts')
-
-    def get_queryset(self):
-        return self.queryset
-
-    def get_status(self, pk, user):
-        try:
-            return self.get_queryset().get(entry__author__id=user, pk=pk)
-        except EntryStatus.DoesNotExist:
-            raise Http404
-
-    def queue_entry(self, status):
-        EntryStatus.objects.filter(pk=status.pk).update(status=STATUS_QUEUED)
-        messages.add_message(self.request, messages.INFO,
-                            u'Your article has been sent to moderators')
-        return True
-             
-
-    def get(self, request, *args, **kwargs):
-        pk = kwargs.get('pk', None)        
-        if not pk:
-            raise Http404
-        status = self.get_status(pk, request.user)
-        if self.queue_entry(status):
-            return super(QueueDraft, self).get(request, *args, **kwargs)
-        return HttpResponse(status=403)
+class QueueDraft(UpdateView):
+    model = DIARIO_MODEL_CLASS
+    queryset = EntryStatus.objects.filter(status=STATUS_DRAFT)  
+    template_name = 'diario/edit_draft.html'    
+    
+    def get_success_url(self):
+        #return reverse('list-queued')
+        return '/' # stub
+    
+    def get_queryset(self):        
+        return DIARIO_MODEL_CLASS.objects.filter(entrystatus__status=STATUS_DRAFT,
+                                                author=self.request.user)
+        
+    def form_valid(self, form):                
+        status = EntryStatus.objects.get(entry__pk=form.instance.pk)
+        status.status = STATUS_QUEUED
+        status.save()
+        return super(QueueDraft, self).form_valid(form)
    
 post_save.connect(create_status_model, sender=DIARIO_MODEL_CLASS)