1. dan mackinlay
  2. tinkerer

Commits

dan mackinlay  committed c8c253d

Now the date_path flag controls whether a blog post is created with a date-containing path or not.

  • Participants
  • Parent commits dc6c5e8
  • Branches default

Comments (0)

Files changed (2)

File tinkerer/post.py

View file
     master document.
     '''
 
-    def __init__(self, title=None, path=None, date=None):
+    def __init__(self, title=None, path=None, date=None, date_path=True):
         '''
         Initializes a new post and creates path to it if it doesn't already
         exist.
             self.name = utils.name_from_path(path)
         else:
             self.name = utils.name_from_title(title)
+        
+        if date_path:
+            # create post directory if it doesn't exist and get post path
+            self.path = os.path.join(
+                                utils.get_path(
+                                        paths.root,
+                                        self.year,
+                                        self.month,
+                                        self.day),
+                                self.name) + tinkerer.source_suffix
 
-        # create post directory if it doesn't exist and get post path
-        self.path = os.path.join(
-                            utils.get_path(
-                                    paths.root,
-                                    self.year,
-                                    self.month,
-                                    self.day),
-                            self.name) + tinkerer.source_suffix
+            # docname as it should appear in TOC
+            self.docname = "/".join([self.year, self.month, self.day, self.name])
+        else:
+            # create post directory if it doesn't exist and get post path
+            self.path = os.path.join(
+                                utils.get_path(paths.root),
+                                self.name) + tinkerer.source_suffix
 
-        # docname as it should appear in TOC
-        self.docname = "/".join([self.year, self.month, self.day, self.name])
-
+            # docname as it should appear in TOC
+            self.docname = self.name
+            
 
 
     def write(self, content="", author="default", 
 
 
 
-def create(title, date=None):
+def create(title, date=None, date_path=True):
     '''
     Creates a new post given its title.
     '''
-    post = Post(title, path=None, date=date)
+    post = Post(title, path=None, date=date, date_path=date_path)
     post.write()
     master.prepend_doc(post.docname)
     return post

File tinkertest/test_post.py

View file
         self.assertEquals(
                 os.path.abspath(os.path.join(
                                     utils.TEST_ROOT, 
-                                    year, 
-                                    month, 
-                                    day, 
                                     "my_note.rst")),
                 new_post.path)