FileField in tgext.admin custom AdminController

11 views
Skip to first unread message

Moritz Schlarb

unread,
Mar 20, 2012, 8:39:57 AM3/20/12
to turbo...@googlegroups.com
Hello at all!

I'm trying to customize tgext.admin to the needs of my application:
Since I have some PickleType columns in my model that should only be filled by uploading plain files, I created the following form:

class TestEditForm(EditableForm):
    __model__ = Test
    __require_fields__     = ['type']
    __omit_fields__        = ['id', 'assignment_id']
    __field_order__        = ['assignment', 'type', 'visible', 'timeout', 'argv', 'input', 'output']
    
    input = FileField(id='input', validator=FieldStorageUploadConverter(not_empty=False))
    output = FileField(id='output',validator=FieldStorageUploadConverter(not_empty=False))

which is included via

class TestCrudConfig(CrudRestControllerConfig):
    edit_form_type = TestEditForm

and

class MyAdminConfig(AdminConfig):
    test = TestCrudConfig

Now if there is already data in the input/output columns, it just gets overwritten with None if the file isn't uploaded again.

Am I missing a parameter to accomplish this non-overwriting behaviour?
Or could someone tell me some hackish way to achieve this!

Thanks a lot,
Moritz

Alessandro Molina

unread,
Mar 20, 2012, 9:36:58 AM3/20/12
to turbo...@googlegroups.com
As the crud controller updates the entity values with the new provided
ones it is the expected behavior to se a file to empty if none is
provided.

It might not be a good solution if you have huge files, but you can
try to use the FileUploadKeeper validator which gets back the current
value and submits it again. I never tried to use it with the crud
controller anyway, so it might need some manual tuning to make it
work.

> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/turbogears/-/pgDiN4rGcP0J.
> To post to this group, send email to turbo...@googlegroups.com.
> To unsubscribe from this group, send email to
> turbogears+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/turbogears?hl=en.

Reply all
Reply to author
Forward
0 new messages