# 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 import template
from diario.models import Entry

    Example usage::

        {% get_diario_month_list as archive %}

        {% get_diario_month_list as blog_months %}
    """
    bits = token.contents.split()
    if len(bits) != 3:
        raise template.TemplateSyntaxError, "'%s' tag takes three arguments" % bits[0]
    if bits[1] != 'as':
        raise template.TemplateSyntaxError, "First argument to '%s' tag must be 'as'" % bits[0]
    return MonthListNode(bits[2])


class EntryListNode(template.Node):
    def __init__(self, num, var_name, start=0):
        try:
            self.start = int(start)
        except ValueError:
            self.start =  template.Variable(start)
        self.num = int(num)
        self.var_name = var_name

    def render(self, context):
        if type(self.start) != int:
            try:
                self.start =  int(self.start.resolve(context))
            except template.VariableDoesNotExist:
                return ''

# 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/templatetags/diario_entries.py
from django import template
from diario.models import Entry


    Example usage::

        {% get_diario_month_list as archive %}

        {% get_diario_month_list as blog_months %}
    """
    bits = token.contents.split()
    if len(bits) != 3:
        raise template.TemplateSyntaxError, "'%s' tag takes three arguments" % bits[0]
    if bits[1] != 'as':
        raise template.TemplateSyntaxError, "First argument to '%s' tag must be 'as'" % bits[0]
    return MonthListNode(bits[2])


class EntryListNode(template.Node):
    def __init__(self, num, var_name, start=0):
        try:
            self.start = int(start)
        except ValueError:
            self.start =  template.Variable(start)
        self.num = int(num)
        self.var_name = var_name

    def render(self, context):
        if type(self.start) != int:
            try:
                self.start =  int(self.start.resolve(context))
            except template.VariableDoesNotExist:
                return ''

        context[self.var_name] = Entry.published_on_site.all()[self.start:][:self.num]