<commit_before>from django.template import Library, Node, TemplateSyntaxError 
from gallery.models import Picture

register = Library()

@register.tag(name='get_latest_pictures')
def do_get_latest_pictures(parser, token):
    """
    This will store the latest pictures in the context.

    Usage:

        {% get_latest_pictures 20 as pictures %}
        {% for picture in pictures %}
        ...
        {% endfor %}
    """
    tokens = token.contents.split()
    if len(tokens) != 4 or tokens[2] != 'as':
        raise TemplateSyntaxError("'get_latest_pictures' requires 'number as variable' (got %r)" % args)
    try:
        count = int(tokens[1])
    except ValueError:
        raise TemplateSyntaxError(
            "'get_latest_pictures' requires an integer as the first parameter (got %r)"
            % tokens[1])
    return GetLatestPictures(count, tokens[3]) 
    

class GetLatestPictures(Node):
    def __init__(self, count, var):
        self.count = count
        self.var = var
    
    def render(self, context):
        context[self.var] = Picture.objects.order_by('-date_created')[:self.count]
        return u''<commit_msg>Fixed the latest pictures query to only get from published galleries.<commit_after>from django.template import Library, Node, TemplateSyntaxError 
from gallery.models import Picture

register = Library()

@register.tag(name='get_latest_pictures')
def do_get_latest_pictures(parser, token):
    """
    This will store the latest pictures in the context.

    Usage:

        {% get_latest_pictures 20 as pictures %}
        {% for picture in pictures %}
        ...
        {% endfor %}
    """
    tokens = token.contents.split()
    if len(tokens) != 4 or tokens[2] != 'as':
        raise TemplateSyntaxError("'get_latest_pictures' requires 'number as variable' (got %r)" % args)
    try:
        count = int(tokens[1])
    except ValueError:
        raise TemplateSyntaxError(
            "'get_latest_pictures' requires an integer as the first parameter (got %r)"
            % tokens[1])
    return GetLatestPictures(count, tokens[3]) 
    

class GetLatestPictures(Node):
    def __init__(self, count, var):
        self.count = count
        self.var = var
    
    def render(self, context):
        context[self.var] = Picture.objects.filter(gallery__published=True). \
            order_by('-date_created')[:self.count]
        return u''
{'fraction_non_alphanumeric': 0.11032177183451734, 'fraction_numerical': 0.0058503969912244045, 'mean_word_length': 2.8488745980707395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3503018', 'n_tokens_mistral': 717, 'n_tokens_neox': 675, 'n_words': 190}