# Path: shopkit/core/settings.py
# PRODUCT_MODEL = getattr(settings, 'SHOPKIT_PRODUCT_MODEL')
# 
# Path: shopkit/core/basemodels.py
# class OrderedInlineItemBase(models.Model):
#     """
#     This base class does what, actually, order_with_respect_to should do
#     but (for now) doesn't implement very well: ordering of objects with
#     a fk-relation to some class.
# 
#     As we do not know what the class with the respective relation is, it
#     is important to note that something like the following is added::
# 
#         class MyOrderedInline(OrderedInlineItemBase):
# 
#             <related> = models.ForeignKey(RelatedModel)
# 
#             class Meta(OrderedInlineItemBase.Meta):
#                 unique_together = ('sort_order', '<related>')
# 
#             def get_related_ordering(self):
#                 return self.__class__.objects.filter(<related>=self.<related>)
# 
# 
# 
#         ... Or we could simply wait for the Django developers to fix
#         `order_with_respect_to` once and for all. (Work in progress...
#         See `Ticket #13 <http://code.djangoproject.com/ticket/13>`.)
# 
# 
#     """
# 
#     class Meta:
#         abstract = True
#         ordering = ('sort_order', )
# 
#     def get_related_ordering(self):
#         """
#         Get a :class:`QuerySet <django.db.models.QuerySet.QuerySet`
#         with related items to be considered for calculating the next
#         `sort_order`.
# 
#         As we do not know in this base class what the related field(s)
#         are, this raises a NotImplementedError. It should be subclassed
#         with something like::
# 
#             return self.objects.filter(<related>=self.<related>)
# 
#         """
#         raise NotImplementedError
# 
#     @staticmethod
#     def get_next_ordering(related):
#         """
#         Get the next ordering based upon the :class:`QuerySet <django.db.models.QuerySet.QuerySet`
#         with related items.
#         """
#         return get_next_ordering(related)
# 
#     def save(self):
#         """
#         If no `sort_order` has been specified, make sure we calculate the
#         it based on the highest available current `sort_order`.
#         """
# 
#         if not self.sort_order:
#             related = self.get_related_ordering()
#             self.sort_order = self.get_next_ordering(related)
# 
#             logger.debug(
#                 u'Generated sort_order %d for object %s',
#                 self.sort_order, self
#             )
# 
#         super(OrderedInlineItemBase, self).save()
# 
#     sort_order = models.PositiveSmallIntegerField(
#         verbose_name=('sort order'),
#         blank=True, db_index=True,
#         help_text=_(
#             'Change this to alter the order in which items are displayed.'
#         )
#     )
# 
# Path: shopkit/variations/settings.py
# PRODUCTVARIATION_MODEL = getattr(settings, 'SHOPKIT_PRODUCTVARIATION_MODEL')


import logging
from django.db import models
from django.utils.translation import ugettext_lazy as _
from shopkit.core.settings import PRODUCT_MODEL
from shopkit.core.basemodels import OrderedInlineItemBase
from shopkit.variations.settings import PRODUCTVARIATION_MODEL




class ProductVariationBase(models.Model):
    """ Base class for variations of a product. """
    
    class Meta:
        verbose_name = _('product variation')
        verbose_name_plural = _('product variations')
        abstract = True
    
    @classmethod
    def get_default_variation(cls):
        """ Return the default variation selected for this product.
            As there is no inherent way to order these, this function
            should be overridden in classes actually implementing the
            variation model.
            
            This might, for example, be overriden by taking the first product
            in the list or by some function selecting a specific variation as
            default.
        """
        
        raise NotImplemented
    
    product = models.ForeignKey(PRODUCT_MODEL)
    """ Product this variation is linked to. """



# Path: shopkit/core/settings.py
# PRODUCT_MODEL = getattr(settings, 'SHOPKIT_PRODUCT_MODEL')
# 
# Path: shopkit/core/basemodels.py
# class OrderedInlineItemBase(models.Model):
#     """
#     This base class does what, actually, order_with_respect_to should do
#     but (for now) doesn't implement very well: ordering of objects with
#     a fk-relation to some class.
# 
#     As we do not know what the class with the respective relation is, it
#     is important to note that something like the following is added::
# 
#         class MyOrderedInline(OrderedInlineItemBase):
# 
#             <related> = models.ForeignKey(RelatedModel)
# 
#             class Meta(OrderedInlineItemBase.Meta):
#                 unique_together = ('sort_order', '<related>')
# 
#             def get_related_ordering(self):
#                 return self.__class__.objects.filter(<related>=self.<related>)
# 
# 
# 
#         ... Or we could simply wait for the Django developers to fix
#         `order_with_respect_to` once and for all. (Work in progress...
#         See `Ticket #13 <http://code.djangoproject.com/ticket/13>`.)
# 
# 
#     """
# 
#     class Meta:
#         abstract = True
#         ordering = ('sort_order', )
# 
#     def get_related_ordering(self):
#         """
#         Get a :class:`QuerySet <django.db.models.QuerySet.QuerySet`
#         with related items to be considered for calculating the next
#         `sort_order`.
# 
#         As we do not know in this base class what the related field(s)
#         are, this raises a NotImplementedError. It should be subclassed
#         with something like::
# 
#             return self.objects.filter(<related>=self.<related>)
# 
#         """
#         raise NotImplementedError
# 
#     @staticmethod
#     def get_next_ordering(related):
#         """
#         Get the next ordering based upon the :class:`QuerySet <django.db.models.QuerySet.QuerySet`
#         with related items.
#         """
#         return get_next_ordering(related)
# 
#     def save(self):
#         """
#         If no `sort_order` has been specified, make sure we calculate the
#         it based on the highest available current `sort_order`.
#         """
# 
#         if not self.sort_order:
#             related = self.get_related_ordering()
#             self.sort_order = self.get_next_ordering(related)
# 
#             logger.debug(
#                 u'Generated sort_order %d for object %s',
#                 self.sort_order, self
#             )
# 
#         super(OrderedInlineItemBase, self).save()
# 
#     sort_order = models.PositiveSmallIntegerField(
#         verbose_name=('sort order'),
#         blank=True, db_index=True,
#         help_text=_(
#             'Change this to alter the order in which items are displayed.'
#         )
#     )
# 
# Path: shopkit/variations/settings.py
# PRODUCTVARIATION_MODEL = getattr(settings, 'SHOPKIT_PRODUCTVARIATION_MODEL')


# Path: shopkit/variations/models.py
import logging
from django.db import models
from django.utils.translation import ugettext_lazy as _
from shopkit.core.settings import PRODUCT_MODEL
from shopkit.core.basemodels import OrderedInlineItemBase
from shopkit.variations.settings import PRODUCTVARIATION_MODEL





class ProductVariationBase(models.Model):
    """ Base class for variations of a product. """
    
    class Meta:
        verbose_name = _('product variation')
        verbose_name_plural = _('product variations')
        abstract = True
    
    @classmethod
    def get_default_variation(cls):
        """ Return the default variation selected for this product.
            As there is no inherent way to order these, this function
            should be overridden in classes actually implementing the
            variation model.
            
            This might, for example, be overriden by taking the first product
            in the list or by some function selecting a specific variation as
            default.
        """
        
        raise NotImplemented
    
    product = models.ForeignKey(PRODUCT_MODEL)
    """ Product this variation is linked to. """



class OrderedProductVariationBase(ProductVariationBase, OrderedInlineItemBase):