Exemplo n.º 1
0
class SQLAlchemyConnectionsForm(crud.CrudForm):
    label = _(u'label_saconnectform', u'Manage SQLAlchemy connection strings')
    update_schema = IConnectionLine

    def __init__(self, context, request):
        crud.CrudForm.__init__(self, context, request)
        self.storage = ISQLAlchemyConnectionStrings(getUtility(ISiteRoot))

    def get_items(self):
        names = self.storage.keys()
        names.sort()
        return [(name, ConnectionLine(name, self.storage[name], self))
                for name in names]

    def add(self, data):
        name = data['connname'].strip()
        if str(name) in self.storage:
            msg = _(u'error_name_already_registered',
                    u'The connection name is already registered')
            msg = translate(msg, self.request)
            raise schema.ValidationError(msg)

        self.storage[name] = data['connstring'].strip()
        return ConnectionLine(name, data['connstring'].strip(), self)

    def remove(self, (id, item)):
        del self.storage[item.connname]
Exemplo n.º 2
0
class SQLAlchemyConnectionsForm(crud.CrudForm):
    label = _(u'label_saconnectform', u'Manage SQLAlchemy connection strings')
    update_schema = IConnectionLine

    def __init__(self, context, request):
        crud.CrudForm.__init__(self, context, request)
        self.storage = ISQLAlchemyConnectionStrings(
            getUtility(ISiteRoot)
        )

    def get_items(self):
        names = self.storage.keys()
        names.sort()
        return [(name, ConnectionLine(name, self.storage[name], self))
                for name in names]

    def add(self, data):
        name = data['connname'].strip()
        if str(name) in self.storage:
            msg = _(u'error_name_already_registered',
                    u'The connection name is already registered')
            msg = translate(msg, self.request)
            raise schema.ValidationError(msg)

        self.storage[name] = data['connstring'].strip()
        return ConnectionLine(name, data['connstring'].strip(), self)

    def remove(self, (id, item)):
        del self.storage[item.connname]
 def __call__(self, context):
     saconnect = ISQLAlchemyConnectionStrings(
         component.getUtility(ISiteRoot))
     items = [SimpleTerm(name, name, name) for name in saconnect.keys()]
     return SimpleVocabulary(items)