Commits

Anonymous committed 96d1924

Cleaned up code and added comments for presentation

  • Participants
  • Parent commits e71481a

Comments (0)

Files changed (3)

File lazybobo/__init__.py

 loader = FileSystemDocsLoader(os.path.join(__path__[0], 'dbdocs/_design'))
 loader.sync(db, verbose=True)
 
+#Setup the template loader
 templates = Environment(loader=PackageLoader('lazybobo', 'templates'))
+
+#Prime oembed with the oohembed endpoints
 oembed_consumer = oembed.OEmbedConsumer()
 oohembed_endpoint = oembed.OEmbedEndpoint('http://oohembed.com/oohembed/', ['http://*.5min.com/Video/*', 
                                                                    'http://*.amazon.(com|co.uk|de|ca|jp)/*/(gp/product|o/ASIN|obidos/ASIN|dp)/*',

File lazybobo/models.py

 from couchdbkit.schema.properties import StringListProperty
 from couchdbkit.schema.properties import DateTimeProperty
 
-#http://pylonshq.com/pasties/ed978a0c7cf66efac8073056ae179161
 
 class Post(Document):
     """A tumblog post"""
     external_url = StringProperty(required=False)
     description = StringProperty(required=True)
     timestamp = DateTimeProperty(auto_now=True, required=False)
-

File lazybobo/views.py

 
     @bobo.query("")
     def index(self):
+        #Get the post model with this process's DB
         WrappedPost = db(Post)
+        #Query the all view for our previous posts, passing descending to get them in blog style
         all_posts = WrappedPost.view("tumblog/all", descending=True).all()
         template = templates.get_template("index.html")
+        #pass them as context to the template
         return template.render(all_posts = all_posts)
 
     @bobo.query("/new")
     def create_form(self):
+        #Create a post object to bind to our form
         new_post = Post()
+        #Get fields for it
         fieldset = fields.bind(new_post)
+        #Set the order of the fields and which ones to include, setting the description as a textarea
         fieldset.configure(include = [fieldset.title, fieldset.subtitle, fieldset.external_url, fieldset.description],
-                              options = [fieldset.description.textarea(size=(30,10)),])
+                           options = [fieldset.description.textarea(size=(30,10)),])
+        #get the HTMl for the form
         form_html = fieldset.render()
         template = templates.get_template("create_form.html")
+        #pass it as context to the template
         return template.render(form_html = form_html)
         
     @bobo.post("/add_entry")
     def add_entry(self):
         data = self.request.POST
+        #Setup a post to pass data into
         new_post = Post()
+        #create a fieldset object and bind the post data to it
         fieldset = fields.bind(new_post, data = data or None)
-        fieldset.configure(include = [fieldset.title, fieldset.subtitle, fieldset.external_url, fieldset.description],
-                           options = [fieldset.description.textarea(size=(30,10)),])
-        if data: # and fieldset.validate():
+        #configure the fieldset so it doesn't complain about omitted fields like the timestamp
+        fieldset.configure(include = [fieldset.title, fieldset.subtitle, fieldset.external_url, fieldset.description],)
+        if data:
+            #sync the fieldset and the post object
             fieldset.sync()
+            #persist the new object
             db(new_post).save()
             return bobo.redirect("/")
         else:
             return bobo.redirect("/new")
-
-
-    @bobo.query("/:entry_id.html")
-    def show_entry(self, entry_id):
-        return "Entry %s" % entry_id