<commit_before>from django.shortcuts import render_to_response, get_object_or_404, redirect
from django import forms
from django.template import RequestContext
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.core.urlresolvers import reverse
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.db.models import Q
from django.views.generic.list_detail import object_list
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core import serializers
from django.utils.translation import ugettext_lazy as _

from pages.models import Page
from portal.models import MediaItem, Comment, Channel, Collection, User, Submittal
from portal.forms import MediaItemForm, CommentForm, getThumbnails, ThumbnailForm, SubmittalForm

from transloadit.client import Client
from taggit.models import Tag
import lambdaproject.settings as settings

import djangotasks

import simplejson as json
import urllib2
from datetime import datetime
import os
import shutil
import re
from threading import Event
from traceback import print_exc
from sys import argv
from operator import attrgetter
import itertools

def list(request):
    ''' This view is the front page of OwnTube. It just gets the first 15 available media items and
    forwards them to the template. We use Django's Paginator to have pagination '''
    queryset = itertools.chain(MediaItem.objects.filter(encodingDone=True, published=True).order_by('-date','-modified'),Collection.objects.all().order_by('-created'))
    queryset_sorted = sorted(queryset, key=attrgetter('date', 'created'), reverse=True)
    paginator = Paginator(queryset_sorted,15)
    channel_list = Channel.objects.all()
    page = request.GET.get('page')
    try:
        mediaitems = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        mediaitems = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        mediaitems = paginator.page(paginator.num_pages)
    return render_to_response('portal/index.html', {'page_list': get_page_list, 'submittal_list':get_submittal_list(request), 'latest_mediaitem_list': mediaitems, 'channel_list': channel_list, 'settings': settings},
                            context_instance=RequestContext(request))

def channel_list(request,slug):
    ''' This view is the view for the channel's list it works almost like the index view'''
    channel = get_object_or_404(Channel, slug=slug)
#    mediaitems_list = MediaItem.objects.filter(encodingDone=True, published=True, channel__slug=slug).order_by('-date','-modified')
    queryset = itertools.chain(MediaItem.objects.filter(encodingDone=True, published=True, channel__slug=slug).order_by('-date','-modified'),Collection.objects.filter(channel__slug=slug).order_by('-created'))
    queryset_sorted = sorted(queryset, key=attrgetter('date', 'created'), reverse=True)
    paginator = Paginator(queryset_sorted,15)
    channel_list = Channel.objects.all()
    page = request.GET.get('page')
    try:
        mediaitems = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        mediaitems = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        mediaitems = paginator.page(paginator.num_pages)
    return render_to_response('portal/channel.html', {'page_list':get_page_list, 'submittal_list':get_submittal_list(request), 'mediaitems_list': mediitems, 'channel': channel, 'channel_list': channel_list, 'settings': settings},
                            context_instance=RequestContext(request))

def detail(request, slug):
    ''' Handles the detail view of a media item (the player so to say) and handles the comments (this should become nicer with AJAX and stuff)'''
    if request.method == 'POST':
        comment = Comment(video=MediaItem.objects.get(slug=slug),ip=request.META["REMOTE_ADDR"])<commit_msg>LAMBDA-27: views-links fixed<commit_after>from django.shortcuts import render_to_response, get_object_or_404, redirect
from django import forms
from django.template import RequestContext
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.core.urlresolvers import reverse
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.db.models import Q
from django.views.generic.list_detail import object_list
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core import serializers
from django.utils.translation import ugettext_lazy as _

from pages.models import Page
from portal.models import MediaItem, Comment, Channel, Collection, User, Submittal
from portal.forms import MediaItemForm, CommentForm, getThumbnails, ThumbnailForm, SubmittalForm

from transloadit.client import Client
from taggit.models import Tag
import lambdaproject.settings as settings

import djangotasks

import simplejson as json
import urllib2
from datetime import datetime
import os
import shutil
import re
from threading import Event
from traceback import print_exc
from sys import argv
from operator import attrgetter
import itertools

def list(request):
    ''' This view is the front page of OwnTube. It just gets the first 15 available media items and
    forwards them to the template. We use Django's Paginator to have pagination '''
    queryset = itertools.chain(MediaItem.objects.filter(encodingDone=True, published=True).order_by('-date','-modified'),Collection.objects.all().order_by('-created'))
    queryset_sorted = sorted(queryset, key=attrgetter('date', 'created'), reverse=True)
    paginator = Paginator(queryset_sorted,15)
    channel_list = Channel.objects.all()
    page = request.GET.get('page')
    try:
        mediaitems = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        mediaitems = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        mediaitems = paginator.page(paginator.num_pages)
    return render_to_response('portal/index.html', {'page_list': get_page_list, 'submittal_list':get_submittal_list(request), 'latest_mediaitems_list': mediaitems, 'channel_list': channel_list, 'settings': settings},
                            context_instance=RequestContext(request))

def channel_list(request,slug):
    ''' This view is the view for the channel's list it works almost like the index view'''
    channel = get_object_or_404(Channel, slug=slug)
#    mediaitems_list = MediaItem.objects.filter(encodingDone=True, published=True, channel__slug=slug).order_by('-date','-modified')
    queryset = itertools.chain(MediaItem.objects.filter(encodingDone=True, published=True, channel__slug=slug).order_by('-date','-modified'),Collection.objects.filter(channel__slug=slug).order_by('-created'))
    queryset_sorted = sorted(queryset, key=attrgetter('date', 'created'), reverse=True)
    paginator = Paginator(queryset_sorted,15)
    channel_list = Channel.objects.all()
    page = request.GET.get('page')
    try:
        mediaitems = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        mediaitems = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        mediaitems = paginator.page(paginator.num_pages)
    return render_to_response('portal/channel.html', {'page_list':get_page_list, 'submittal_list':get_submittal_list(request), 'mediaitems_list': mediaitems, 'channel': channel, 'channel_list': channel_list, 'settings': settings},
                            context_instance=RequestContext(request))

def detail(request, slug):
    ''' Handles the detail view of a media item (the player so to say) and handles the comments (this should become nicer with AJAX and stuff)'''
    if request.method == 'POST':
        comment = Comment(video=MediaItem.objects.get(slug=slug),ip=request.META["REMOTE_ADDR"])
{'fraction_non_alphanumeric': 0.09330406147091108, 'fraction_numerical': 0.006586169045005488, 'mean_word_length': 4.844618674269423, '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': '297737', 'n_tokens_mistral': 2368, 'n_tokens_neox': 2330, 'n_words': 669}