# HG changeset patch # User Ludovic Chabant # Date 1507188173 25200 # Node ID b61dd60aff36ff53fb09bd63cf6550f99a56d7e1 # Parent e1b33cbf98746156236d0c3ad7435cda1558db63 sources: Posts source accepts more arguments for creating a post. diff -r e1b33cbf9874 -r b61dd60aff36 piecrust/sources/posts.py --- 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