<commit_before>from django.shortcuts import render, get_object_or_404

from django.http import HttpResponse
from django.template import Context, loader
import math

from articles.models import Article, ArticleCategory, ArticleEntity, Gallery, InGallery, Picture
from listing.pages import PageHelper

default_count_per_page = 5
max_count_per_page = 25
max_pages_listed_on_screen = 5


def index(request):
    t = loader.get_template('article_list.html')
    article_list = Article.objects.all().order_by('date').reverse()
    if len(article_list) == 0:
        article_list = None
    c = Context({'eventType': 'All', 'article_list': article_list})
    return HttpResponse(t.render(c))
 
def general_listing(request, eventType, category):
    type_id = ArticleCategory.objects.filter(name=category)[0].id
    t = loader.get_template('article_list.html')
    article_list = Article.objects.filter(category=type_id)
    article_count = PageHelper.get_request_count(request, default_count_per_page, max_count_per_page)
    page_number = PageHelper.get_page_number(request)
    articles_range_min = (page_number - 1) * article_count
    articles_range_max = (page_number) * article_count    
    number_of_articles = len(article_list)
    total_pages = int(math.ceil(number_of_articles / float(article_count)))
    article_list = article_list[articles_range_min:articles_range_max]
    page_numbers_list = PageHelper.calculate_page_range(total_pages, page_number, max_pages_listed_on_screen)    
    next_page = page_number + 1 if number_of_articles > articles_range_max else 0
    prev_page = page_number - 1
    context_dict = {
                    'eventType': eventType,
                    'article_list' : article_list, 
                    'page_number' : page_number, 
                    'prev_page': prev_page, 
                    'next_page' : next_page, 
                    'page_numbers' : page_numbers_list
                    }
    c = Context(context_dict)
    return HttpResponse(t.render(c))
    
 
def service(request):
    return general_listing(request, 'Service', 'Service')

def professional_development(request):
    return general_listing(request, 'Professional Development', 'PD')

def social(request):
    return general_listing(request, 'Social', 'Social')

def get_article(request, article_id):
    art = get_object_or_404(Article, pk=article_id)
    gal_id = art.gallery.id
    in_gals = InGallery.objects.filter(gallery=gal_id)
    pics = set()
    for in_gal in in_gals:
        pics.add(in_gal.image)
    return render(request, 'article.html', {'article_entity': ArticleEntity(art), 'pictures': pics})<commit_msg>Issue #19: Move index listing to general_listing<commit_after>from django.shortcuts import render, get_object_or_404

from django.http import HttpResponse
from django.template import Context, loader
import math

from articles.models import Article, ArticleCategory, ArticleEntity, Gallery, InGallery, Picture
from listing.pages import PageHelper

default_count_per_page = 5
max_count_per_page = 25
max_pages_listed_on_screen = 5
 
def general_listing(request, eventType, category):
    t = loader.get_template('article_list.html')
    if category != None:
        type_id = ArticleCategory.objects.filter(name=category)[0].id
        article_list = Article.objects.filter(category=type_id).order_by('date').reverse()
    else:
        article_list = Article.objects.all().order_by('date').reverse()
    article_count = PageHelper.get_request_count(request, default_count_per_page, max_count_per_page)
    page_number = PageHelper.get_page_number(request)
    articles_range_min = (page_number - 1) * article_count
    articles_range_max = (page_number) * article_count    
    number_of_articles = len(article_list)
    total_pages = int(math.ceil(number_of_articles / float(article_count)))
    article_list = article_list[articles_range_min:articles_range_max]
    page_numbers_list = PageHelper.calculate_page_range(total_pages, page_number, max_pages_listed_on_screen)    
    next_page = page_number + 1 if number_of_articles > articles_range_max else 0
    prev_page = page_number - 1
    context_dict = {
                    'eventType': eventType,
                    'article_list' : article_list, 
                    'page_number' : page_number, 
                    'prev_page': prev_page, 
                    'next_page' : next_page, 
                    'page_numbers' : page_numbers_list
                    }
    c = Context(context_dict)
    return HttpResponse(t.render(c))

def index(request):
    return general_listing(request, 'All', None)    
 
def service(request):
    return general_listing(request, 'Service', 'Service')

def professional_development(request):
    return general_listing(request, 'Professional Development', 'PD')

def social(request):
    return general_listing(request, 'Social', 'Social')

def get_article(request, article_id):
    art = get_object_or_404(Article, pk=article_id)
    gal_id = art.gallery.id
    in_gals = InGallery.objects.filter(gallery=gal_id)
    pics = set()
    for in_gal in in_gals:
        pics.add(in_gal.image)
    return render(request, 'article.html', {'article_entity': ArticleEntity(art), 'pictures': pics})
{'fraction_non_alphanumeric': 0.09332568368712947, 'fraction_numerical': 0.006310958118187034, 'mean_word_length': 3.901593252108716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2176591', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1551, 'n_words': 315}