#pocoo

/

      • jjmalina has quit
      • AshleyMcNamara joined the channel
      • lac_ joined the channel
      • lac has quit
      • zepolen joined the channel
      • kite joined the channel
      • untitaker joined the channel
      • zepolen has quit
      • VinceZa_ joined the channel
      • breakingmatter joined the channel
      • breakingmatter has quit
      • srilux has quit
      • AshleyMcNamara has quit
      • afidegnum has quit
      • Sonderblade joined the channel
      • citizen-stig joined the channel
      • davidism joined the channel
      • Arfrever joined the channel
      • tachyondecay joined the channel
      • epopt37 joined the channel
      • rglen has quit
      • AshleyMcNamara joined the channel
      • cruor99 joined the channel
      • Kronuz has quit
      • epopt37 joined the channel
      • VinceZa_ has quit
      • Kronuz joined the channel
      • TheAdversary has quit
      • mbordas has quit
      • cewing has quit
      • breakingmatter joined the channel
      • breakingmatter has quit
      • lritter has quit
      • OtherAllan has quit
      • heytrav joined the channel
      • evilt0ne has quit
      • heytrav has quit
      • heytrav joined the channel
      • schneider has quit
      • zepolen joined the channel
      • johtso has quit
      • zepolen has quit
      • breakingmatter joined the channel
      • citizen-stig joined the channel
      • breakingmatter has quit
      • citizen-stig has quit
      • hyperknot joined the channel
      • hyperknot
        hi, how is it possible to render a full wtforms form in jinja2?
      • panda__ joined the channel
      • csotelo__ joined the channel
      • tachyondecay
        The wtforms docs have some sample macros, if that's what you mean
      • panda__ has quit
      • hyperknot
        tachyondecay: i'm trying to create a simple admin, and I understand that wtforms alchemy can auto-create the form for me. my problem is that it seems there is no simple way to get a html out of that form
      • AshleyMcNamara has quit
      • terratoma joined the channel
      • davidism has quit
      • tachyondecay
        hyperknot: Pass the form object to the template. Then {{ form.field_name }} outputs the input element, and {{ form.field_name.label }} will output a label element
      • hyperknot
        and how can I get a list of all the fields in the form?
      • tachyondecay
        You can iterate over the form
      • hyperknot
        ah, I was looking for it for a long time in Meta...
      • massover joined the channel
      • so I create the <form> element manually, loop over the fields, call a macro on each one and close the </form>?
      • tachyondecay
        That's one way you can do it, sure
      • hyperknot
        is there a better one?
      • i mean I can just type out instead of using a macro
      • tachyondecay
      • Read over that section to get a sense of your options
      • I tend to output my fields by hands, in most cases, because I need more control over how the fields are displayed. That might not be your case
      • But I build a "render_field" macro that outputs a div with a specified class, the label/field elements (by calling the wtforms widget), and an error (if any errors)
      • hyperknot
        tachyondecay: but it's all basically the same idea
      • tachyondecay
        Yes.
      • You have lots of options and flexibility depending on what you want to do and how automated you need it to be.
      • hyperknot
        you still do the form, submit button, etc. manually and render one field at a time
      • tachyondecay
        I mean if I wanted to I could build a macro and then hardcode classes and stuff into the form field definitions
      • But that doesn't separate my app logic and presentation logic as neatly, IMO
      • paroneayea has quit
      • If all you're doing is spitting out form fields and not worrying a lot about layout, you could use a single, generic macro that loops over all the fields for you.
      • paroneayea joined the channel
      • hyperknot
        ok, I did this: http://paste.ee/r/wP6oX
      • seems to work
      • tachyondecay
        Yep
      • FYI, you don’t need to specify an action attribute on your form if you just want to submit to the same page
      • hyperknot
        tachyondecay: I was never sure on that one. maybe some old browsers liked it? I'm just used to it
      • tachyondecay
        Also technically your error list should be outside your paragraph element
      • hyperknot
        I think I shouldn't use p for it anyway, should I?
      • tachyondecay
        Or make your p elements a div
      • That is a whole other debate, I think :P
      • hyperknot
        I just need to figure out how to pre-populate the form with my object
      • tachyondecay
        That is covered in the docs :)
      • hyperknot
        ah, obj=
      • nice
      • josuebrunel joined the channel
      • so the view logic would be something like this, wouldn't it? http://paste.ee/r/n4Pv0
      • tachyondecay
        It's request.form, not request.POST
      • And you can instantiate the form outside your first if statement: form = form_class(request.form, obj=item)
      • Wtforms will populate the form with your object info if request.form is empty
      • hyperknot
        aha, so it can take both at the same time
      • super
      • it's request.POST because of pyramid.
      • tachyondecay
        Ah
      • Sorry, assumed Flask :P
      • Carry on then!
      • hyperknot
        thanks
      • i'm trying to solve my Could not obtain SQLAlchemy session but it might be a WTForms-Alchemy specific error
      • tachyondecay
        You might need to subclass your model form class from wtforms_alchemy and use the get_session classmethod
      • hyperknot
        thanks, looking at those lines in the docs
      • just found it
      • tachyondecay
        I love WTForms-Alchemy :D
      • hyperknot
        wow, it works
      • it had to do this: ModelForm_ = model_form_factory(ModelForm)
      • can I not do it once, instead of defining get_session for each form?
      • tachyondecay
        In my paste above, I did that for a class I called BaseModelForm and then subclassed it
      • hyperknot
        ok, yes I see it
      • tachyondecay
        I don't know if you need to do that second step
      • I had to do it because it wasn't finding my session otherwise
      • But it's an easy hack :D
      • hyperknot
        it's just more complicated for me, as I don't have Form
      • zepolen joined the channel
      • here is my version: http://paste.ee/r/c0XCA
      • zepolen has quit
      • tachyondecay: thank you so much, there were multiple concepts here which I wouldn't have figured out!
      • tachyondecay
        You're welcome
      • tachyondecay has quit
      • massover has quit
      • toothrot has quit
      • ramteid joined the channel
      • AshleyMcNamara joined the channel
      • csotelo_ joined the channel
      • davidism joined the channel
      • latro has quit
      • breakingmatter joined the channel
      • mbordas joined the channel
      • dinnu93 joined the channel
      • dinnu93
        hi
      • how to post files from ajax to a flask application ?
      • I'm getting a lot of problems
      • Toba_
        make sure to set the enctype to multipart/form-data
      • breakingmatter has quit
      • AshleyMcNamara has quit
      • latro joined the channel
      • thesquib has quit
      • hyperknot has quit
      • thesquib joined the channel
      • panda__ joined the channel
      • cruor99 joined the channel
      • zepolen joined the channel
      • panda__ has quit
      • illume joined the channel
      • zepolen has quit