Re: User getting inadvertently logged out

2009-06-06 Thread Karen Tracey
On Sat, Jun 6, 2009 at 7:50 PM, metametagirl  wrote:

>
> Hi folks,
> I'm new to Django and web development in general (though I'm
> experienced with Python).  I'm developing two sites on my local
> desktop machine.  Each site is a separate Django site with one app,
> and each site has a separate sqlite3 database file.  I'm experiencing
> the following odd behavior:
>
> - User logs into site A (django.contrib.auth)
> - User logs into site B in another Firefox tab
> - User checks (refreshes) site A -- the user has been logged out
> - User checks site B -- the user has been logged out
>
> I've noticed that if I access site A and site B from different web
> browsers, this issue doesn't occur (i.e. use Firefox for site A,
> Safari for site B).  However, I'd still like to know what the problem
> is and how to fix it so that the user can access both sites in the
> same browser and get the expected behavior!
>

Configure different session cookie names:

http://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-name

for the different apps running on the same server.  As it is it sounds like
the default value 'sessionid' is being used by both and the browser is
keeping just one value for its content, because app A and B are on the same
server.  So when the value for B's sessionid cookie is presented by the
browser to app A, no matching session is found and a new login is requested,
setting a new sessionid cookie value (and thus making it impossible to
access app B without logging in there again).

Karen

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Strange: named URL only works in root urlconf..

2009-06-06 Thread Karen Tracey
On Fri, Jun 5, 2009 at 8:17 AM, gnijholt  wrote:

>
> I've used named URLs for some time now, never had any trouble with
> them.
> But now I have added an app 'website' to a new Django project.
> (version 1.1 beta 1 SVN-10924)
>
> My root urlconf (as defined in settings.py) contains an include to
> website.urls:
> ---
> urlpatterns = patterns('',
>(r'^admin/doc/', include('django.contrib.admindocs.urls')),
>(r'^admin/', include(admin.site.urls)),
>(r'^$', include('website.urls')),
> )
> ---
>

Notice you've specified the regex as r'^$' for the include of
'website.urls'.  So the only thing that is going to match is an empty
string.


>
>
> The included urlconf website.urls looks like this:
> ---
> from django.conf.urls.defaults import *
> from django.contrib.auth.decorators import login_required
> from django.views.generic.simple import direct_to_template
>
> urlpatterns = patterns('',
>url(r'search/', 'website.views.search', name='website-search'),
>url(r'^$', 'website.views.index', name='website-index'),
> )
> ---
>

Yet within it you have an entry for r'search/'.  This won't ever get used
since the only url that will get routed to website.urls is the empty string,
and that won't match r'search/'.  Thus you get:

The problem is that the {% url website-search %} tags don't work. They
> give this error:
> ---
> TemplateSyntaxError at /
> Caught an exception while rendering: Reverse for 'website-search' with
> arguments '()' and keyword arguments '{}' not found.
> ---
>

because there is no way construct a url that will get resolved to the
'website-search' named url as you have it set up.



>
> But if I move the 'search' entry to the root urlconf, it works..
> ---
> urlpatterns = patterns('',
>(r'^admin/doc/', include('django.contrib.admindocs.urls')),
>(r'^admin/', include(admin.site.urls)),
>url(r'search/', 'website.views.search', name='website-search'),
>(r'^$', include('website.urls')),
> )
> ---


It works there because you've removed the constraint that in order to route
to 'website-search' the url must first match the empty string r'^$'.  So now
it is possible to reverse it.


>
> I'd rather have this entry in the included urlconf. This worked in the
> past..
> I don't understand why this won't work. What am I not seeing? Thanks
> for any help!
>

If you want 'website.urls' to handle anything not yet matched in the main
urls file, specify it as:

 (r'', include('website.urls')),

Karen

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Question about login

2009-06-06 Thread David

Your reply is truely helpful!

Thanks Gabriel!


On Jun 6, 7:22 pm, Gabriel  wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA256
>
> David escribió:
>
>
>
>
>
> > Hello,
>
> > Just wonder if anybody has met this. I modified LOGIN_REDIRECT_URL
> > from "accounts/profile" to 'accounts' but Django still re-directs to
> > "accounts/profile" after a user has logined successfully. If
> > LOGIN_REDIRECT_URL is the url for default re-directing, then why it
> > still comes the word "profile"?
>
> > I tried to add that user's login name to the re-directed url but
> > failed. In 'django.contrib.auth.views.login', I added
> > "redirect_to = redirect_to + form.get_user()", however this had no
> > use. If I can append this user's userName to the url, then I can parse
> > the url and retrieve this user's information from database later. So
> > how to you add users' name to the url?
>
> > Can anybody help me? Thanks so much.
>
> mmm, I can't imagine why LOGIN_REDIRECT_URL is not working for you.
> However you can also pass the url with a hidden field called 'next' in
> your login form.
>
> You don't need to parse anything to get the current logged in user, you
> have it available in request.user.
> I recommend you to 
> readhttp://docs.djangoproject.com/en/dev/topics/auth/#authentication-in-w...
>
> Regards.
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v2.0.9 (GNU/Linux)
>
> iEYEAREIAAYFAkorJFwACgkQNHr4BkRe3pKMHgCfepvXlBzGUNH6bzcPG/NCFehf
> sqQAoKr5J22MScuUxXJKYNB7qVJ3soqu
> =KXCc
> -END PGP SIGNATURE-- Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Related Managers and use_for_related_fields strangeness

