Commits

Guilherme Gondim committed 49b4ce2

Add lead property

  • Participants
  • Parent commits ebe6d19

Comments (0)

Files changed (2)

File diario/app_settings.py

         Default value for ``Entry.allow_comments`` boolean field.
         Default: True
 
+    DIARIO_LEAD_SIZE
+        The number of words the property ``Entry.lead`` should use to
+        trucante body. Default: 25
+
     DIARIO_PAGINATE_BY
         Number of itens per page on list and archive views. Default: 12
 
 
 
 ALLOW_COMMENTS = getattr(settings, 'DIARIO_ALLOW_COMMENTS', True)
+LEAD_SIZE = getattr(settings, 'DIARIO_LEAD_SIZE', True)
 PAGINATE_BY = getattr(settings, 'DIARIO_PAGINATE_BY', 12)
 STATUS_CHOICES = getattr(settings, 'DIARIO_STATUS_CHOICES', (
     # ('archived', _('Archived')),

File diario/models.py

 
 from django.contrib.auth.models import User
 from django.db import models
+from django.utils.text import Truncator
 from django.utils.translation import ugettext_lazy as _
 from django.utils.timezone import now
 from taggit.managers import TaggableManager
 
     def is_hidden(self):
         return not self.status in self.VISIBLE_STATUS
+
+    @property
+    def lead(self):
+        return Truncator(self.body).words(
+            app_settings.LEAD_SIZE,
+            truncate=' ...'
+        )