1 # BiaWeb Website content manager (c) 2010 V.Harishankar
2 # Database handling functions
8 # function to create a category
9 def create_category (dbname
, category_name
, category_desc
, category_stub
):
11 conn
= sqlite3
.connect (dbname
)
13 c
.execute ("INSERT INTO categories (name, desc, stub) VALUES (?, ?, ?);",
14 (category_name
, category_desc
, category_stub
))
22 # function to create a new site database
23 def create_db (dbname
, site_title
, site_url
, keywords
, description
, copyright
,
26 if os
.path
.exists (dbname
):
32 conn
= sqlite3
.connect (dbname
)
34 c
.execute ("CREATE TABLE IF NOT EXISTS \
35 categories (cid INTEGER PRIMARY KEY, \
36 name TEXT, desc TEXT, \
38 c
.execute ("CREATE TABLE IF NOT EXISTS \
39 articles (aid INTEGER PRIMARY KEY, \
40 title TEXT, summary TEXT, keywords TEXT, \
41 content TEXT, cdate NUMERIC, mdate NUMERIC, cid NUMERIC, \
42 stub TEXT, rating NUMERIC);")
43 c
.execute ("CREATE TABLE IF NOT EXISTS \
44 config (config_name TEXT, config_param TEXT);")
46 c
.execute ("CREATE TABLE IF NOT EXISTS \
47 templates (template_name TEXT, template_content);")
49 template_main
= """<?xml version="1.0" encoding="UTF-8"?>
50 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
51 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
53 <title>${site_title}</title>
54 <base href="${site_url}" />
55 <meta name="generator" content="BiaWeb"/>
56 <meta name="keywords" content="${meta_keywords}"/>
57 <meta name="description" content="${meta_description}"/>
58 <link rel="StyleSheet" type="text/css" href="style.css" />
59 <link rel="alternate" type="application/rss+xml" title="Entries RSS 2.0" href="subscribe.xml" />
63 <h1><a href="${site_url}">${page_title}</a></h1>
64 <div class="headerdesc">${page_desc}</div>
75 <a href="subscribe.xml">Latest articles (RSS)</a>
77 <form action="cgi-bin/search.py" method="post" enctype="multipart/form-data">
78 <p><input type="text" name="query" maxlength="255" style="width:142px;border: 1px inset #5A5A5A; color:#5A5A5A; background-color:#FFFFFF;" value="" /><br />
79 <input type="submit" value="Search" /><br />
80 <input type="hidden" name="fromsearch" value="fromsearch" />
81 <input type="radio" name="criteria" value="1" checked="checked" />All words<br />
82 <input type="radio" name="criteria" value="2" />Any word</p>
85 <div id="footer">${copyright}<br />Site generated by
86 <a href=\"http://harishankar.org/software/biaweb.php\">BiaWeb</a> created by V. Harishankar</div>
90 template_article_bit
= """<h2>${article_title}</h2>
91 <div class="modified">Created: ${article_cdate} | Last modified: ${article_mdate}</div>
92 <div class="rating">Rating: ${rating}</div>
93 <div class="content">${article_contents}</div>
96 template_news_item_bit
= """<h3><a href="${news_link}">${news_title}</a></h3>
97 <div class="modified">${news_datetime}</div>
98 <div class="content">${news_description}</div>
101 template_index_bit
= """<h2>Welcome to ${site_name}</h2>
102 <div class="content">
103 Welcome to my site, ${site_name}.
105 <h2>Latest Articles</h2>
109 template_table_bit
= """<h2>${category_title}</h2>
110 <p>${category_desc}</p>
111 <table class="categorytable">
114 <td style="width:50%">Title</td>
125 template_tablerow_bit
= """<tr>
126 <td style="width:50%"><a href="${article_url}">${title}</a></td>
132 template_style
= """body {
133 font-family: "Bitstream Vera Sans", Verdana, Arial, Sans Serif;
135 background-color: #ffffff;
141 background-color: #efefef;
165 background-color: #efefef;
169 font-variant: small-caps;
182 .categorytable thead {
197 font-family: "Bitstream Vera Serif", Serif;
206 border-bottom: 1px solid;
207 border-color: #888888;
215 h1 a, h1 a:hover, h1 a:visited, h2 a:active {
216 text-decoration: none;
220 background-color: #efefef;
222 h2 a, h2 a:hover, h2 a:visited, h2 a:active {
223 text-decoration: none;
237 c
.executemany ("INSERT INTO templates (template_name, template_content) VALUES (?, ?);",
238 [["main_template", template_main
],
239 ["article_bit", template_article_bit
],
240 ["news_bit", template_news_item_bit
],
241 ["table_bit", template_table_bit
],
242 ["tablerow_bit", template_tablerow_bit
],
243 ["stylesheet", template_style
],
244 ["index_bit", template_index_bit
]])
246 c
.executemany ("INSERT INTO config (config_name, config_param) VALUES (?, ?); ",
247 [["Website URL", site_url
],
248 ["Website Title", site_title
],
249 ["Keywords", keywords
],
250 ["Description", description
],
251 ["No. of RSS items", num_rss
],
252 ["Destination path", dest_path
],
253 ["Copyright", copyright
]])
258 except sqlite3
.Error
: