def _importItem(self, fileobj, txn):
     sItem = fileobj.read()
     oItem = persist.loads(sItem)
     oParent = self.db.get_item(oItem.parentid, txn)
     #check if the item already exists
     oOldItem = self.db.get_item(oItem.id, txn)
     if oOldItem == None:
         # write external attributes
         for prop in [getattr(oItem, x) for x in oItem.__props__]:
             if isinstance(prop, datatypes.ExternalAttribute):
                 prop._isDirty = True
                 prop._eventHandler.on_create(oItem, prop, txn)
 
         if oParent and not(oItem._id in oParent._items.values() + \
                                        oParent._subfolders.values()):
             if oItem.isCollection:
                 oParent._subfolders[oItem.displayName.value] = oItem._id
             else:
                 oParent._items[oItem.displayName.value] = oItem._id
             self.db.put_item(oParent, txn)
         self.db.put_item(oItem, txn)
     else:
         print 'WARNING: Item "%s" already exists. Upgrading object...' % \
             oItem.displayName.value
         oItem.displayName.value = oOldItem.displayName.value
         oItem.description.value = oOldItem.description.value
         oItem.inheritRoles = oOldItem.inheritRoles
         oItem.modifiedBy = oOldItem.modifiedBy
         oItem.modified = oOldItem.modified
         oItem._created = oOldItem._created
         oItem.security = oOldItem.security
         if oItem.isCollection:
             oItem._subfolders = oOldItem._subfolders
             oItem._items = oOldItem._items
         self.db.put_item(oItem, txn)
 def callback(key, value):
     item = _cache.get(value, persist.loads(value))
     index_value = None
     if hasattr(item, self.name):
         attr = getattr(item, self.name)
         if attr.__class__.__module__ != '__builtin__':
             attr = attr.value
         index_value = cPickle.dumps(attr, 2)
     _cache[value] = item
     return index_value
 def _get_item(self, s):
     item = persist.loads(s)
     if self.fetch_all:
         if self.resolve_shortcuts:
             while item != None and isinstance(item, Shortcut):
                 item = _db.get_item(item.target.value, self._txn)
     else:
         # check read permissions
         access = permsresolver.get_access(item, self._thread.context.user)
         if item._isDeleted or access == 0:
             item = None
         elif self.resolve_shortcuts and isinstance(item, Shortcut):
             item = item.get_target(self._txn)
     return item
Esempio n. 4
0
 def _get_item(self, s):
     item = persist.loads(s)
     if not self.enforce_permissions:
         if self.resolve_shortcuts:
             while item is not None and isinstance(item, Shortcut):
                 item = _db.get_item(item.target.value)
     else:
         # check read permissions
         access = permsresolver.get_access(item, context.user)
         if item._isDeleted or access == 0:
             item = None
         elif self.resolve_shortcuts and isinstance(item, Shortcut):
             item = item.get_target()
     return item
Esempio n. 5
0
 def _get_item(self, s):
     item = persist.loads(s)
     if not self.enforce_permissions:
         if self.resolve_shortcuts:
             while item is not None and isinstance(item, Shortcut):
                 item = _db.get_item(item.target.value)
     else:
         # check read permissions
         access = permsresolver.get_access(item, context.user)
         if item._isDeleted or access == 0:
             item = None
         elif self.resolve_shortcuts and isinstance(item, Shortcut):
             item = item.get_target()
     return item
def get_item(oid):
    item = _db_handle.get_item(oid)
    if item is None:
        path_tokens = oid.split('/')
        path_depth = len(path_tokens)
        if path_depth > 1:
            # /[itemID]
            if path_depth == 2:
                item = _db_handle.get_item(path_tokens[1])
            # /folder1/folder2/item
            if item is None:
                return _get_item_by_path(path_tokens)
    if item is not None:
        item = persist.loads(item)
        return item
