<commit_before>import re

from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponse
from django.template.loader import render_to_string

from content.filters import IntervalOrderFilterSet
from content.generic.views import GenericObjectDetail, GenericObjectList 
from gallery.models import Gallery, GalleryItem

def galleryimage_response(context):
    template = "gallery/ajax/galleriffic_galleryimage.html"
    return render_to_string(template, context)
    
def videoembed_response(context):
    template = "gallery/ajax/galleriffic_videoembed.html"
    result = render_to_string(template, context)
    result = re.sub('width=".{0,4}"', 'width="606"', result)
    result = re.sub('height=".{0,4}"', 'height="340"', result)
    return result
    
def videofile_response(context):
    template = "gallery/ajax/galleriffic_videofile.html"
    return render_to_string(template, context)

def gallery_item_ajax_galleriffic(request, slug):
    try:
        obj = GalleryItem.permitted.filter(slug=slug).get()
    except GalleryItem.DoesNotExist:
        raise Http404

    obj = obj.as_leaf_class()

    options = {
        'GalleryImage': galleryimage_response,
        'VideoEmbed': videoembed_response,
        'VideoFile': videofile_response,
    }
    
    context = {'object':  obj}
    result = options[obj._meta.object_name](context)
    return HttpResponse(result)

class ObjectList(GenericObjectList):
    def get_extra_context(self, *args, **kwargs):
        extra_context = super(ObjectList, self).get_extra_context(*args, **kwargs)
        added_context = {'title': 'Galleries'}
        if extra_context:
            extra_context.update(
                added_context,
            )
        else:
            extra_context = added_context

        return extra_context
    
    def get_filterset(self, request, queryset):
        return IntervalOrderFilterSet(request.GET, queryset=queryset)
    
    def get_paginate_by(self):
        return 12
    
    def get_queryset(self):
        return Gallery.permitted.all()

object_list = ObjectList()

class ObjectDetail(GenericObjectDetail):
    def get_queryset(self):
        return Gallery.permitted.all()
    
    def get_extra_context(self, *args, **kwargs):
        extra_context = super(ObjectDetail, self).get_extra_context(*args, **kwargs)
        added_context = {'title': 'Galleries'}
        if extra_context:
            extra_context.update(
                added_context,
            )
        else:
            extra_context = added_context

        return extra_context
    
    def get_filterset(self, request, queryset):
        return IntervalOrderFilterSet(request.GET, queryset=queryset, action_url=reverse('gallery_object_list'))

object_detail = ObjectDetail()
<commit_msg>completed videoembed eand videofile respone views<commit_after>import re

from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponse
from django.template.loader import render_to_string

from content.filters import IntervalOrderFilterSet
from content.generic.views import GenericObjectDetail, GenericObjectList 
from gallery.models import Gallery, GalleryItem

from photologue.models import PhotoSize

def galleryimage_response(context):
    template = "gallery/ajax/galleriffic_galleryimage.html"
    return render_to_string(template, context)
    
def videoembed_response(context):
    template = "gallery/ajax/galleriffic_videoembed.html"
    result = render_to_string(template, context)

    try:
        photosize = context['object'].get_videoembed_large_photosize()
    except AttributeError:
        return result
        
    result = re.sub('width=".{0,4}"', 'width="%s"' % photosize.width, result)
    result = re.sub('height=".{0,4}"', 'height="%s"' % photosize.height, result)
    return result
    
def videofile_response(context):
    # grab a photosize and fallback to default if not available
    try:
        photosize = context['object'].get_videofile_large_photosize()
        width = photosize.width
        height = photosize.height
    except AttributeError:
        # TODO: get some better way to specify defaults
        width = 500
        height = 300
   
    context.update({
        'width': width,
        'height': height,
    })
    template = "gallery/ajax/galleriffic_videofile.html"
    return render_to_string(template, context)

def gallery_item_ajax_galleriffic(request, slug):
    try:
        obj = GalleryItem.permitted.filter(slug=slug).get()
    except GalleryItem.DoesNotExist:
        raise Http404

    obj = obj.as_leaf_class()

    options = {
        'GalleryImage': galleryimage_response,
        'VideoEmbed': videoembed_response,
        'VideoFile': videofile_response,
    }
    
    context = {'object':  obj}
    result = options[obj._meta.object_name](context)
    return HttpResponse(result)

class ObjectList(GenericObjectList):
    def get_extra_context(self, *args, **kwargs):
        extra_context = super(ObjectList, self).get_extra_context(*args, **kwargs)
        added_context = {'title': 'Galleries'}
        if extra_context:
            extra_context.update(
                added_context,
            )
        else:
            extra_context = added_context

        return extra_context
    
    def get_filterset(self, request, queryset):
        return IntervalOrderFilterSet(request.GET, queryset=queryset)
    
    def get_paginate_by(self):
        return 12
    
    def get_queryset(self):
        return Gallery.permitted.all()

object_list = ObjectList()

class ObjectDetail(GenericObjectDetail):
    def get_queryset(self):
        return Gallery.permitted.all()
    
    def get_extra_context(self, *args, **kwargs):
        extra_context = super(ObjectDetail, self).get_extra_context(*args, **kwargs)
        added_context = {'title': 'Galleries'}
        if extra_context:
            extra_context.update(
                added_context,
            )
        else:
            extra_context = added_context

        return extra_context
    
    def get_filterset(self, request, queryset):
        return IntervalOrderFilterSet(request.GET, queryset=queryset, action_url=reverse('gallery_object_list'))

object_detail = ObjectDetail()

{'fraction_non_alphanumeric': 0.0928479794740218, 'fraction_numerical': 0.005772931366260423, 'mean_word_length': 3.239972807613868, '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': '2921542', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1771, 'n_words': 376}