Merge remote-tracking branch 'origin/production'
[wolnelektury.git] / apps / funding / models.py
index ba14947..800a15a 100644 (file)
@@ -9,7 +9,8 @@ from django.core.mail import send_mail
 from django.conf import settings
 from django.template.loader import render_to_string
 from django.db import models
 from django.conf import settings
 from django.template.loader import render_to_string
 from django.db import models
-from django.utils.translation import ugettext_lazy as _, ugettext, override
+from django.utils.timezone import utc
+from django.utils.translation import ugettext_lazy as _, override
 import getpaid
 from catalogue.models import Book
 from catalogue.utils import get_random_hash, related_tag_name
 import getpaid
 from catalogue.models import Book
 from catalogue.utils import get_random_hash, related_tag_name
@@ -30,8 +31,8 @@ class Offer(models.Model):
     redakcja_url = models.URLField(_('redakcja URL'), blank=True)
     book = models.ForeignKey(Book, null=True, blank=True,
         help_text=_('Published book.'))
     redakcja_url = models.URLField(_('redakcja URL'), blank=True)
     book = models.ForeignKey(Book, null=True, blank=True,
         help_text=_('Published book.'))
-    cover = models.ImageField(_('Cover'), upload_to = 'funding/covers')
-    poll = models.ForeignKey(Poll, help_text = _('Poll'),  null = True, blank = True, on_delete = models.SET_NULL)
+    cover = models.ImageField(_('Cover'), upload_to='funding/covers')
+    poll = models.ForeignKey(Poll, help_text=_('Poll'), null=True, blank=True, on_delete=models.SET_NULL)
 
     notified_near = models.DateTimeField(_('Near-end notifications sent'), blank=True, null=True)
     notified_end = models.DateTimeField(_('End notifications sent'), blank=True, null=True)
 
     notified_near = models.DateTimeField(_('Near-end notifications sent'), blank=True, null=True)
     notified_end = models.DateTimeField(_('End notifications sent'), blank=True, null=True)
@@ -40,7 +41,7 @@ class Offer(models.Model):
         return u'<img src="%s" />' % self.cover.url
     cover_img_tag.short_description = _('Cover preview')
     cover_img_tag.allow_tags = True
         return u'<img src="%s" />' % self.cover.url
     cover_img_tag.short_description = _('Cover preview')
     cover_img_tag.allow_tags = True
-        
+
     class Meta:
         verbose_name = _('offer')
         verbose_name_plural = _('offers')
     class Meta:
         verbose_name = _('offer')
         verbose_name_plural = _('offers')
@@ -53,7 +54,7 @@ class Offer(models.Model):
         return reverse('funding_offer', args=[self.slug])
 
     def save(self, *args, **kw):
         return reverse('funding_offer', args=[self.slug])
 
     def save(self, *args, **kw):
-        published_now = (self.book_id is not None and 
+        published_now = (self.book_id is not None and
             self.pk is not None and
             type(self).objects.values('book').get(pk=self.pk)['book'] != self.book_id)
         retval = super(Offer, self).save(*args, **kw)
             self.pk is not None and
             type(self).objects.values('book').get(pk=self.pk)['book'] != self.book_id)
         retval = super(Offer, self).save(*args, **kw)
@@ -109,7 +110,7 @@ class Offer(models.Model):
 
     def get_perks(self, amount=None):
         """ Finds all the perks for the offer.
 
     def get_perks(self, amount=None):
         """ Finds all the perks for the offer.
-        
+
         If amount is provided, returns the perks you get for it.
 
         """
         If amount is provided, returns the perks you get for it.
 
         """
@@ -148,7 +149,7 @@ class Offer(models.Model):
                 'remaining': self.remaining(),
                 'current': self.current(),
             })
                 'remaining': self.remaining(),
                 'current': self.current(),
             })
-        self.notified_end = datetime.now()
+        self.notified_end = datetime.utcnow().replace(tzinfo=utc)
         self.save()
 
     def notify_near(self, force=False):
         self.save()
 
     def notify_near(self, force=False):
@@ -165,7 +166,7 @@ class Offer(models.Model):
                 'sum': sum_,
                 'need': need,
             })
                 'sum': sum_,
                 'need': need,
             })
-        self.notified_near = datetime.now()
+        self.notified_near = datetime.utcnow().replace(tzinfo=utc)
         self.save()
 
     def notify_published(self):
         self.save()
 
     def notify_published(self):
@@ -182,7 +183,7 @@ class Offer(models.Model):
 
 class Perk(models.Model):
     """ A perk offer.
 
 class Perk(models.Model):
     """ A perk offer.
-    
+
     If no attached to a particular Offer, applies to all.
 
     """
     If no attached to a particular Offer, applies to all.
 
     """
@@ -213,7 +214,7 @@ class Funding(models.Model):
     amount = models.DecimalField(_('amount'), decimal_places=2, max_digits=10)
     payed_at = models.DateTimeField(_('payed at'), null=True, blank=True, db_index=True)
     perks = models.ManyToManyField(Perk, verbose_name=_('perks'), blank=True)
     amount = models.DecimalField(_('amount'), decimal_places=2, max_digits=10)
     payed_at = models.DateTimeField(_('payed at'), null=True, blank=True, db_index=True)
     perks = models.ManyToManyField(Perk, verbose_name=_('perks'), blank=True)
-    language_code = models.CharField(max_length = 2, null = True, blank = True)
+    language_code = models.CharField(max_length=2, null=True, blank=True)
     notifications = models.BooleanField(_('notifications'), default=True, db_index=True)
     notify_key = models.CharField(max_length=32)
 
     notifications = models.BooleanField(_('notifications'), default=True, db_index=True)
     notify_key = models.CharField(max_length=32)
 
@@ -273,7 +274,7 @@ class Funding(models.Model):
         with override(self.language_code or app_settings.DEFAULT_LANGUAGE):
             send_mail(subject,
                 render_to_string(template_name, context),
         with override(self.language_code or app_settings.DEFAULT_LANGUAGE):
             send_mail(subject,
                 render_to_string(template_name, context),
-                getattr(settings, 'CONTACT_EMAIL', 'wolnelektury@nowoczesnapolska.org.pl'),
+                settings.CONTACT_EMAIL,
                 [self.email],
                 fail_silently=False
             )
                 [self.email],
                 fail_silently=False
             )
@@ -317,7 +318,7 @@ getpaid.signals.user_data_query.connect(user_data_query_listener)
 def payment_status_changed_listener(sender, instance, old_status, new_status, **kwargs):
     """ React to status changes from getpaid. """
     if old_status != 'paid' and new_status == 'paid':
 def payment_status_changed_listener(sender, instance, old_status, new_status, **kwargs):
     """ React to status changes from getpaid. """
     if old_status != 'paid' and new_status == 'paid':
-        instance.order.payed_at = datetime.now()
+        instance.order.payed_at = datetime.utcnow().replace(tzinfo=utc)
         instance.order.save()
         if instance.order.email:
             instance.order.notify(
         instance.order.save()
         if instance.order.email:
             instance.order.notify(