django-admin-sortable2, Release 2.1.8
2.3.5 Adding new Features
If you want to add a new feature to django-admin-sortable2, please integrate a demo into the testing app (ie.
testapp). Doing so has two benefits:
I can understand way better what it does and how that new feature works. This increases the chances that such a
feature is merged.
You can use that extra code to adopt the test suite.
Remember: For UI-centric applications such as this one, where the client- and server-side are strongly entangled with
each other, I prefer end-to-end tests way more rather than unit tests. Reason is, that otherwise I would have to mock
the interfaces, which itself is error-prone and additional work.
Don’t hide yourself : I will not accept large pull requests from anonymous users, so please publish an email address in
your GitHub’s profile. Reason is that when refactoring the code, I must be able to contact the initial author of a feature
not added by myself.
2.3.6 Quoting
Please follow these rules when quoting strings:
• A string intended to be read by humans shall be quoted using double quotes: “. . . ”.
• An internal string, such as dictionary keys, etc. (and thus usually not intended to be read by humans), shall be
quoted using single quotes: ‘. . . ’. This makes it easier to determine if we have to extra check for wording.
There is a good reason to follow this rule: Strings intended for humans, sometimes contain apostrophes, for instance
“This is John’s profile”. By using double quotes, those apostrophes must not be escaped. On the other side whenever
we write HTML, we have to use double quotes for parameters, for instance ‘<a href=”https://example.org”>Click
here!</a>’. By using single quotes, those double quotes must not be escaped.
2.3.7 Lists versus Tuples
Unfortunately in Django, we developers far too often intermixed lists and tuples without being aware of their intention.
Therefore please follow this rule:
Always use lists, if there is a theoretical possibility that someday, someone might add another item. Therefore
list_display, list_display_links, fields, etc. must always be lists.
Always use tuples, if the number of items is restricted by nature, and there isn’t even a theoretical possibility of being
extended.
Example:
color = ChoiceField(
label="Color",
choices=[('ff0000', "Red"), ('00ff00', "Green"), ('0000ff', "Blue")],
)
A ChoiceField must provide a list of choices. Attribute choices must be a list because it is eligible for extension.
Its inner items however must be tuples, because they can exlusively containin the choice value and a human readable
label. Here we also intermix single with double quotes to distinguish strings intended to be read by the machine versus
a human.
18 Chapter 2. Contents: