from django.contrib.auth.models import User
from django.db import models
from django.utils.translation import ugettext_lazy as _

import settings


class Campaign(models.Model):
    name = models.CharField(_("Name"), max_length=255, unique=True)
    description = models.TextField(_("Description"), blank=True, null=True)

    class Meta:
        ordering = ['name']

    def __unicode__(self):
        return self.name

class Referrer(models.Model):
    name = models.CharField(_("Name"), max_length=255, unique=True)
    description = models.TextField(_("Description"), blank=True, null=True)
    creation_date = models.DateTimeField(_("Creation date"), auto_now_add=True)
    campaign = models.ForeignKey(Campaign, verbose_name=_("Campaign"), blank=True, null=True)

    class Meta:
        ordering = ['name']

    def __unicode__(self):
        return self.name

class UserReferrerManager(models.Manager):
    def apply_referrer(self, user, request):
        try:
            referrer = request.session.pop(settings.SESSION_KEY)
        except KeyError:
            pass
        else:
            user_referrer = UserReferrer(user=user, referrer=referrer)
            user_referrer.save()

class UserReferrer(models.Model):
    user = models.OneToOneField(User, verbose_name=_("User"), related_name='referrer')
    referrer = models.ForeignKey(Referrer, verbose_name=_("Referrer"), related_name='users')

    objects = UserReferrerManager()

    class Meta:
        ordering = ['referrer__name']

    def __unicode__(self):
        return "%s -> %s" % (self.user.username, self.referrer.name)


@@ -351,32 +351,114 @@
 ering = %5B'name'%5D
+%0A        verbose_name = _(%22Campaign%22)%0A        verbose_name_plural = _(%22Campaigns%22)
 %0A%0A    def __unic
@@ -884,24 +884,106 @@
 g = %5B'name'%5D
+%0A        verbose_name = _(%22Referrer%22)%0A        verbose_name_plural = _(%22Referrers%22)
 %0A%0A    def __
@@ -1612,32 +1612,32 @@
     class Meta:%0A
-
         ordering
@@ -1657,16 +1657,108 @@
 __name'%5D
+%0A        verbose_name = _(%22User Referrer%22)%0A        verbose_name_plural = _(%22User Referrers%22)
 %0A%0A    de

add verbose names for models