2009-06-06 Thread Streamweaver

I'll have to look harder at the documentation then as I'm a bit
confuesed.

What I thought was happening was that I would get a Project object (p)
by filtering.

I thought p.release_set returned a query set of Release filtered to
those related to that project and I could just continue to filter down
through the custom manager.

Sorry for any missunderstanding.


> But documentation doesn't say nor imply that there will be
> any automatic (magic?) per-Project filtering of Release querysets generated
> by your manager just because you have set its use_for_related_fields
> to True.
>
> Even further, it recommends against returning filtered querysets whe
>  use_for_related_fields=True.
>
> --
> Ramiro Moraleshttp://rmorales.net
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Type Error str is not callable in base.py

2009-06-06 Thread Alex Gaynor
On Sat, Jun 6, 2009 at 11:05 PM, grElement  wrote:

>
> I found the tickets regarding this error on the bug reports and
> noticed that it comes up when there is something wrong with your view,
> but I can't seem to find anything off. Here is my view.py in that app.
> Weird thing is I'm just copying this over from another project and it
> was working fine there and also this was working fine and I was
> viewing these pages, no problem, and I haven't changed anything on
> this file since it started throwing this error? And yes codes/
> models.py does exist.
>
> from django.http import HttpResponse
> from codes.models import *
> from django.shortcuts import *
>
>
> def tableofcontents(request):
>queryset = get_object_or_404(CodeDocument, pk=1)
>return render_to_response(
>'tableofcontents.html',
>{'queryset' : queryset},
>)
>
>
> def codedocument(request):
>queryset = get_object_or_404(CodeDocument, pk=1)
>return render_to_response(
>'codedocument.html',
>{'queryset' : queryset},
>)
>
> def chapter(request, chapter_number):
>queryset = get_object_or_404(Chapter, number=chapter_number)
>return render_to_response(
>'chapter.html',
>{'queryset' : queryset},
>)
>
> def section(request, chapter_number, section_number):
>queryset = get_object_or_404(Section, number=section_number)
>return render_to_response(
>'section.html',
>{'queryset' : queryset},
>)
>
> def subsection(request, chapter_number, section_number,
> subsection_number,template_name="subsection.html"):
>queryset = get_object_or_404(Subsection, number=subsection_number)
>return render_to_response(
>template_name,
>{'subsection' : queryset},
>)
>
>
> >
>
Are you sure this is being thrown from this file?  Looking through it I
don't see anything that would cause it here.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Type Error str is not callable in base.py

2009-06-06 Thread grElement

I found the tickets regarding this error on the bug reports and
noticed that it comes up when there is something wrong with your view,
but I can't seem to find anything off. Here is my view.py in that app.
Weird thing is I'm just copying this over from another project and it
was working fine there and also this was working fine and I was
viewing these pages, no problem, and I haven't changed anything on
this file since it started throwing this error? And yes codes/
models.py does exist.

from django.http import HttpResponse
from codes.models import *
from django.shortcuts import *


def tableofcontents(request):
queryset = get_object_or_404(CodeDocument, pk=1)
return render_to_response(
'tableofcontents.html',
{'queryset' : queryset},
)


def codedocument(request):
queryset = get_object_or_404(CodeDocument, pk=1)
return render_to_response(
'codedocument.html',
{'queryset' : queryset},
)

def chapter(request, chapter_number):
queryset = get_object_or_404(Chapter, number=chapter_number)
return render_to_response(
'chapter.html',
{'queryset' : queryset},
)

def section(request, chapter_number, section_number):
queryset = get_object_or_404(Section, number=section_number)
return render_to_response(
'section.html',
{'queryset' : queryset},
)

def subsection(request, chapter_number, section_number,
subsection_number,template_name="subsection.html"):
queryset = get_object_or_404(Subsection, number=subsection_number)
return render_to_response(
template_name,
{'subsection' : queryset},
)


--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Question about login

2009-06-06 Thread Gabriel

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

David escribió:
> Hello,
> 
> Just wonder if anybody has met this. I modified LOGIN_REDIRECT_URL
> from "accounts/profile" to 'accounts' but Django still re-directs to
> "accounts/profile" after a user has logined successfully. If
> LOGIN_REDIRECT_URL is the url for default re-directing, then why it
> still comes the word "profile"?
> 
> I tried to add that user's login name to the re-directed url but
> failed. In 'django.contrib.auth.views.login', I added
> "redirect_to = redirect_to + form.get_user()", however this had no
> use. If I can append this user's userName to the url, then I can parse
> the url and retrieve this user's information from database later. So
> how to you add users' name to the url?
> 
> Can anybody help me? Thanks so much.
> 

mmm, I can't imagine why LOGIN_REDIRECT_URL is not working for you.
However you can also pass the url with a hidden field called 'next' in
your login form.

You don't need to parse anything to get the current logged in user, you
have it available in request.user.
I recommend you to read
http://docs.djangoproject.com/en/dev/topics/auth/#authentication-in-web-requests

Regards.
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEAREIAAYFAkorJFwACgkQNHr4BkRe3pKMHgCfepvXlBzGUNH6bzcPG/NCFehf
sqQAoKr5J22MScuUxXJKYNB7qVJ3soqu
=KXCc
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Tricky URL / Reverse Regex

2009-06-06 Thread bimsland

