# Path: diario/models.py
# class Entry(models.Model):
#     """A weblog entry."""
# 
#     title = models.CharField(_('title'), max_length=100)
#     slug = models.SlugField(
#         _('slug'),
#         unique_for_date='pub_date',
#         help_text=_('Automatically built from the title. A slug is a short '
#                     'label generally used in URLs.'),
#     )
#     author = models.ForeignKey(User, editable=False, verbose_name=_('author'))
#     body_source = models.TextField(_('body'))
#     body = models.TextField(
#         _('body in HTML'),
#         blank=True,
#         editable=False,
#     )
#     markup = models.CharField(
#         _('markup language'),
#         default=DIARIO_DEFAULT_MARKUP_LANG,
#         max_length=8,
#         choices=MARKUP_CHOICES,
#         help_text=_('Select "Raw text" to enter HTML or apply markup '
#                     'elsewhere.'),
#     )
#     is_draft = models.BooleanField(
#         _('draft'),
#         default=False,
#         help_text=_('Drafts are not published.'),
#     )
#     pub_date = models.DateTimeField(
#         _('date published'),
#         default=datetime.now,
#         help_text=_('Entries in future dates are only published on '
#                     'correct date.'),
#     )
#     publish_on = models.ManyToManyField(
#         Site,
#         default=[settings.SITE_ID],
#         verbose_name=_('publish on')
#     )
#     enable_comments = models.BooleanField(_('enable comments'), default=True)
# 
#     if HAS_TAG_SUPPORT:
#         tags = TagField(blank=True)
# 
#     # managers
#     objects   = models.Manager()
#     published = PublishedManager()
#     on_site   = CurrentSiteManager('publish_on')
#     published_on_site = CurrentSitePublishedManager('publish_on')
# 
#     class Meta:
#         abstract      = True
#         get_latest_by = 'pub_date'
#         ordering      = ('-pub_date',)
#         verbose_name  = _('entry')
#         verbose_name_plural = _('entries')
# 
#     def __unicode__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         return ('diario-entry', None, {
#             'year' : str(self.pub_date.year),
#             'month': str(self.pub_date.month).zfill(2),
#             'day'  : str(self.pub_date.day).zfill(2),
#             'slug' : str(self.slug)
#         })
#     get_absolute_url = permalink(get_absolute_url)
# 
#     def in_future(self):
#         return self.pub_date > datetime.now()


from django.views.generic import date_based, list_detail
from diario.models import Entry
def entry_detail(request, *args, **kwargs):
    """
    A wrapper around ``django.views.generic.date_based.object_detail``
    which creates a ``QuerySet`` containing drafts and future entries
    if user has permission to change entries
    (``diario.change_entry``).

    This is useful for preview entries with your own templates and
    CSS.

    Tip: Uses the *View on site* button in Admin interface to access
    yours drafts and entries in future.
    """
    kwargs['date_field'] = 'pub_date'
    kwargs['slug_field'] = 'slug'
    if request.user.has_perm('diario.change_entry'):
        kwargs['allow_future'] = True
        kwargs['queryset'] = Entry.on_site.all()
    else:
        kwargs['allow_future'] = False
        if 'queryset' not in kwargs:
            kwargs['queryset'] = Entry.published_on_site.all()
    return date_based.object_detail(request, *args, **kwargs)

def entry_archive_year(request, *args, **kwargs):
    """
    A thin wrapper around ``django.views.generic.date_based.archive_year``.
    """
    kwargs['date_field'] = 'pub_date'
    if 'queryset' not in kwargs:

# Path: diario/models.py
# class Entry(models.Model):
#     """A weblog entry."""
# 
#     title = models.CharField(_('title'), max_length=100)
#     slug = models.SlugField(
#         _('slug'),
#         unique_for_date='pub_date',
#         help_text=_('Automatically built from the title. A slug is a short '
#                     'label generally used in URLs.'),
#     )
#     author = models.ForeignKey(User, editable=False, verbose_name=_('author'))
#     body_source = models.TextField(_('body'))
#     body = models.TextField(
#         _('body in HTML'),
#         blank=True,
#         editable=False,
#     )
#     markup = models.CharField(
#         _('markup language'),
#         default=DIARIO_DEFAULT_MARKUP_LANG,
#         max_length=8,
#         choices=MARKUP_CHOICES,
#         help_text=_('Select "Raw text" to enter HTML or apply markup '
#                     'elsewhere.'),
#     )
#     is_draft = models.BooleanField(
#         _('draft'),
#         default=False,
#         help_text=_('Drafts are not published.'),
#     )
#     pub_date = models.DateTimeField(
#         _('date published'),
#         default=datetime.now,
#         help_text=_('Entries in future dates are only published on '
#                     'correct date.'),
#     )
#     publish_on = models.ManyToManyField(
#         Site,
#         default=[settings.SITE_ID],
#         verbose_name=_('publish on')
#     )
#     enable_comments = models.BooleanField(_('enable comments'), default=True)
# 
#     if HAS_TAG_SUPPORT:
#         tags = TagField(blank=True)
# 
#     # managers
#     objects   = models.Manager()
#     published = PublishedManager()
#     on_site   = CurrentSiteManager('publish_on')
#     published_on_site = CurrentSitePublishedManager('publish_on')
# 
#     class Meta:
#         abstract      = True
#         get_latest_by = 'pub_date'
#         ordering      = ('-pub_date',)
#         verbose_name  = _('entry')
#         verbose_name_plural = _('entries')
# 
#     def __unicode__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         return ('diario-entry', None, {
#             'year' : str(self.pub_date.year),
#             'month': str(self.pub_date.month).zfill(2),
#             'day'  : str(self.pub_date.day).zfill(2),
#             'slug' : str(self.slug)
#         })
#     get_absolute_url = permalink(get_absolute_url)
# 
#     def in_future(self):
#         return self.pub_date > datetime.now()


# Path: diario/views/entries.py
from django.views.generic import date_based, list_detail
from diario.models import Entry

def entry_detail(request, *args, **kwargs):
    """
    A wrapper around ``django.views.generic.date_based.object_detail``
    which creates a ``QuerySet`` containing drafts and future entries
    if user has permission to change entries
    (``diario.change_entry``).

    This is useful for preview entries with your own templates and
    CSS.

    Tip: Uses the *View on site* button in Admin interface to access
    yours drafts and entries in future.
    """
    kwargs['date_field'] = 'pub_date'
    kwargs['slug_field'] = 'slug'
    if request.user.has_perm('diario.change_entry'):
        kwargs['allow_future'] = True
        kwargs['queryset'] = Entry.on_site.all()
    else:
        kwargs['allow_future'] = False
        if 'queryset' not in kwargs:
            kwargs['queryset'] = Entry.published_on_site.all()
    return date_based.object_detail(request, *args, **kwargs)

def entry_archive_year(request, *args, **kwargs):
    """
    A thin wrapper around ``django.views.generic.date_based.archive_year``.
    """
    kwargs['date_field'] = 'pub_date'
    if 'queryset' not in kwargs:

        kwargs['queryset'] = Entry.published_on_site.all()