def get(self, id, pk='id', deleted=False):
        try:
            if pk == 'id':
                id = int(id)
            if deleted:
                spec = {pk: id}
            else:
                spec = {pk: id, 'data': {'$exists': 1}}
            fields = {'_id': 0}
            row = self.db.docs.find_one(spec, fields)
        except Exception as e:
            raise DatabaseException(e)
        if row:
            return Document(**row)
        raise NotFoundError('%s %s not found' % (pk, id))
def on_backend_added(self, sender, backend_id):
        """
        Signal callback executed when a new backend is loaded

        @param sender: not used, only here to let this function be used as a
                       callback
        @param backend_id: the id of the backend to add
        """
        # Add
        backend = self.req.get_backend(backend_id)
        if not backend:
            return
        self.add_backend(backend)
        self.refresh()
        # Select
        self.select_backend(backend_id)
        # Update it's enabled state
        self.on_backend_state_changed(None, backend.get_id())