comparison 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
comparison
equal deleted inserted replaced
942:e1b33cbf9874 943:b61dd60aff36
175 except ValueError: 175 except ValueError:
176 raise Exception("Dates must be of the form: " 176 raise Exception("Dates must be of the form: "
177 "YEAR/MONTH/DAY.") 177 "YEAR/MONTH/DAY.")
178 dt = datetime.date(year, month, day) 178 dt = datetime.date(year, month, day)
179 elif isinstance(date, datetime.datetime): 179 elif isinstance(date, datetime.datetime):
180 year = date.year 180 dt = datetime.date(date.year, date.month, date.day)
181 month = date.month
182 day = date.day
183 else: 181 else:
184 raise Exception("Unknown date: %s" % date) 182 try:
185 183 dt = datetime.date(
186 slug, ext = os.path.splitext(args.get('slug')) 184 int(args.get('year')),
185 int(args.get('month')),
186 int(args.get('day')))
187 except ValueError:
188 raise Exception("Incorrect year/month/day values: %s" %
189 args)
190
191 slug = args.get('slug')
192 if slug is None:
193 raise Exception("No slug in args: %s" % args)
194 slug, ext = os.path.splitext(slug)
187 if not ext: 195 if not ext:
188 ext = self.default_auto_format 196 ext = self.default_auto_format
189 year, month, day = dt.year, dt.month, dt.day 197 year, month, day = dt.year, dt.month, dt.day
190 tokens = { 198 tokens = {
191 'slug': args.get('slug'), 199 'slug': args.get('slug'),