You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to dev-webdev
Hey All,
I have looked at some of the code in our Socorro base and did some
reading online but I cannot seem to find a useful resource for this so I
thought I would ask on the list.
In forms.py there are now two places that uses this exact code:
This smells of refactoring into a reusable bit but, is there a specific
way this is handled/done in Django?
Thanks!
--
Kind Regards
Schalk Neethling
Lead Front-End Engineer
Mozilla
Paul McLanahan
unread,
Jul 7, 2014, 10:35:04 AM7/7/14
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to dev-webdev
Hi Schalk,
Probably best thing is to put those methods in a mixin class and add
them to the inheritance of your form classes. You could also make a Form
subclass (e.g. DateRangeForm) that adds those methods, then inherit from
that, but I've not gone through the Form metaclass craziness to verify
if that would work without side-effect.
I'm pretty sure either strategy would work though, and it should be easy
to test.
HTH,
pmac
Jannis Leidel
unread,
Jul 7, 2014, 11:06:19 AM7/7/14
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
All you’d have to do is to subclass the DateTimeField class and override the to_python method in the field (make sure to get the original value with a super() call).
Since you want to check for a value of one field in the clean method of another I could also see this being applied to a subclass of a SplitDateTimeField, a special form field that consists of multiple form inputs (“MultiValueField”). In that case all you’d have to do is to implement the compress method and handle the values passed as a list the way you do in your example.
> Hey All,
>
> I have looked at some of the code in our Socorro base and did some reading online but I cannot seem to find a useful resource for this so I thought I would ask on the list.
>
> In forms.py there are now two places that uses this exact code:
>
> http://sneethling.pastebin.mozilla.org/5529334 >
> This smells of refactoring into a reusable bit but, is there a specific way this is handled/done in Django?
>
> Thanks!
>
> --
> Kind Regards
> Schalk Neethling
> Lead Front-End Engineer
> Mozilla