Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom add_form template création issues #2115

Open
Romia25 opened this issue Sep 20, 2023 · 0 comments
Open

Custom add_form template création issues #2115

Romia25 opened this issue Sep 20, 2023 · 0 comments

Comments

@Romia25
Copy link

Romia25 commented Sep 20, 2023

Hello!
I'm new in development and am facing some issue about customisation.
I'm trying to upload file and I want to perform a lot of customisation like remove uuid automatically generated for filename so that the file upload process save the original filename in the db and the upload_folder. I somehow figure out how to do this by overriding pre_add and post_add methods. But the ultimate goal of this is to be able to show a modal dialog for user to confirm if he or she wants to continue upload process of an already existing file (from db) or cancel the whole thing. I know it's possible to have the dialog box because we see it when we want for example to delete a record. It's something similar I want to achieve. After clicking save button for the file to be uploaded, I want to have a similar dialog box in case the Same filename already exist in db.

So far I have override the pre_add method to get the original filename using the function in file manager that helps perform this. In this pre_add method I am also able to fetch the db table and know if a similar file was already upload. But then I'm confused.

From the post add side I used shutil to rename the file in the upload folder.
My big point of confusion is where and how could i make a modal dialog visible when the form is post and the filename already exist in the db.

So I decided to create my own upload form based on upload file model but here again fab can create the form by itself and I can't see where and how could I add maybe some JavaScript to have my modal dialog box showed up.
Going further in docs I saw I could define my own add_template and used extra_args for other elements that must be provided to the template. But here I don't know how to make my way.
Here is what I have done
add_temolate = 'form.html'
extra_args = {'form' : 'add_form'}

add_form was define early as MyUPloadFom

In the form.html
I have something like

{% extends 'appbuilder/general/model/add.html' %}

{% block body %}

{{ form.hidden_tag() }}

{{ form.name.label }}
{{ form.name() }}

{{ form.description.label }}
{{ form.description(s) }}

{{ form.submit() }}

{% endblock %}

But when I run the app I get hidden_tag() missing required positional argument self.
If I go up and comment this part and run the app again I get jinja2 error unboundedfield has no attribute label.

I really don't know what to do. I need guidance on how to achieve my goals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant