mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-01-26 02:44:27 +01:00
1) fix problem in rtf metadata writer -- categories isn't a standard option.
2) fix book/base.py to always return a default. That is what python is supposed to do. 3) add ability to code 'key in mi' (the __iter__ function) (base.py) 4) add has_key() to base.py 5) have rename refuse to allow & characters in author names
This commit is contained in:
parent
fa9c23031e
commit
bb97bd6cab
4 changed files with 25 additions and 9 deletions
|
|
@ -133,6 +133,12 @@ def __setattr__(self, field, val, extra=None):
|
|||
# Don't abuse this privilege
|
||||
self.__dict__[field] = val
|
||||
|
||||
def __iter__(self):
|
||||
return object.__getattribute__(self, '_data').iterkeys()
|
||||
|
||||
def has_key(self, key):
|
||||
return key in object.__getattribute__(self, '_data')
|
||||
|
||||
def deepcopy(self):
|
||||
m = Metadata(None)
|
||||
m.__dict__ = copy.deepcopy(self.__dict__)
|
||||
|
|
@ -140,12 +146,10 @@ def deepcopy(self):
|
|||
return m
|
||||
|
||||
def get(self, field, default=None):
|
||||
if default is not None:
|
||||
try:
|
||||
return self.__getattribute__(field)
|
||||
except AttributeError:
|
||||
return default
|
||||
return self.__getattribute__(field)
|
||||
try:
|
||||
return self.__getattribute__(field)
|
||||
except AttributeError:
|
||||
return default
|
||||
|
||||
def get_extra(self, field):
|
||||
_data = object.__getattribute__(self, '_data')
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ def create_metadata(stream, options):
|
|||
au = u', '.join(au)
|
||||
author = au.encode('ascii', 'ignore')
|
||||
md += r'{\author %s}'%(author,)
|
||||
if options.category:
|
||||
if options.get('category', None):
|
||||
category = options.category.encode('ascii', 'ignore')
|
||||
md += r'{\category %s}'%(category,)
|
||||
comp = options.comment if hasattr(options, 'comment') else options.comments
|
||||
|
|
@ -180,7 +180,7 @@ def add_metadata_item(src, name, val):
|
|||
src = pat.sub(r'{\\author ' + author + r'}', src)
|
||||
else:
|
||||
src = add_metadata_item(src, 'author', author)
|
||||
category = options.category
|
||||
category = options.get('category', None)
|
||||
if category != None:
|
||||
category = category.encode('ascii', 'replace')
|
||||
pat = re.compile(base_pat.replace('name', 'category'), re.DOTALL)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
from PyQt4.Qt import Qt, QDialog, QTableWidgetItem, QAbstractItemView
|
||||
|
||||
from calibre.ebooks.metadata import author_to_author_sort
|
||||
from calibre.gui2 import error_dialog
|
||||
from calibre.gui2.dialogs.edit_authors_dialog_ui import Ui_EditAuthorsDialog
|
||||
|
||||
class tableItem(QTableWidgetItem):
|
||||
|
|
@ -109,6 +110,12 @@ def cell_changed(self, row, col):
|
|||
if col == 0:
|
||||
item = self.table.item(row, 0)
|
||||
aut = unicode(item.text()).strip()
|
||||
amper = aut.find('&')
|
||||
if amper >= 0:
|
||||
error_dialog(self.parent(), _('Invalid author name'),
|
||||
_('Author names cannot contain & characters.')).exec_()
|
||||
aut = aut.replace('&', '%')
|
||||
self.table.item(row, 0).setText(aut)
|
||||
c = self.table.item(row, 1)
|
||||
c.setText(author_to_author_sort(aut))
|
||||
item = c
|
||||
|
|
|
|||
|
|
@ -505,7 +505,12 @@ def setData(self, index, value, role=Qt.EditRole):
|
|||
key = item.parent.category_key
|
||||
# make certain we know about the item's category
|
||||
if key not in self.db.field_metadata:
|
||||
return
|
||||
return False
|
||||
if key == 'authors':
|
||||
if val.find('&') >= 0:
|
||||
error_dialog(self.tags_view, _('Invalid author name'),
|
||||
_('Author names cannot contain & characters.')).exec_()
|
||||
return False
|
||||
if key == 'search':
|
||||
if val in saved_searches().names():
|
||||
error_dialog(self.tags_view, _('Duplicate search name'),
|
||||
|
|
|
|||
Loading…
Reference in a new issue