That's most likely what I'm going to do, but from a purely academic
perspective (and because I love using regex to shorten things) I was
hoping someone might have an idea on how to accomplish what I'm going
for without splitting things up. ;)

On Jun 6, 6:42 pm, Alex Gaynor  wrote:
> On Sat, Jun 6, 2009 at 9:39 PM, bimsland  wrote:
>
> > Working on making some URLs on a project of mine ReSTful, and decided
> > to go with the filename extensions route for specifying content-type.
>
> > I've got a view named concerts, and to keep backwards compatibility, I
> > need to make sure the old URLs still work.  I need the urlpattern to
> > match...
>
> > ^/concerts
> > ^/concerts/
> > ^/concerts.html
> > ^/concerts/123
> > ^/concerts/123/
> > ^/concerts/123.html
>
> > The regex I wrote up to do this is...
>
> > ^/concerts(?:/(?P\d+))?(?:/|\.(?P\w{4}))?$
>
> > Which matches everything perfectly when going forward, but any attempt
> > to use reverse fails with a NoReverseMatch exception, any ideas on an
> > alternate regex or the correct way to reverse this?
>
> > The reverse call I'm using is...
>
> > reverse('concerts', kwargs={'id': concert.id, 'format': format})
>
> > Thanks!
>
> Split it up into several regexes which all point to the same view, but have
> different names.  That's going to be the easiest way, and you don't have to
> worry about the complexity of the regex anymore :)
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Tricky URL / Reverse Regex

2009-06-06 Thread Alex Gaynor
On Sat, Jun 6, 2009 at 9:39 PM, bimsland  wrote:

>
> Working on making some URLs on a project of mine ReSTful, and decided
> to go with the filename extensions route for specifying content-type.
>
> I've got a view named concerts, and to keep backwards compatibility, I
> need to make sure the old URLs still work.  I need the urlpattern to
> match...
>
> ^/concerts
> ^/concerts/
> ^/concerts.html
> ^/concerts/123
> ^/concerts/123/
> ^/concerts/123.html
>
> The regex I wrote up to do this is...
>
> ^/concerts(?:/(?P\d+))?(?:/|\.(?P\w{4}))?$
>
> Which matches everything perfectly when going forward, but any attempt
> to use reverse fails with a NoReverseMatch exception, any ideas on an
> alternate regex or the correct way to reverse this?
>
> The reverse call I'm using is...
>
> reverse('concerts', kwargs={'id': concert.id, 'format': format})
>
> Thanks!
>
> >
>
Split it up into several regexes which all point to the same view, but have
different names.  That's going to be the easiest way, and you don't have to
worry about the complexity of the regex anymore :)

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Tricky URL / Reverse Regex

2009-06-06 Thread bimsland

Working on making some URLs on a project of mine ReSTful, and decided
to go with the filename extensions route for specifying content-type.

I've got a view named concerts, and to keep backwards compatibility, I
need to make sure the old URLs still work.  I need the urlpattern to
match...

^/concerts
^/concerts/
^/concerts.html
^/concerts/123
^/concerts/123/
^/concerts/123.html

The regex I wrote up to do this is...

^/concerts(?:/(?P\d+))?(?:/|\.(?P\w{4}))?$

Which matches everything perfectly when going forward, but any attempt
to use reverse fails with a NoReverseMatch exception, any ideas on an
alternate regex or the correct way to reverse this?

The reverse call I'm using is...

reverse('concerts', kwargs={'id': concert.id, 'format': format})

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Question about login

2009-06-06 Thread David

Hello,

Just wonder if anybody has met this. I modified LOGIN_REDIRECT_URL
from "accounts/profile" to 'accounts' but Django still re-directs to
"accounts/profile" after a user has logined successfully. If
LOGIN_REDIRECT_URL is the url for default re-directing, then why it
still comes the word "profile"?

I tried to add that user's login name to the re-directed url but
failed. In 'django.contrib.auth.views.login', I added
"redirect_to = redirect_to + form.get_user()", however this had no
use. If I can append this user's userName to the url, then I can parse
the url and retrieve this user's information from database later. So
how to you add users' name to the url?

Can anybody help me? Thanks so much.


--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: The best hoster to install Django

2009-06-06 Thread Kenneth Gonsalves

On Sunday 07 June 2009 05:14:20 Bro wrote:
> I ask a question : What is the best hoster to install Django ?

http://djangofriendly.com/hosts/   < study them all and remember that you 
have to choose the best for your proposed application:

small - a shared hosting like webfaction
medium - a VPS like slicehost or gandi
large - dedicated server
huge - you would not be asking here ;-)
-- 
regards
kg
http://lawgon.livejournal.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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



User getting inadvertently logged out

2009-06-06 Thread metametagirl

Hi folks,
I'm new to Django and web development in general (though I'm
experienced with Python).  I'm developing two sites on my local
desktop machine.  Each site is a separate Django site with one app,
and each site has a separate sqlite3 database file.  I'm experiencing
the following odd behavior:

- User logs into site A (django.contrib.auth)
- User logs into site B in another Firefox tab
- User checks (refreshes) site A -- the user has been logged out
- User checks site B -- the user has been logged out

I've noticed that if I access site A and site B from different web
browsers, this issue doesn't occur (i.e. use Firefox for site A,
Safari for site B).  However, I'd still like to know what the problem
is and how to fix it so that the user can access both sites in the
same browser and get the expected behavior!

