Added error, error_i18n tables, updated document_error also so it is fully

internationalized.
Added Errs, Err objects to represent these.
Update DcErrors, DocError to DocErrs, DocErr, and also internationalized.
Updated unit tests to match.
This commit is contained in:
david 2002-05-19 08:09:52 +00:00
parent 1c4cbfa829
commit 192c4f5b86
10 changed files with 124 additions and 61 deletions

View File

@ -14,6 +14,8 @@ psql lampadas -qf document_user.sql
psql lampadas -qf document_wiki.sql
psql lampadas -qf doc_vote.sql
psql lampadas -qf dtd.sql
psql lampadas -qf error.sql
psql lampadas -qf error_i18n.sql
psql lampadas -qf format.sql
psql lampadas -qf format_i18n.sql
psql lampadas -qf language.sql

View File

@ -3,5 +3,5 @@ DROP TABLE document_error;
CREATE TABLE document_error
(
doc_id INT4 NOT NULL,
error TEXT
err_id INT4 NOT NULL
);

View File

@ -0,0 +1,8 @@
DROP TABLE error;
CREATE TABLE error
(
err_id INT4 NOT NULL,
PRIMARY KEY (err_id)
);

View File

@ -0,0 +1,11 @@
DROP TABLE error_i18n;
CREATE TABLE error_i18n
(
err_id INT4 NOT NULL,
lang CHAR(2) NOT NULL,
err_name TEXT NOT NULL,
err_desc TEXT,
PRIMARY KEY (err_id, lang)
);

View File

@ -21,6 +21,8 @@ ALTER TABLE document_wiki ADD CONSTRAINT doc_id_fk FOREIGN KEY (doc_id) REFER
ALTER TABLE document_wiki ADD CONSTRAINT user_id_fk FOREIGN KEY (user_id) REFERENCES username(user_id);
ALTER TABLE doc_vote ADD CONSTRAINT doc_id_fk FOREIGN KEY (doc_id) REFERENCES document(doc_id);
ALTER TABLE doc_vote ADD CONSTRAINT user_id_fk FOREIGN KEY (user_id) REFERENCES username(user_id);
ALTER TABLE error_i18n ADD CONSTRAINT err_id_fk FOREIGN KEY (err_id) REFERENCES error(err_id);
ALTER TABLE error_i18n ADD CONSTRAINT lang_fk FOREIGN KEY (lang) REFERENCES language(isocode);
ALTER TABLE format_i18n ADD CONSTRAINT format_fk FOREIGN KEY (format) REFERENCES format(format);
ALTER TABLE format_i18n ADD CONSTRAINT format_lang_fk FOREIGN KEY (lang) REFERENCES language(isocode);
ALTER TABLE language_i18n ADD CONSTRAINT language_fk FOREIGN KEY (language) REFERENCES language(isocode);

View File

@ -12,6 +12,8 @@ copy document_topic from '/tmp/lampadas_document_topic.txt';
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 error from '/tmp/lampadas_error.txt';
copy error_i18n from '/tmp/lampadas_error_i18n.txt';
copy format from '/tmp/lampadas_format.txt';
copy format_i18n from '/tmp/lampadas_format_i18n.txt';
copy language from '/tmp/lampadas_language.txt';

View File

@ -12,6 +12,8 @@ copy document_topic to '/tmp/lampadas_document_topic.txt';
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 error to '/tmp/lampadas_error.txt';
copy error_i18n to '/tmp/lampadas_error_i18n.txt';
copy format to '/tmp/lampadas_format.txt';
copy format_i18n to '/tmp/lampadas_format_i18n.txt';
copy language to '/tmp/lampadas_language.txt';

View File

