1 # BiaWeb Website content manager (c) 2010 V.Harishankar
2 # Database handling functions
6 def create_db (dbname
, site_title
, site_url
, keywords
, description
, copyright
,
9 conn
= sqlite3
.connect (dbname
)
11 c
.execute ("CREATE TABLE IF NOT EXISTS \
12 categories (cid INTEGER PRIMARY KEY, \
13 name TEXT, desc TEXT, \
15 c
.execute ("CREATE TABLE IF NOT EXISTS \
16 articles (aid INTEGER PRIMARY KEY, \
17 title TEXT, summary TEXT, keywords TEXT, \
18 content TEXT, cdate NUMERIC, mdate NUMERIC, cid NUMERIC, \
19 stub TEXT, rating NUMERIC);")
20 c
.execute ("CREATE TABLE IF NOT EXISTS \
21 config (config_name TEXT, config_param TEXT);")
23 c
.execute ("CREATE TABLE IF NOT EXISTS \
24 templates (template_name TEXT, template_content);")
26 template_main
= """<?xml version="1.0" encoding="UTF-8"?>
27 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
28 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
30 <title>${site_title}</title>
31 <base href="${site_url}" />
32 <meta name="generator" content="BiaWeb"/>
33 <meta name="keywords" content="${meta_keywords}"/>
34 <meta name="description" content="${meta_description}"/>
35 <link rel="StyleSheet" type="text/css" href="style.css" />
36 <link rel="alternate" type="application/rss+xml" title="Entries RSS 2.0" href="subscribe.xml" />
40 <h1><a href="${site_url}">${page_title}</a></h1>
41 <div class="headerdesc">${page_desc}</div>
52 <a href="subscribe.xml">Latest articles (RSS)</a>
54 <form action="cgi-bin/search.py" method="post" enctype="multipart/form-data">
55 <p><input type="text" name="query" maxlength="255" style="width:142px;border: 1px inset #5A5A5A; color:#5A5A5A; background-color:#FFFFFF;" value="" /><br />
56 <input type="submit" value="Search" /><br />
57 <input type="hidden" name="fromsearch" value="fromsearch" />
58 <input type="radio" name="criteria" value="1" checked="checked" />All words<br />
59 <input type="radio" name="criteria" value="2" />Any word</p>
62 <div id="footer">${copyright}<br />Site generated by
63 <a href=\"http://harishankar.org/software/biaweb.php\">BiaWeb</a> created by V. Harishankar</div>
67 template_article_bit
= """<h2>${article_title}</h2>
68 <div class="modified">Created: ${article_cdate} | Last modified: ${article_mdate}</div>
69 <div class="rating">Rating: ${rating}</div>
70 <div class="content">${article_contents}</div>
73 template_news_item_bit
= """<h3><a href="${news_link}">${news_title}</a></h3>
74 <div class="modified">${news_datetime}</div>
75 <div class="content">${news_description}</div>
78 template_index_bit
= """<h2>Welcome to ${site_name}</h2>
80 Welcome to my site, ${site_name}.
82 <h2>Latest Articles</h2>
86 template_table_bit
= """<h2>${category_title}</h2>
87 <p>${category_desc}</p>
88 <table class="categorytable">
91 <td style="width:50%">Title</td>
102 template_tablerow_bit
= """<tr>
103 <td style="width:50%"><a href="${article_url}">${title}</a></td>
109 template_style
= """body {
110 font-family: "Bitstream Vera Sans", Verdana, Arial, Sans Serif;
112 background-color: #ffffff;
118 background-color: #efefef;
142 background-color: #efefef;
146 font-variant: small-caps;
159 .categorytable thead {
174 font-family: "Bitstream Vera Serif", Serif;
183 border-bottom: 1px solid;
184 border-color: #888888;
192 h1 a, h1 a:hover, h1 a:visited, h2 a:active {
193 text-decoration: none;
197 background-color: #efefef;
199 h2 a, h2 a:hover, h2 a:visited, h2 a:active {
200 text-decoration: none;
214 c
.executemany ("INSERT INTO templates (template_name, template_content) VALUES (?, ?);",
215 [["main_template", template_main
],
216 ["article_bit", template_article_bit
],
217 ["news_bit", template_news_item_bit
],
218 ["table_bit", template_table_bit
],
219 ["tablerow_bit", template_tablerow_bit
],
220 ["stylesheet", template_style
],
221 ["index_bit", template_index_bit
]])
223 c
.executemany ("INSERT INTO config (config_name, config_param) VALUES (?, ?); ",
224 [["Website URL", site_url
],
225 ["Website Title", site_title
],
226 ["Keywords", keywords
],
227 ["Description", description
],
228 ["No. of RSS items", num_rss
],
229 ["Destination path", dest_path
],
230 ["Copyright", copyright
]])
235 except sqlite3
.Error
: