Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Migrate admin to messages framework. Adapt to Django 1.4 timezones support #15

Closed
wants to merge 2 commits into from

2 participants

@gloriamh

Hi!

I've adapted your code to work with Django 1.4.
Maybe you'll want to have a look at the changes I've made :)

Thanks!

@dokterbob
Owner

Hey Gloria, that's awesome! Thanks!

However, for now we are still using this package on sites that are not yet upgraded to 1.4 - hence, I suppose it's better to keep this in a branch (or until me or someone is able to make sure it's also compatible with 1.3).

One last question: did you try to see whether the unittests are running?

@gloriamh

Hi!

Thanks to you for sharing your code!
Yes, all the unittest passed, but there are some deprecation warnings to fix. I'll have a look at them after holidays :)

@dokterbob
Owner

@gloriamh I am planning a 0.5 release of django-newsletter, and I need your feedback! Since GH has removed private messaging and you don't have an email address set on your profile, I thought I might as well abuse GH's issues to give you a little heads-up:

Dear contributors to django-newsletter,

Your efforts, pull requests, bugreports and feature-suggestions have not gone unnoticed. Thanks so much for your contributions!

In the next two weeks I am planning to take about a day to:

Fix some long-standing issues
Implement some much-needed features
Merge in some of your contributions!
In order to have a good view on what to implement first, I would very much like some feedback from you guys. Both on currently opened issues (+1/-1) or in the form of new issues (bugs, feature requests etc).

Please take a look at all the currently open issues at:
https://github.com/dokterbob/django-newsletter/issues?state=open

The idea is to have django-newsletter 0.5 finished, tested and documented by the 16th of september. If you want some clue as to what day exactly I will take for this, look to see when there's rainy weather in Amsterdam. ;) It'll highly likely be the 15th or 16th.

Until that time: please feel free to nag, bug me, discuss and work with me on this upcoming release.

Kind regards,
Mathijs

'The long-lost maintainer of django-newsletter.' ;)

@dokterbob
Owner

33d6809 is merged in now - Django 1.1 support is dropped anyway. ^^

@dokterbob dokterbob closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 29, 2012
  1. Migrate code to use messaging framework

    Gloria authored
Commits on Jul 30, 2012
  1. Adapt to Django 1.4 time zones support

    Gloria authored
