# Path: bidb/buildinfo/models.py
# class Buildinfo(models.Model):
#     sha1 = models.CharField(max_length=40, unique=True)
# 
#     source = models.ForeignKey(
#         'packages.Source',
#         related_name='buildinfos',
#     )
# 
#     architecture = models.ForeignKey(
#         'packages.Architecture',
#         related_name='buildinfos',
#     )
#     version = models.CharField(max_length=200)
# 
#     build_path = models.CharField(max_length=512)
#     build_date = models.DateTimeField(null=True)
#     build_origin = models.ForeignKey('Origin', null=True)
#     build_architecture = models.ForeignKey(
#         'packages.Architecture',
#         related_name='buildinfos_build',
#     )
# 
#     environment = models.TextField()
# 
#     created = models.DateTimeField(default=datetime.datetime.utcnow)
# 
#     class Meta:
#         ordering = ('-created',)
#         get_latest_by = 'created'
# 
#     def __unicode__(self):
#         return u"pk=%d source=%r version=%r" % (
#             self.pk,
#             self.source,
#             self.version,
#         )
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return 'buildinfo:view', (self.sha1, self.get_filename())
# 
#     @models.permalink
#     def get_absolute_raw_url(self):
#         return 'buildinfo:raw-text', (self.sha1, self.get_filename())
# 
#     def get_filename(self):
#         return '{}_{}_{}'.format(
#             self.source.name,
#             self.version,
#             self.architecture.name.split(' ')[0],
#         )
# 
#     def get_storage_name(self):
#         return 'buildinfo.Buildinfo/{}/{}/{}'.format(
#             self.sha1[:2],
#             self.sha1[2:4],
#             self.sha1,
#         )


from django.conf import settings
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render, get_object_or_404, redirect
from django.core.files.storage import default_storage
from .models import Buildinfo



def view(request, sha1, filename=None):
    buildinfo = get_object_or_404(Buildinfo, sha1=sha1)

    if filename != buildinfo.get_filename():
        return redirect(buildinfo)

    return render(request, 'buildinfo/view.html', {
        'buildinfo': buildinfo,
    })

def raw_text(request, sha1, filename=None):

# Path: bidb/buildinfo/models.py
# class Buildinfo(models.Model):
#     sha1 = models.CharField(max_length=40, unique=True)
# 
#     source = models.ForeignKey(
#         'packages.Source',
#         related_name='buildinfos',
#     )
# 
#     architecture = models.ForeignKey(
#         'packages.Architecture',
#         related_name='buildinfos',
#     )
#     version = models.CharField(max_length=200)
# 
#     build_path = models.CharField(max_length=512)
#     build_date = models.DateTimeField(null=True)
#     build_origin = models.ForeignKey('Origin', null=True)
#     build_architecture = models.ForeignKey(
#         'packages.Architecture',
#         related_name='buildinfos_build',
#     )
# 
#     environment = models.TextField()
# 
#     created = models.DateTimeField(default=datetime.datetime.utcnow)
# 
#     class Meta:
#         ordering = ('-created',)
#         get_latest_by = 'created'
# 
#     def __unicode__(self):
#         return u"pk=%d source=%r version=%r" % (
#             self.pk,
#             self.source,
#             self.version,
#         )
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return 'buildinfo:view', (self.sha1, self.get_filename())
# 
#     @models.permalink
#     def get_absolute_raw_url(self):
#         return 'buildinfo:raw-text', (self.sha1, self.get_filename())
# 
#     def get_filename(self):
#         return '{}_{}_{}'.format(
#             self.source.name,
#             self.version,
#             self.architecture.name.split(' ')[0],
#         )
# 
#     def get_storage_name(self):
#         return 'buildinfo.Buildinfo/{}/{}/{}'.format(
#             self.sha1[:2],
#             self.sha1[2:4],
#             self.sha1,
#         )


# Path: bidb/buildinfo/views.py
from django.conf import settings
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render, get_object_or_404, redirect
from django.core.files.storage import default_storage
from .models import Buildinfo




def view(request, sha1, filename=None):
    buildinfo = get_object_or_404(Buildinfo, sha1=sha1)

    if filename != buildinfo.get_filename():
        return redirect(buildinfo)

    return render(request, 'buildinfo/view.html', {
        'buildinfo': buildinfo,
    })

def raw_text(request, sha1, filename=None):

    buildinfo = get_object_or_404(Buildinfo, sha1=sha1)