On Thu, May 19, 2016 at 02:56:48PM -0700, Quentin Fulsher wrote:
> Here is a super quick proof of concept that I put together. I just branched
> my fork of django and added a little to it. Here is the comparing changes
> page[1].
>
> Quick summary of changes: I created a dictionary that would contain the
> (id: message) pairs. I also modified the CheckMessage.__init__ method so
> that it will attempt to find a hint message for the id that was passed to
> it. If no key was found then it continues as normal. This allows me to
> comment out the hint parameter when it is created but still be able to pass
> when it is run through its normal tests.
Personally, I'm not entirely convinced – this approach might work OK
for hints, which are just static strings, but not so much for the
error messages themselves, which (at least in the case of field
checks) contain arbitrary string interpolation. I can see three
options here:
1. Put both hints, and error message format strings into a central
place. This way, each is only defined in one place, which is nice,
but with the arbitrary string interpolation, we'd need to extend
the CheckMessage API to handle it after retrieving the message
template. Also, this way, the format strings and their arguments
will reside in different files, which doesn't seem very nice.
2. Use a central definition for hints, but keep messages as they are.
No special handling of string interpolation would be necessary, but
we lose the benefits of having a single definition for error
messages.
3. Keep things the way they are.
Personally, I don't like option 2 much, because it solves only half of
the problem, but I'm not certain option 1 is worth it either. Random
things to note:
- As Tim pointed out, certain parts of the check framework already do
something similar, but in a different way that doesn't seem to mix
well with string interpolation.
- Different parts of the check framework use different styles of
string formatting, which means if we try to tidy up the message
format strings, we'd have to settle on a single style.
I do agree that having to change the message in three places is a bit
annoying, though.
I hope this makes at least some sense...
Cheers,
Michal