<commit_before>from piston.handler import BaseHandler, AnonymousBaseHandler
from data.models import AnnualStateEnergyConsumption, AnnualStateEnergyExpenditures, StateEnergyProductionEstimates, MSNCodes, StatePostalCodes, FIPSState
from data.models import ANSICountyState, FIPSCountyCongressDistrict, NCESSchoolDistrict
from django.conf import settings

def page_limits(request_get):    
    page = 1
    if 'page' in request_get:
        page = int(request_get['page'])

    lower_row = (page*settings.SEARCH_PAGINATE_BY) - settings.SEARCH_PAGINATE_BY
    upper_row = lower_row + settings.SEARCH_PAGINATE_BY
    
    return {'lower_row':lower_row, 'upper_row':upper_row}
    

class GenericHandler(BaseHandler):
    def __init__(self, allowed_keys, model):
        self.model = model
        self.allowed_keys = allowed_keys 
    allowed_methods = ('GET',)
    
    def read(self, request):
        bounds = page_limits(request.GET)

        params = {}
        for key,val in request.GET.items():
            if key in self.allowed_keys:
                params[str(key)] = val
 
        records = self.model.objects.all()           
        records = records.filter(**params)[bounds['lower_row']:bounds['upper_row']]
        return records<commit_msg>tiny change to page_limits<commit_after>from piston.handler import BaseHandler, AnonymousBaseHandler
from data.models import AnnualStateEnergyConsumption, AnnualStateEnergyExpenditures, StateEnergyProductionEstimates, MSNCodes, StatePostalCodes, FIPSState
from data.models import ANSICountyState, FIPSCountyCongressDistrict, NCESSchoolDistrict
from django.conf import settings

def page_limits(request_get):    
    page = 1
    if 'page' in request_get:
        page = int(request_get['page'])

    lower_row = (page*settings.SEARCH_PAGINATE_BY) - settings.SEARCH_PAGINATE_BY
    upper_row = lower_row + settings.SEARCH_PAGINATE_BY
    
    return {'lower_row':lower_row, 'upper_row':upper_row}
    

class GenericHandler(BaseHandler):
    def __init__(self, allowed_keys, model, fields=None, exclude=None):
        self.fields = fields
        self.exclude = exclude
        self.model = model
        self.allowed_keys = allowed_keys 
    allowed_methods = ('GET',)
    
    def read(self, request):
        bounds = page_limits(request.GET)

        params = {}
        for key,val in request.GET.items():
            if key in self.allowed_keys:
                params[str(key)] = val
 
        records = self.model.objects.all()           
        records = records.filter(**params)[bounds['lower_row']:bounds['upper_row']]
        return records
{'fraction_non_alphanumeric': 0.08986175115207373, 'fraction_numerical': 0.0007680491551459293, 'mean_word_length': 3.445392491467577, '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': '783776', 'n_tokens_mistral': 791, 'n_tokens_neox': 747, 'n_words': 162}