# Path: advertisements/managers.py
# class AdvertisementManager(models.Manager):
#     def get_queryset(self):
#         return AdvertisementQueryset(model=self.model, using=self._db)


from django.db import models
from random import randint, sample
from django.utils import timezone
from datetime import timedelta
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.core.signing import TimestampSigner
from django.utils.functional import cached_property
from .managers import AdvertisementManager
import uuid
import os
    def __unicode__(self):
        return self.name

    def active_ads(self):
        return self.advertisement_set.filter(status=Advertisement.ACTIVE).count()

    def active_ads_list(self):
        return self.advertisement_set.filter(status=Advertisement.ACTIVE)

    def inactive_ads(self):
        return self.advertisement_set.filter(status=Advertisement.INACTIVE).count()

    def total_clicks(self):
        click_count = 0
        for advert in self.advertisement_set.filter(status=Advertisement.ACTIVE):
            click_count += advert.click_set.count()
        return click_count

    def get_absolute_url(self):
        return reverse('advertisements.views.view_provider_statistics', args=[self.pk])


def get_file_path(instance, filename):
    ext = filename.split('.')[-1]
    filename = "%s.%s" % (uuid.uuid4(), ext)
    return os.path.join('resources', filename)


class AdvertisementPanel(models.Model):
    name = models.CharField(max_length=255)

# Path: advertisements/managers.py
# class AdvertisementManager(models.Manager):
#     def get_queryset(self):
#         return AdvertisementQueryset(model=self.model, using=self._db)


# Path: advertisements/models.py
from django.db import models
from random import randint, sample
from django.utils import timezone
from datetime import timedelta
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.core.signing import TimestampSigner
from django.utils.functional import cached_property
from .managers import AdvertisementManager
import uuid
import os

    def __unicode__(self):
        return self.name

    def active_ads(self):
        return self.advertisement_set.filter(status=Advertisement.ACTIVE).count()

    def active_ads_list(self):
        return self.advertisement_set.filter(status=Advertisement.ACTIVE)

    def inactive_ads(self):
        return self.advertisement_set.filter(status=Advertisement.INACTIVE).count()

    def total_clicks(self):
        click_count = 0
        for advert in self.advertisement_set.filter(status=Advertisement.ACTIVE):
            click_count += advert.click_set.count()
        return click_count

    def get_absolute_url(self):
        return reverse('advertisements.views.view_provider_statistics', args=[self.pk])


def get_file_path(instance, filename):
    ext = filename.split('.')[-1]
    filename = "%s.%s" % (uuid.uuid4(), ext)
    return os.path.join('resources', filename)


class AdvertisementPanel(models.Model):
    name = models.CharField(max_length=255)

    height = models.PositiveIntegerField()