<commit_before>import datetime

from django.contrib.auth.models import User
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.views.generic.list_detail import object_list

from localtv import models
from localtv.decorators import get_sitelocation

@get_sitelocation
def index(request, sitelocation=None):
    return render_to_response(
        'localtv/subsite/browse.html', {},
        context_instance=RequestContext(request))


@get_sitelocation
def new_videos(request, sitelocation=None):
    videos = models.Video.objects.new(
        site=sitelocation.site,
        status=models.VIDEO_STATUS_ACTIVE)
    return object_list(
        request=request, queryset=videos,
        paginate_by=15,
        template_name='localtv/subsite/video_listing_new.html',
        allow_empty=True, template_object_name='video')


@get_sitelocation
def popular_videos(request, sitelocation=None):
    videos = models.Video.objects.popular_since(
        datetime.timedelta(days=7), sitelocation,
        status=models.VIDEO_STATUS_ACTIVE)
    return object_list(
        request=request, queryset=videos,
        paginate_by=15,
        template_name='localtv/subsite/video_listing_popular.html',
        allow_empty=True, template_object_name='video')

@get_sitelocation
def featured_videos(request, sitelocation=None):
    videos = models.Video.objects.filter(
        site=sitelocation.site, last_featured__isnull=False,
        status=models.VIDEO_STATUS_ACTIVE)
    videos = videos.order_by(
        '-last_featured', '-when_approved', '-when_published',
        '-when_submitted')
    return object_list(
        request=request, queryset=videos,
        paginate_by=15,
        template_name='localtv/subsite/video_listing_featured.html',
        allow_empty=True, template_object_name='video')

@get_sitelocation
def tag_videos(request, tag, sitelocation=None):
    tag = get_object_or_404(models.Tag, name=tag)
    videos = tag.video_set.filter(
        site=sitelocation.site,
        status=models.VIDEO_STATUS_ACTIVE)
    videos = videos.order_by(
        '-when_approved', '-when_published', '-when_submitted')
    return object_list(
        request=request, queryset=videos,
        paginate_by=15,
        template_name='localtv/subsite/video_listing_tag.html',
        allow_empty=True, template_object_name='video',
        extra_context={'tag': tag})

@get_sitelocation
def feed_videos(request, feed_id, sitelocation=None):
    feed = get_object_or_404(models.Feed, pk=feed_id,
                             site=sitelocation.site)
    videos = feed.video_set.filter(
        site=sitelocation.site,
        status=models.VIDEO_STATUS_ACTIVE)
    videos = videos.order_by(
        '-when_approved', '-when_published', '-when_submitted')
    return object_list(
        request=request, queryset=videos,
        paginate_by=15,
        template_name='localtv/subsite/video_listing_feed.html',
        allow_empty=True, template_object_name='video',
        extra_context={'feed': feed})

@get_sitelocation
def user_videos(request, username, sitelocation=None):
    user = get_object_or_404(User, username=username)
    videos = user.video_set.filter(
        site=sitelocation.site,
        status=models.VIDEO_STATUS_ACTIVE)
    videos = videos.order_by(
        '-when_approved', '-when_published', '-when_submitted')
    return object_list(
        request=request, queryset=videos,
        paginate_by=15,
        template_name='localtv/subsite/video_listing_user.html',
        allow_empty=True, template_object_name='video',
        extra_context={'user': user})
<commit_msg>sort the feed videos chronologically<commit_after>import datetime

from django.contrib.auth.models import User
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.views.generic.list_detail import object_list

from localtv import models
from localtv.decorators import get_sitelocation

@get_sitelocation
def index(request, sitelocation=None):
    return render_to_response(
        'localtv/subsite/browse.html', {},
        context_instance=RequestContext(request))


@get_sitelocation
def new_videos(request, sitelocation=None):
    videos = models.Video.objects.new(
        site=sitelocation.site,
        status=models.VIDEO_STATUS_ACTIVE)
    return object_list(
        request=request, queryset=videos,
        paginate_by=15,
        template_name='localtv/subsite/video_listing_new.html',
        allow_empty=True, template_object_name='video')


@get_sitelocation
def popular_videos(request, sitelocation=None):
    videos = models.Video.objects.popular_since(
        datetime.timedelta(days=7), sitelocation,
        status=models.VIDEO_STATUS_ACTIVE)
    return object_list(
        request=request, queryset=videos,
        paginate_by=15,
        template_name='localtv/subsite/video_listing_popular.html',
        allow_empty=True, template_object_name='video')

@get_sitelocation
def featured_videos(request, sitelocation=None):
    videos = models.Video.objects.filter(
        site=sitelocation.site, last_featured__isnull=False,
        status=models.VIDEO_STATUS_ACTIVE)
    videos = videos.order_by(
        '-last_featured', '-when_approved', '-when_published',
        '-when_submitted')
    return object_list(
        request=request, queryset=videos,
        paginate_by=15,
        template_name='localtv/subsite/video_listing_featured.html',
        allow_empty=True, template_object_name='video')

@get_sitelocation
def tag_videos(request, tag, sitelocation=None):
    tag = get_object_or_404(models.Tag, name=tag)
    videos = tag.video_set.filter(
        site=sitelocation.site,
        status=models.VIDEO_STATUS_ACTIVE)
    videos = videos.order_by(
        '-when_approved', '-when_published', '-when_submitted')
    return object_list(
        request=request, queryset=videos,
        paginate_by=15,
        template_name='localtv/subsite/video_listing_tag.html',
        allow_empty=True, template_object_name='video',
        extra_context={'tag': tag})

@get_sitelocation
def feed_videos(request, feed_id, sitelocation=None):
    feed = get_object_or_404(models.Feed, pk=feed_id,
                             site=sitelocation.site)
    videos = models.Video.objects.new(site=sitelocation.site,
                                      feed=feed,
                                      status=models.VIDEO_STATUS_ACTIVE)
    return object_list(
        request=request, queryset=videos,
        paginate_by=15,
        template_name='localtv/subsite/video_listing_feed.html',
        allow_empty=True, template_object_name='video',
        extra_context={'feed': feed})

@get_sitelocation
def user_videos(request, username, sitelocation=None):
    user = get_object_or_404(User, username=username)
    videos = user.video_set.filter(
        site=sitelocation.site,
        status=models.VIDEO_STATUS_ACTIVE)
    videos = videos.order_by(
        '-when_approved', '-when_published', '-when_submitted')
    return object_list(
        request=request, queryset=videos,
        paginate_by=15,
        template_name='localtv/subsite/video_listing_user.html',
        allow_empty=True, template_object_name='video',
        extra_context={'user': user})

{'fraction_non_alphanumeric': 0.09811423886307734, 'fraction_numerical': 0.006832467887400929, 'mean_word_length': 3.7280361757105944, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5033630', 'n_tokens_mistral': 2315, 'n_tokens_neox': 2278, 'n_words': 345}