barseghyanartur / django-fobi

Form generator/builder application for Django done right: customisable, modular, user- and developer- friendly.
https://pypi.python.org/pypi/django-fobi
485 stars 112 forks source link

Make an example with embed form/wizard #85

Open barseghyanartur opened 7 years ago

barseghyanartur commented 7 years ago

Make an example with embed form/wizard

jstacoder commented 6 years ago

@barseghyanartur so by this are you wanting an example embedding a form or wizard into another view? because i would love if that example existed. if so ill do it.

barseghyanartur commented 6 years ago

@jstacoder:

It has been a long time since I wrote this. I'm not sure of what I exactly meant by that. Unfortunately, I haven't applied my good intentions to write/explain as much as possible in this case, so I'm quite unsure of what I could have meant.

However, if you explain what you might need, I might give you a good advice.

jstacoder commented 6 years ago

i would like to embed the wizard into a view, as well as embed the forms it creates into a view, since they are generated dynamically i am having trouble doing this...

barseghyanartur commented 6 years ago

Ah, ok. It's very simple. Now I remember what I meant.

Examples (stripped down) taken from a working custom made fobi setup (made a couple of years ago).

In your sample view:

views.py

from fobi.views import FormWizardView

def embed_form_wizard_view(request, **kwargs):
    # Do whatever you want, feed extra params to the wizard. You can even override
    # the standard wizard somewhere above, customise it and use it instead of 
    # FormWizardView.
    wizard = FormWizardView.as_view()
    return wizard(request)

urls.py

from django.conf.urls import url

from .views import embed_form_wizard_view

urlpatterns = [
    url(r'^wizards/(?P<some_argument>[\w_\-]+)/$',
        view=embed_form_wizard_view,
        name='myproject.embed_form_wizard_view'),
]
jstacoder commented 6 years ago

after a little digging i realized what i was looking for were the functions in fobi/dynamic.py, assemble_form_class, assemble_form_wizard_class, to get the actual form classes i can render inside templates, i think i will provide an example using these functions.