Opened 19 years ago
Closed 18 years ago
#2835 closed enhancement (wontfix)
Processing of urlconf extra args, and removing args
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Core (Other) | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Triage Stage: | Design decision needed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Allows for arguments to be pre-processed to allow urls to be more sensible, ie. comments below blog post.
Also allows arguments to be removed so arguments needed for preprocessing can be removed befor being passed to views.
Not sure if this is a good idea, but i just wanted to see if this is something django needs.
Example code:
form page.models import Page
class comments_urlprocessor:
def init(self, model, args=[]):
self.model, self.args = model, args
def call(self, *args, kwargs):
for key in kwargs.keys():
if key not in self.args:
del kwargskey
try:
commented_object = self.model.objects.get(kwargs)
except:
commented_object = False
return {'commented_object': commented_object}
info_dict = {
'queryset': Page.objects.all(),
}
commments_dict = {
'process_kwargs': comments_urlprocessor,
'remove_kwargs': ['pk','comments_urlprocessor'],
'comments_urlprocessor': comments_urlprocessor(Page, pk),
'commented_object_template': 'page.html'
}
urlpatterns = patterns(,
(r'(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', dict(info_dict, object_id=1, template_name='page.html')),
(r'(?P<pk>\d+)/comments/', include('advancedcomments.urls'), commments_dict ),
)
Attachments (1)
Change History (4)
by , 19 years ago
| Attachment: | 3874-process-remove-kwargs-in-urlconf.diff added |
|---|
comment:1 by , 19 years ago
comment:2 by , 19 years ago
| Triage Stage: | Unreviewed → Design decision needed |
|---|
comment:3 by , 18 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
I really can't see the use case here.
Ouch, needs some formatting
from django.conf.urls.defaults import * from pages.models import Page class comments_urlprocessor: def __init__(self, model, args=[]): self.model, self.args = model, args def __call__(self, *args, **kwargs): for key in kwargs.keys(): if key not in self.args: del kwargs['key'] try: commented_object = self.model.objects.get(**kwargs) except: commented_object = False return {'commented_object': commented_object} info_dict = { 'queryset': Page.objects.all(), } commments_dict = { 'process_kwargs': ['comments_urlprocessor'], 'remove_kwargs': ['pk','comments_urlprocessor'], 'comments_urlprocessor': comments_urlprocessor(Page, ['pk']), 'commented_object_template': 'page.html' } urlpatterns = patterns('', (r'^(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', dict(info_dict, object_id=1, template_name='page.html')), (r'^(?P<pk>\d+)/comments/', include('advancedcomments.urls'), commments_dict ), )