/[theodore]/bunnyblog/index.cgi


UCC Code Repository

Contents of /bunnyblog/index.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations) (download)
Tue Jan 29 14:32:01 2008 UTC (12 years, 2 months ago) by svn-admin
File size: 4664 byte(s)
Re-import of repository after repository database corruption.

1 svn-admin 1 #!/usr/bin/python
2     import cgi
3     import cgitb; cgitb.enable()
4     import blog
5    
6     """
7     Here we set up all the variables for generating the page
8     """
9     main = ""
10     title = "<@site_name@> - "
11     header = ""
12    
13     """
14     Here we retrieve the blog and any arguments
15     Defaults are assigned here
16     """
17     form = cgi.FieldStorage()
18     myblog = blog.Blog(True)
19     numarticles = len(myblog.articles)
20     perpage = 10
21     pagenum = 1
22     httpstatuscode = "200"
23    
24    
25     def listarticles(pagenum = 0, perpage = 10):
26     main = ""
27     start = numarticles - pagenum * perpage - 1
28     finish = start - perpage
29     i = 0
30     if finish < 1:
31     articles = myblog.articles[start::-1]
32     else:
33     articles = myblog.articles[start:finish:-1]
34     for article in articles:
35     main += article.htmlize()
36     i += 1
37     return main
38    
39     def linkto(page,text="",classname=""):
40     if text == "prev":
41     page = page-1
42     text = "&lt;"*3 + " Prev"
43     classname = "class = 'prev'"
44     elif text == "next":
45     page = page+1
46     text = "Next " + 3*"&gt;"
47     classname = "class = 'next'"
48     elif text != "":
49     text = text
50     else:
51     text = str(page)
52     link = " <a href='index.cgi?pagenum=%d&amp;perpage=%d' %s>%s</a> " % (page,perpage,classname,text)
53     return link
54    
55     def generatetoc(currentpage = 1):
56     toc = "<div class='toc'>"
57     if currentpage > 1:
58     toc += linkto(currentpage,"prev")
59     toc += "Page:"
60     for i in range(1,pages + 1):
61     if i == currentpage:
62     toc += "<a> %d </a>" % i
63     else:
64     toc += linkto(i)
65    
66     if currentpage <= numarticles // perpage:
67     toc += linkto(currentpage,"next")
68     toc += "</div>"
69     return toc
70    
71     if form.has_key('pagenum'):
72     if form.has_key('perpage'):
73     perpage = int(form['perpage'].value)
74     if perpage < 1 or perpage > 100:
75     perpage = 10
76     pages = numarticles // perpage + 1
77     pagenum = int(form['pagenum'].value)
78     if pagenum < 1 or pagenum > pages:
79     pagenum = 1
80     toc = numarticles > perpage and generatetoc(pagenum) or ""
81     main += toc + "<hr />" + listarticles(pagenum-1, perpage) + "<hr />" + toc
82     header += "Archives - Page %d" % pagenum
83     title += header
84     elif form.has_key('action') and form.has_key('index'):
85     action = form['action'].value
86     articleindex = int(form['index'].value)
87     article = myblog.findbyindex(articleindex)
88     if article:
89     comment = form['comment'].value
90     author = form['author'].value
91     if action == 'addcomment' and comment and author:
92     if form.has_key('comment') and form.has_key('author'):
93     if action == 'addcomment' and comment and author:
94     article.addcomment(author,comment)
95     myblog.saveblog()
96     main += "Successfully saved"
97     main += article.htmlize()
98     main += article.showcomments()
99     else:
100     main += blog.error('invalid comment or author')
101     else:
102     main += blog.error('nosuchindex: ' + str(articleindex))
103     elif form.has_key('article'):
104     index = int(form['article'].value)
105     article = myblog.findbyindex(index)
106     if article:
107     main += article.htmlize()
108     main += article.showcomments()
109     title = article.title
110     else:
111     main += blog.error('indexoutrange')
112     elif form.has_key('title'):
113     articletitle = form['title'].value
114     article = myblog.findbytitle(articletitle)
115     if article:
116     main += article.htmlize()
117     main += article.showcomments()
118     header = article.title
119     title += header
120     else:
121     main += blog.error('nosuchtitle: ' + articletitle)
122     elif form.has_key('page'):
123     pagetodisplay = form['page'].value
124     if pagetodisplay == 'home':
125     pages = numarticles // 5 + 1
126     (cmspage,header) = blog.getcmspage("home")
127     main += cmspage + "<br /><hr />"
128     title = "Welcome to <@site_name@>"
129     if len(myblog.articles):
130     main += "<h2>Latest Rant:</h2>" + myblog.articles[-1].htmlize() + "For more reading material, please continue to the " + linkto(1,"Archives")
131     elif pagetodisplay == 'archive':
132     perpage = 10
133     pages = numarticles // perpage + 1
134     pagenum = 1
135     toc = numarticles > perpage and generatetoc(pagenum) or ""
136     main += toc + "<hr />" + listarticles(pagenum-1, perpage) + "<hr />" + toc
137     header += "Archives - Page %d" % pagenum
138     title += header
139     else:
140     (cmspage,header) = blog.getcmspage(pagetodisplay)
141     if cmspage.find("404") != -1:
142     myblog.httpcode = "404"
143     main += cmspage
144     title = "<@site_name@> - %s" % header
145     else:
146     pages = numarticles // 5 + 1
147     (cmspage,header) = blog.getcmspage("home")
148     main += cmspage
149     if len(myblog.articles):
150     main += "<h2>Latest Rant:</h2>" + myblog.articles[-1].htmlize() + "For more reading material, please continue to the " + linkto(1,"Archives")
151     else:
152     main += "Login to the <a href='admin.cgi'>admin page</a> to begin your new blog"
153     title = "Welcome to <@site_name@>"
154    
155    
156     sidebar = blog.gettemplate("data/menu/shoutbox")
157     if blog.isadmin():
158     sidebar += "<hr />" + blog.gettemplate("template/admin/toolbar")
159     myblog.display(title,header,main, sidebar)

Properties

Name Value
svn:executable

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26