Time for action implementing a wiki topic screen

When we request a URL of the form show?topic=value, this will result in calling the show() method. If value equals an existing topic, the following (as yet unstyled) screen is the result:

Time for action implementing a wiki topic screen

Just as for the opening screen, we take steps to:

  • Identify the main areas on screen
  • Identify specific functionality
  • Identify any hidden functionality

The page structure is very similar to the opening screen, with the same navigational items, but instead of a list of topics, we see the content of the requested topic together with some additional information like the tags associated with this subject and a button that may be clicked to edit the contents of this topic. After all, collaboratively editing content is what a Wiki is all about.

We deliberately made the choice not to refresh the contents of just a part of the opening screen with an AJAX call, but opted instead for a simple link that replaces the whole page. This way, there will be an unambiguous URL in the address bar of the browser that will point at the topic. This allows for easy bookmarking. An AJAX call would have left the URL of the opening screen that is visible in the address bar of the browser unaltered and although there are ways to alleviate this problem, we settle for this simple solution here.

What just happened?

As the main structure we identified is almost identical to the one for the opening page, the show() method will reuse the markup in basepage.html.

Chapter6/wikiweb.py

@cherrypy.expose
def show(self,topic):
		topic = topic.capitalize()
		currentcontent,tags = wiki.gettopic(topic)
		currentcontent = "".join(wiki.render(currentcontent))
		tags = ['<li><a href="http://searchtags?tags=%s">%s</a></li>'%(
										t,t) for t in tags]
		content = '''
		<div>
				<h1>%s</h1><a href="edit?topic=%s">Edit</a>
		</div>
		<div id="wikitopic">%s</div>
		<div id="wikitags"><ul>%s</ul></div>
		<div id="revisions">revisions</div>
		''' % ( topic, topic, currentcontent,"
".join(tags))
		return basepage % content

The show() method delegates most of the work to the wiki.gettopic() method (highlighted) that we will examine in the next section and concentrates on creating the markup it will deliver to the client. wiki.gettopic() will return a tuple that consists of both the current content of the topic and a list of tags.

Those tags are converted to<li> elements with anchors that point to the searchtags URL. This list of tags provides a simple way for the reader to find related topics with a single click. The searchtags URL takes a tags argument so a single<li> element constructed this way may look like this:<li><a href="http://searchtags?tags=Python">Python</a></li>.

The content and the clickable list of tags are embedded in the markup of the basepage together with an anchor that points to the edit URL. Later, we will style this anchor to look like a button and when the user clicks it, it will present a page where the content may be edited.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.158.134