Opened 15 years ago
Last modified 8 years ago
#9967 new enhancement
Allow setting option values through Option objects
| Reported by: | Owned by: | ||
|---|---|---|---|
| Priority: | normal | Milestone: | next-major-releases |
| Component: | general | Version: | 0.12.1 |
| Severity: | normal | Keywords: | config patch |
| Cc: | Jun Omae | Branch: | |
| Release Notes: | |||
| API Changes: | |||
| Internal Changes: | |||
Description
Trac currently allows the user to read an option's value through a Option object, like in the following code:
class MyComponent(Component): my_option = Option('my_section', 'my_option') def my_func(self): # retrieving option value my_option_value = self.my_option
When calling my_func(), my_option_value will be filled with the current option values (as specified in trac.ini).
Now, while retrieving works this way, one can't set the option value this way.
class MyComponent(Component): my_option = Option('my_section', 'my_option') def my_func(self): # setting option value # will raise an AttributeError self.my_option = 'test' self.config.save()
I've created a patch that enables this functionality. I've done some tests with it and it seems to work for Option and all of its subclasses.
Attachments (1)
Change History (4)
by , 15 years ago
| Attachment: | config.diff added |
|---|
comment:1 by , 15 years ago
| Keywords: | config patch added |
|---|---|
| Milestone: | → next-major-0.1X |
Interesting. You may want to revise the patch once #7378 is finalized.
comment:2 by , 11 years ago
| Cc: | added |
|---|
comment:3 by , 8 years ago
It might be good to delegate to the setter code that checks valid values, such as: LoggingAdminPanel.render_admin_panel.
Related, it would be nice if TracAdmin config set raised an error when setting an invalid value, at least for options defined in ExtensionOption and OrderedExtensionOption. Similarly, when enabling/disabling components with TracAdmin, we autocomplete the components:
> config set components tracopt.versioncontrol. tracopt.versioncontrol.git.git_fs.csetpropertyrenderer tracopt.versioncontrol.git.git_fs.gitconnector tracopt.versioncontrol.git.git_fs.gitwebprojectsrepositoryprovider tracopt.versioncontrol.svn.svn_fs.subversionconnector tracopt.versioncontrol.svn.svn_prop.subversionmergepropertydiffrenderer tracopt.versioncontrol.svn.svn_prop.subversionmergepropertyrenderer tracopt.versioncontrol.svn.svn_prop.subversionpropertyrenderer
It would be nice to raise an error when attempting to enable/disable a invalid component.



Patch against Trac 0.12.1