Change import in permalink decorator from function to module
|Reported by:||jcassee||Owned by:||mtredinnick|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The permalink decorator uses the urlresolvers.reverse function to generate a permanent link to objects. It imports the reverse function itself instead of the urlresolvers module. This causes trouble in projects that also use the localeurl application, because this application monkey-patches the reverse function in order to add a prefix. Although monkey-patching a core Django function is bad form, it is currently the only way I see to provide this functionality. Additionally, importing elements from a module instead of the module itself is slightly frowned upon in general (Python docs, Python FAQ: "Guido van Rossum recommends...", Fredrik Lundh). It is common in Django, though, so that might not impress anyone.
The attached patch changes the permalink decorator to import the urlresolvers module instead of the reverse function. Because the change is small, I hope the patch will be accepted.
Change History (5)
Changed 5 years ago by jcassee
comment:1 follow-up: ↓ 3 Changed 5 years ago by mtredinnick
- Needs documentation unset
- Needs tests unset
- Owner changed from nobody to mtredinnick
- Patch needs improvement unset
- Status changed from new to assigned