예제 #1
0
    def getLastVersion(self):
        context = self.__context__
        try:
            rel = self.__relation__.query(
                self.__relation__.Type.source == context.oid).order_by(
                sqlalchemy.sql.expression.desc(
                    self.__relation__.Type.version)).first()
        except StopIteration:
            rel = None

        if rel is None:
            item = storage.insertItem(IVersionItem)
            for sch in context.schemas:
                item.applySchema(sch)

            for schId in context.schemas:
                sch = storage.querySchema(schId)
                if sch is not None:
                    item.getDatasheet(schId).__load__(sch(context))

            self.__relation__.insert(self.oid, item.oid, version=1)
            content = item
            versionInfo = IVersionsSchema(content)
            versionInfo.proxy = context.oid
            versionInfo.version = 1
            versionInfo.comment = 'Create content.'
        else:
            content = rel.__destination__

        versionInfo = IVersionsSchema(content)
        if versionInfo.commit:
            item = storage.insertItem(IVersionItem)
            for sch in context.schemas:
                item.applySchema(sch)

            for schId in context.schemas:
                if schId == 'content.versions':
                    continue
                sch = storage.querySchema(schId)
                if sch is not None:
                    item.getDatasheet(schId).__load__(sch(content))

            self.__relation__.insert(self.oid, item.oid, version=rel.version+1)
            content = item
            versionInfo = IVersionsSchema(content)
            versionInfo.proxy = context.oid
            versionInfo.version = rel.version+1

        return content
예제 #2
0
    def __call__(self, **data):
        # create content with behaviors
        content = storage.insertItem(IContent)
        if self.behaviors:
            content.applyBehavior(*self.behaviors)

        for schId in self.schemas:
            schema = queryUtility(storage.ISchema, schId)
            if schema is None:
                continue
            content.applySchema(schema.spec)
            #schema.apply(content.oid)

        ds = content.getDatasheet(IContent)
        if 'content.item' in data:
            ds.__load__(data['content.item'])
        ds.type = self.name

        for schId in self.schemas:
            if schId in data:
                ds = content.getDatasheet(schId)
                ds.__load__(data[schId])

        event.notify(ObjectCreatedEvent(content))
        return content
예제 #3
0
    def create(self, data):
        item = storage.insertItem(ISchema)
        ds = ISchema(item)
        for key, val in data.items():
            setattr(ds, key, val)

        ttwschema = ISchema(item)
        return LocationProxy(ds, self, item.oid)
예제 #4
0
    def __item__(self):
        try:
            if self.__oid__ is None:
                self.__oid__ = self.__behavior__.getBehaviorOIDs().next()
            item = storage.getItem(self.__oid__)
        except StopIteration:
            item = storage.insertItem(self.__behavior__.name)
            self.__oid__ = item.oid

        return item
예제 #5
0
    def get(cls, principal):
        if cls.__schema__ is None:
            cls.__schema__ = storage.getSchema(IPreferences)

        rec = cls.__schema__.query(
            cls.__schema__.Type.principal == principal).first()
        if rec is None:
            item = storage.insertItem(IPreferences)
            IPreferences(item).principal = principal
        else:
            item = storage.getItem(rec.oid)

        item.id = principal
        return Preferences(item)
예제 #6
0
    def create(self, data):
        # create user
        item = storage.insertItem('memphis.user')

        datasheet = IUserInfo(item)
        datasheet.login = data['login']
        datasheet.fullname = u'%s %s'%(data['firstname'], data['lastname'])
        datasheet.confirmed = True

        # set password
        passwordtool = getUtility(IPasswordTool)
        datasheet.password = passwordtool.encodePassword(data['password'])

        event.notify(ObjectCreatedEvent(item))
        return item
예제 #7
0
def getRoot():
    global rootOID

    behavior = storage.getBehavior(IRoot)
    try:
        if rootOID is None:
            rootOID = behavior.getBehaviorOIDs().next()
        return LocationProxy(storage.getItem(rootOID), None, "")
    except StopIteration:
        item = storage.insertItem(IRoot)
        rootOID = item.oid
        dc = IContent(item)
        dc.title = u"Site"
        dc.description = u"Default memphis site."

        event.notify(ObjectCreatedEvent(item))
        return LocationProxy(item, None, "")
예제 #8
0
 def create(self, data):
     item = storage.insertItem(IContentType)
     ds = IContentTypeSchema(item)
     for key, val in data.items():
         setattr(ds, key, val)
     return LocationProxy(ds, self, item.oid)