# Path: bidb/utils/itertools.py
# def groupby(iterable, keyfunc, sortfunc=lambda x: x):
#     return [
#         (x, list(sorted(y, key=sortfunc)))
#         for x, y in itertools.groupby(iterable, keyfunc)
#     ]
# 
# Path: bidb/utils/paginator.py
# class AutoPaginator(Paginator):
#     def __init__(self, request, *args, **kwargs):
#         self.request = request
#         self.default = kwargs.pop('default', 1)
#         super(AutoPaginator, self).__init__(*args, **kwargs)
# 
#     def current_page(self):
#         try:
#             page = int(self.request.GET['page'])
# 
#             if page <= 0:
#                 raise ValueError()
#         except (ValueError, KeyError):
#             page = self.default
# 
#         try:
#             return self.page(page)
#         except EmptyPage:
#             return Page([], page, self)
# 
#     def validate_number(self, number):
#         """
#         Our version ignores EmptyPage.
#         """
#         try:
#             return max(1, int(number))
#         except (TypeError, ValueError):
#             return 1
# 
# Path: bidb/buildinfo/buildinfo_submissions/models.py
# class Submission(models.Model):
#     buildinfo = models.ForeignKey(
#         'buildinfo.Buildinfo',
#         related_name='submissions',
#     )
# 
#     slug = models.CharField(
#         unique=True,
#         default=functools.partial(
#             get_random_string, 8, '3479abcdefghijkmnopqrstuvwxyz',
#         ),
#         max_length=8,
#     )
# 
#     key = models.ForeignKey('keys.Key', related_name='submissions')
# 
#     created = models.DateTimeField(default=datetime.datetime.utcnow)
# 
#     class Meta:
#         ordering = ('created',)
#         get_latest_by = 'created'
# 
#     def __unicode__(self):
#         return u"pk=%d buildinfo=%r" % (
#             self.pk,
#             self.buildinfo,
#         )
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return 'buildinfo:submissions:view', (
#             self.buildinfo.sha1,
#             self.buildinfo.get_filename(),
#             self.slug,
#         )
# 
#     def get_storage_name(self):
#         return 'buildinfo_submissions.Submission/{}/{}/{}'.format(
#             self.slug[:2],
#             self.slug[2:4],
#             self.slug,
#         )
# 
# Path: bidb/packages/models.py
# class Binary(models.Model):
#     name = models.CharField(max_length=200, unique=True)
# 
#     class Meta:
#         ordering = ('name',)
#         get_latest_by = 'created'
# 
#     def __unicode__(self):
#         return u"pk=%d name=%r" % (
#             self.pk,
#             self.name,
#         )
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return 'packages:binary', (self.name,)
# 
# class Source(models.Model):
#     name = models.CharField(max_length=200, unique=True)
# 
#     created = models.DateTimeField(default=datetime.datetime.utcnow)
# 
#     class Meta:
#         ordering = ('name',)
#         get_latest_by = 'created'
# 
#     def __unicode__(self):
#         return u"pk=%d name=%r" % (
#             self.pk,
#             self.name,
#         )
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return 'packages:source', (self.name,)


from django.conf import settings
from django.http import Http404, JsonResponse
from django.shortcuts import render, get_object_or_404
from bidb.utils.itertools import groupby
from bidb.utils.paginator import AutoPaginator
from bidb.buildinfo.buildinfo_submissions.models import Submission
from .models import Binary, Source





def sources(request):
    page = AutoPaginator(request, Source.objects.all(), 250).current_page()

    return render(request, 'packages/sources.html', {
        'page': page,
    })

def binaries(request):

# Path: bidb/utils/itertools.py
# def groupby(iterable, keyfunc, sortfunc=lambda x: x):
#     return [
#         (x, list(sorted(y, key=sortfunc)))
#         for x, y in itertools.groupby(iterable, keyfunc)
#     ]
# 
# Path: bidb/utils/paginator.py
# class AutoPaginator(Paginator):
#     def __init__(self, request, *args, **kwargs):
#         self.request = request
#         self.default = kwargs.pop('default', 1)
#         super(AutoPaginator, self).__init__(*args, **kwargs)
# 
#     def current_page(self):
#         try:
#             page = int(self.request.GET['page'])
# 
#             if page <= 0:
#                 raise ValueError()
#         except (ValueError, KeyError):
#             page = self.default
# 
#         try:
#             return self.page(page)
#         except EmptyPage:
#             return Page([], page, self)
# 
#     def validate_number(self, number):
#         """
#         Our version ignores EmptyPage.
#         """
#         try:
#             return max(1, int(number))
#         except (TypeError, ValueError):
#             return 1
# 
# Path: bidb/buildinfo/buildinfo_submissions/models.py
# class Submission(models.Model):
#     buildinfo = models.ForeignKey(
#         'buildinfo.Buildinfo',
#         related_name='submissions',
#     )
# 
#     slug = models.CharField(
#         unique=True,
#         default=functools.partial(
#             get_random_string, 8, '3479abcdefghijkmnopqrstuvwxyz',
#         ),
#         max_length=8,
#     )
# 
#     key = models.ForeignKey('keys.Key', related_name='submissions')
# 
#     created = models.DateTimeField(default=datetime.datetime.utcnow)
# 
#     class Meta:
#         ordering = ('created',)
#         get_latest_by = 'created'
# 
#     def __unicode__(self):
#         return u"pk=%d buildinfo=%r" % (
#             self.pk,
#             self.buildinfo,
#         )
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return 'buildinfo:submissions:view', (
#             self.buildinfo.sha1,
#             self.buildinfo.get_filename(),
#             self.slug,
#         )
# 
#     def get_storage_name(self):
#         return 'buildinfo_submissions.Submission/{}/{}/{}'.format(
#             self.slug[:2],
#             self.slug[2:4],
#             self.slug,
#         )
# 
# Path: bidb/packages/models.py
# class Binary(models.Model):
#     name = models.CharField(max_length=200, unique=True)
# 
#     class Meta:
#         ordering = ('name',)
#         get_latest_by = 'created'
# 
#     def __unicode__(self):
#         return u"pk=%d name=%r" % (
#             self.pk,
#             self.name,
#         )
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return 'packages:binary', (self.name,)
# 
# class Source(models.Model):
#     name = models.CharField(max_length=200, unique=True)
# 
#     created = models.DateTimeField(default=datetime.datetime.utcnow)
# 
#     class Meta:
#         ordering = ('name',)
#         get_latest_by = 'created'
# 
#     def __unicode__(self):
#         return u"pk=%d name=%r" % (
#             self.pk,
#             self.name,
#         )
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return 'packages:source', (self.name,)


# Path: bidb/packages/views.py
from django.conf import settings
from django.http import Http404, JsonResponse
from django.shortcuts import render, get_object_or_404
from bidb.utils.itertools import groupby
from bidb.utils.paginator import AutoPaginator
from bidb.buildinfo.buildinfo_submissions.models import Submission
from .models import Binary, Source






def sources(request):
    page = AutoPaginator(request, Source.objects.all(), 250).current_page()

    return render(request, 'packages/sources.html', {
        'page': page,
    })

def binaries(request):

    page = AutoPaginator(request, Binary.objects.all(), 250).current_page()