Thanks, your help is appreciated,
mmg (metametagirl)



--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: The best hoster to install Django

2009-06-06 Thread Dj Gilcrease

Webfaction

Dj Gilcrease
OpenRPG Developer
~~http://www.openrpg.com



On Sat, Jun 6, 2009 at 5:44 PM, Bro wrote:
>
> Hi Everyone,
>
> I ask a question : What is the best hoster to install Django ?
> Because Django is a very cool project, I want to buy a Hoster that
> support Django.
>
> 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



The best hoster to install Django

2009-06-06 Thread Bro

Hi Everyone,

I ask a question : What is the best hoster to install Django ?
Because Django is a very cool project, I want to buy a Hoster that
support Django.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Related Managers and use_for_related_fields strangeness

2009-06-06 Thread Ramiro Morales

On Thu, Jun 4, 2009 at 11:41 PM, Streamweaver wrote:
>
> I'm still struggling a bit with related managers.  I have what I think
> should work right by the documentation but behavior isn't as expect.
>
> [...]
>
> I have a Project model which has Releases so Releases have a FK field
> for Projects.  I want to be able to get Releses with particular
> combinations of settings so I created a custom manager for releases.
> It returns the values I want just fine.
>
> My problem is with related sets of releases called from a Project.
> I've used the 'use_for_related_fields' flag as per the official docs
> but if I have a Project p and call p.release_set.in_development() for
> instance, it gives me all Releases in the DB with those flags instead
> of just the ones related to the instance in p.

But documentation doesn't say nor imply that there will be
any automatic (magic?) per-Project filtering of Release querysets generated
by your manager just because you have set its use_for_related_fields
to True.

Even further, it recommends against returning filtered querysets whe
 use_for_related_fields=True.

-- 
Ramiro Morales
http://rmorales.net

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: default settings for applications

2009-06-06 Thread ben

Thanks for the answer.
In particular I'm wondering about apps that will be shared by several
projects.  The
default_settings.py would then be the values of the settings if the
projects don't
override these settings in their DJANGO_SETTINGS_MODULEs.  Effectively
I'm planning
on using something like django.conf.settings but where the defaults
are in the application
itself rather than in django.conf.global_settings.  It sounds like
there's no convention
for something like this.

On Jun 5, 10:46 pm, Ben Davis  wrote:
> I'm not sure that there's a real "standard" for it,  but that's more or less
> what I've done for my projects,  except my multi-environment setup looks
> like this:
>
> settings/
>     __init__.py
>     defaults.py
>     development.py
>     staging.py
>     production.py
>
> all my default/common settings go in defaults.py,  and for each environment
> (development, staging, production) I have  "from defaults import *" at the
> top.   I then set DJANGO_SETTINGS_MODULE to one of the appropriate modules,
> eg: "settings.development".   I'm not sure how standard that is, but it
> works well for me.
>
> On Fri, Jun 5, 2009 at 11:39 PM, ben  wrote:
>
> > I'm wondering if a convention exists for dealing with applications
> > settings.  I'm thinking of having the default  settings to be
> > specified in my application in a default_settings.py file but be
> > overridden by any values in DJANGO_SETTINGS_MODULE.  I can do this
> > easily enough, but it feels like something that might be already
> > standardised.  Does a convention exist, and if so what is it?
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Fwd: nortech

2009-06-06 Thread Ramdas S
-- Forwarded message --
From: Ramdas S 
Date: Sun, Jun 7, 2009 at 2:34 AM
Subject: nortech
To: Dhaval Valia , Bhaswati Das <
bhaswa...@ubmindia.com>




-- 
Ramdas S
+91 9342 583 065




-- 
Ramdas S
+91 9342 583 065

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



nortech.doc
Description: MS-Word document


Re: Related Managers and use_for_related_fields strangeness

2009-06-06 Thread Streamweaver

Cutting down the code sample I gave above in case that helps.  Code
snippet below

Again, my problem is that if I call Release.objects.planning_backlog()
it works and I get all relavant Releases.  If I call
Project.release_set.planning_backlog() I again get all Releases that
fit the filter instead of just the ones related to that Project
instance.

Hopefully that'll help tease out what I'm missing and thanks again.

class ReleaseManager(models.Manager):
use_for_related_fields = True

def planning_backlog(self):
return super(ReleaseManager, self).get_query_set().filter
(development_status__in=self.DEV_REVIEW)

...

class Project(models.Model):
title = models.CharField(max_length=141)
...


class Release(models.Model):
project_fk = models.ForeignKey(Project)
title = models.CharField(max_length=141)
...

# Add my custom manager.
objects = ReleaseManager()


--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Related Managers and use_for_related_fields strangeness

2009-06-06 Thread Streamweaver

No insights at all in the group?
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to switch of autosaving for a m2m-relationship

2009-06-06 Thread Julian

hi russell,

thanks, this is what I've found studying the code but not in the
documentation. thanks a lot!
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



OT: running custom management command from cron & Unicode output error

2009-06-06 Thread Carlos A. Carnero Delgado

Hi there!

I'm having a problem with a custom management command. Running
interactively on the console will work perfectly, merrily printing its
output in Unicode (I need that; accented characters among other
things).

But, if I put that command in a cron job, it will fail with

  UnicodeEncodeError: 'ascii' codec can't encode character

