<commit_before>from django.views.generic import DetailView, ListView, FormView
from django.db.models import Count
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from leaflets.models import Leaflet
from .forms import ConstituencyLookupForm
from .models import Constituency
from core.helpers import geocode
from datetime import datetime

class ConstituencyView(DetailView):
    model = Constituency

    def get_context_data(self, **kwargs):
        context = super(ConstituencyView, self).get_context_data(**kwargs)
        qs = Leaflet.objects.filter(constituency_id=self.kwargs['pk'])

        paginator = Paginator(qs, 60)
        page = self.request.GET.get('page')

        if not page or page == 1:
            if qs:
                context['last_leaflet_days'] = (datetime.now() - qs[0].date_uploaded).days

        try:
            context['constituency_leaflets'] = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            context['constituency_leaflets'] = paginator.page(1)

        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            context['constituency_leaflets'] = paginator.page(paginator.num_pages)

        return context

class ConstituencyList(ListView, FormView):
    form_class = ConstituencyLookupForm
    queryset = Constituency.objects.all()\
               .annotate(num_leaflets=Count('leaflet'))\
               .order_by('-num_leaflets')

    def get(self, request, *args, **kwargs):
        form_class = self.get_form_class()<commit_msg>Changes the constituency ordering to be alphabetic<commit_after>from django.views.generic import DetailView, ListView, FormView
from django.db.models import Count
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from leaflets.models import Leaflet
from .forms import ConstituencyLookupForm
from .models import Constituency
from core.helpers import geocode
from datetime import datetime

class ConstituencyView(DetailView):
    model = Constituency

    def get_context_data(self, **kwargs):
        context = super(ConstituencyView, self).get_context_data(**kwargs)
        qs = Leaflet.objects.filter(constituency_id=self.kwargs['pk'])

        paginator = Paginator(qs, 60)
        page = self.request.GET.get('page')

        if not page or page == 1:
            if qs:
                context['last_leaflet_days'] = (datetime.now() - qs[0].date_uploaded).days

        try:
            context['constituency_leaflets'] = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            context['constituency_leaflets'] = paginator.page(1)

        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            context['constituency_leaflets'] = paginator.page(paginator.num_pages)

        return context

class ConstituencyList(ListView, FormView):
    form_class = ConstituencyLookupForm
    queryset = Constituency.objects.all()\
               .annotate(num_leaflets=Count('leaflet'))\
               .order_by('name')

    def get(self, request, *args, **kwargs):
        form_class = self.get_form_class()
{'fraction_non_alphanumeric': 0.09437996334758705, 'fraction_numerical': 0.005497861942577886, 'mean_word_length': 3.124685138539043, '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': '5927307', 'n_tokens_mistral': 969, 'n_tokens_neox': 932, 'n_words': 235}