LGTM and nice work, with consideration of various fairly trivial
comments.
I'm interested in bac's comments. Calling something Zope-like these
days is unfortunately not a complement. Perhaps he's referring to using
classes for fields? Certainly these fields could be data as well: your
classes really simply have some flags and some functions, and the
validation functions could be composed (more?) attractively
functionally, to my eyes. That said, while I am intrigued by the idea
of simplifying the fields into data, and think it might be a win, I
don't think it will be a big enough win to justify refactoring at this
time; and I think people with an OOP bent might not like the refactoring
at all.
Moreover, maybe that's not anywhere close to what bac means?
https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode49
quickstart/models/fields.py:49: - autogenerated: indicates this is a
string field that can be
It strikes me that this functionality is along a different logical axis
than field type. I'd be tempted to have the code look for a generate
method, for instance, as a flag: if it exists, it can autogenerate (a
string, a number, whatever). I don't think this is very important: just
a suggestion.
the key identifying a specific piece of information in the environments
data
...or not? Might be good to clarify, either way.
https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode83
quickstart/models/fields.py:83: self, name, label=None, help='',
required=True, editable=True):
I generally prefer flags to default to false, but I think this is
probably the right compromise between clarity and convenience for
required and editable...unless we can choose different names?
optional=False, readonly=False
readonly conveys the idea well. Less sure about "optional"
Return None if the value is an empty string or None. In these cases,
the field value is considered not set.
https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode186
quickstart/models/fields.py:186: if self.required:
The duplication of this code from the base class is one possible
argument for the greater flexibility of using functional composition to
build validation. Not suggesting the change, because that would slow
things down, but I'm comparing this in my mind with an approach in the
"Functional Javascript" book I've been reading.
https://codereview.appspot.com/37820046/diff/1/quickstart/models/fields.py#newcode218
quickstart/models/fields.py:218: the default value (True or False) to
use if the value is unset (None).
Seems like the default functionality could be shared in the base class.
If you wanted to be paranoid, you could even run it through the
"validate" function.
LGTM and nice work, with consideration of various fairly trivial
comments.
I'm interested in bac's comments. Calling something Zope-like these
days is unfortunately not a complement. Perhaps he's referring to using
classes for fields? Certainly these fields could be data as well: your
classes really simply have some flags and some functions, and the
validation functions could be composed (more?) attractively
functionally, to my eyes. That said, while I am intrigued by the idea
of simplifying the fields into data, and think it might be a win, I
don't think it will be a big enough win to justify refactoring at this
time; and I think people with an OOP bent might not like the refactoring
at all.
Moreover, maybe that's not anywhere close to what bac means?
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py models/ fields. py (right):
File quickstart/
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode24 models/ fields. py:24: each provider type is associated to a
quickstart/
sequence of fields. Those fields describe
...associated with a sequence of fields.
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode49 models/ fields. py:49: - autogenerated: indicates this is a
quickstart/
string field that can be
It strikes me that this functionality is along a different logical axis
than field type. I'd be tempted to have the code look for a generate
method, for instance, as a flag: if it exists, it can autogenerate (a
string, a number, whatever). I don't think this is very important: just
a suggestion.
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode53 models/ fields. py:53: edited using the usual input edit
quickstart/
widget.
Which effectively means multi-line string, right? Might as well be
explicit about it.
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode56 models/ fields. py:56: - name: the name identifying a specific
quickstart/
piece of information
Is this...
the key identifying a specific piece of information in the environments
data
...or not? Might be good to clarify, either way.
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode83 models/ fields. py:83: self, name, label=None, help='',
quickstart/
required=True, editable=True):
I generally prefer flags to default to false, but I think this is
probably the right compromise between clarity and convenience for
required and editable...unless we can choose different names?
optional=False, readonly=False
readonly conveys the idea well. Less sure about "optional"
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode84 models/ fields. py:84: """Initialize a field, only the name
quickstart/
identifier is required."""
Run-on sentence. Any of the following are better
Initialize a field. Only...
Initialize a field; only...
I prefer the period in this case.
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode100 models/ fields. py:100: if isinstance(value, str):
quickstart/
When would this happen? Or is this just insurance?
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode117 models/ fields. py:117: return value value) so you can show the intended use?
quickstart/
Maybe "return self.normalize(
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode122 models/ fields. py:122:
quickstart/
Maybe call out that this has no field_type because it is the default?
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode135 models/ fields. py:135: value = self.normalize( value)
quickstart/
You could delete this line if you make my suggested change to the base
class' validate method.
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode156 models/ fields. py:156: Return None if the value is an empty
quickstart/
string or None: in this case the
I suggest the following.
Return None if the value is an empty string or None. In these cases,
the field value is considered not set.
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode186 models/ fields. py:186: if self.required:
quickstart/
The duplication of this code from the base class is one possible
argument for the greater flexibility of using functional composition to
build validation. Not suggesting the change, because that would slow
things down, but I'm comparing this in my mind with an approach in the
"Functional Javascript" book I've been reading.
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode218 models/ fields. py:218: the default value (True or False) to
quickstart/
use if the value is unset (None).
Seems like the default functionality could be shared in the base class.
If you wanted to be paranoid, you could even run it through the
"validate" function.
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode238 models/ fields. py:238: class AutoGeneratedFi eld(StringField ): ringField?
quickstart/
AutoGeneratedSt
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ models/ fields. py#newcode257 models/ fields. py:257: self.choices = choices
quickstart/
tuple(choices) just to be paranoid?
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ tests/models/ test_fields. py tests/models/ test_fields. py (right):
File quickstart/
https:/ /codereview. appspot. com/37820046/ diff/1/ quickstart/ tests/models/ test_fields. py#newcode63 tests/models/ test_fields. py:63: l(unicode( value), field.display( value), value)
quickstart/
self.assertEqua
I guess it is good that all fields can handle None, but guaranteeing
that None is displayed as u'None' doesn't seem ideal on the face of it.
https:/ /codereview. appspot. com/37820046/