Viclog.com Introduction
Hello world (or a small subset thereof)! This will serve as an introduction to my newly remodeled blog. I'd like to start by leaving myself some notes on the tagging system I implemented for this site, which is potentially a very boring topic for some most people. These additions were made on top of Bret Taylor's blog (source).
Let's get started.
One of the first things that need to be done is to add an attribute, in this case tags, to the data model (using a framework similar to Django). We must also define the data type for this attribute. For adding something relative simple, such as a list of tags, the choices are straight forward since they have been limited by the Google App Engine Datastore API. Simply add a list of strings to the class that describes each post, and call it tags:
class Entry(db.Model):
"""A single blog entry."""
author = db.UserProperty()
title = db.StringProperty(required=True)
slug = db.StringProperty(required=True)
body = db.TextProperty(required=True)
markdown = db.TextProperty(required=True)
published = db.DateTimeProperty(auto_now_add=True)
updated = db.DateTimeProperty(auto_now=True)
tags = db.StringListProperty(required=True)
Tags will also need to be displayed and entered along with each post. For this, the handler for post composition and editing will need the ability to handle the new data type. Conversion from strings separated by commas to a list of strings will need to be done when passed in from the composition form. From the post composition handler:
if key:
entry = Entry.get(key)
entry.title = self.get_argument("title")
entry.body = self.get_argument("markdown")
entry.markdown = markdown.
markdown(self.get_argument("markdown"))
entry.tags = self.get_argument("tags").split(",")
entry.tags = filter(None, entry.tags)
for i in range(0,len(entry.tags)): entry.tags[i] =
entry.tags[i].strip()
else:
title = self.get_argument("title")
slug = unicodedata.normalize("NFKD", title).
encode("ascii", "ignore")
slug = re.sub(r"[^\w]+", " ", slug)
slug = "-".join(slug.lower().strip().split())
tags = self.get_argument("tags").split(",")
tags = filter(None, tags)
The adjustments to the composition template or form needed to include this field are trivial and involve little more than adding an input field named "tags."
Tune in next time where I'll cover the handler for tag attributes and the ability to display and link to this tag handler from each post.
Oh, and Welcome!

