Exemple #1
0
    def last_sync_log(self):
        if self.params.sync_log_id:
            try:
                sync_log = get_properly_wrapped_sync_log(
                    self.params.sync_log_id)
            except ResourceNotFound:
                # if we are in loose mode, return an HTTP 412 so that the phone will
                # just force a fresh sync
                raise MissingSyncLog('No sync log with ID {} found'.format(
                    self.params.sync_log_id))
            if sync_log.doc_type != 'SyncLog':
                raise InvalidSyncLogException(
                    'Bad sync log doc type for {}'.format(
                        self.params.sync_log_id))
            elif sync_log.user_id != self.user.user_id:
                raise SyncLogUserMismatch(
                    'Sync log {} does not match user id {} (was {})'.format(
                        self.params.sync_log_id, self.user.user_id,
                        sync_log.user_id))

            # convert to the right type if necessary
            if not isinstance(sync_log, self.sync_log_class):
                # this call can fail with an IncompatibleSyncLogType error
                sync_log = self.sync_log_class.from_other_format(sync_log)
            return sync_log
        else:
            return None
Exemple #2
0
    def last_sync_log(self):
        if self._last_sync_log is Ellipsis:
            if self.params.sync_log_id:
                # if we are in loose mode, return an HTTP 412 so that the phone will
                # just force a fresh sync
                # This raises MissingSyncLog exception if synclog not found
                sync_log = get_properly_wrapped_sync_log(
                    self.params.sync_log_id)
                if sync_log.doc_type not in ('SyncLog', 'SimplifiedSyncLog'):
                    raise InvalidSyncLogException(
                        'Bad sync log doc type for {}'.format(
                            self.params.sync_log_id))
                elif sync_log.user_id != self.restore_user.user_id:
                    raise SyncLogUserMismatch(
                        'Sync log {} does not match user id {} (was {})'.
                        format(self.params.sync_log_id,
                               self.restore_user.user_id, sync_log.user_id))

                # convert to the right type if necessary
                if not isinstance(sync_log, SimplifiedSyncLog):
                    # this call can fail with an IncompatibleSyncLogType error
                    sync_log = SimplifiedSyncLog.from_other_format(sync_log)
                self._last_sync_log = sync_log
            else:
                self._last_sync_log = None
        return self._last_sync_log
Exemple #3
0
 def last_sync_log(self):
     if self._last_sync_log is Ellipsis:
         if self.params.sync_log_id:
             # if we are in loose mode, return an HTTP 412 so that the phone will
             # just force a fresh sync
             # This raises MissingSyncLog exception if synclog not found
             sync_log = get_properly_wrapped_sync_log(self.params.sync_log_id)
             if sync_log.doc_type != 'SimplifiedSyncLog':
                 raise InvalidSyncLogException('Bad sync log doc type for {}'.format(self.params.sync_log_id))
             elif sync_log.user_id != self.restore_user.user_id:
                 raise SyncLogUserMismatch('Sync log {} does not match user id {} (was {})'.format(
                     self.params.sync_log_id, self.restore_user.user_id, sync_log.user_id
                 ))
             self._last_sync_log = sync_log
         else:
             self._last_sync_log = None
     return self._last_sync_log