Anonymous avatar Anonymous committed 6c8f185

First part of the fix for #161.

Comments (0)

Files changed (3)

     'profiles_url_prefix':      TextField(default=u'/authors',
                                           validators=[is_valid_url_prefix()]),
     'ascii_slugs':              BooleanField(default=True),
+    'fixed_url_date_digits':    BooleanField(default=False),
 
     # cache settings
     'enable_eager_caching':     BooleanField(default=False),
 
     def set_auto_slug(self):
         """Generate a slug for this post."""
+        cfg = get_application().cfg
         slug = gen_slug(self.title)
         if not slug:
             slug = self.pub_date.strftime('%H:%M')
-        prefix = get_application().cfg['blog_url_prefix'].lstrip('/')
+        prefix = cfg['blog_url_prefix'].lstrip('/')
         if prefix:
             prefix += '/'
-        full_slug = u'%s%04d/%d/%d/%s' % (
+        if cfg['fixed_url_date_digits']:
+            date_pattern = '%04d/%02d/%02d'
+        else:
+            date_pattern = '%d/%d/%d'
+        full_slug = u'%s%s/%s' % (
             prefix,
-            self.pub_date.year,
-            self.pub_date.month,
-            self.pub_date.day,
+            date_pattern % (
+                self.pub_date.year,
+                self.pub_date.month,
+                self.pub_date.day,
+            ),
             slug
         )
 
 
     # add the more complex url rule for archive and show post
     tmp = '/'
-    for digits, part in [(4, 'year'), (2, 'month'), (2, 'day')]:
+    for digits, part in zip(app.cfg['fixed_url_date_digits'] and (4, 2, 2)
+                            or (0, 0, 0), ('year', 'month', 'day')):
         tmp += '<int(fixed_digits=%d):%s>/' % (digits, part)
         blog_urls.extend([
             Rule(tmp, defaults={'page': 1}, endpoint='blog/archive'),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.