Goldblog - A TurboGears Blogging Package

Goldblog is inspired by Quoins (http://quoins.net/). Like Quoins, Goldblog is a blogging system that can be incorporated into a TurboGears project. I chose to develop my own system as an exercise to develop my Python and TurboGears skills.

Goldblog was written by Bruce Webber (self@brucewebber.us, http://www.brucewebber.us).

License

Goldblog is licensed under a BSD style license. See LICENSE.txt for details.

Requirements

  • TurboGears 1.0
  • Genshi 0.5 or higher
  • SQLAlchemy 0.5 or higher
  • TinyMCE
  • TurboTinyMCE
  • TurboMail

Installation

Follow these steps to install Goldblog.

  1. Set up your TurboGears 1.0 project. Use identity.

  2. Install and configure TurboMail.

  3. Create your project tables with the command:

    tg-admin sql create
  4. Easy install the goldblog egg.

  5. Run the command:

    tg-admin goldblog create

    This will create the additional tables needed by Goldblog.

  6. Create a folder under your templates directory called blog, and copy the templates from install-in-project/templates. Edit the templates as needed. You may choose to copy your master template into the blog directory and include it in the blog templates.

    In your master template, include the following in the <head> section for feed auto-discovery (change the path if necessary):

    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="/blog/rss2.0" />
  7. Copy CSS files from install-in-project/css to your css directory. Edit the CSS file as needed.

  8. Copy the image files from install-in-project/images to your images directory.

  9. Download TinyMCE and copy the tiny_mce folder from tinymce/jscripts into your javascript folder.

  10. Add the following line to your controllers.py file:

    from goldblog import blog_controller
    
  11. Add the following line in your Root controller:

    blog = blog_controller.BlogController(path='/blog')
    

    (The path keyword must match the subcontroller mount point name.)

  12. In app.cfg, add the following line (change “secret” to a strong password):

    goldblog.key = 'secret'
    
  13. In app.cfg, add the following line (change “my_package” to the name of your TurboGears project name):

    goldblog.parent_package = 'my_package'
    
  14. In app.cfg, uncomment the following line to enable sessions:

    session_filter.on = True
    
  15. Create the groups and users in your TG project for Goldblog. Launch the tg-admin shell:

    tg-admin shell

    In the shell, enter the following commands (change the usernames, email addresses and passwords):

    u1 = User(u'user1', u'email1@in.valid', u'Full Name 1', u'password1')
    session.add(u1)
    
    u2 = User(u'user2', u'email2@in.valid', u'Full Name 2', u'password2')
    session.add(u2)
    
    bloggers = Group(u'bloggers', u'Bloggers')
    session.add(bloggers)
    
    blogadmins = Group(u'blogadmin', u'Blog Administrators')
    session.add(blogadmins)
    
    blogadmins.users.append(u1)
    bloggers.users.append(u2)
    
  16. In your application, log in as a user in the blogadmin group, go to the Administration page, and set the blog information.

URIs

The subcontroller provides a RESTful interface for blog posts. If the arguments are not sufficient for a given operation, it defaults to listing the blog posts.

Assuming this controller is mounted at /blog, the following URIs are provided:

URI function
/blog list all blog entries
/blog/index list all blog entries
/blog/admin view the blog administration screen
/blog/edit edit the blog information
/blog/addcategory add a new blog category
/blog/newpost create a new blog post
/blog/category/1 list blog posts with blog category 1
/blog/category/1/edit edit blog category 1
/blog/category/1/delete delete blog category 1
/blog/month/200812 list blog posts from December 2008
/blog/post/20081225131030 view a specific blog post
/blog/post/20081225131030/edit edit a specific blog post
/blog/post/20081225131030/delete delete a specific blog post
/blog/post/20081225131030/comment post a comment about a specific blog post
/blog/rssfeed RSS 2.0 feed
/blog/comment/1/accept accept a comment about a specific blog post
/blog/comment/1/delete delete a comment about a specific blog post

blognav object

The goldblog instance provides an object called blognav, which is a singleton instance of the BlogNav class:

class BlogNav

Navigation links for the blog, organized into general links, links to posts by category, and links to posts by month.

Variable general_links:
 list of general links (the blog list, creating a new blog entry, and administering the blog)
Variable category_links:
 list of links to blog posts by category
Variable date_links:
 list of links to blog posts by month
Variable rss_link:
 a link to the RSS feed

The links mentioned above are NavLink objects. A NavLink object has two instance variables:

Navigation links for the blog, organized into general links, links to posts by category, and links to posts by month.

Variable name:the text to display
Variable url:the URL of the link

blog_master.html uses the blognav object. It replaces the blognav div with links from the blognav object.

Controller methods which return the blognav object should call the update_blognav() method.

get_latest_posts()

The subcontroller provides a method called get_latest_posts(), which returns a list of the latest n published posts, where n is an integer. This allows you to include recent blog post summaries in your home page, for example.

Example

Here is a simple index() method which uses blognav and get_latest_posts():

def index(self):
    self.blog.update_blognav(blog_controller.blognav)
    return dict(blognav=blog_controller.blognav,
            latest_posts=self.blog.get_latest_posts(3))

Simple CAPTCHA

Goldblog provides a simple text based CAPTCHA scheme employed when a visitor enters a comment. The visitor is prompted to enter the correct number from a list of numbers.