(getting those from cron's email messages). I *think* it's because the
interactive environment is different from cron's. I've tried putting a
LANG=en_US.UTF-8 into cron's (dunno if that's Ubuntu specific) but I'm
getting the same error.

Any ideas?

Best regards,
Carlos.

  >>> import sys
  >>> print sys.platform
  linux2
  >>> print sys.version
  2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
  [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)]'
  >>> import django
  >>> django.VERSION
  (1, 1, 0, 'beta', 1)

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bulk get

2009-06-06 Thread Daniel Roseman



On Jun 6, 4:13 pm, Andrew Fong  wrote:
> Was hoping not to have to loop back through it -- but I guess I'll
> just have to suck it up and do it. Thanks.
>

If you've got the order already in model_pk_list, you can use the
order_by parameter to .extra() to get the results in that order
straight from the database.

x = MyModel.objects.filter(pk__in=model_pk_list).extra
(order_by=model_pk_list)

This works for MySQL at least, not sure about other backends.
--
DR.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to deal with object that have out of date querysets

2009-06-06 Thread AlexM

Thats what i was looking for , thanks guys .

On Jun 6, 6:10 pm, Andrew Fong  wrote:
> What you're dealing with is called a "race condition". Transactions
> ensure that a set of database operations occur together in a single
> uninterrupted unit. That's not quite the exact definition, but if
> you're picky, see this:http://en.wikipedia.org/wiki/Database_transaction
>
> You can find documentation of Django's support for transactions 
> here:http://docs.djangoproject.com/en/dev/topics/db/transactions/
>
> Note that this is dependent on your database supporting transactions.
> If whatever reason your DB doesn't (e.g. using MySQL's MyISAM tables),
> I think using Django's update call will work. Calling
> MyModel.objects.filter(value=10, id=my_id).update(value=15) will
> update the record with the given id to have a value of 15 if and only
> if it's current value is already 10. It returns the number of records
> it successfully modifies, so if there was no conflict, it'll return 1.
> If it returns 0, you know that another process changed the value first
> and that you'll need to get the new value to increment from the
> database again.
>
> -- Andrew
>
> On Jun 6, 10:26 am, Masklinn  wrote:
>
> > On 6 juin 09, at 15:34, AlexM  wrote:
>
> > > In one of my views i am using a custom manager , the custom manager
> > > finds a user , alters his "balance" (where balance is an integer
> > > value) , and then saves the user with the new balance.
>
> > > The problem occurs when http requests coming really fast on that
> > > view.
>
> > > Lets say the "original" value of a users balance is 10 .
> > > Two requests are made , each one asking for the users balance to be
> > > credited plus 5 of the original one.
> > > The "perfect" solution would be the first requests to be
> > > processed ,saved and then the second to do the same.
>
> > > However what happens is that the first request will come , it will do
> > > its query and load the object , and the second request will also do
> > > the query before the first request was able to complete the process of
> > > saving the new balance, because of that the second request will have
> > > and "out of date" balance which it will then save . So in the end the
> > > user will have 10 (origina ballance) + 5 (second request) = 15 on his
> > > balance when he should have 20.
>
> > > What could i do to prevent this from happening ?
>
> > Use transactions?
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to deal with object that have out of date querysets

2009-06-06 Thread Tomasz Zieliński



On 6 Cze, 17:05, Alex Gaynor  wrote:
> 2009/6/6 Tomasz Zieliński 
>
>
>
> > On 6 Cze, 16:26, Masklinn  wrote:
>
> > > Use transactions?
>
> > Or use atomic SQL increment - bypassing Django ORM,
> > if speed is main concern here.
>
>
> In the development version Django's ORM can do atomic SQL 
> operations:http://docs.djangoproject.com/en/dev/topics/db/queries/#updating-mult...
>

Good to know!

--
Tomasz Zieliński
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bulk get

2009-06-06 Thread Andrew Fong

Was hoping not to have to loop back through it -- but I guess I'll
just have to suck it up and do it. Thanks.

On Jun 6, 11:04 am, Michael  wrote:
> On Sat, Jun 6, 2009 at 10:55 AM, Andrew Fong  wrote:
>
> > Hi all,
>
> > I'm trying to figure out how to do this and can't seem to wrap my head
> > around it today. I have currently have a piece of code like this:
>
> > x = [MyModel.objects.get(pk=pk) for pk in model_pk_list]
>
> x = MyModel.objects.filter(pk__in=model_pk_list)
>
> Does this in one db call, returns a queryset so it is lazy. As for the
> order, this will come back as the default ordering of the model. You can
> change the ordering based on something else by using the .order_by on the
> queryset. otherwise you would have to loop through it and create an ordered
> list based on your arbitrary ordering.
>
> Hope that helps,
>
> Michael
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to deal with object that have out of date querysets

2009-06-06 Thread Andrew Fong

What you're dealing with is called a "race condition". Transactions
ensure that a set of database operations occur together in a single
uninterrupted unit. That's not quite the exact definition, but if
you're picky, see this: http://en.wikipedia.org/wiki/Database_transaction

You can find documentation of Django's support for transactions here:
http://docs.djangoproject.com/en/dev/topics/db/transactions/

