<commit_before># Create your views here.

from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.http import Http404
from django.core.paginator import Paginator

from site_media.models import Image, ImageCategory
from hwm.paginator import generator as pgenerator

from vcms.www.views.html import _get_page_parameters
from vcms.image_gallery.models import ImageGalleryPage

def gallery(request, page=None, category=None, page_number=1, reverse_url="vcms.image_gallery.views.gallery"):
    reverse_kwargs={}
    page = request.current_page['current_page']

    if len(request.cms_menu_extrapath) == 2:
        category = request.cms_menu_extrapath[0]
        page_number = request.cms_menu_extrapath[1]
    if len(request.cms_menu_extrapath):
        if request.cms_menu_extrapath[0].isdigit():
            page_number = request.cms_menu_extrapath[0]
        else:
            category = request.cms_menu_extrapath[0]
            
    page_info = _get_page_parameters(page)
    reverse_kwargs['page'] = page.slug

    if category:
        images_category = ImageCategory.objects.get_image_category_from_slug(category)
        reverse_kwargs['category'] = category
        images = page.get_all_images_for_category(images_category)
    else:
        images = page.get_all_images()
    
    thumbnail_size =  str(page.thumbnail_width) + 'x' + str(page.thumbnail_height)
    
    paginator = Paginator(images, page.thumbnail_per_page)
    if int(page_number) > int(paginator.num_pages):
        page_number = paginator.num_pages
    paginator_html = pgenerator.get_page_navigation(paginator, page_number, reverse_url, reverse_kwargs=reverse_kwargs)
    paginator_page = paginator.page(page_number)

    start_index = paginator_page.start_index()-1
    end_index = paginator_page.end_index()
    <commit_msg>updated image_gallery to redirect when an exception occurs<commit_after># Create your views here.

from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.http import Http404
from django.core.paginator import Paginator
from django.http import Http404

from site_media.models import Image, ImageCategory
from hwm.paginator import generator as pgenerator

from vcms.www.views.html import _get_page_parameters
from vcms.image_gallery.models import ImageGalleryPage

def gallery(request, page=None, current_page=None, category=None, page_number=1, reverse_url="vcms.image_gallery.views.gallery"):
    reverse_kwargs={}
    try:
        page = request.current_page['current_page']
    except:
        raise Http404
    
    if len(request.cms_menu_extrapath) == 2:
        category = request.cms_menu_extrapath[0]
        page_number = request.cms_menu_extrapath[1]
    if len(request.cms_menu_extrapath):
        if request.cms_menu_extrapath[0].isdigit():
            page_number = request.cms_menu_extrapath[0]
        else:
            category = request.cms_menu_extrapath[0]
            
    page_info = _get_page_parameters(page)
    reverse_kwargs['page'] = page.slug

    if category:
        images_category = ImageCategory.objects.get_image_category_from_slug(category)
        reverse_kwargs['category'] = category
        images = page.get_all_images_for_category(images_category)
    else:
        images = page.get_all_images()
    
    thumbnail_size =  str(page.thumbnail_width) + 'x' + str(page.thumbnail_height)
    
    paginator = Paginator(images, page.thumbnail_per_page)
    if int(page_number) > int(paginator.num_pages):
        page_number = paginator.num_pages
    paginator_html = pgenerator.get_page_navigation(paginator, page_number, reverse_url, reverse_kwargs=reverse_kwargs)
    paginator_page = paginator.page(page_number)

    start_index = paginator_page.start_index()-1
    end_index = paginator_page.end_index()
    
{'fraction_non_alphanumeric': 0.08005148005148005, 'fraction_numerical': 0.008751608751608752, 'mean_word_length': 4.14021164021164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '955758', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1192, 'n_words': 224}