Added invalid date format to configs, with bold default

svn: r10618
This commit is contained in:
Doug Blank 2008-04-22 01:36:03 +00:00
parent c760272054
commit 20420efec2
4 changed files with 64 additions and 9 deletions

View File

@ -173,6 +173,7 @@ PRIVATE_SURNAME_TEXT = ('preferences', 'private-surname-text', 2)
PRIVATE_GIVEN_TEXT = ('preferences', 'private-given-text', 2) PRIVATE_GIVEN_TEXT = ('preferences', 'private-given-text', 2)
PRIVATE_RECORD_TEXT = ('preferences', 'private-record-text', 2) PRIVATE_RECORD_TEXT = ('preferences', 'private-record-text', 2)
RELATION_DISPLAY_THEME= ('preferences', 'relation-display-theme', 2) RELATION_DISPLAY_THEME= ('preferences', 'relation-display-theme', 2)
INVALID_DATE_FORMAT = ('preferences', 'invalid-date-format', 2)
default_value = { default_value = {
DEFAULT_SOURCE : False, DEFAULT_SOURCE : False,
@ -299,4 +300,5 @@ default_value = {
PRIVATE_GIVEN_TEXT : "[%s]" % _("Living"), PRIVATE_GIVEN_TEXT : "[%s]" % _("Living"),
PRIVATE_RECORD_TEXT : "[%s]" % _("Private Record"), PRIVATE_RECORD_TEXT : "[%s]" % _("Private Record"),
RELATION_DISPLAY_THEME: "CLASSIC", RELATION_DISPLAY_THEME: "CLASSIC",
INVALID_DATE_FORMAT : "<b>%s</b>",
} }

View File

@ -66,6 +66,7 @@ from Filters import SearchFilter, ExactSearchFilter
from Lru import LRU from Lru import LRU
_CACHE_SIZE = 250 _CACHE_SIZE = 250
invalid_date_format = Config.get(Config.INVALID_DATE_FORMAT)
def locale_sort(mylist): def locale_sort(mylist):
""" """
@ -549,7 +550,7 @@ class PeopleModel(gtk.GenericTreeModel):
if date_str != "": if date_str != "":
retval = cgi.escape(date_str) retval = cgi.escape(date_str)
if not DateHandler.get_date_valid(birth): if not DateHandler.get_date_valid(birth):
return u'<span background="#ffd5d5">%s</span>' % retval return invalid_date_format % retval
else: else:
return retval return retval
except: except:
@ -566,7 +567,7 @@ class PeopleModel(gtk.GenericTreeModel):
and date_str != ""): and date_str != ""):
retval = u"<i>%s</i>" % cgi.escape(date_str) retval = u"<i>%s</i>" % cgi.escape(date_str)
if not DateHandler.get_date_valid(event): if not DateHandler.get_date_valid(event):
return u'<span background="#ffd5d5">%s</span>' % retval return invalid_date_format % retval
else: else:
return retval return retval
@ -593,7 +594,7 @@ class PeopleModel(gtk.GenericTreeModel):
if date_str != "": if date_str != "":
retval = cgi.escape(date_str) retval = cgi.escape(date_str)
if not DateHandler.get_date_valid(event): if not DateHandler.get_date_valid(event):
return u'<span background="#ffd5d5">%s</span>' % retval return invalid_date_format % retval
else: else:
return retval return retval
except: except:
@ -610,7 +611,7 @@ class PeopleModel(gtk.GenericTreeModel):
and date_str): and date_str):
retval = "<i>%s</i>" % cgi.escape(date_str) retval = "<i>%s</i>" % cgi.escape(date_str)
if not DateHandler.get_date_valid(event): if not DateHandler.get_date_valid(event):
return u'<span background="#ffd5d5">%s</span>' % retval return invalid_date_format % retval
else: else:
return retval return retval
return u"" return u""

View File

@ -34,6 +34,14 @@ import cgi
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import DateHandler import DateHandler
import Config
#-------------------------------------------------------------------------
#
# Globals
#
#-------------------------------------------------------------------------
invalid_date_format = Config.get(Config.INVALID_DATE_FORMAT)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -64,7 +72,7 @@ class EventRefModel(gtk.ListStore):
event = self.db.get_event_from_handle(event_ref.ref) event = self.db.get_event_from_handle(event_ref.ref)
retval = DateHandler.get_date(event) retval = DateHandler.get_date(event)
if not DateHandler.get_date_valid(event): if not DateHandler.get_date_valid(event):
return u'<span background="#ffd5d5">%s</span>' % cgi.escape(retval) return invalid_date_format % cgi.escape(retval)
else: else:
return retval return retval

