1👍
No override way without touching any code.
from ModalFormView
in horizon/forms/views.py
You can see that form_valid
method uses form.handle(...)
.
So this handle
method is HARD CODED in Horizon.
At least, you have to touch one place to override handle
without directly modifying CreateImageForm
:
# openstack_dashboard/dashboards/project/images/images/forms.py
class YourCreateImageForm(CreateImageForm): # <== Create your form inherited from CreateImageForm!
def handle(self, request, data):
...
(the whole your logic here)
...
# openstack_dashboard/dashboards/project/images/images/views.py
class CreateView(forms.ModalFormView):
form_class = project_forms.YourCreateImageForm # <== touch here!
...
Maybe you want to override it because you are afraid of the conflict when upgrading Horizon in future.
If you want to customize Horizon and don’t touch any thing, the best way is:
- Create a your dashborad(tab)
- Add your panel. In your panel, you can easily inherit any classes you want from Project/Admin, and change the part you want to. Add logic, add form elements, add anything…
Finally, in your case, you just want to add ONE line into code, so why not just add it? If you upgrade your Horizon, I don’t think that this part will cause a conflict.
1👍
You can add any overrides you want using the customization_module in HORIZON_CONFIG. Just add the path to your file containing the overrides like so:
HORIZON_CONFIG = {
'customization_module': 'some_path.overrides',
}
In the overrides.py file that you created you can add a monkey patch to override an existing class with your new class:
class YourCreateImageForm(CreateImageForm):
...
form_class = project_forms.YourCreateImageForm
It’s basically the same idea mentioned in the above comment but you can avoid touching upstream code using the customization_module.
- [Answered ]-Get annual count within the given range of years
- [Answered ]-Internal Server Error on Django after I changed database
- [Answered ]-Django-summernote : How can I make it work based on model form?
- [Answered ]-Django admin page adding save as pdf button
- [Answered ]-Django database connection issue