This page is out of date. Refresh to see the latest.
View
19 newsletter/admin.py
@@ -2,12 +2,11 @@
logger = logging.getLogger(__name__)
-from datetime import datetime
-
from django.conf import settings
from django.conf.urls.defaults import patterns, url
from django.contrib import admin
+from django.contrib import messages
from django.contrib.admin.util import force_unicode
from django.contrib.sites.models import Site
@@ -25,6 +24,8 @@
from django.shortcuts import render_to_response
+from django.utils import timezone
+
from django.utils.translation import ugettext, ugettext_lazy as _
from tinymce.widgets import TinyMCE
@@ -93,7 +94,7 @@ def admin_status(self, obj):
if obj.sent:
return u'<img src="%s" width="10" height="10" alt="%s"/>' % (settings.ADMIN_MEDIA_PREFIX+'img/admin/icon-yes.gif', self.admin_status_text(obj))
else:
- if obj.publish_date > datetime.now():
+ if obj.publish_date > timezone.now():
return u'<img src="%s" width="10" height="10" alt="%s"/>' % (settings.STATIC_URL+'newsletter/admin/img/waiting.gif', self.admin_status_text(obj))
else:
return u'<img src="%s" width="12" height="12" alt="%s"/>' % (settings.STATIC_URL+'newsletter/admin/img/submitting.gif', self.admin_status_text(obj))
@@ -108,7 +109,7 @@ def admin_status_text(self, obj):
if obj.sent:
return ugettext("Sent.")
else:
- if obj.publish_date > datetime.now():
+ if obj.publish_date > timezone.now():
return ugettext("Delayed submission.")
else:
return ugettext("Submitting.")
@@ -121,14 +122,14 @@ def submit(self, request, object_id):
submission = self._getobj(request, object_id)
if submission.sent or submission.prepared:
- request.user.message_set.create(message=ugettext('Submission already sent.'))
+ messages.info(request, ugettext("Submission already sent."))
return HttpResponseRedirect('../')
submission.prepared=True
submission.save()
- request.user.message_set.create(message=ugettext('Your submission is being sent.'))
+ messages.info(request, ugettext("Your submission is being sent."))
return HttpResponseRedirect('../../')
@@ -220,7 +221,7 @@ def preview_html(self, request, object_id):
c = Context({'message' : message,
'site' : Site.objects.get_current(),
'newsletter' : message.newsletter,
- 'date' : datetime.now(),
+ 'date' : timezone.now(),
'STATIC_URL': settings.STATIC_URL,
'MEDIA_URL': settings.MEDIA_URL})
@@ -235,7 +236,7 @@ def preview_text(self, request, object_id):
c = Context({'message' : message,
'site' : Site.objects.get_current(),
'newsletter' : message.newsletter,
- 'date' : datetime.now(),
+ 'date' : timezone.now(),
'STATIC_URL': settings.STATIC_URL,
'MEDIA_URL': settings.MEDIA_URL},
autoescape=False)
@@ -398,7 +399,7 @@ def subscribers_import_confirm(self, request):
address.save()
finally:
del request.session['addresses']
- request.user.message_set.create(message=_('%s subscriptions have been successfully added.') % len(addresses))
+ messages.success(request, _('%s subscriptions have been successfully added.') % len(addresses))
return HttpResponseRedirect('../../')
else:
View
18 newsletter/models.py
@@ -2,8 +2,6 @@
logger = logging.getLogger(__name__)
-from datetime import datetime
-
from django.db import models
from django.db.models import permalink
@@ -23,8 +21,10 @@
from django.conf import settings
+from django.utils import timezone
+
def make_activation_code():
- return sha_constructor(sha_constructor(str(random.random())).hexdigest()[:5]+str(datetime.now().microsecond)).hexdigest()
+ return sha_constructor(sha_constructor(str(random.random())).hexdigest()[:5]+str(timezone.now().microsecond)).hexdigest()
def get_default_sites():
return [site.id for site in Site.objects.all()]
@@ -174,7 +174,7 @@ def set_email(self, email):
def subscribe(self):
logger.debug(u'Subscribing subscription %s.', self)
- self.subscribe_date = datetime.now()
+ self.subscribe_date = timezone.now()
self.subscribed = True
self.unsubscribed = False
@@ -183,7 +183,7 @@ def unsubscribe(self):
self.subscribed = False
self.unsubscribed = True
- self.unsubscribe_date = datetime.now()
+ self.unsubscribe_date = timezone.now()
def save(self, *args, **kwargs):
assert self.user or self.email_field, _('Neither an email nor a username is set. This asks for inconsistency!')
@@ -226,7 +226,7 @@ def save(self, *args, **kwargs):
newsletter = models.ForeignKey('Newsletter', verbose_name=_('newsletter'))
- create_date = models.DateTimeField(editable=False, default=datetime.now)
+ create_date = models.DateTimeField(editable=False, default=timezone.now)
activation_code = models.CharField(verbose_name=_('activation code'), max_length=40, default=make_activation_code)
@@ -451,7 +451,7 @@ def submit(self):
logger.info(ugettext(u"Submitting %(submission)s to %(count)d people"),
{'submission':self, 'count':subscriptions.count()})
- assert self.publish_date < datetime.now(), 'Something smells fishy; submission time in future.'
+ assert self.publish_date < timezone.now(), 'Something smells fishy; submission time in future.'
self.sending = True
self.save()
@@ -505,7 +505,7 @@ def submit(self):
@classmethod
def submit_queue(cls):
- todo = cls.objects.filter(prepared=True, sent=False, sending=False, publish_date__lt=datetime.now())
+ todo = cls.objects.filter(prepared=True, sent=False, sending=False, publish_date__lt=timezone.now())
for submission in todo:
submission.submit()
@@ -537,7 +537,7 @@ def get_absolute_url(self):
subscriptions = models.ManyToManyField('Subscription', help_text=_('If you select none, the system will automatically find the subscribers for you.'), blank=True, db_index=True, verbose_name=_('recipients'), limit_choices_to={ 'subscribed' :True })
- publish_date = models.DateTimeField(verbose_name=_('publication date'), blank=True, null=True, default=datetime.now(), db_index=True)
+ publish_date = models.DateTimeField(verbose_name=_('publication date'), blank=True, null=True, default=timezone.now(), db_index=True)
publish = models.BooleanField(default=True, verbose_name=_('publish'), help_text=_('Publish in archive.'), db_index=True)
prepared = models.BooleanField(default=False, verbose_name=_('prepared'), db_index=True, editable=False)
View
9 newsletter/tests/test_web.py
@@ -1,9 +1,10 @@
-from datetime import datetime, timedelta
+from datetime import timedelta
import time
from django.core import mail
from django.core.urlresolvers import reverse
+from django.utils import timezone
from newsletter.models import *
from newsletter.forms import *
@@ -268,7 +269,7 @@ def test_unsubscribe_view(self):
subscription.unsubscribed = False
subscription.save()
- self.assertLessThan(subscription.subscribe_date, datetime.now() \
+ self.assertLessThan(subscription.subscribe_date, timezone.now() \
+ timedelta(seconds=1))
r = self.client.get(self.unsubscribe_url)
@@ -302,7 +303,7 @@ def test_unsubscribe_post(self):
subscription = self.get_user_subscription()
self.assertFalse(subscription.subscribed)
self.assert_(subscription.unsubscribed)
- self.assertLessThan(subscription.unsubscribe_date, datetime.now() \
+ self.assertLessThan(subscription.unsubscribe_date, timezone.now() \
+ timedelta(seconds=1))
def test_unsubscribe_twice(self):
@@ -483,7 +484,7 @@ def test_unsubscribe_request_activate(self):
self.assertEqual(subscription.name, testname2)
self.assertEqual(subscription.email, testemail2)
- dt = (datetime.now() - subscription.unsubscribe_date).seconds
+ dt = (timezone.now() - subscription.unsubscribe_date).seconds
self.assertLessThan(dt, 2)
def test_update_request_view(self):
Something went wrong with that request. Please try again.