View File

@ -22,11 +22,13 @@
Provide a simplified table creation interface Provide a simplified table creation interface
""" """
import cgi
import copy import copy
from gettext import gettext as _ from gettext import gettext as _
import gen.lib import gen.lib
import Errors import Errors
import Config
import DateHandler import DateHandler
class SimpleTable: class SimpleTable:
@ -41,6 +43,7 @@ class SimpleTable:
self.access = access self.access = access
self.title = title self.title = title
self.__columns = [] self.__columns = []
self.__cell_markup = {} # [col][row] = "<b>data</b>"
self.__rows = [] self.__rows = []
self.__link = [] self.__link = []
self.__sort_col = None self.__sort_col = None
@ -172,6 +175,7 @@ class SimpleTable:
""" """
retval = [] retval = []
link = None link = None
row = len(self.__rows)
for col in range(len(data)): for col in range(len(data)):
item = data[col] item = data[col]
# FIXME: add better text representations of these objects # FIXME: add better text representations of these objects
@ -228,12 +232,16 @@ class SimpleTable:
link = ('Note', item.handle) link = ('Note', item.handle)
elif isinstance(item, gen.lib.Date): elif isinstance(item, gen.lib.Date):
text = DateHandler.displayer.display(item) text = DateHandler.displayer.display(item)
retval.append(text)
if item.get_valid(): if item.get_valid():
retval.append(text)
self.row_sort_val(col, item.sortval) self.row_sort_val(col, item.sortval)
else: else:
retval.append("Invalid: " + text) # sort before others:
self.row_sort_val(col, -1) self.row_sort_val(col, -1)
# give formatted version:
invalid_date_format = Config.get(Config.INVALID_DATE_FORMAT)
self.set_cell_markup(col, row,
invalid_date_format % text)
if (self.__link_col == col or link == None): if (self.__link_col == col or link == None):
link = ('Date', item) link = ('Date', item)
elif isinstance(item, gen.lib.Span): elif isinstance(item, gen.lib.Span):
@ -309,7 +317,10 @@ class SimpleTable:
sort_data_types = [] sort_data_types = []
for col in self.__columns: for col in self.__columns:
types.append(type(col)) types.append(type(col))
column = gtk.TreeViewColumn(col,renderer,text=model_index) if self.get_cell_markup(cnt):
column = gtk.TreeViewColumn(col,renderer,markup=model_index)
else:
column = gtk.TreeViewColumn(col,renderer,text=model_index)
if self.__sort_vals[cnt] != []: if self.__sort_vals[cnt] != []:
sort_data.append(self.__sort_vals[cnt]) sort_data.append(self.__sort_vals[cnt])
column.set_sort_column_id(len(self.__columns) + column.set_sort_column_id(len(self.__columns) +
@ -333,8 +344,41 @@ class SimpleTable:
text_view.add_child_at_anchor(treeview, anchor) text_view.add_child_at_anchor(treeview, anchor)
count = 0 count = 0
for data in self.__rows: for data in self.__rows:
model.append(row=([count] + list(data) + [col[count] for col in sort_data])) col = 0
rowdata = []
for cell in data:
rowdata.append(self.get_cell_markup(col, count, cell))
col += 1
model.append(row=([count] + list(rowdata) + [col[count] for col in sort_data]))
count += 1 count += 1
text_view.show_all() text_view.show_all()
self.simpledoc.paragraph("") self.simpledoc.paragraph("")
self.simpledoc.paragraph("") self.simpledoc.paragraph("")
def get_cell_markup(self, x, y=None, data=None):
"""
See if a column has formatting (if x and y are supplied) or
see if a cell has formatting. If it does, return the formatted
string, otherwise return data that is escaped (if that column
has formatting), or just the plain data.
"""
if x in self.__cell_markup:
if y == None:
return True # markup for this column
elif y in self.__cell_markup[x]:
return self.__cell_markup[x][y]
else:
return cgi.escape(data)
else:
if y == None:
return False # no markup for this column
else:
return data
def set_cell_markup(self, x, y, data):
"""
Set the cell at position [x][y] to a formatted string.
"""
col_dict = self.__cell_markup.get(x, {})
col_dict[y] = data
self.__cell_markup[x] = col_dict