1. Matt Bowen
  2. LazyBobo


Matt Bowen  committed 96d1924

Cleaned up code and added comments for presentation

  • Participants
  • Parent commits e71481a
  • Branches default

Comments (0)

Files changed (3)

File lazybobo/__init__.py

View file
 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/*', 

File lazybobo/models.py

View file
 from couchdbkit.schema.properties import StringListProperty
 from couchdbkit.schema.properties import DateTimeProperty
 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

View file
     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)
     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)
     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
+            #persist the new object
             return bobo.redirect("/")
             return bobo.redirect("/new")
-    @bobo.query("/:entry_id.html")
-    def show_entry(self, entry_id):
-        return "Entry %s" % entry_id