# Path: patchwork/models.py
# class Bundle(models.Model):
#     owner = models.ForeignKey(User, on_delete=models.CASCADE)
#     project = models.ForeignKey(Project, on_delete=models.CASCADE)
#     name = models.CharField(max_length=50, null=False, blank=False)
#     patches = models.ManyToManyField(Patch, through='BundlePatch')
#     public = models.BooleanField(default=False)
# 
#     def n_patches(self):
#         return self.patches.all().count()
# 
#     def ordered_patches(self):
#         return self.patches.order_by('bundlepatch__order')
# 
#     def append_patch(self, patch):
#         # todo: use the aggregate queries in django 1.1
#         orders = BundlePatch.objects.filter(bundle=self).order_by('-order') \
#             .values('order')
# 
#         if len(orders) > 0:
#             max_order = orders[0]['order']
#         else:
#             max_order = 0
# 
#         # see if the patch is already in this bundle
#         if BundlePatch.objects.filter(bundle=self, patch=patch).count():
#             raise Exception("patch is already in bundle")
# 
#         bp = BundlePatch.objects.create(bundle=self, patch=patch,
#                                         order=max_order + 1)
#         bp.save()
# 
#     def public_url(self):
#         if not self.public:
#             return None
#         site = Site.objects.get_current()
#         return 'http://%s%s' % (site.domain,
#                                 reverse('bundle',
#                                         kwargs={
#                                             'username': self.owner.username,
#                                             'bundlename': self.name
#                                         }))
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('bundle', (), {
#             'username': self.owner.username,
#             'bundlename': self.name,
#         })
# 
#     class Meta:
#         unique_together = [('owner', 'name')]


from django.contrib.sites.models import Site
from patchwork.models import Bundle
# Patchwork - automated patch tracking system
# Copyright (C) 2017 Intel Corporation
#
# This file is part of the Patchwork package.
#
# Patchwork is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Patchwork is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA




def settings(request):
    return {'settings': settings}


def site(request):
    return {'site': Site.objects.get_current()}



# Path: patchwork/models.py
# class Bundle(models.Model):
#     owner = models.ForeignKey(User, on_delete=models.CASCADE)
#     project = models.ForeignKey(Project, on_delete=models.CASCADE)
#     name = models.CharField(max_length=50, null=False, blank=False)
#     patches = models.ManyToManyField(Patch, through='BundlePatch')
#     public = models.BooleanField(default=False)
# 
#     def n_patches(self):
#         return self.patches.all().count()
# 
#     def ordered_patches(self):
#         return self.patches.order_by('bundlepatch__order')
# 
#     def append_patch(self, patch):
#         # todo: use the aggregate queries in django 1.1
#         orders = BundlePatch.objects.filter(bundle=self).order_by('-order') \
#             .values('order')
# 
#         if len(orders) > 0:
#             max_order = orders[0]['order']
#         else:
#             max_order = 0
# 
#         # see if the patch is already in this bundle
#         if BundlePatch.objects.filter(bundle=self, patch=patch).count():
#             raise Exception("patch is already in bundle")
# 
#         bp = BundlePatch.objects.create(bundle=self, patch=patch,
#                                         order=max_order + 1)
#         bp.save()
# 
#     def public_url(self):
#         if not self.public:
#             return None
#         site = Site.objects.get_current()
#         return 'http://%s%s' % (site.domain,
#                                 reverse('bundle',
#                                         kwargs={
#                                             'username': self.owner.username,
#                                             'bundlename': self.name
#                                         }))
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('bundle', (), {
#             'username': self.owner.username,
#             'bundlename': self.name,
#         })
# 
#     class Meta:
#         unique_together = [('owner', 'name')]


# Path: patchwork/context_processors.py
from django.contrib.sites.models import Site
from patchwork.models import Bundle

# Patchwork - automated patch tracking system
# Copyright (C) 2017 Intel Corporation
#
# This file is part of the Patchwork package.
#
# Patchwork is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Patchwork is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA




def settings(request):
    return {'settings': settings}


def site(request):
    return {'site': Site.objects.get_current()}



def bundle(request):