Note that this is dependent on your database supporting transactions.
If whatever reason your DB doesn't (e.g. using MySQL's MyISAM tables),
I think using Django's update call will work. Calling
MyModel.objects.filter(value=10, id=my_id).update(value=15) will
update the record with the given id to have a value of 15 if and only
if it's current value is already 10. It returns the number of records
it successfully modifies, so if there was no conflict, it'll return 1.
If it returns 0, you know that another process changed the value first
and that you'll need to get the new value to increment from the
database again.

-- Andrew

On Jun 6, 10:26 am, Masklinn  wrote:
> On 6 juin 09, at 15:34, AlexM  wrote:
>
>
>
> > In one of my views i am using a custom manager , the custom manager
> > finds a user , alters his "balance" (where balance is an integer
> > value) , and then saves the user with the new balance.
>
> > The problem occurs when http requests coming really fast on that
> > view.
>
> > Lets say the "original" value of a users balance is 10 .
> > Two requests are made , each one asking for the users balance to be
> > credited plus 5 of the original one.
> > The "perfect" solution would be the first requests to be
> > processed ,saved and then the second to do the same.
>
> > However what happens is that the first request will come , it will do
> > its query and load the object , and the second request will also do
> > the query before the first request was able to complete the process of
> > saving the new balance, because of that the second request will have
> > and "out of date" balance which it will then save . So in the end the
> > user will have 10 (origina ballance) + 5 (second request) = 15 on his
> > balance when he should have 20.
>
> > What could i do to prevent this from happening ?
>
> Use transactions?
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to deal with object that have out of date querysets

2009-06-06 Thread Alex Gaynor
2009/6/6 Tomasz Zieliński 

>
>
>
> On 6 Cze, 16:26, Masklinn  wrote:
>
> > Use transactions?
>
> Or use atomic SQL increment - bypassing Django ORM,
> if speed is main concern here.
>
> --
> Tomasz Zieliński
> http://pyconsultant.eu
> >
>
In the development version Django's ORM can do atomic SQL operations:
http://docs.djangoproject.com/en/dev/topics/db/queries/#updating-multiple-objects-at-once

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bulk get

2009-06-06 Thread Michael
On Sat, Jun 6, 2009 at 10:55 AM, Andrew Fong  wrote:

>
> Hi all,
>
> I'm trying to figure out how to do this and can't seem to wrap my head
> around it today. I have currently have a piece of code like this:
>
> x = [MyModel.objects.get(pk=pk) for pk in model_pk_list]
>

x = MyModel.objects.filter(pk__in=model_pk_list)

Does this in one db call, returns a queryset so it is lazy. As for the
order, this will come back as the default ordering of the model. You can
change the ordering based on something else by using the .order_by on the
queryset. otherwise you would have to loop through it and create an ordered
list based on your arbitrary ordering.

Hope that helps,

Michael

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to deal with object that have out of date querysets

2009-06-06 Thread Tomasz Zieliński



On 6 Cze, 16:26, Masklinn  wrote:

> Use transactions?

Or use atomic SQL increment - bypassing Django ORM,
if speed is main concern here.

--
Tomasz Zieliński
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Bulk get

2009-06-06 Thread Andrew Fong

Hi all,

I'm trying to figure out how to do this and can't seem to wrap my head
around it today. I have currently have a piece of code like this:

x = [MyModel.objects.get(pk=pk) for pk in model_pk_list]

I want to modify this such that ...
* Everything is done with one call to the DB instead len
(model_pk_list) calls
* x is lazily-evaluated (e.g. like a QuerySet object)
* The results come back in the same order as they are in model_pk_list

Is this possible? Thanks in advance!


-- Andrew
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Customizing extends template tag for mobile version of site

2009-06-06 Thread Andrew Fong

I thought about doing that, but the problem with that approach is it
sort of violates the distinction between developer and designer that
the Django template system establishes. I'm not sure having the
designer muck around in Python to change which template their design
extends is a good idea.

I've come up with a somewhat hackish approach to this though. There
are three pieces to this:
1) You adopt a naming convention with mobile templates -- e.g. the
mobile version of bob.html would bob.html.m. Or something. Your
choice.
2) Instead of setting a mobile variable in the context, set it in some
global.
3) Write a custom template loader that checks said global variable and
gets a modified template according to naming convention if the mobile
variable evaluates to True.

I'm not a huge fan of that -- first, not a fan of forced naming
conventions that the designer can't easily change. Second, that global
variable could potentially pollute other requests. You basically have
to ensure it's reset for every request (e.g. using middleware) and
mark that piece of code as not thread safe.

Any suggestions?

-- Andrew

