# Path: sponsors/models/assets.py
# class GenericAsset(PolymorphicModel):
#     """
#     Base class used to add required assets to Sponsor or Sponsorship objects
#     """
#     objects = GenericAssetQuerySet.as_manager()
#     non_polymorphic = models.Manager()
# 
#     # UUID can't be the object ID because Polymorphic expects default django integer ID
#     uuid = models.UUIDField(default=uuid.uuid4, editable=False)
#     # The next 3 fields are required by Django to enable and set up generic relations
#     # pointing the asset to a Sponsor or Sponsorship object
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey("content_type", "object_id")
# 
#     # must match with internal_name from benefits configuration which describe assets
#     internal_name = models.CharField(
#         max_length=128,
#         verbose_name="Internal Name",
#         db_index=True,
#     )
# 
#     class Meta:
#         verbose_name = "Asset"
#         verbose_name_plural = "Assets"
#         unique_together = ["content_type", "object_id", "internal_name"]
#         base_manager_name = 'non_polymorphic'
# 
#     @property
#     def value(self):
#         return None
# 
#     @property
#     def is_file(self):
#         return isinstance(self.value, FileField) or isinstance(self.value, ImageFieldFile)
# 
#     @property
#     def from_sponsorship(self):
#         return self.content_type.name == "sponsorship"
# 
#     @property
#     def from_sponsor(self):
#         return self.content_type.name == "sponsor"
# 
#     @property
#     def has_value(self):
#         if self.is_file:
#             return self.value and getattr(self.value, "url", None)
#         else:
#             return bool(self.value)
# 
#     @classmethod
#     def all_asset_types(cls):
#         return cls.__subclasses__()
# 
# Path: sponsors/models/managers.py
# class SponsorContactQuerySet(QuerySet):
#     def get_primary_contact(self, sponsor):
#         contact = self.filter(sponsor=sponsor, primary=True).first()
#         if not contact:
#             raise self.model.DoesNotExist()
#         return contact
# 
#     def filter_by_contact_types(self, primary=False, administrative=False, accounting=False, manager=False):
#         if not any([primary, administrative, accounting, manager]):
#             return self.none()
# 
#         query = Q()
#         if primary:
#             query |= Q(primary=True)
#         if administrative:
#             query |= Q(administrative=True)
#         if accounting:
#             query |= Q(accounting=True)
#         if manager:
#             query |= Q(manager=True)
# 
#         return self.filter(query)


from allauth.account.models import EmailAddress
from django.conf import settings
from django.db import models
from django.core.exceptions import ObjectDoesNotExist
from django.template.defaultfilters import slugify
from django.urls import reverse
from django_countries.fields import CountryField
from ordered_model.models import OrderedModel
from django.contrib.contenttypes.fields import GenericRelation
from cms.models import ContentManageable
from sponsors.models.assets import GenericAsset
from sponsors.models.managers import SponsorContactQuerySet
    def primary_contact(self):
        try:
            return SponsorContact.objects.get_primary_contact(self)
        except SponsorContact.DoesNotExist:
            return None

    @property
    def slug(self):
        return slugify(self.name)

    @property
    def admin_url(self):
        return reverse("admin:sponsors_sponsor_change", args=[self.pk])


class SponsorContact(models.Model):
    """
    Sponsor contact information
    """
    PRIMARY_CONTACT = "primary"
    ADMINISTRATIVE_CONTACT = "administrative"
    ACCOUTING_CONTACT = "accounting"
    MANAGER_CONTACT = "manager"
    CONTACT_TYPES = [
        (PRIMARY_CONTACT, "Primary"),
        (ADMINISTRATIVE_CONTACT, "Administrative"),
        (ACCOUTING_CONTACT, "Accounting"),
        (MANAGER_CONTACT, "Manager"),
    ]


# Path: sponsors/models/assets.py
# class GenericAsset(PolymorphicModel):
#     """
#     Base class used to add required assets to Sponsor or Sponsorship objects
#     """
#     objects = GenericAssetQuerySet.as_manager()
#     non_polymorphic = models.Manager()
# 
#     # UUID can't be the object ID because Polymorphic expects default django integer ID
#     uuid = models.UUIDField(default=uuid.uuid4, editable=False)
#     # The next 3 fields are required by Django to enable and set up generic relations
#     # pointing the asset to a Sponsor or Sponsorship object
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey("content_type", "object_id")
# 
#     # must match with internal_name from benefits configuration which describe assets
#     internal_name = models.CharField(
#         max_length=128,
#         verbose_name="Internal Name",
#         db_index=True,
#     )
# 
#     class Meta:
#         verbose_name = "Asset"
#         verbose_name_plural = "Assets"
#         unique_together = ["content_type", "object_id", "internal_name"]
#         base_manager_name = 'non_polymorphic'
# 
#     @property
#     def value(self):
#         return None
# 
#     @property
#     def is_file(self):
#         return isinstance(self.value, FileField) or isinstance(self.value, ImageFieldFile)
# 
#     @property
#     def from_sponsorship(self):
#         return self.content_type.name == "sponsorship"
# 
#     @property
#     def from_sponsor(self):
#         return self.content_type.name == "sponsor"
# 
#     @property
#     def has_value(self):
#         if self.is_file:
#             return self.value and getattr(self.value, "url", None)
#         else:
#             return bool(self.value)
# 
#     @classmethod
#     def all_asset_types(cls):
#         return cls.__subclasses__()
# 
# Path: sponsors/models/managers.py
# class SponsorContactQuerySet(QuerySet):
#     def get_primary_contact(self, sponsor):
#         contact = self.filter(sponsor=sponsor, primary=True).first()
#         if not contact:
#             raise self.model.DoesNotExist()
#         return contact
# 
#     def filter_by_contact_types(self, primary=False, administrative=False, accounting=False, manager=False):
#         if not any([primary, administrative, accounting, manager]):
#             return self.none()
# 
#         query = Q()
#         if primary:
#             query |= Q(primary=True)
#         if administrative:
#             query |= Q(administrative=True)
#         if accounting:
#             query |= Q(accounting=True)
#         if manager:
#             query |= Q(manager=True)
# 
#         return self.filter(query)


# Path: sponsors/models/sponsors.py
from allauth.account.models import EmailAddress
from django.conf import settings
from django.db import models
from django.core.exceptions import ObjectDoesNotExist
from django.template.defaultfilters import slugify
from django.urls import reverse
from django_countries.fields import CountryField
from ordered_model.models import OrderedModel
from django.contrib.contenttypes.fields import GenericRelation
from cms.models import ContentManageable
from sponsors.models.assets import GenericAsset
from sponsors.models.managers import SponsorContactQuerySet

    def primary_contact(self):
        try:
            return SponsorContact.objects.get_primary_contact(self)
        except SponsorContact.DoesNotExist:
            return None

    @property
    def slug(self):
        return slugify(self.name)

    @property
    def admin_url(self):
        return reverse("admin:sponsors_sponsor_change", args=[self.pk])


class SponsorContact(models.Model):
    """
    Sponsor contact information
    """
    PRIMARY_CONTACT = "primary"
    ADMINISTRATIVE_CONTACT = "administrative"
    ACCOUTING_CONTACT = "accounting"
    MANAGER_CONTACT = "manager"
    CONTACT_TYPES = [
        (PRIMARY_CONTACT, "Primary"),
        (ADMINISTRATIVE_CONTACT, "Administrative"),
        (ACCOUTING_CONTACT, "Accounting"),
        (MANAGER_CONTACT, "Manager"),
    ]


    objects = SponsorContactQuerySet.as_manager()