-
-
djblets/extensions/base.py (Diff revision 1) I feel this is the wrong place for this import, I may be wrong.
-
djblets/extensions/base.py (Diff revision 1) This chunk of code could probably be refactored. Usually you don't want to explicitly return a boolean, but rather do something similar to this: return super(Settings, self).__contains__(key) (I know this isn't a solution in your case, but you should try something similar)
Enable extensions to provide a default settings dictionary
Review Request #2907 — Created Feb. 20, 2012 and submitted
Information | |
---|---|
smacleod | |
Djblets | |
Reviewers | |
djblets | |
When an extension is loaded for the first time it is initialized with an empty settings dictionary. All extension authors must either initialize the settings dictionary and save it, or check at use if the setting exists. This modification allows an extension author to specify a default settings dictionary, which will be used if a key is not present in extension.settings. Instead of copying all defaults, I only reference them when a missing key is accessed. Another option would be to initialize the settings when the extension is loaded. Feel free to suggest other ideas.
Tested in local dev with dummy extensions. Ran djblets unit tests.
Description | From | Last Updated |
---|---|---|
This chunk of code could probably be refactored. Usually you don't want to explicitly return a boolean, but rather do … |
ME medanat | |
I'd prefer "" instead of []. To make it more readable code-wise with "", you can use '' for the … |
|
|
Each dict key should be on its own line: "" % { 'key': key, 'ext': self.extension.id, } |
|
|
If you make the default for default_settings be {} instead, this can just be: return key in self.extension.default_settings You can … |
|
ME
-
-
djblets/extensions/base.py (Diff revision 2) I'd prefer "" instead of []. To make it more readable code-wise with "", you can use '' for the string itself.
-
djblets/extensions/base.py (Diff revision 2) Each dict key should be on its own line: "" % { 'key': key, 'ext': self.extension.id, }
-
djblets/extensions/base.py (Diff revision 2) If you make the default for default_settings be {} instead, this can just be: return key in self.extension.default_settings You can also simplify the logic in __getitem__.