Commits

Guilherme Gondim committed e9185ad

Add initial support to entry preview

  • Participants
  • Parent commits 35c5c76

Comments (0)

Files changed (3)

             'slug': self.slug
         })
 
+    @models.permalink
+    def get_preview_url(self):
+        return ('diario:entry-preview', None, {'pk': self.pk})
+
     def is_visible(self):
         return self.status in self.VISIBLE_STATUS
 

diario/urls/__init__.py

     'diario.views',
     url('^$', 'entry_list', name='entry-list'),
     url('^(?P<pk>\d)-(?P<slug>[-\w]+)/$', 'entry_detail', name='entry-detail'),
+    url('^preview/(?P<pk>\d)/$', 'entry_preview', name='entry-preview'),
     url('^feed/$', 'feed', name='feed'),
 )
         ] + super(EntryDetailView, self).get_template_names()
 
 
+class EntryPreviewView(EntryDetailView):
+    """Allow a authorized user preview a entry even if it is not visible.
+    """
+    queryset = models.Entry.objects.all()
+
+    def get_object(self, *args, **kwargs):
+        obj = super(EntryPreviewView).get_object(*args, **kwargs)
+        user = self.request.user
+        if user.is_superuser or user == obj.user:
+            return obj
+        elif user.has_perm('diario.can_change_other_user_entry'):
+            return obj
+        raise models.Entry.DoesNotExist
+
+
 class EntryListView(BaseEntryView, ListView):
     pass
 
         context = super(TagView, self).get_context_data(**kwargs)
         context['tag'] = self.tag
         return context
-        
+
 
 class UserView(EntryListView):
     def get_template_names(self):
 
 
 entry_detail = EntryDetailView.as_view()
+entry_preview = EntryPreviewView.as_view()
 entry_list = EntryListView.as_view()
 
 category = CategoryView.as_view()