diff piecrust/sources/posts.py @ 943:b61dd60aff36

sources: Posts source accepts more arguments for creating a post.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 05 Oct 2017 00:22:53 -0700
parents 86b684cc0551
children 84fc72a17f7a
line wrap: on
line diff
--- a/piecrust/sources/posts.py	Thu Oct 05 00:21:50 2017 -0700
+++ b/piecrust/sources/posts.py	Thu Oct 05 00:22:53 2017 -0700
@@ -177,13 +177,21 @@
                                     "YEAR/MONTH/DAY.")
                 dt = datetime.date(year, month, day)
         elif isinstance(date, datetime.datetime):
-            year = date.year
-            month = date.month
-            day = date.day
+            dt = datetime.date(date.year, date.month, date.day)
         else:
-            raise Exception("Unknown date: %s" % date)
+            try:
+                dt = datetime.date(
+                    int(args.get('year')),
+                    int(args.get('month')),
+                    int(args.get('day')))
+            except ValueError:
+                raise Exception("Incorrect year/month/day values: %s" %
+                                args)
 
-        slug, ext = os.path.splitext(args.get('slug'))
+        slug = args.get('slug')
+        if slug is None:
+            raise Exception("No slug in args: %s" % args)
+        slug, ext = os.path.splitext(slug)
         if not ext:
             ext = self.default_auto_format
         year, month, day = dt.year, dt.month, dt.day