On Jun 6, 6:29 am, Matthias Kestenholz 
wrote:
> On Fri, Jun 5, 2009 at 6:35 PM, Andrew Fong  wrote:
>
> > I was hoping someone could explain to me what the exact behavior would
> > be if the Extends Node in the template was not first.
>
> > Here's my use-case scenario: I need to maintain separate mobile and
> > desktop templates for my site. I'm finding out that 90% of my
> > templates would be identical -- the only difference would be which
> > templates they extended from -- e.g. {% extends 'base.html' %} vs. {%
> > extends 'm_base.html' %}.
>
> > My views insert a mobile variable into the context if they think the
> > user-agent is a mobile device. So I want behavior like this:
>
> > {% if mobile_var %}
> >  {% extends 'm_base.html' %}
> > {% else %}
> >  {% extends 'base.html' %}
> > {% endif %}
>
> > This won't work because the the extends tag doesn't really understand
> > the {% if %} tag above it and just throws up when it comes to the {%
> > else %} tag. So as an alternative, I plan to encapsulate that logic in
> > a custom extends tag -- e.g. {% mextends mobile_var 'm_base.html'
> > 'base.html' %} that wraps the existing do_extends function.
>
> > When going over the ExtendNode source code however, I noticed it has
> > to be first. However, in order to use my custom tag, I need to call {%
> > load %}, and that call means any ExtendNode created after that can't
> > be first. I'm tempted to simply disable that, but I'm not really sure
> > what will happen if I do. Are there any problems with calling a load
> > tag before an extends?
>
> I don't know the answer to your question, but here is a suggestion how
> you might accomplish using a different base template for the mobile
> version of your site. The extends tag accepts a variable too, so you
> could just use a context processor to pass the base template into the
> renderer, something like this (in pseudo-code):
>
> def base_template(request):
>      return {'base_template': is_mobile(request) and 'm_base.html' or
> 'base.html'}
>
> And inside your templates, use:
> {% extends base_template %}
>
> Matthias
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to deal with object that have out of date querysets

2009-06-06 Thread Masklinn

On 6 juin 09, at 15:34, AlexM  wrote:
> In one of my views i am using a custom manager , the custom manager
> finds a user , alters his "balance" (where balance is an integer
> value) , and then saves the user with the new balance.
>
> The problem occurs when http requests coming really fast on that
> view.
>
> Lets say the "original" value of a users balance is 10 .
> Two requests are made , each one asking for the users balance to be
> credited plus 5 of the original one.
> The "perfect" solution would be the first requests to be
> processed ,saved and then the second to do the same.
>
> However what happens is that the first request will come , it will do
> its query and load the object , and the second request will also do
> the query before the first request was able to complete the process of
> saving the new balance, because of that the second request will have
> and "out of date" balance which it will then save . So in the end the
> user will have 10 (origina ballance) + 5 (second request) = 15 on his
> balance when he should have 20.
>
> What could i do to prevent this from happening ?
>
Use transactions?

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Feedbacks and recommendations about test coverage tools

2009-06-06 Thread Michelschr

Here is another interesting link:

http://siddhi.blogspot.com/2007/04/code-coverage-for-your-django-code.html

It's a bit old, but it points itself to other interesting links (read
the comments also...)

After reading and testing a bit all these things, I arrive for the
moment at the conclusion that we will have some work to integrate
different parts, but at the end, this will give more flexibility...

I would like to be able to take into account the coverage from
'external' tests also, like web browsing or Selenium scripts... Thus I
need to be able to start and stop manually the recording of
coverage.py (Ned Batchelder) Hope it will be possible... On the other
hand, with this approach, the integration with the Django test support
is not that important...

After that, it's nice to have a copy of the source coloured to see
what part was covered by the tests. That can probably be done with the
code mentioned in the link above.

I spend (loosed) some time testing the coverage functionality in
Netbeans 6.7RC... It worked a bit, but only for doctests (in my OS:
ubuntu)... At the end, it don't worked anymore!! (Menu in grey!!) It
was never possible to mention something like a test root directory
that it maybe need to take more test into account... I still like
Netbeans (for example for the integration with svn)  but will stay in
6.5.

That the progress on my side...

And I still would really appreciate recommendations and feedbacks from
experimented group members.

Thanks in advance,

Michel



On Jun 6, 12:11 pm, kRON  wrote:
> Thanks for posting the links, I'll be sure to try and test it during
> the weekend.
>
> On Jun 5, 1:37 pm, Michelschr  wrote:
>
> > Hello everyone,
>
> > What are the current trends about the best test coverage tools to use
> > with Django?
> > Do you have feedback or recommendations for me?
>
> > Up to now, I founded this links:
>
> >http://opensource.55minutes.com/trac/browser/python/trunk/django/apps...
>
> > and I would be happy if I can receive some light from the community
> > before digging further.
>
> > Thanks in advance,
>
> > Michel
>
>
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to deal with object that have out of date querysets

2009-06-06 Thread AlexM

In one of my views i am using a custom manager , the custom manager
finds a user , alters his "balance" (where balance is an integer
value) , and then saves the user with the new balance.

The problem occurs when http requests coming really fast on that
view.

Lets say the "original" value of a users balance is 10 .
Two requests are made , each one asking for the users balance to be
credited plus 5 of the original one.
The "perfect" solution would be the first requests to be
processed ,saved and then the second to do the same.

However what happens is that the first request will come , it will do
its query and load the object , and the second request will also do
the query before the first request was able to complete the process of
saving the new balance, because of that the second request will have
and "out of date" balance which it will then save . So in the end the
user will have 10 (origina ballance) + 5 (second request) = 15 on his
balance when he should have 20.

What could i do to prevent this from happening ?

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to switch of autosaving for a m2m-relationship

2009-06-06 Thread Russell Keith-Magee

On Sat, Jun 6, 2009 at 5:11 PM, Julian wrote:
>
> hello,
>
> i have a queryset and a model with a manytomany-relationship, let's
> say a pizza has toppings.
>
> my pizza margharita has already some toppings and now i retrieve a
> queryset of some more and want to add them to the pizza:
>
> for topping in toppings:
>    pizza.toppings.add(topping)
>
> the problem is: everytime i call add, the pizza is stored again in the
> database and an insert statement is done. how can I avoid this? for my
> case it would be much better if I could do something like:
>
> pizza.toppings.add(toppings)
>
> to add all toppings in one step.

