# Path: symposion/conference/models.py
# class Conference(models.Model):
#     """
#     the full conference for a specific year, e.g. US PyCon 2012.
#     """
#     
#     title = models.CharField(_("title"), max_length=100)
#     
#     # when the conference runs
#     start_date = models.DateField(_("start date"), null=True, blank=True)
#     end_date = models.DateField(_("end date"), null=True, blank=True)
#     
#     # timezone the conference is in
#     timezone = TimeZoneField(_("timezone"), blank=True)
#     
#     def __unicode__(self):
#         return self.title
#     
#     def save(self, *args, **kwargs):
#         super(Conference, self).save(*args, **kwargs)
#         if self.id in CONFERENCE_CACHE:
#             del CONFERENCE_CACHE[self.id]
#     
#     def delete(self):
#         pk = self.pk
#         super(Conference, self).delete()
#         try:
#             del CONFERENCE_CACHE[pk]
#         except KeyError:
#             pass
#     
#     class Meta(object):
#         verbose_name = _("conference")
#         verbose_name_plural = _("conferences")
# 
# Path: pycon/sponsorship/managers.py
# class SponsorManager(models.Manager):
# 
#     def active(self):
#         return self.get_query_set().filter(active=True).order_by("level")
#     
#     def with_weblogo(self):
#         queryset = self.raw("""
#         SELECT DISTINCT
#             "sponsorship_sponsor"."id",
#             "sponsorship_sponsor"."applicant_id",
#             "sponsorship_sponsor"."name",
#             "sponsorship_sponsor"."external_url",
#             "sponsorship_sponsor"."annotation",
#             "sponsorship_sponsor"."contact_name",
#             "sponsorship_sponsor"."contact_email",
#             "sponsorship_sponsor"."level_id",
#             "sponsorship_sponsor"."added",
#             "sponsorship_sponsor"."active",
#             "sponsorship_sponsorlevel"."order"
#         FROM
#             "sponsorship_sponsor"
#             INNER JOIN
#                 "sponsorship_sponsorbenefit" ON ("sponsorship_sponsor"."id" = "sponsorship_sponsorbenefit"."sponsor_id")
#             INNER JOIN
#                 "sponsorship_benefit" ON ("sponsorship_sponsorbenefit"."benefit_id" = "sponsorship_benefit"."id")
#             LEFT OUTER JOIN
#                 "sponsorship_sponsorlevel" ON ("sponsorship_sponsor"."level_id" = "sponsorship_sponsorlevel"."id")
#         WHERE (
#             "sponsorship_sponsor"."active" = 't' AND
#             "sponsorship_benefit"."type" = 'weblogo' AND
#             "sponsorship_sponsorbenefit"."upload" != ''
#         )
#         ORDER BY "sponsorship_sponsorlevel"."order" ASC, "sponsorship_sponsor"."added" ASC
#         """)
#         return queryset


import datetime
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.db import models
from django.db.models.signals import post_init, post_save
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from symposion.conference.models import Conference
from pycon.sponsorship import SPONSOR_COORDINATORS
from pycon.sponsorship.managers import SponsorManager
    
    class Meta:
        verbose_name = _("sponsor")
        verbose_name_plural = _("sponsors")
    
    def get_absolute_url(self):
        if self.active:
            return reverse("sponsor_detail", kwargs={"pk": self.pk})
        return reverse("sponsor_list")
    
    def get_display_url(self):
        if self.display_url:
            return self.display_url
        else:
            return self.external_url

    @property
    def website_logo_url(self):
        if not hasattr(self, "_website_logo_url"):
            self._website_logo_url = None
            benefits = self.sponsor_benefits.filter(benefit__type="weblogo", upload__isnull=False)
            if benefits.exists():
                # @@@ smarter handling of multiple weblogo benefits?
                # shouldn't happen
                if benefits[0].upload:
                    self._website_logo_url = benefits[0].upload.url
        return self._website_logo_url
    
    @property
    def listing_text(self):

