Permalink
Browse files

refactor notify application

change attribute that does a query to a property - so the query will be done only when the property is needed
change % operator to format
  • Loading branch information...
1 parent 532b940 commit 9bc5bc530c770505855f85eb6f60a44aa2177b81 @OriHoch OriHoch committed Dec 9, 2013
Showing with 13 additions and 17 deletions.
  1. +6 −2 notify/management/commands/notify.py
  2. +1 −1 notify/models.py
  3. +6 −14 notify/tests.py
@@ -33,15 +33,19 @@ class Command(NoArgsCommand):
from_email = getattr(settings, 'DEFAULT_FROM_EMAIL', 'email@example.com')
days_back = getattr(settings, 'DEFAULT_NOTIFICATION_DAYS_BACK', 10)
lang = getattr(settings, 'LANGUAGE_CODE', 'he')
- domain = Site.objects.get_current().domain
+
+ @property
+ def domain(self):
+ if not hasattr(self, '_domain'):
+ self._domain = Site.objects.get_current().domain
+ return self._domain
option_list = NoArgsCommand.option_list + (
make_option('--daily', action='store_true', dest='daily',
help="send notifications to users that requested a daily update"),
make_option('--weekly', action='store_true', dest='weekly',
help="send notifications to users that requested a weekly update"))
-
def agenda_update(self, agenda):
''' generate the general update email for this agenda.
this will be called, and its output added to the email,
View
@@ -14,5 +14,5 @@ class LastSent(models.Model):
time = models.DateTimeField(auto_now=True)
def __unicode__(self):
- return "%s %s %s" % (self.user.username, self.content_object, self.time)
+ return u"{} {} {}".format(self.user.username, self.content_object, self.time)
View
@@ -13,6 +13,7 @@
from laws.models import Vote
from management.commands import notify
from actstream import follow, action
+from models import LastSent
class SimpleTest(TestCase):
@@ -42,19 +43,10 @@ def test_empty_email(self):
self.assertIn(u'supports mk 1', text)
email, email_html = cmd.get_email_for_user(self.jacob)
self.assertEqual(email, [])
-
-
- def test_basic_addition(self):
- """
- Tests that 1 + 1 always equals 2.
- """
- self.failUnlessEqual(1 + 1, 2)
-
-__test__ = {"doctest": """
-Another way to test that 1 + 1 is equal to 2.
-
->>> 1 + 1 == 2
-True
-"""}
+ def test_LastsSent_unicode(self):
+ dt = datetime(2013, 2, 3)
+ lastsent = LastSent.objects.create(user = self.jacob, content_object = self.mk_1)
+ lastsent.time = dt
+ self.assertEqual(lastsent.__unicode__(), u'{} {} {}'.format(self.jacob, self.mk_1, dt))

0 comments on commit 9bc5bc5

Please sign in to comment.