Esempio n. 7
0
def get_item(oid):
    item = _db_handle.get_item(oid)
    if item is None:
        path_tokens = oid.split('/')
        path_depth = len(path_tokens)
        if path_depth > 1:
            # /[itemID]
            if path_depth == 2:
                item = _db_handle.get_item(path_tokens[1])
            # /folder1/folder2/item
            if item is None:
                return _get_item_by_path(path_tokens)
    if item is not None:
        item = persist.loads(item)
        return item
 def load(request):
     i = 0
     chunks = []
     session = request.cookies.get('_s%d' % i, None)
     while session is not None and session.value:
         chunks.append(session.value)
         i += 1
         session = request.cookies.get('_s%d' % i, None)
     if chunks:
         session = persist.loads(''.join(chunks))
         sig = Session.generate_sig(session)
         if session.sig != sig:
             session = None
     else:
         session = None
     return session
Esempio n. 9
0
 def load(request):
     i = 0
     chunks = []
     session = request.cookies.get('_s%d' % i, None)
     while session is not None and session.value:
         chunks.append(session.value)
         i += 1
         session = request.cookies.get('_s%d' % i, None)
     if chunks:
         session = persist.loads(''.join(chunks))
         sig = Session.generate_sig(session)
         if session.sig != sig:
             session = None
     else:
         session = None
     return session
 def callback(key, value):
     item = _cache.get(value, persist.loads(value))
     index_value = None
     if item._isDeleted and not self.name == "_id":
         # do not index attributes of deleted objects
         return None
     if self.name == "_id" or (hasattr(item, self.name) and hasattr(item, "_owner")):
         # if item is composite index only the _id attribute
         # otherwise allow indexing of all
         attr = getattr(item, self.name)
         if attr.__class__.__module__ != None.__class__.__module__:
             attr = attr.value
         if self.name == "_id":
             index_value = pack_value(attr)
         else:
             index_value = pack_value(item._pid) + b"_" + pack_value(attr)
     _cache[value] = item
     return index_value
Esempio n. 11
0
 def callback(key, value):
     item = _cache.get(value, persist.loads(value))
     index_value = None
     if item._isDeleted and not self.name == '_id':
         # do not index attributes of deleted objects
         return None
     if self.name == '_id' or \
             (hasattr(item, self.name) and hasattr(item, '_owner')):
         # if item is composite index only the _id attribute
         # otherwise allow indexing of all
         attr = getattr(item, self.name)
         if attr.__class__.__module__ != None.__class__.__module__:
             attr = attr.value
         if self.name == '_id':
             index_value = pack_value(attr)
         else:
             index_value = (pack_value(item._pid) + b'_' +
                            pack_value(attr))
     _cache[value] = item
     return index_value
Esempio n. 12
0
    def _import_item(self, fileobj):
        stream = fileobj.read()
        item = persist.loads(stream)

        # TODO: remove next block
        # kept for backwards compatibility
        if hasattr(item, '_parentid'):
            pid = item._parentid
            delattr(item, '_parentid')
            item._pid = pid
        if hasattr(item, '_containerid'):
            pid = item._containerid
            delattr(item, '_containerid')
            item._pid = pid

        #check if the item already exists
        old_item = db._db.get_item(item.id)
        if old_item is None:
            # write external attributes
            for prop in [getattr(item, x) for x in item.__props__
                         if hasattr(item, x)]:
                if isinstance(prop, datatypes.ExternalAttribute):
                    prop._isDirty = True
                    prop._eventHandler.on_create(item, prop)
            # update parent's modification date
            p = db._db.get_item(item._pid)
            if p is not None:
                p.modified = time.time()
                db._db.put_item(p)
            db._db.put_item(item)
        else:
            logger.info('Item "%s" already exists. Upgrading object...' %
                        item.displayName.value)
            item.displayName.value = old_item.displayName.value
            item.description.value = old_item.description.value
            item.inheritRoles = old_item.inheritRoles
            item.modifiedBy = old_item.modifiedBy
            item.modified = old_item.modified
            item._created = old_item._created
            item.security = old_item.security
            db._db.put_item(item)
Esempio n. 13
0
def get_child_by_name(container_id, name):
    item = _db_handle.get_child_by_name(container_id, name)
    if item is not None:
        item = persist.loads(item)
    return item
Esempio n. 14
0
def get_child_by_name(container_id, name):
    item = _db_handle.get_child_by_name(container_id, name)
    if item is not None:
        item = persist.loads(item)
    return item