=== alexpilotti_ is now known as alexpilotti | ||
=== jfarschman is now known as MilesDenver | ||
=== jfarschman is now known as MilesDenver | ||
=== jfarschman is now known as MilesDenver | ||
=== jfarschman is now known as MilesDenver | ||
=== jfarschman is now known as MilesDenver | ||
=== jfarschman is now known as MilesDenver | ||
=== kickinz1|afk is now known as kickinz1 | ||
=== jfarschman is now known as MilesDenver | ||
=== CyberJacob|Away is now known as CyberJacob | ||
=== kickinz1 is now known as kickinz1|afk | ||
=== kickinz1|afk is now known as kickinz1 | ||
rvba | jtv1: it's in /etc/maas/templates/deployment-user-data/maas_configure_interfaces.py | 07:16 |
---|---|---|
jtv1 | rvba: great, thanks. That's the expected location. | 07:20 |
jtv1 | I just mis-typed it earlier. | 07:21 |
rvba | Ah, okay. | 07:21 |
=== kickinz1 is now known as kickinz1|afk | ||
=== CyberJacob is now known as CyberJacob|Away | ||
=== kickinz1|afk is now known as kickinz1 | ||
=== jfarschman is now known as MilesDenver | ||
=== jfarschman is now known as MilesDenver | ||
=== jfarschman is now known as MilesDenver | ||
=== kickinz1 is now known as kickinz1|afk | ||
=== jtv1 is now known as jtv | ||
=== jfarschman is now known as MilesDenver | ||
=== kickinz1|afk is now known as kickinz1 | ||
jtv | rvba: can I impose on your Django knowledge? | 11:29 |
jtv | I'm trying to set a computed default value for a form field. | 11:29 |
jtv | When I clean the field in the form, it's always present and its cleaned_data value is never None. | 11:30 |
jtv | The django docs say that setting an "initial" value is not the way to do this, but they don't say what is. | 11:30 |
jtv | (Even setting a callable default on the model wouldn't do the trick, because the default needs to refer to the Node object itself) | 11:31 |
rvba | jtv: I don't understand why you're saying that the field is always present and that its cleaned_data value is never None. Is that a result of something you've done? | 11:32 |
rvba | jtv: why can't you set your default value in the form's __init__? | 11:34 |
jtv | Could be. When my clean_<field> method (on the form) looks for self.cleaned_data.get(<field>) it never gets None back. | 11:34 |
jtv | Set it in the form's __init__? Do I have the instance at that point, when the form is creating a new object? | 11:34 |
rvba | No, unless you create it yourself manually, then *update* it when save() is called. | 11:35 |
rvba | So, you want the initial value to depend on a non-yet created object? | 11:35 |
rvba | I don't understand. | 11:35 |
jtv | This is NodeForm; all I really need is its NodeGroup. | 11:36 |
jtv | If I can get that, I can get the default value. | 11:36 |
rvba | Then presumably you want to pass the nodegroup to the form's __init__ and derive the default value from it. | 11:37 |
rvba | Same as what NodeGroupDefineForm does with 'status'. | 11:38 |
=== jfarschman is now known as MilesDenver | ||
jtv | rvba: so... overriding save() looks like the only way to set a computed default with access to the object's properties..? | 11:41 |
rvba | jtv: yes, save() is where the object is created by the form. | 11:41 |
rvba | jtv: but surely the data you need (the nodegroup) is part of the data sent to the form? | 11:42 |
jtv | Probably, yes. I'm more worried at this stage about how I'll know whether a value was submitted for my field. | 11:43 |
rvba | jtv: if no value was submitted for the field, cleaned_data should be set to the default value. | 11:46 |
rvba | cleaned_data.get(field_name) that is | 11:46 |
jtv | The default _model_ value? | 11:46 |
jtv | Well stupid question I guess, | 11:47 |
jtv | since there doesn't seem to be a default form value. | 11:47 |
jtv | I guess I'd have to make the model-level field default to None, but disallow nulls? | 11:48 |
rvba | Yes, I assume the default model value is there when the form gets validated. | 11:49 |
rvba | I don't think you need to make the model-level field default to None. | 11:50 |
jtv | Well it's a boolean field that can't be null, and I need a way to know whether a value was provided to the form... | 11:53 |
jtv | I get the impression that the model is the only level where I can provide a default. | 11:54 |
jtv | (Unless we count "initial" which the docs say won't do this.) | 11:54 |
* jtv eats for a bit | 11:54 | |
* rvba → lunch | 11:56 | |
=== jfarschman is now known as MilesDenver | ||
jtv | Arrrrrgh! My problem was in factory.make_NodeGroup accepting my new field but not passing it on! | 12:42 |
jtv | That's why my test failed: the default was always False, even if I explicitly set it to True. | 12:44 |
jtv | Question now is: at what point in all my experiments did the test start failing for that reason? | 12:44 |
jtv | Urgh. That's enough for tonight. Have a good weekend everyone. | 13:07 |
=== kickinz1 is now known as kickinz1|afk | ||
=== jfarschman is now known as MilesDenver | ||
=== allenap_ is now known as allenap | ||
=== jefferai__ is now known as jefferai_ | ||
=== roadmr_ is now known as roadmr_afk | ||
=== CyberJacz is now known as CyberJacob | ||
=== roadmr_afk is now known as roadmr | ||
=== roadmr is now known as roadmr_afk | ||
=== roadmr_afk is now known as roadmr | ||
=== jfarschman is now known as MilesDenver | ||
=== jfarschman is now known as MilesDenver | ||
=== alexpilotti_ is now known as alexpilotti | ||
=== alexpilotti_ is now known as alexpilotti |
Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!