[cmsiki-svn] SF.net SVN: cmsiki: [11] trunk/cmsiki
Status: Pre-Alpha
Brought to you by:
cnu
From: <cn...@us...> - 2007-03-24 20:05:10
|
Revision: 11 http://cmsiki.svn.sourceforge.net/cmsiki/?rev=11&view=rev Author: cnu Date: 2007-03-24 12:49:05 -0700 (Sat, 24 Mar 2007) Log Message: ----------- Added method replaced_body to the story model. Changed template to show replace_body instead of story.body Introduced Exception handling in cmsikireplace Modified Paths: -------------- trunk/cmsiki/apps/story/models.py trunk/cmsiki/cmsikireplace.py trunk/cmsiki/templates/story/story_archive.html trunk/cmsiki/templates/story/story_archive_day.html trunk/cmsiki/templates/story/story_archive_month.html trunk/cmsiki/templates/story/story_detail.html Modified: trunk/cmsiki/apps/story/models.py =================================================================== --- trunk/cmsiki/apps/story/models.py 2007-03-24 17:20:10 UTC (rev 10) +++ trunk/cmsiki/apps/story/models.py 2007-03-24 19:49:05 UTC (rev 11) @@ -1,5 +1,6 @@ from django.db import models from django.contrib.auth.models import User +import cmsikireplace # Create your models here. class Category(models.Model): @@ -34,4 +35,9 @@ search_fields = ('title','body') def get_absolute_url(self): + '''Return the absolute url of the story.''' return '/%s/%s/' % (self.pub_date.strftime("%Y/%m/%d").lower(), self.slug) + + def replaced_body(self): + '''Replace the tags in the body from the data in the wiki.''' + return cmsikireplace.tagreplace(self.body) Modified: trunk/cmsiki/cmsikireplace.py =================================================================== --- trunk/cmsiki/cmsikireplace.py 2007-03-24 17:20:10 UTC (rev 10) +++ trunk/cmsiki/cmsikireplace.py 2007-03-24 19:49:05 UTC (rev 11) @@ -12,6 +12,7 @@ import re import xmlrpclib +import httplib # List of wiki and its various information. # Must change to get the list dynamically from a django database. @@ -23,51 +24,76 @@ 'url':'http://nrcfosshelpline.in/chennaipy/', 'xmlrpc':'http://nrcfosshelpline.in/chennaipy/?action=xmlrpc2'} ] - +class WikiNameError(Exception): + def __init__(self, value): + self.value = value + def __str__(self): + return repr(self.value) + def wikirpc(wikiname): '''Return the wiki dictionary for the given wikiname.''' for wiki in wikilist: if wiki['name'] == wikiname: return wiki + raise WikiNameError('No wiki found') def getPageHTML(tag): '''Return the page contents from the wiki as HTML.''' - page_pattern = re.compile(':[a-zA-Z]+@') + page_pattern = re.compile(':[a-zA-Z_0-9]+@') wiki_pattern = re.compile('@[a-zA-Z]+\]') page_match = page_pattern.findall(tag)[0] page_name = page_match[1:-1] wiki_match = wiki_pattern.findall(tag)[0] wiki_name = wiki_match[1:-1] - wiki = wikirpc(wiki_name) + try: + wiki = wikirpc(wiki_name) + except WikiNameError: + return '' srcwiki = xmlrpclib.ServerProxy(wiki['xmlrpc']) - page_html_content = srcwiki.getPageHTML(page_name) + try: + page_html_content = srcwiki.getPageHTML(page_name) + except httplib.socket.error: + page_html_content = '' + page_html_content = page_html_content.replace('<a class="nonexistent" href="/','<a class="nonexistent" href="%s' %(wiki['url'])) return page_html_content.replace('<a href="/','<a href="%s' %(wiki['url'])) def getPage(tag): '''Returns the page contents from the wiki as WikiText.''' - page_pattern = re.compile(':[a-zA-Z]+@') + page_pattern = re.compile(':[a-zA-Z_0-9]+@') wiki_pattern = re.compile('@[a-zA-Z]+\]') page_match = page_pattern.findall(tag)[0] page_name = page_match[1:-1] wiki_match = wiki_pattern.findall(tag)[0] wiki_name = wiki_match[1:-1] - wiki = wikirpc(wiki_name) + try: + wiki = wikirpc(wiki_name) + except WikiNameError: + return '' srcwiki = xmlrpclib.ServerProxy(wiki['xmlrpc']) - page_content = srcwiki.getPage(page_name) + try: + page_content = srcwiki.getPage(page_name) + except httplib.socket.error: + page_content = '' return page_content def getPageInfo(tag): '''Return the page contents from the wiki as WikiText.''' - page_pattern = re.compile(':[a-zA-Z]+@') + page_pattern = re.compile(':[a-zA-Z_0-9]+@') wiki_pattern = re.compile('@[a-zA-Z]+\]') page_match = page_pattern.findall(tag)[0] page_name = page_match[1:-1] wiki_match = wiki_pattern.findall(tag)[0] wiki_name = wiki_match[1:-1] - wiki = wikirpc(wiki_name) + try: + wiki = wikirpc(wiki_name) + except WikiNameError: + return '' srcwiki = xmlrpclib.ServerProxy(wiki['xmlrpc']) - page_info = srcwiki.getPageInfo(page_name) + try: + page_info = srcwiki.getPageInfo(page_name) + except httplib.socket.error: + page_info = '' # return the wiki page info in a string format page_string_info = 'PageName: %s \nAuthor: %s \nVersion: %s \n' \ %(page_info['name'], page_info['author'], page_info['version']) @@ -89,8 +115,11 @@ for tag in tagmatches: wikireplace = {} methodmatch = methodpattern.findall(tag)[0][1:] # Find the method in a tag - # Must decide which method is better. - wikipage = dict_func[methodmatch](tag) + # Must decide which method is better. + try: + wikipage = dict_func[methodmatch](tag) + except KeyError: + wikipage = '' # wikipage = eval(methodmatch)(tag) wikireplacelist.append(dict({'tag':tag,'page':wikipage})) for item in wikireplacelist: Modified: trunk/cmsiki/templates/story/story_archive.html =================================================================== --- trunk/cmsiki/templates/story/story_archive.html 2007-03-24 17:20:10 UTC (rev 10) +++ trunk/cmsiki/templates/story/story_archive.html 2007-03-24 19:49:05 UTC (rev 11) @@ -17,7 +17,7 @@ <h2><a href="{{ story.get_absolute_url }}">{{ story.title }}</a></h2> <div class="postinfo">Posted on <span class="postdate">{{ story.pub_date|date:"F j, Y" }}</span> by <strong>{{ story.author }}</strong></div> - {{ story.body }} + {{ story.replaced_body }} <div class="postinfo">Posted under category <a href="/category/{{ story.category }}">{{ story.category }}</a>.</div> </div> {% endfor %} Modified: trunk/cmsiki/templates/story/story_archive_day.html =================================================================== --- trunk/cmsiki/templates/story/story_archive_day.html 2007-03-24 17:20:10 UTC (rev 10) +++ trunk/cmsiki/templates/story/story_archive_day.html 2007-03-24 19:49:05 UTC (rev 11) @@ -18,7 +18,7 @@ <h2><a href="{{ story.get_absolute_url }}">{{ story.title }}</a></h2> <div class="postinfo">Posted on <span class="postdate">{{ story.pub_date|date:"F j, Y" }}</span> by <strong>{{ story.author }}</strong></div> - {{ story.body }} + {{ story.replaced_body }} <div class="postinfo">Posted under category <a href="/category/{{ story.category }}">{{ story.category }}</a>.</div> </div> Modified: trunk/cmsiki/templates/story/story_archive_month.html =================================================================== --- trunk/cmsiki/templates/story/story_archive_month.html 2007-03-24 17:20:10 UTC (rev 10) +++ trunk/cmsiki/templates/story/story_archive_month.html 2007-03-24 19:49:05 UTC (rev 11) @@ -19,7 +19,7 @@ <h2><a href="{{ story.get_absolute_url }}">{{ story.title }}</a></h2> <div class="postinfo">Posted on <span class="postdate">{{ story.pub_date|date:"F j, Y" }}</span> by <strong>{{ story.author }}</strong></div> - {{ story.body }} + {{ story.replaced_body }} <div class="postinfo">Posted under category <a href="/category/{{ story.category }}">{{ story.category }}</a>.</div> </div> {% endfor %} Modified: trunk/cmsiki/templates/story/story_detail.html =================================================================== --- trunk/cmsiki/templates/story/story_detail.html 2007-03-24 17:20:10 UTC (rev 10) +++ trunk/cmsiki/templates/story/story_detail.html 2007-03-24 19:49:05 UTC (rev 11) @@ -20,7 +20,7 @@ </div> <div class="entry"> - {{ object.body }} + {{ object.replaced_body }} </div> <div class="postinfo">Posted under category <a href="/category/{{ object.category }}">{{ object.category }}</a>.</div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |