Re: Generic views in magic removal

2006-03-22 Thread Arthur

> I think I figured it out, your RegEx should be:
> (?P\d+)/$

Ah, much better. I've looked at the completely wrong places. I still
wonder a bit about the error message.

Now it only complains about missing templates which I should be able to fix.

Thanks so much

Arthur

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Generic views in magic removal

2006-03-22 Thread limodou

On 3/23/06, Arthur <[EMAIL PROTECTED]> wrote:
>
> > I got it . You should pass the info_dict as **info_dict, but not
> > info_dict directly.
>
> Thanks for your answer. I don't think you can do that inside tuples.
> It throws a syntax error.
>
> Arthur

Oh, I made a mistake. I'm sorry.

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Generic views in magic removal

2006-03-22 Thread limodou

On 3/23/06, Arthur <[EMAIL PROTECTED]> wrote:
>
> > The info_dict never gets implicitly passed -- it's always explicitly
> > passed. We're removing the magic, not adding to it! :)
> >
> > But as for your question, it seems like you're getting that error
> > because you're passing in 'queryset' twice.
>
> I've minimized the app to the bare minimum, but the error is still showing up:
>
> urls.py:
>
> from django.conf.urls.defaults import *
> from models import TodoItem
>
> # todolist URLs
> #
> info_dict = {
> 'queryset': TodoItem.objects.all() #,
> #'slug_field': 'detail'
> }
>
> urlpatterns = patterns(
>  'django.views.generic.list_detail',
> (r'(\d+)/$', 'object_detail', info_dict),
>  )
>
> models.py:
>
> from django.db import models
>
> class TodoItem(models.Model):
> text = models.CharField(maxlength=1000)
> dueDate = models.DateField(blank=True, null=True)
> class Admin:
> list_display = ('dueDate', 'text')
>
>
> The strange thing is that when I don't pass the info_dict there's
> still a variable queryset with the string value '1' and with passing
> it I get the
> "object_detail() got multiple values for keyword argument 'queryset'"
> error. Strange
>
> Thanks, Arthur

I got it . You should pass the info_dict as **info_dict, but not
info_dict directly.
--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Generic views in magic removal

2006-03-22 Thread Arthur

> The info_dict never gets implicitly passed -- it's always explicitly
> passed. We're removing the magic, not adding to it! :)
>
> But as for your question, it seems like you're getting that error
> because you're passing in 'queryset' twice.

I've minimized the app to the bare minimum, but the error is still showing up:

urls.py:

from django.conf.urls.defaults import *
from models import TodoItem

# todolist URLs
#
info_dict = {
'queryset': TodoItem.objects.all() #,
#'slug_field': 'detail'
}

urlpatterns = patterns(
 'django.views.generic.list_detail',
(r'(\d+)/$', 'object_detail', info_dict),
 )

models.py:

from django.db import models

class TodoItem(models.Model):
text = models.CharField(maxlength=1000)
dueDate = models.DateField(blank=True, null=True)
class Admin:
list_display = ('dueDate', 'text')


The strange thing is that when I don't pass the info_dict there's
still a variable queryset with the string value '1' and with passing
it I get the
"object_detail() got multiple values for keyword argument 'queryset'"
error. Strange

Thanks, Arthur

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Generic views in magic removal

2006-03-22 Thread Adrian Holovaty

On 3/22/06, Arthur <[EMAIL PROTECTED]> wrote:
> > Your example you aren't passing in that info_dict you created.
>
> Thanks Max. That's what I tried first. But from the partially updated
> tutorial in the mr branch docs and the error message
> "object_detail() got multiple values for keyword argument 'queryset'"
> when I try that I surmised that the info_dict somehow gets implicitly
> passed. Where could those multiple values for 'queryset' come from?

The info_dict never gets implicitly passed -- it's always explicitly
passed. We're removing the magic, not adding to it! :)

But as for your question, it seems like you're getting that error
because you're passing in 'queryset' twice.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Generic views in magic removal

2006-03-22 Thread Arthur

> > I'm trying to use generics on the magic removal trunc and I'm a bit at
> > a loss because the queryset variable seems to get autoconverted to a
> > string. The following urls.py always results in a "AttributeError:
> > 'str' object has no attribute 'model'":
> >
> > from django.conf.urls.defaults import *
> > from models import TodoItem
> >
> > info_dict = {
> > 'queryset': TodoItem.objects.all()
> > }
> >
> > urlpatterns = patterns(
> > 'django.views.generic.list_detail',
> >  (r'(\d+)/$', 'object_detail'),
> >  )
> >
>
> Shouldn't that be:
>
> urlpatterns = patterns(
>  'django.views.generic.list_detail',
>   (r'(\d+)/$', 'object_detail', info_dict),
>   )
>
> Your example you aren't passing in that info_dict you created.

Thanks Max. That's what I tried first. But from the partially updated
tutorial in the mr branch docs and the error message
"object_detail() got multiple values for keyword argument 'queryset'"
when I try that I surmised that the info_dict somehow gets implicitly
passed. Where could those multiple values for 'queryset' come from?

Arthur

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Generic views in magic removal

2006-03-22 Thread Max Battcher

Arthur wrote:
> Hi all
> 
> I'm trying to use generics on the magic removal trunc and I'm a bit at
> a loss because the queryset variable seems to get autoconverted to a
> string. The following urls.py always results in a "AttributeError:
> 'str' object has no attribute 'model'":
> 
> from django.conf.urls.defaults import *
> from models import TodoItem
> 
> info_dict = {
> 'queryset': TodoItem.objects.all()
> }
> 
> urlpatterns = patterns(
> 'django.views.generic.list_detail',
>  (r'(\d+)/$', 'object_detail'),
>  )
> 

Shouldn't that be:

urlpatterns = patterns(
 'django.views.generic.list_detail',
  (r'(\d+)/$', 'object_detail', info_dict),
  )

Your example you aren't passing in that info_dict you created.

-- 
--Max Battcher--
http://www.worldmaker.net/
"I'm gonna win, trust in me / I have come to save this world / and in 
the end I'll get the grrrl!" --Machinae Supremacy, Hero (Promo Track)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Generic views in magic removal

2006-03-22 Thread Arthur

Hi all

I'm trying to use generics on the magic removal trunc and I'm a bit at
a loss because the queryset variable seems to get autoconverted to a
string. The following urls.py always results in a "AttributeError:
'str' object has no attribute 'model'":

from django.conf.urls.defaults import *
from models import TodoItem

info_dict = {
'queryset': TodoItem.objects.all()
}

urlpatterns = patterns(
'django.views.generic.list_detail',
 (r'(\d+)/$', 'object_detail'),
 )

Any help appreciated. Thanks

Arthur

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Help with Generic Views in Magic Removal Branch

2006-02-25 Thread ChaosKCW

Hi

Thanks for your responses. Thats what I thought, just wanted to make
sure. The all() just seems unitutive to me, but given that Djangos
syntax is so easy, a little bit of something here and there is no
biggie.

Thanks again.

PS I just posted a patch for the generic views on the developers list
to add a template model name: http://code.djangoproject.com/ticket/1399

C


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Help with Generic Views in Magic Removal Branch

2006-02-25 Thread Luke Plant

On Saturday 25 February 2006 18:25, ChaosKCW wrote:

> A dumb question, but will objects.all() cause any kind of performance
> hit ?
>
> I mean when the code appends QuerySet.filter(pk=object_id), will it
> condense that to a SQL statement that returns one object or reutrn
> all obejcts then do the PK query ?

It creates a new SQL statement that returns one objects, without ever 
having done the original query, so there is no performance hit.  To do 
the PK query client side would mean you'd have to replicate all the 
features of the DB in Python.

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Help with Generic Views in Magic Removal Branch

2006-02-25 Thread ChaosKCW

A dumb question, but will objects.all() cause any kind of performance
hit ?

I mean when the code appends QuerySet.filter(pk=object_id), will it
condense that to a SQL statement that returns one object or reutrn all
obejcts then do the PK query ? 

Thanks,


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Help with Generic Views in Magic Removal Branch

2006-02-25 Thread Luke Plant

On Saturday 25 February 2006 17:43, ChaosKCW wrote:

> Just one question, I have used model.objects, not
> model.objects.all(). It appears to work and makes more sense to me.
> Any comments?

Use model.objects.all() (at least for now). model.objects will work in 
some cases, but perhaps not in others. (Technically, it's to do with 
QuerySets caching their result for efficiency, and the fact that you 
don't want 'model.objects' to cache it's result).

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Help with Generic Views in Magic Removal Branch

2006-02-25 Thread Luke Plant

On Saturday 25 February 2006 17:47, ChaosKCW wrote:
> Hi
>
> Is there some documentation on the "Sites" functionality. I have seen
> it, but not seen any docs ?

'Site' in that example was a model in my own app -- there is a Django 
model of the same name, but I don't know that much about it.

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Help with Generic Views in Magic Removal Branch

2006-02-25 Thread ChaosKCW

Hi

Is there some documentation on the "Sites" functionality. I have seen
it, but not seen any docs ? 

Thanks,


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Help with Generic Views in Magic Removal Branch

2006-02-25 Thread ChaosKCW

Thanks, I had a look at the code and worked that out.

Just one question, I have used model.objects, not model.objects.all().
It appears to work and makes more sense to me. Any comments?

Thanks, 

Stephen


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Help with Generic Views in Magic Removal Branch

2006-02-25 Thread Luke Plant

On Saturday 25 February 2006 16:58, ChaosKCW wrote:

> Please can someone help. I am following Tutorial4 for generic views,
> plus adapting it to the magic removal instructions on the wiki page.
> As far as I can tell i followed the instructions exactly, But I get
> an error stating that 'model' is not a valid paremeter to the view.

The tutorial is now badly out of date for magic-removal.  Instead of 
taking a model and app_label, they take a 'queryset' argument, which 
should be a QuerySet object.  QuerySet objects are what you implicitly 
use in magic removal to do all lookups on the database.  For instance, 
Poll.objects.all() is a QuerySet.  Because QuerySets are 'lazy', you 
can create them in your URL conf and the data won't be retrieved at 
that point, but each time the generic view is actually called.  In my 
urls.py I have something like this:

(r'^sites/$', 'list_detail.object_list',
{'queryset': Site.objects.all(),
 'template_name': 'cciw/sites/index'
}
),
 
(r'^sites/(?P.*)/$', 'list_detail.object_detail',
{'queryset': Site.objects.all(),
 'slug_field': 'slug_name',
 'template_name': 'cciw/sites/detail'
 }
),
...

Note how I use all the 'Site' objects in the both cases, but don't worry 
-- only in the first case does it actually result in all the objects 
being retrieved from the db, in the second case the view derives a new 
QuerySet, based on the one passed in, that only gets a single object.

I personally think the new syntax is much nicer - no need for 
'extra_lookup_args' etc.  If you wanted to have a different ordering 
plus extra filtering, you could change Site.objects.all() to e.g.
Site.objects.filter(visible=True).order_by('name').

One thing - I'm not sure all the generic views have been updated yet.  I 
do know the above examples work.

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Help with Generic Views in Magic Removal Branch

2006-02-25 Thread ChaosKCW

Hi

Please can someone help. I am following Tutorial4 for generic views,
plus adapting it to the magic removal instructions on the wiki page.
As far as I can tell i followed the instructions exactly, But I get an
error stating that 'model' is not a valid paremeter to the view.

I am sure its somthing dumb I have done, but if anyone spots it I would
appreciate some help. I have pasted the ERROR and the urls.py below
(cant see an attach  file option in GG).


Thanks in Advance,

S

** ERROR 

TypeError at /surveys/survey/1/
object_detail() got an unexpected keyword argument 'model'
Request Method: GET
Request URL:http://127.0.0.1:8000/surveys/survey/1/
Exception Type: TypeError
Exception Value:object_detail() got an unexpected keyword argument
'model'
Exception Location:

H:\Programming\Python\Python24\lib\site-packages\django\core\handlers\base.py
in get_response, line 72
Traceback (innermost last)

*
H:\Programming\Python\Python24\lib\site-packages\django\core\handlers\base.py
in get_response
65. # Apply view middleware
66. for middleware_method in self._view_middleware:
67. response = middleware_method(request, callback,
callback_args, callback_kwargs)
68. if response:
69. return response
70.
71. try:
72. response = callback(request, *callback_args,
**callback_kwargs) ...
73. except Exception, e:
74. # If the view raised an exception, run it through exception
75. # middleware, and if the exception middleware returns a
76. # response, use that. Otherwise, reraise the exception.
77. for middleware_method in self._exception_middleware:
78. response = middleware_method(request, e)
  ▶ Local vars

***  URL ***

from django.conf.urls.defaults import *

from bard.survey.models import Survey

info_dict = {'model': Survey}

urlpatterns = patterns('',
(r'^$', 'bard.survey.views.index'),
   #(r'^survey/(?P\d+)/$',
'django.views.generic.list_detail.object_detail')
(r'^survey/(?P\d+)/$',
'django.views.generic.list_detail.object_detail', info_dict)
)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---