@ -324,14 +324,10 @@ $conn->exec("INSERT INTO topic_i18n SELECT topic_num, 'EN' as lang, topic_name,
# Drop some fields from the document table
# Convert class to class_id
#
$sql = "DROP TABLE document_new";
$conn->exec("$sql");
$sql = "CREATE TABLE document_new (doc_id INT4 NOT NULL, title TEXT NOT NULL, class_id INT4, format CHAR(12), dtd CHAR(12), dtd_version CHAR(12), version CHAR(12), last_update DATE, URL TEXT, ISBN TEXT, pub_status CHAR, review_status CHAR, tickle_date DATE, pub_date DATE, ref_url TEXT, tech_review_status CHAR, maintained BOOLEAN DEFAULT False, license CHAR(12), abstract TEXT, rating REAL, lang CHAR(2), PRIMARY KEY (doc_id))";
$conn->exec("$sql");
$sql = "INSERT INTO document_new SELECT doc_id, title, class_id, format, dtd, dtd_version, version, last_update, url, isbn, pub_status, review_status, tickle_date, pub_date, ref_url, tech_review_status, maintained, license, abstract, rating FROM document d, class_i18n c WHERE d.class=c.class_name";
$conn->exec("$sql");
$sql = "UPDATE document_new SET lang='EN'";
$conn->exec("$sql");
$conn->exec("DROP TABLE document_new");
$conn->exec("CREATE TABLE document_new (doc_id INT4 NOT NULL, title TEXT NOT NULL, class_id INT4, format CHAR(12), dtd CHAR(12), dtd_version CHAR(12), version CHAR(12), last_update DATE, URL TEXT, ISBN TEXT, pub_status CHAR, review_status CHAR, tickle_date DATE, pub_date DATE, ref_url TEXT, tech_review_status CHAR, maintained BOOLEAN DEFAULT False, license CHAR(12), abstract TEXT, rating REAL, lang CHAR(2), PRIMARY KEY (doc_id))");
$conn->exec("INSERT INTO document_new SELECT doc_id, title, class_id, format, dtd, dtd_version, version, last_update, url, isbn, pub_status, review_status, tickle_date, pub_date, ref_url, tech_review_status, maintained, license, abstract, rating FROM document d, class_i18n c WHERE d.class=c.class_name");
$conn->exec("UPDATE document_new SET lang='EN'");
# Add document sk_seriesid values
@ -341,37 +337,27 @@ die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus;
while (@row = $result->fetchrow) {
$doc_id = $row[0];
$sk_seriesid = &trim(qx('scrollkeeper-gen-seriesid'));
$sql = "UPDATE document_new SET sk_seriesid='$sk_seriesid' WHERE doc_id=$doc_id";
$conn->exec($sql);
$conn->exec("UPDATE document_new SET sk_seriesid='$sk_seriesid' WHERE doc_id=$doc_id");
}
# Switch doc_vote to use user_id instead of username
#
$sql = "DROP TABLE doc_vote_new";
$conn->exec("$sql");
$sql = "CREATE TABLE doc_vote_new (doc_id INT4 NOT NULL, user_id INT4 NOT NULL, date_entered TIMESTAMP NOT NULL DEFAULT now(), vote INT4 NOT NULL, PRIMARY KEY (doc_id, user_id))";
$conn->exec("$sql");
$sql = "INSERT INTO doc_vote_new SELECT doc_id, user_id, date_entered, vote FROM doc_vote, username_new WHERE username_new.username = doc_vote.username";
$conn->exec("$sql");
$conn->exec("DROP TABLE doc_vote_new");
$conn->exec("CREATE TABLE doc_vote_new (doc_id INT4 NOT NULL, user_id INT4 NOT NULL, date_entered TIMESTAMP NOT NULL DEFAULT now(), vote INT4 NOT NULL, PRIMARY KEY (doc_id, user_id))");
$conn->exec("INSERT INTO doc_vote_new SELECT doc_id, user_id, date_entered, vote FROM doc_vote, username_new WHERE username_new.username = doc_vote.username");
# Update the document_wiki table
#
$sql = "DROP TABLE document_wiki_new";
$conn->exec("$sql");
$sql = "CREATE TABLE document_wiki_new(doc_id INT4 NOT NULL, revision INT4 NOT NULL, date_entered TIMESTAMP NOT NULL DEFAULT now(), wiki TEXT, notes CHAR(256), user_id INT4)";
$conn->exec("$sql");
$sql = "INSERT INTO document_wiki_new SELECT doc_id, revision, date_entered, wiki, document_wiki.notes, user_id FROM document_wiki, username_new WHERE document_wiki.username = username_new.username";
$conn->exec("$sql");
$conn->exec("DROP TABLE document_wiki_new");
$conn->exec("CREATE TABLE document_wiki_new(doc_id INT4 NOT NULL, revision INT4 NOT NULL, date_entered TIMESTAMP NOT NULL DEFAULT now(), wiki TEXT, notes CHAR(256), user_id INT4)");
$conn->exec("INSERT INTO document_wiki_new SELECT doc_id, revision, date_entered, wiki, document_wiki.notes, user_id FROM document_wiki, username_new WHERE document_wiki.username = username_new.username");
# Add "free" column to license table
#
$sql = "ALTER TABLE license ADD COLUMN free BOOLEAN";
$conn->exec($sql);
$sql = "UPDATE license SET free='t' WHERE license='GPL' or license='GFDL' or license='PD' or license='OPL'";
$conn->exec($sql);
$sql = "UPDATE license SET free='f' WHERE free IS NULL";
$conn->exec($sql);
$conn->exec("ALTER TABLE license ADD COLUMN free BOOLEAN");
$conn->exec("UPDATE license SET free='t' WHERE license='GPL' or license='GFDL' or license='PD' or license='OPL'");
$conn->exec("UPDATE license SET free='f' WHERE free IS NULL");
# Prepend format strings to filenames
#
@ -390,19 +376,14 @@ $conn->exec("UPDATE document SET filename='howto/' || filename where class='TEMP
# Create document_file table
#
$sql = "DROP TABLE document_file";
$conn->exec($sql);
$sql = "CREATE TABLE document_file(doc_id INT4 NOT NULL, filename TEXT NOT NULL, format CHAR(12), PRIMARY KEY (doc_id, filename))";
$conn->exec($sql);
$sql = "INSERT INTO document_file(doc_id, filename) SELECT doc_id, filename FROM document WHERE filename<>''";
$conn->exec($sql);
$conn->exec("DROP TABLE document_file");
$conn->exec("CREATE TABLE document_file(doc_id INT4 NOT NULL, filename TEXT NOT NULL, format CHAR(12), PRIMARY KEY (doc_id, filename))");
$conn->exec("INSERT INTO document_file(doc_id, filename) SELECT doc_id, filename FROM document WHERE filename<>''");
# Create document_error table
#
$sql = "DROP TABLE document_error";
$conn->exec($sql);
$sql = "CREATE TABLE document_error(doc_id INT4 NOT NULL, error TEXT)";
$conn->exec($sql);
$conn->exec("DROP TABLE document_error");
$conn->exec("CREATE TABLE document_error(doc_id INT4 NOT NULL, err_id INT4 NOT NULL)");
# Create string table
#
@ -414,6 +395,15 @@ $conn->exec("CREATE TABLE string (string_id INT4 NOT NULL, PRIMARY KEY (string_i
$conn->exec("DROP TABLE string_i18n");
$conn->exec("CREATE TABLE string_i18n (string_id INT4 NOT NULL, lang CHAR(2) NOT NULL, string TEXT NOT NULL, PRIMARY KEY (string_id, lang))");
# Create error table
$conn->exec("DROP TABLE error");
$conn->exec("CREATE TABLE error (err_id INT4 NOT NULL, PRIMARY KEY (err_id))");
$conn->exec("DROP TABLE error_i18n");
$conn->exec("CREATE TABLE error_i18n (err_id INT4 NOT NULL, err_name TEXT NOT NULL, err_desc TEXT PRIMARY KEY (err_id))");
# Copy the new tables over to replace the old ones
#
$conn->exec("DROP TABLE class");

View File

@ -257,7 +257,7 @@ class Doc:
self.LanguageCode = trim(row[20])
self.SeriesID = trim(row[21])
self.Errors = DocErrors(self.ID)
self.Errs = DocErrs(self.ID)
self.Files = DocFiles(self.ID)
self.Ratings = DocRatings(self.ID)
self.Ratings.Parent = self
@ -269,9 +269,9 @@ class Doc:
DB.Commit()
# DocErrors
# DocErrs
class DocErrors(LampadasList):
class DocErrs(LampadasList):
"""
A collection object providing access to all document errors, as identified by the
Lintadas subsystem.
@ -280,30 +280,30 @@ class DocErrors(LampadasList):
def __init__(self, DocID):
assert not DocID == None
self.DocID = DocID
self.sql = "SELECT error FROM document_error WHERE doc_id=" + str(DocID)
self.sql = "SELECT err_id FROM document_error WHERE doc_id=" + str(DocID)
self.cursor = DB.Select(self.sql)
while (1):
row = self.cursor.fetchone()
if row == None: break
newDocError = DocError()
newDocError.Load(DocID, row)
self.list = self.list + [newDocError]
newDocErr = DocErr()
newDocErr.Load(DocID, row)
self.list = self.list + [newDocErr]
def Clear(self):
self.sql = "DELETE FROM document_error WHERE doc_id=" + str(self.DocID)
DB.Exec(self.sql)
self.list = []
def Add(self, Error):
self.sql = "INSERT INTO document_error(doc_id, error) VALUES (" + str(self.DocID) + ", " + wsq(Error)
def Add(self, ErrID):
self.sql = "INSERT INTO document_error(doc_id, err_id) VALUES (" + str(self.DocID) + ", " + wsq(ErrID)
assert DB.Exec(self.sql) == 1
newDocError = DocError()
newDocError.DocID = self.DocID
newDocError.Error = Error
self.list = self.list + [newDocError]
newDocErr = DocErr()
newDocErr.DocID = self.DocID
newDocErr.ErrID = ErrID
self.list = self.list + [newDocErr]
DB.Commit()
class DocError:
class DocErr:
"""
An error filed against a document by the Lintadas subsystem.
"""
@ -312,7 +312,7 @@ class DocError:
assert not DocID == None
assert not row == None
self.DocID = DocID
self.Error = trim(row[0])
self.ErrID = safeint(row[0])
# DocFiles
@ -499,6 +499,52 @@ class DTD:
self.DTD = trim(row[0])
# Errs
class Errs(LampadasCollection):
"""
A collection object of all errors that can be filed against a document.
"""
def __init__(self):
self.data = {}
self.sql = "SELECT err_id FROM error"
self.cursor = DB.Select(self.sql)
while (1):
row = self.cursor.fetchone()
if row == None: break
newErr = Err()
newErr.Load(row)
self.data[newErr.ErrID] = newErr
class Err:
def __init__(self, ErrID=None):
self.I18n = {}
if Err==None: return
self.ErrID = ErrID
def Load(self, row):
self.ErrID = trim(row[0])
self.sql = "SELECT lang, err_name, err_desc FROM error_i18n WHERE err_id=" + wsq(self.ErrID)
self.cursor = DB.Select(self.sql)
while (1):
self.row = self.cursor.fetchone()
if self.row == None: break
newErrI18n = ErrI18n()
newErrI18n.Load(self.row)
self.I18n[newErrI18n.Lang] = newErrI18n
# ErrI18n
class ErrI18n:
def Load(self, row):
self.Lang = row[0]
self.Name = trim(row[1])
self.Description = trim(row[1])
# Formats
class Formats(LampadasCollection):

View File

@ -106,19 +106,19 @@ class testDocs(unittest.TestCase):
self.Doc2 = L.Docs[1]
assert self.Doc2.Title == self.Title
class testDocErrors(unittest.TestCase):
class testDocErrs(unittest.TestCase):
def testDocErrors(self):
def testDocErrs(self):
keys = L.Docs.keys()
for key in keys:
Doc = L.Docs[key]
assert not Doc == None
if Doc.Errors.Count() > 0:
if Doc.Errs.Count() > 0:
print "found a doc with errors"
for Error in Doc.Errors:
assert not Error == None
assert Error.DocID == Doc.ID
assert Error.Error > ''
for Err in Doc.Errs:
assert not Err == None
assert Err.DocID == Doc.ID
assert Err.ErrID > 1
class testDocFiles(unittest.TestCase):