From b1fee4802ce00b95bec0d7261fecc7f6fb4ee9c7 Mon Sep 17 00:00:00 2001 From: david <> Date: Sat, 18 May 2002 20:44:15 +0000 Subject: [PATCH] Added Formats, Format Added I18n support for formats --- LDP/lampadas/database/createdb.sh | 1 + LDP/lampadas/database/format.sql | 1 - LDP/lampadas/database/format_i18n.sql | 10 ++++++ LDP/lampadas/database/load.sql | 1 + LDP/lampadas/database/save.sql | 1 + LDP/lampadas/pylib/DataLayer.py | 48 ++++++++++++++++++++++++++- LDP/lampadas/pylib/UnitTest.py | 6 ++++ 7 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 LDP/lampadas/database/format_i18n.sql diff --git a/LDP/lampadas/database/createdb.sh b/LDP/lampadas/database/createdb.sh index 63981fc4..e1707c6c 100755 --- a/LDP/lampadas/database/createdb.sh +++ b/LDP/lampadas/database/createdb.sh @@ -15,6 +15,7 @@ psql lampadas -qf document_wiki.sql psql lampadas -qf doc_vote.sql psql lampadas -qf dtd.sql psql lampadas -qf format.sql +psql lampadas -qf format_i18n.sql psql lampadas -qf language.sql psql lampadas -qf license.sql psql lampadas -qf notes.sql diff --git a/LDP/lampadas/database/format.sql b/LDP/lampadas/database/format.sql index 4ec4a7b8..97c3b71f 100644 --- a/LDP/lampadas/database/format.sql +++ b/LDP/lampadas/database/format.sql @@ -3,7 +3,6 @@ DROP TABLE format; CREATE TABLE format ( format CHAR(12) NOT NULL, - format_name TEXT NOT NULL, PRIMARY KEY (format) ); diff --git a/LDP/lampadas/database/format_i18n.sql b/LDP/lampadas/database/format_i18n.sql new file mode 100644 index 00000000..def71de0 --- /dev/null +++ b/LDP/lampadas/database/format_i18n.sql @@ -0,0 +1,10 @@ +DROP TABLE format_i18n; + +CREATE TABLE format_i18n +( + format CHAR(12) NOT NULL, + lang CHAR(2) NOT NULL, + format_name TEXT NOT NULL, + + PRIMARY KEY (format, lang) +); diff --git a/LDP/lampadas/database/load.sql b/LDP/lampadas/database/load.sql index 65d16d08..1918b208 100644 --- a/LDP/lampadas/database/load.sql +++ b/LDP/lampadas/database/load.sql @@ -13,6 +13,7 @@ copy document_user from '/tmp/lampadas_document_user.txt'; copy document_wiki from '/tmp/lampadas_document_wiki.txt'; copy dtd from '/tmp/lampadas_dtd.txt'; copy format from '/tmp/lampadas_format.txt'; +copy format_i18n from '/tmp/lampadas_format_i18n.txt'; copy language from '/tmp/lampadas_language.txt'; copy license from '/tmp/lampadas_license.txt'; copy notes from '/tmp/lampadas_notes.txt'; diff --git a/LDP/lampadas/database/save.sql b/LDP/lampadas/database/save.sql index ac5ef6a3..a5639723 100644 --- a/LDP/lampadas/database/save.sql +++ b/LDP/lampadas/database/save.sql @@ -13,6 +13,7 @@ copy document_user to '/tmp/lampadas_document_user.txt'; copy document_wiki to '/tmp/lampadas_document_wiki.txt'; copy dtd to '/tmp/lampadas_dtd.txt'; copy format to '/tmp/lampadas_format.txt'; +copy format_i18n to '/tmp/lampadas_format_i18n.txt'; copy language to '/tmp/lampadas_language.txt'; copy license to '/tmp/lampadas_license.txt'; copy notes to '/tmp/lampadas_notes.txt'; diff --git a/LDP/lampadas/pylib/DataLayer.py b/LDP/lampadas/pylib/DataLayer.py index 80378955..41bfbea4 100755 --- a/LDP/lampadas/pylib/DataLayer.py +++ b/LDP/lampadas/pylib/DataLayer.py @@ -115,6 +115,7 @@ class Lampadas: self.Docs = Docs() self.Docs.Load() self.DTDs = DTDs() + self.Formats = Formats() self.Languages = Languages() self.Strings = Strings() self.Topics = Topics() @@ -497,6 +498,51 @@ class DTD: self.DTD = trim(row[0]) +# Formats + +class Formats(LampadasCollection): + """ + A collection object of all formats. + """ + + def __init__(self): + self.data = {} + self.sql = "SELECT format FROM format" + self.cursor = DB.Select(self.sql) + while (1): + row = self.cursor.fetchone() + if row == None: break + newFormat = Format() + newFormat.Load(row) + self.data[newFormat.Format] = newFormat + +class Format: + + def __init__(self, Format=None): + self.I18n = {} + if Format==None: return + self.Code = Format + + def Load(self, row): + self.Format = trim(row[0]) + self.sql = "SELECT lang, format_name FROM format_i18n WHERE format=" + wsq(self.Format) + self.cursor = DB.Select(self.sql) + while (1): + self.row = self.cursor.fetchone() + if self.row == None: break + newFormatI18n = FormatI18n() + newFormatI18n.Load(self.row) + self.I18n[newFormatI18n.Lang] = newFormatI18n + +# FormatI18n + +class FormatI18n: + + def Load(self, row): + self.Lang = row[0] + self.Name = trim(row[1]) + + # Languages class Languages(LampadasCollection): @@ -529,7 +575,7 @@ class Language: self.Name = trim(row[1]) -# String +# Strings class Strings(LampadasCollection): """ diff --git a/LDP/lampadas/pylib/UnitTest.py b/LDP/lampadas/pylib/UnitTest.py index c3e76325..73f138cc 100755 --- a/LDP/lampadas/pylib/UnitTest.py +++ b/LDP/lampadas/pylib/UnitTest.py @@ -194,6 +194,12 @@ class testDTDs(unittest.TestCase): assert L.DTDs.Count() > 0 assert not L.DTDs['DocBook'] == None +class testFormats(unittest.TestCase): + + def testFormats(self): + assert L.Formats.Count() > 0 + assert not L.Formats['XML'] == None + class testLanguages(unittest.TestCase): def testLanguages(self):