Wireless device: Do not attempt to sync data when sending books for the first time.

This commit is contained in:
Charles Haley 2014-03-13 12:52:27 +01:00
parent f0d676502f
commit 5024757c94

View File

@ -1513,12 +1513,23 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
return None return None
sync_type = book.get('_sync_type_', None); sync_type = book.get('_sync_type_', None);
is_read = book.get('_is_read_', None) # We need to check if our attributes are in the book. If they are not
# then this is metadata coming from calibre to the device for the first
# time, in which case we must not sync it.
if hasattr(book, '_is_read_'):
is_read = book.get('_is_read_', None)
has_is_read = True
else:
has_is_read = False
# parse_date returns UNDEFINED_DATE if the value is None if hasattr(book, '_last_read_date_'):
is_read_date = parse_date(book.get('_last_read_date_', None)); # parse_date returns UNDEFINED_DATE if the value is None
if is_date_undefined(is_read_date): is_read_date = parse_date(book.get('_last_read_date_', None));
is_read_date = None if is_date_undefined(is_read_date):
is_read_date = None
has_is_read_date = True
else:
has_is_read_date = False
force_return_changed_books = False force_return_changed_books = False
changed_books = set() changed_books = set()
@ -1539,7 +1550,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
# calibre value wins. # calibre value wins.
# Check is_read # Check is_read
if self.is_read_sync_col: if has_is_read and self.is_read_sync_col:
try: try:
calibre_val = db.new_api.field_for(self.is_read_sync_col, calibre_val = db.new_api.field_for(self.is_read_sync_col,
id_, default_value=None) id_, default_value=None)
@ -1564,7 +1575,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
traceback.print_exc() traceback.print_exc()
# Check is_read_date. # Check is_read_date.
if self.is_read_date_sync_col: if has_is_read_date and self.is_read_date_sync_col:
try: try:
# The db method returns None for undefined dates. # The db method returns None for undefined dates.
calibre_val = db.new_api.field_for(self.is_read_date_sync_col, calibre_val = db.new_api.field_for(self.is_read_date_sync_col,
@ -1588,7 +1599,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
# This is the standard sync case. If the CC value has changed, it # This is the standard sync case. If the CC value has changed, it
# wins, otherwise the calibre value is synced to CC in the normal # wins, otherwise the calibre value is synced to CC in the normal
# fashion (mod date) # fashion (mod date)
if self.is_read_sync_col: if has_is_read and self.is_read_sync_col:
try: try:
orig_is_read = book.get(self.is_read_sync_col, None) orig_is_read = book.get(self.is_read_sync_col, None)
if is_read != orig_is_read: if is_read != orig_is_read:
@ -1605,7 +1616,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
self._debug('exception standard syncing is_read', self.is_read_sync_col) self._debug('exception standard syncing is_read', self.is_read_sync_col)
traceback.print_exc() traceback.print_exc()
if self.is_read_date_sync_col: if has_is_read_date and self.is_read_date_sync_col:
try: try:
orig_is_read_date = book.get(self.is_read_date_sync_col, None) orig_is_read_date = book.get(self.is_read_date_sync_col, None)
if is_date_undefined(orig_is_read_date): if is_date_undefined(orig_is_read_date):