# Path: symposion/conference/models.py
# class Conference(models.Model):
#     """
#     the full conference for a specific year, e.g. US PyCon 2012.
#     """
#     
#     title = models.CharField(_("title"), max_length=100)
#     
#     # when the conference runs
#     start_date = models.DateField(_("start date"), null=True, blank=True)
#     end_date = models.DateField(_("end date"), null=True, blank=True)
#     
#     # timezone the conference is in
#     timezone = TimeZoneField(_("timezone"), blank=True)
#     
#     def __unicode__(self):
#         return self.title
#     
#     def save(self, *args, **kwargs):
#         super(Conference, self).save(*args, **kwargs)
#         if self.id in CONFERENCE_CACHE:
#             del CONFERENCE_CACHE[self.id]
#     
#     def delete(self):
#         pk = self.pk
#         super(Conference, self).delete()
#         try:
#             del CONFERENCE_CACHE[pk]
#         except KeyError:
#             pass
#     
#     class Meta(object):
#         verbose_name = _("conference")
#         verbose_name_plural = _("conferences")
# 
# Path: pycon/sponsorship/managers.py
# class SponsorManager(models.Manager):
# 
#     def active(self):
#         return self.get_query_set().filter(active=True).order_by("level")
#     
#     def with_weblogo(self):
#         queryset = self.raw("""
#         SELECT DISTINCT
#             "sponsorship_sponsor"."id",
#             "sponsorship_sponsor"."applicant_id",
#             "sponsorship_sponsor"."name",
#             "sponsorship_sponsor"."external_url",
#             "sponsorship_sponsor"."annotation",
#             "sponsorship_sponsor"."contact_name",
#             "sponsorship_sponsor"."contact_email",
#             "sponsorship_sponsor"."level_id",
#             "sponsorship_sponsor"."added",
#             "sponsorship_sponsor"."active",
#             "sponsorship_sponsorlevel"."order"
#         FROM
#             "sponsorship_sponsor"
#             INNER JOIN
#                 "sponsorship_sponsorbenefit" ON ("sponsorship_sponsor"."id" = "sponsorship_sponsorbenefit"."sponsor_id")
#             INNER JOIN
#                 "sponsorship_benefit" ON ("sponsorship_sponsorbenefit"."benefit_id" = "sponsorship_benefit"."id")
#             LEFT OUTER JOIN
#                 "sponsorship_sponsorlevel" ON ("sponsorship_sponsor"."level_id" = "sponsorship_sponsorlevel"."id")
#         WHERE (
#             "sponsorship_sponsor"."active" = 't' AND
#             "sponsorship_benefit"."type" = 'weblogo' AND
#             "sponsorship_sponsorbenefit"."upload" != ''
#         )
#         ORDER BY "sponsorship_sponsorlevel"."order" ASC, "sponsorship_sponsor"."added" ASC
#         """)
#         return queryset


# Path: pycon/sponsorship/models.py
import datetime
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.db import models
from django.db.models.signals import post_init, post_save
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from symposion.conference.models import Conference
from pycon.sponsorship import SPONSOR_COORDINATORS
from pycon.sponsorship.managers import SponsorManager

    
    class Meta:
        verbose_name = _("sponsor")
        verbose_name_plural = _("sponsors")
    
    def get_absolute_url(self):
        if self.active:
            return reverse("sponsor_detail", kwargs={"pk": self.pk})
        return reverse("sponsor_list")
    
    def get_display_url(self):
        if self.display_url:
            return self.display_url
        else:
            return self.external_url

    @property
    def website_logo_url(self):
        if not hasattr(self, "_website_logo_url"):
            self._website_logo_url = None
            benefits = self.sponsor_benefits.filter(benefit__type="weblogo", upload__isnull=False)
            if benefits.exists():
                # @@@ smarter handling of multiple weblogo benefits?
                # shouldn't happen
                if benefits[0].upload:
                    self._website_logo_url = benefits[0].upload.url
        return self._website_logo_url
    
    @property
    def listing_text(self):

        if not hasattr(self, "_listing_text"):