Exemplo n.º 1
0
 class TableFileSchema(ContentSchema):
     file = colander.SchemaNode(
         deform.FileData(),
         title=_(u'File'),
         missing=colander.null,
         widget=deform.widget.FileUploadWidget(tmpstore),
         #validator=validate_file_size_limit,
     )
     table_name = colander.SchemaNode(
         colander.String(),
         title=_(u"Table Name"),
         validator=validate_name,
     )
Exemplo n.º 2
0
class RDBTableColumn(Content):
    id = Column(Integer, ForeignKey('contents.id'), primary_key=True)
    src_column_name = Column(Unicode(80))
    dest_column_name = Column(Unicode(80), nullable=False)
    column_type = Column(Unicode(10), nullable=False)
    column_lenght = Column(Integer)
    is_pk = Column(Boolean(), nullable=False)

    type_info = Content.type_info.copy(
        name=u'Column',
        title=_(u'Column'),
        add_view=u'add_column',
        addable_to=[u'Table'],
    )

    def __init__(self,
                 src_column_name=None,
                 dest_column_name=None,
                 column_type=None,
                 column_lenght=None,
                 is_pk=False,
                 in_navigation=False,
                 **kwargs):
        super(RDBTableColumn, self).__init__(in_navigation=in_navigation,
                                             **kwargs)
        self.src_column_name = src_column_name
        self.dest_column_name = dest_column_name
        self.column_type = column_type
        self.column_lenght = column_lenght
        self.is_pk = is_pk
Exemplo n.º 3
0
class AddRDBTableFormView(AddFileFormView):
    item_type = _(u"Table")
    item_class = RDBTable

    def schema_factory(self):
        tmpstore = FileUploadTempStore(self.request)

        class TableFileSchema(ContentSchema):
            file = colander.SchemaNode(
                deform.FileData(),
                title=_(u'File'),
                widget=deform.widget.FileUploadWidget(tmpstore),
                #validator=validate_file_size_limit,
            )
            table_name = colander.SchemaNode(
                colander.String(),
                title=_(u"Table Name"),
                validator=validate_name,
                missing=None,
            )

        return TableFileSchema()

    def add(self, **appstruct):
        buf = appstruct['file']['fp'].read()
        return self.item_class(
            title=appstruct['title'],
            table_name=appstruct['table_name'],
            description=appstruct['description'],
            data=buf,
            filename=appstruct['file']['filename'],
            mimetype=appstruct['file']['mimetype'],
            size=len(buf),
            tags=appstruct['tags'],
        )
Exemplo n.º 4
0
def validate_name(node, value):
    if value is not None:
        if check_name(value) is None:
            msg = _(
                'Table and column names must consist of lowercase letters, _ and numbers only'
            )
            raise colander.Invalid(node, msg)
Exemplo n.º 5
0
class RDBTableColumnSchema(ContentSchema):
    src_column_name = colander.SchemaNode(
        colander.String(),
        title=_(u"Source Name"),
        description=_('Column Name in the uploaded table'),
        missing=None,
    )
    dest_column_name = colander.SchemaNode(
        colander.String(),
        title=_(u"Destination Name"),
        description=_('Column Name in the table to be created in the DB'),
        validator=validate_name,
    )
    column_type = colander.SchemaNode(
        colander.String(),
        title=_(u"Type"),
        missing=None,
        validator=colander.OneOf(valid_column_types),
        widget=deform.widget.SelectWidget(values=tuple(column_type_values)))
    column_lenght = colander.SchemaNode(
        colander.Integer(),
        title=_(u"Lenght"),
        missing=0,
    )
    is_pk = colander.SchemaNode(
        colander.Boolean(),
        title=_(u"Primary Key"),
    )
Exemplo n.º 6
0
class RDBTable(File):
    implements(IRDBTable, IDefaultWorkflow)
    id = Column('id', Integer, ForeignKey('files.id'), primary_key=True)
    table_name = Column(String(80), nullable=False, unique=True)
    is_created = Column(Boolean(), nullable=False)
    #XXX + more table metadata

    type_info = Content.type_info.copy(
        name=u'Table',
        title=_(u'Table'),
        add_view=u'add_table',
        addable_to=[u'Document'],
    )

    def __init__(self, table_name=None, **kwargs):
        super(RDBTable, self).__init__(**kwargs)
        if table_name:
            self.table_name = camel_case_to_name(table_name.split('.')[0])
        else:
            self.table_name = camel_case_to_name(self.filename.split('.')[0])
        self.is_created = False
Exemplo n.º 7
0
def validate_name(node, value):
    if value is not None:
        if check_name(value) is None:
            msg = _('Table and column names must consist of lowercase letters, _ and numbers only')
            raise colander.Invalid(node, msg)