You're very close:

pizza.toppings.add(*toppings)

will do exactly what you want, and will be executed as a single
insert. The '*' operator effectively unrolls the toppings list into a
series of arguments - essentially, this call is the equivalent of
saying:

pizza.toppings.add(toppings[0], toppings[1], toppings[2],...

but without actually needing to know the number of toppings in advance.

Alternatively, you can completely overwrite the existing set of
toppings with a new set:

pizza.toppings = toppings

This will be issued as a delete and an insert - a delete to remove
existing items, and an insert to add the new items.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Customizing extends template tag for mobile version of site

2009-06-06 Thread Matthias Kestenholz

On Fri, Jun 5, 2009 at 6:35 PM, Andrew Fong  wrote:
>
> I was hoping someone could explain to me what the exact behavior would
> be if the Extends Node in the template was not first.
>
> Here's my use-case scenario: I need to maintain separate mobile and
> desktop templates for my site. I'm finding out that 90% of my
> templates would be identical -- the only difference would be which
> templates they extended from -- e.g. {% extends 'base.html' %} vs. {%
> extends 'm_base.html' %}.
>
> My views insert a mobile variable into the context if they think the
> user-agent is a mobile device. So I want behavior like this:
>
> {% if mobile_var %}
>  {% extends 'm_base.html' %}
> {% else %}
>  {% extends 'base.html' %}
> {% endif %}
>
> This won't work because the the extends tag doesn't really understand
> the {% if %} tag above it and just throws up when it comes to the {%
> else %} tag. So as an alternative, I plan to encapsulate that logic in
> a custom extends tag -- e.g. {% mextends mobile_var 'm_base.html'
> 'base.html' %} that wraps the existing do_extends function.
>
> When going over the ExtendNode source code however, I noticed it has
> to be first. However, in order to use my custom tag, I need to call {%
> load %}, and that call means any ExtendNode created after that can't
> be first. I'm tempted to simply disable that, but I'm not really sure
> what will happen if I do. Are there any problems with calling a load
> tag before an extends?
>


I don't know the answer to your question, but here is a suggestion how
you might accomplish using a different base template for the mobile
version of your site. The extends tag accepts a variable too, so you
could just use a context processor to pass the base template into the
renderer, something like this (in pseudo-code):


def base_template(request):
 return {'base_template': is_mobile(request) and 'm_base.html' or
'base.html'}


And inside your templates, use:
{% extends base_template %}



Matthias

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Feedbacks and recommendations about test coverage tools

2009-06-06 Thread kRON

Thanks for posting the links, I'll be sure to try and test it during
the weekend.

On Jun 5, 1:37 pm, Michelschr  wrote:
> Hello everyone,
>
> What are the current trends about the best test coverage tools to use
> with Django?
> Do you have feedback or recommendations for me?
>
> Up to now, I founded this links:
>
> http://opensource.55minutes.com/trac/browser/python/trunk/django/apps...http://pypi.python.org/pypi/django-test-coverage/
>
> and I would be happy if I can receive some light from the community
> before digging further.
>
> Thanks in advance,
>
> Michel
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django SVN vs. stable

2009-06-06 Thread Tomasz Zieliński

Hello

On 6 Cze, 10:50, "K.Berkhout"  wrote:
> Hi,
>
> I'm about to start a new project using Django.
> Do you recommend me to start with the stable release and convert to
> 1.1 later, or would it be better to start with the development SVN
> version?

According to this:

http://www.djangoproject.com/weblog/2009/may/07/django-1-1-update/

there are still some bugs in SVN version
- so you should probably check bug tickets
to get the idea of what is broken and if it can
influence your project or not.

--
Tomasz Zieliński
http://pyconsultant.eu

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django SVN vs. stable

2009-06-06 Thread Masklinn

On 6 Jun 2009, at 10:50 , K.Berkhout wrote:
> Hi,
>
> I'm about to start a new project using Django.
> Do you recommend me to start with the stable release and convert to
> 1.1 later, or would it be better to start with the development SVN
> version?
>
> Thanks,
>
> Kevin

I'd say it depends on two things:

* your needs, if there are things in svn/1.1 that would make your life  
easier/that you need (e.g. aggregates, abstract models) then you might  
want to go 1.1 for simplicity's sake (though do check the 1.1 blocker  
bugs to ensure that there's a low chance you'll run into them)

* you release timeframe, if you want to release the site in 2 weeks  
1.1 most likely won't have landed, but if you have 3 months then you  
have a chance of seeing the official 1.1 before your project's release


--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



how to switch of autosaving for a m2m-relationship

2009-06-06 Thread Julian

hello,

i have a queryset and a model with a manytomany-relationship, let's
say a pizza has toppings.

my pizza margharita has already some toppings and now i retrieve a
queryset of some more and want to add them to the pizza:

for topping in toppings:
pizza.toppings.add(topping)

the problem is: everytime i call add, the pizza is stored again in the
database and an insert statement is done. how can I avoid this? for my
case it would be much better if I could do something like:

pizza.toppings.add(toppings)

to add all toppings in one step.

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django SVN vs. stable

2009-06-06 Thread K.Berkhout

Hi,

I'm about to start a new project using Django.
Do you recommend me to start with the stable release and convert to
1.1 later, or would it be better to start with the development SVN
version?

Thanks,

Kevin
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---