# Path: advertisements/models.py
# class Advertisement(models.Model):
# 
#     ACTIVE = 'a'
#     INACTIVE = 'i'
#     PENDING = 'p'
# 
#     STATUS_CHOICES = (
#         (ACTIVE, 'Active'),
#         (INACTIVE, 'Inactive'),
#         (PENDING, 'Pending'),
#     )
# 
#     panel = models.ForeignKey(AdvertisementPanel)
#     provider = models.ForeignKey(Provider)
#     url = models.URLField(max_length=255)
#     status = models.CharField(max_length=1, choices=STATUS_CHOICES, default=ACTIVE)
# 
#     image_height = models.IntegerField(max_length=64, editable=False)
#     image_width = models.IntegerField(max_length=64, editable=False)
# 
#     image = models.ImageField(
#         max_length=255,
#         upload_to=get_file_path,
#         height_field='image_height',
#         width_field='image_width'
#     )
# 
#     created = models.DateTimeField(auto_now_add=True)
#     updated = models.DateTimeField(auto_now=True)
# 
#     objects = AdvertisementManager()
# 
#     def __unicode__(self):
#         return "{0} - {1}".format(self.provider.name, self.panel)
# 
#     def clicked(self):
#         click = Click(
#             ad=self,
#         )
#         click.save()
# 
#         return click
# 
#     def click_history(self, history_days=10):
#         today = timezone.now().date()
#         click_data = []
#         for days_back in reversed(xrange(history_days)):
#             date = today - timedelta(days=days_back)
#             clicks = self.click_set.filter(
#                 date__year=date.year,
#                 date__month=date.month,
#                 date__day=date.day,
#             ).count()
#             click_data.append({
#                 "date": date,
#                 "clicks": clicks
#             })
#         return click_data
# 
#     def get_absolute_url(self):
#         return reverse('advertisements.views.view_advert_statistics', args=[self.pk])
# 
#     def get_signed_link(self):
#         signer = TimestampSigner()
#         advert_signed = signer.sign(self.pk)
# 
#         return reverse('advert:go', args=[advert_signed])
# 
#     def total_clicks(self):
#         return self.click_set.count()


from django import forms
from advertisements.models import Advertisement
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit


class AdvertisementURLForm(forms.Form):
    url = forms.URLField(max_length=255)

    def __init__(self, *args, **kwargs):
        super(AdvertisementURLForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.add_input(Submit('submit', 'Submit'))


class AdvertisementRequestForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        super(AdvertisementRequestForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.add_input(Submit('submit', 'Submit'))


# Path: advertisements/models.py
# class Advertisement(models.Model):
# 
#     ACTIVE = 'a'
#     INACTIVE = 'i'
#     PENDING = 'p'
# 
#     STATUS_CHOICES = (
#         (ACTIVE, 'Active'),
#         (INACTIVE, 'Inactive'),
#         (PENDING, 'Pending'),
#     )
# 
#     panel = models.ForeignKey(AdvertisementPanel)
#     provider = models.ForeignKey(Provider)
#     url = models.URLField(max_length=255)
#     status = models.CharField(max_length=1, choices=STATUS_CHOICES, default=ACTIVE)
# 
#     image_height = models.IntegerField(max_length=64, editable=False)
#     image_width = models.IntegerField(max_length=64, editable=False)
# 
#     image = models.ImageField(
#         max_length=255,
#         upload_to=get_file_path,
#         height_field='image_height',
#         width_field='image_width'
#     )
# 
#     created = models.DateTimeField(auto_now_add=True)
#     updated = models.DateTimeField(auto_now=True)
# 
#     objects = AdvertisementManager()
# 
#     def __unicode__(self):
#         return "{0} - {1}".format(self.provider.name, self.panel)
# 
#     def clicked(self):
#         click = Click(
#             ad=self,
#         )
#         click.save()
# 
#         return click
# 
#     def click_history(self, history_days=10):
#         today = timezone.now().date()
#         click_data = []
#         for days_back in reversed(xrange(history_days)):
#             date = today - timedelta(days=days_back)
#             clicks = self.click_set.filter(
#                 date__year=date.year,
#                 date__month=date.month,
#                 date__day=date.day,
#             ).count()
#             click_data.append({
#                 "date": date,
#                 "clicks": clicks
#             })
#         return click_data
# 
#     def get_absolute_url(self):
#         return reverse('advertisements.views.view_advert_statistics', args=[self.pk])
# 
#     def get_signed_link(self):
#         signer = TimestampSigner()
#         advert_signed = signer.sign(self.pk)
# 
#         return reverse('advert:go', args=[advert_signed])
# 
#     def total_clicks(self):
#         return self.click_set.count()


# Path: advertisements/forms.py
from django import forms
from advertisements.models import Advertisement
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit



class AdvertisementURLForm(forms.Form):
    url = forms.URLField(max_length=255)

    def __init__(self, *args, **kwargs):
        super(AdvertisementURLForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.add_input(Submit('submit', 'Submit'))


class AdvertisementRequestForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        super(AdvertisementRequestForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.add_input(Submit('submit', 'Submit'))


    class Meta: