Comments custom columns:

- collapse the two booleans controlling the heading into one string
- allow short-text to appear on the right in book details
- make the new server and book details do (more-or-less) the same thing with headings
- use different CSS for short-text and long-text.

I changed the name of the show_heading property to heading_position to ensure the properties had no odd values, making it easier to test.
This commit is contained in:
Charles Haley 2016-07-24 12:42:50 +02:00
parent 0b0f6e6b9d
commit 6439b98723
4 changed files with 37 additions and 40 deletions

View File

@ -89,24 +89,20 @@ def mi_to_html(mi, field_list=None, default_author_link=None, use_roman_numbers=
if val: if val:
ctype = disp.get('interpret_as') or 'html' ctype = disp.get('interpret_as') or 'html'
val = force_unicode(val) val = force_unicode(val)
if ctype == 'short-text': if ctype == 'long-text':
ans.append((field, row % (name, p(val)))) val = '<pre style="white-space:pre-wrap">%s</pre>' % p(val)
elif ctype == 'short-text':
val = '<span>%s</span>' % p(val)
elif ctype == 'markdown':
val = markdown(val)
else: else:
if ctype == 'long-text': val = comments_to_html(val)
val = '<pre>%s</pre>' % p(val) if disp.get('heading_position', 'hide') == 'side':
elif ctype == 'markdown': ans.append((field, row % (name, val)))
val = markdown(val) else:
else: if disp.get('heading_position', 'hide') == 'above':
val = comments_to_html(val) val = '<h3 class="comments-heading">%s</h3>%s' % (p(name), val)
add_comment = True comment_fields.append('<div id="%s" class="comments">%s</div>' % (field.replace('#', '_'), val))
if disp.get('show_heading'):
if disp.get('heading_on_side'):
ans.append((field, row % (name, val)))
add_comment = False
else:
val = '<h3 class="comments-heading">%s</h3>%s' % (p(name), val)
if add_comment:
comment_fields.append('<div id="%s" class="comments">%s</div>' % (field.replace('#', '_'), val))
elif metadata['datatype'] == 'rating': elif metadata['datatype'] == 'rating':
val = getattr(mi, field) val = getattr(mi, field)
if val: if val:

View File

@ -164,8 +164,8 @@ class CreateCustomColumn(QDialog):
if c['display'].get('number_format', None): if c['display'].get('number_format', None):
self.format_box.setText(c['display'].get('number_format', '')) self.format_box.setText(c['display'].get('number_format', ''))
elif ct == 'comments': elif ct == 'comments':
self.show_comments_heading.setChecked(c['display'].get('show_heading', False)) idx = max(0, self.comments_heading_position.findData(c['display'].get('heading_position', 'hide')))
self.comments_heading_on_side.setChecked(c['display'].get('heading_on_side', False)) self.comments_heading_position.setCurrentIndex(idx)
idx = max(0, self.comments_type.findData(c['display'].get('interpret_as', 'html'))) idx = max(0, self.comments_type.findData(c['display'].get('interpret_as', 'html')))
self.comments_type.setCurrentIndex(idx) self.comments_type.setCurrentIndex(idx)
self.datatype_changed() self.datatype_changed()
@ -207,8 +207,7 @@ class CreateCustomColumn(QDialog):
}[which]) }[which])
self.composite_sort_by.setCurrentIndex(0) self.composite_sort_by.setCurrentIndex(0)
if which == 'text': if which == 'text':
self.show_comments_heading.setChecked(True) self.comments_heading_position.setCurrentIndex(self.comments_heading_position.findData('side'))
self.comments_heading_on_side.setChecked(True)
self.comments_type.setCurrentIndex(self.comments_type.findData('short-text')) self.comments_type.setCurrentIndex(self.comments_type.findData('short-text'))
# }}} # }}}
@ -309,14 +308,17 @@ class CreateCustomColumn(QDialog):
self.composite_label = add_row(_("&Template"), h) self.composite_label = add_row(_("&Template"), h)
# Comments properties # Comments properties
self.show_comments_heading = sch = QCheckBox(_('Show heading in the Book Details panel')) self.comments_heading_position = ct = QComboBox(self)
sch.setToolTip(_( for k, text in (
'Choose whether to show the heading for this column in the Book Details panel')) ('hide', _('No heading')),
add_row(None, sch) ('above', _('Show heading above the text')),
self.comments_heading_on_side = sch = QCheckBox(_('Show column heading to the side of the text')) ('side', _('Show heading to the side of the text'))
sch.setToolTip(_( ):
'Choose whether to show the heading above or to the side of the text in the Book Details panel')) ct.addItem(text, k)
add_row(None, sch) ct.setToolTip(_('Choose whether or not the column heading is shown in the Book\n'
'Details panel and, if shown, where'))
self.comments_heading_position_label = add_row(_('Column heading'), ct)
self.comments_type = ct = QComboBox(self) self.comments_type = ct = QComboBox(self)
for k, text in ( for k, text in (
('html', 'HTML'), ('html', 'HTML'),
@ -326,7 +328,7 @@ class CreateCustomColumn(QDialog):
): ):
ct.addItem(text, k) ct.addItem(text, k)
ct.setToolTip(_('Choose how the data in this column is interpreted.\n' ct.setToolTip(_('Choose how the data in this column is interpreted.\n'
'This control how the data is displayed in the Book Details panel\n' 'This controls how the data is displayed in the Book Details panel\n'
'and how it is edited.')) 'and how it is edited.'))
self.comments_type_label = add_row(_('Interpret this column as:') + ' ', ct) self.comments_type_label = add_row(_('Interpret this column as:') + ' ', ct)
@ -421,10 +423,10 @@ class CreateCustomColumn(QDialog):
self.use_decorations.setVisible(col_type in ['text', 'composite', 'enumeration']) self.use_decorations.setVisible(col_type in ['text', 'composite', 'enumeration'])
self.is_names.setVisible(col_type == '*text') self.is_names.setVisible(col_type == '*text')
is_comments = col_type == 'comments' is_comments = col_type == 'comments'
self.show_comments_heading.setVisible(is_comments) self.comments_heading_position.setVisible(is_comments)
self.comments_heading_position_label.setVisible(is_comments)
self.comments_type.setVisible(is_comments) self.comments_type.setVisible(is_comments)
self.comments_type_label.setVisible(is_comments) self.comments_type_label.setVisible(is_comments)
self.comments_heading_on_side.setVisible(is_comments)
def accept(self): def accept(self):
col = unicode(self.column_name_box.text()).strip() col = unicode(self.column_name_box.text()).strip()
@ -520,9 +522,8 @@ class CreateCustomColumn(QDialog):
else: else:
display_dict = {'number_format': None} display_dict = {'number_format': None}
elif col_type == 'comments': elif col_type == 'comments':
display_dict['show_heading'] = bool(self.show_comments_heading.isChecked()) display_dict['heading_position'] = type(u'')(self.comments_heading_position.currentData())
display_dict['interpret_as'] = type(u'')(self.comments_type.currentData()) display_dict['interpret_as'] = type(u'')(self.comments_type.currentData())
display_dict['heading_on_side'] = bool(self.comments_heading_on_side.isChecked())
if col_type in ['text', 'composite', 'enumeration'] and not is_multiple: if col_type in ['text', 'composite', 'enumeration'] and not is_multiple:
display_dict['use_decorations'] = self.use_decorations.checkState() display_dict['use_decorations'] = self.use_decorations.checkState()

View File

@ -53,10 +53,10 @@ def add_field(field, db, book_id, ans, field_metadata):
ctype = field_metadata.get('display', {}).get('interpret_as', 'html') ctype = field_metadata.get('display', {}).get('interpret_as', 'html')
if ctype == 'markdown': if ctype == 'markdown':
val = markdown(val) val = markdown(val)
elif ctype == 'short-text':
pass
elif ctype == 'long-text': elif ctype == 'long-text':
val = '<pre>%s</pre>' % prepare_string_for_xml(val) val = '<pre style="white-space:pre-wrap">%s</pre>' % prepare_string_for_xml(val)
elif ctype == 'short-text':
val = '<span">%s</span>' % prepare_string_for_xml(val)
else: else:
val = comments_to_html(val) val = comments_to_html(val)
elif datatype == 'composite' and field_metadata['display'].get('contains_html'): elif datatype == 'composite' and field_metadata['display'].get('contains_html'):

View File

@ -201,8 +201,8 @@ def render_metadata(mi, interface_data, table, field_list=None):
datatype = fm.datatype datatype = fm.datatype
val = mi[field] val = mi[field]
if field is 'comments' or datatype is 'comments': if field is 'comments' or datatype is 'comments':
if fm.display?.heading_on_side: if fm.display?.heading_position is 'side':
add_row(name, val, is_html=fm.display?.interpret_as is not 'short-text') add_row(name, val, is_html=True)
else: else:
comments[field] = val comments[field] = val
return return
@ -256,7 +256,7 @@ def render_metadata(mi, interface_data, table, field_list=None):
comment = comments[field] comment = comments[field]
div = E.div() div = E.div()
div.innerHTML = comment div.innerHTML = comment
if fm.display?.show_heading: if fm.display?.heading_position is 'above':
name = fm.name or field name = fm.name or field
div.insertBefore(E.h3(name), div.firstChild or None) div.insertBefore(E.h3(name), div.firstChild or None)
table.parentNode.appendChild(div) table.parentNode.appendChild(div)