Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix NewsArticle.get_when; also a test for it

  • Loading branch information...
commit 3b71b96fb0aa753d9717ffd4e4bf9d22d4bcb5c5 1 parent d4d8dd6
@evildmp authored
View
4 arkestra_utilities/settings.py
@@ -49,7 +49,9 @@
# -------- Date formats ----------------------
-DATE_FORMAT = getattr(settings, "DATE_FORMAT",
+DATE_FORMAT = getattr(settings, "ARKESTRA_DATE_FORMATS", "jS F Y")
+
+ARKESTRA_DATE_FORMATS = getattr(settings, "ARKESTRA_DATE_FORMATS",
{
"date_groups": "F Y",
"not_this_year": "jS F Y",
View
12 news_and_events/models.py
@@ -22,7 +22,7 @@
from arkestra_utilities.generic_models import ArkestraGenericPluginOptions, ArkestraGenericModel
from arkestra_utilities.mixins import URLModelMixin, LocationModelMixin
from arkestra_utilities.managers import ArkestraGenericModelManager
-from arkestra_utilities.settings import PLUGIN_HEADING_LEVELS, PLUGIN_HEADING_LEVEL_DEFAULT, COLLECT_TOP_ALL_FORTHCOMING_EVENTS, DATE_FORMAT, AGE_AT_WHICH_ITEMS_EXPIRE
+from arkestra_utilities.settings import PLUGIN_HEADING_LEVELS, PLUGIN_HEADING_LEVEL_DEFAULT, COLLECT_TOP_ALL_FORTHCOMING_EVENTS, DATE_FORMAT, ARKESTRA_DATE_FORMATS, AGE_AT_WHICH_ITEMS_EXPIRE
from managers import EventManager
@@ -75,7 +75,7 @@ def get_when(self):
"""
if getattr(self, "sticky", None):
return "Top news"
- get_when = nice_date(self.date, DATE_FORMAT["date_groups"])
+ get_when = nice_date(self.date, ARKESTRA_DATE_FORMATS["date_groups"])
return get_when
@@ -250,14 +250,14 @@ def get_dates(self):
end_date = self.end_date
if not end_date or self.single_day_event:
end_date = start_date
- start_date_format = end_date_format = DATE_FORMAT["not_this_year"]
+ start_date_format = end_date_format = ARKESTRA_DATE_FORMATS["not_this_year"]
now = datetime.now()
if start_date.year == end_date.year: # start and end in the same year, so:
- start_date_format = DATE_FORMAT["not_this_month"] # start format example: "3rd May"
+ start_date_format = ARKESTRA_DATE_FORMATS["not_this_month"] # start format example: "3rd May"
if start_date.month == end_date.month: # start and end in the same month, so:
- start_date_format = DATE_FORMAT["this_month"] # start format example: "21st"
+ start_date_format = ARKESTRA_DATE_FORMATS["this_month"] # start format example: "21st"
if end_date.year == now.year: # they're both this year, so:
- end_date_format = DATE_FORMAT["not_this_month"] # end format example: "23rd May"
+ end_date_format = ARKESTRA_DATE_FORMATS["not_this_month"] # end format example: "23rd May"
if self.single_day_event:
dates = nice_date(start_date, end_date_format)
else:
View
8 news_and_events/tests.py
@@ -28,7 +28,7 @@ def setUp(self):
slug = "all-about-teeth",
date = datetime.datetime.now() + datetime.timedelta(days=30),
)
- print self.tootharticle.date
+
def test_generic_attributes(self):
self.tootharticle.save()
# the item has no informative content
@@ -39,7 +39,11 @@ def test_generic_attributes(self):
# since there are no Entities in the database, default to settings's template
self.assertEqual(self.tootharticle.get_template, settings.CMS_TEMPLATES[0][0])
-
+
+ def test_date_related_attributes(self):
+ self.tootharticle.date = datetime.datetime(year=2012, month=12, day=12)
+ self.assertEqual(self.tootharticle.get_when, "December 2012")
+
class NewsEventsViewsTests(TestCase):
def setUp(self):
# Every test needs a client.

0 comments on commit 3b71b96

Please sign in to comment.
Something went wrong with that request. Please try again.