Opened 18 years ago

Closed 17 years ago

#2835 closed enhancement (wontfix)

Processing of urlconf extra args, and removing args

Reported by: oyvind@… 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)

3874-process-remove-kwargs-in-urlconf.diff (1.8 KB ) - added by [530] 18 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 by [530], 18 years ago

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 ),
)

comment:2 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedDesign decision needed

comment:3 by Jacob, 17 years ago

Resolution: wontfix
Status: newclosed

I really can't see the use case here.

Note: See TracTickets for help on using tickets.
Back to Top