Re: Two ForeignKeys to show a combo in admin

2010-10-25 Thread derek
You'll need to use AJAX - I suggest you look at:
http://www.texotela.co.uk/code/jquery/select/

There are also other ways of pre-filtering a model's choices... have a
look at:
http://www.stereoplex.com/blog/filtering-dropdown-lists-in-the-django-admin
and
http://www.artfulcode.net/articles/runtime-choicefield-filtering-in-djangos-admin/

On Oct 23, 4:58 pm, Alexandre González  wrote:
> Hi! I have a model as this:
>
> class User:
>    id
>
> class Type:
>    user = ForeignKey(User)
>
> class B:
>    user = ForeignKey(User)
>    type = ForeignKey(Type)
>
> When I'm creating a B object in the admin I like to show a combo with all
> the users, and after select the user in the first combo, fill the second
> combo only with Type of their users...
>
> I must do that with ajax and subquerys? or admin.py allow me to do this
> easily?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Slug auto-complete after save

2010-10-25 Thread Alex
File "admin_modify.py" method "def prepopulated_fields_js(context)"
Line 11:

if context['add'] and 'adminform' in context:

should be changed to

if 'adminform' in context:

to allow slug be auto updated every time and not only on the entity
creation in admin.

Is there any setting to do it without changing Django internal source
code?

On 24 Жов, 18:29, Alex  wrote:
> Hi all,
>
> Slug autocomplete feature is really cool with:
>
> prepopulated_fields = {'slug':('title',)}
>
> Is it possible to prepopulating slug field even after save - when I
> want to change title for example?
>
> Actually I use django-multilingual and prepopulating of slug works
> only for the first language (en for example), when I switch to another
> language tab (es for example) - the entity is already saved and I have
> now prepopulating for Spanish language.
>
> Is it possible to solve this issue somehow?
>
> 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-us...@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: inheriting User class

2010-10-25 Thread Miguel Araujo
Thanks Rob,

I'm using the same approach here, but I don't really like to access some of
my fields in the template doing `user.get_profile.field` I would simply love
to do `user.field`. Also Sometimes I'm pointing to my profile instead of
User, to access the extra information so queries become more obscure and
less elegant if I need to access User though my Profile
 `userprofile__user__username__exact`

If there is no better option, I will try to wrap everything in some helpers,

Regards,
Miguel Araujo

2010/10/25 Rob 

> Probably most of us are using the separate profile model, as
> recommended.
>
> I actually have multiple models associated with users on one project:
>
> User (from auth)
> UserInfo (things rarely accessed such as address, emergency contact
> info, etc.)
> UserProfile (my application specific profile)
>
> I'm going to break UserProfile into EmployeeProfile and StudentProfile
> at some point or keep UserProfile add the other two profile types.
> Depends on how looking into Django model polymorphism goes :-)
>
> I prefer the separation of profile and login in my case.  Many
> students do not want or need logins to the system.
>
>
>
>
> On Oct 24, 6:32 am, Miguel Araujo  wrote:
> > ¿no one knows anything about this?
> >
> > Thanks, regards
> > Miguel Araujo
> >
> > 2010/10/22 Miguel Araujo 
> >
> >
> >
> >
> >
> >
> >
> > > Hello everyone,
> >
> > > I'm not very aware about what's the direction Django is taking about
> the
> > > User model and making it swappable. Meanwhile I would like to ask if
> > > inheriting the User class is advisable or not. As I have read many
> places
> > > obscure bugs can happen and my code will be in production.
> >
> > > I'm using now an AUTH_PROFILE_MODULE at the moment, but I don't realy
> like
> > > this approach, as it makes my class hierarchy more complicated.
> >
> > > Thanks, best regards
> > > Miguel Araujo
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: possible bug in joining on a geo field

2010-10-25 Thread Miguel Araujo
Should I report it? who should I contact? Anyone can confirm this is a bug?

2010/10/23 Miguel Araujo 

> Thanks Karen, you are right. But I missed the underscore for sending this,
> although I was trying here with double underscore:
>
> So If I do it right:
>
> Item.objects.filter(location__point__distance__lte = (point, D(km=10)))
>
> I get:
>
> FieldError: Join on field 'point' not permitted. Did you misspell
> 'distance' for the lookup type?
>
> So it's still not working.
>
> Regards,
> Miguel Araujo
>
> 2010/10/23 Karen Tracey 
>
> On Sat, Oct 23, 2010 at 1:07 PM, Miguel Araujo wrote:
>>
>>> Item.objects.filter(location__point__distance_lte = (point, D(km=10)))
>>>
>>
>> Looks like you are missing an underscore in distance__lte
>>
>> Karen
>> --
>> http://tracey.org/kmt/
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@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.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Slug auto-complete after save

2010-10-25 Thread Piotr Kilczuk
Hi Alex,

2010/10/25 Alex 

> File "admin_modify.py" method "def prepopulated_fields_js(context)"
> Line 11:
>
> if context['add'] and 'adminform' in context:
>
> should be changed to
>
> if 'adminform' in context:
>
> to allow slug be auto updated every time and not only on the entity
> creation in admin.
>
> Is there any setting to do it without changing Django internal source
> code?


Well, yes, you should not modify source code of external project unless you
have a really good reason to.

A way to fix this would be to write your own field type or at least own
widget. My approach to 'slugification' is CentralniakSlugField (
http://github.com/centralniak/django-centralniak-slugfield). It does not
allow real-time js autoslugs (slug are done in background when saving)
however, since the widget is a simple text field.

I guess there might already be a better slug solution on the web.

Regards, PK

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 same table in 2 apps

2010-10-25 Thread robos85
Yes that's exactly what I mean. I have defined class "Links" in one of
the app, and want to use it in another app (user profile) to show all
user's links.
After reading this links I see, that there's nothing wrong in linking
models from another apps. I read that part of manual, but I didn't
remember that part of manual:
"It's perfectly OK to relate a model to one from another app."

So thanks for your links.

On 23 Paź, 19:51, werefr0g  wrote:
> Hello,
>
> You have defined "MyClass" for "foo" application in its models.py, and
> you want to use that class in your application "bar"?
>
> You'll find how to use models from another app in Django documentation
> [1]. A widly spread example is the import of User in your app from
> django.contrib.auth [2]. By searching the web for "from
> django.contrib.auth import User", I found a discussion about the best
> way to import [3].
>
> Regards
>
> [1]http://docs.djangoproject.com/en/dev/topics/db/models/#models-across-...
> [2]http://docs.djangoproject.com/en/dev/topics/auth/#module-django.contr...
> [3]http://stackoverflow.com/questions/1704058/python-and-django-best-imp...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Two ForeignKeys to show a combo in admin

2010-10-25 Thread Alexandre González
Thanks derek! I will test it ASAP :)

On Mon, Oct 25, 2010 at 09:41, derek  wrote:

> You'll need to use AJAX - I suggest you look at:
> http://www.texotela.co.uk/code/jquery/select/
>
> There are also other ways of pre-filtering a model's choices... have a
> look at:
> http://www.stereoplex.com/blog/filtering-dropdown-lists-in-the-django-admin
> and
>
> http://www.artfulcode.net/articles/runtime-choicefield-filtering-in-djangos-admin/
>
> On Oct 23, 4:58 pm, Alexandre González  wrote:
> > Hi! I have a model as this:
> >
> > class User:
> >id
> >
> > class Type:
> >user = ForeignKey(User)
> >
> > class B:
> >user = ForeignKey(User)
> >type = ForeignKey(Type)
> >
> > When I'm creating a B object in the admin I like to show a combo with all
> > the users, and after select the user in the first combo, fill the second
> > combo only with Type of their users...
> >
> > I must do that with ajax and subquerys? or admin.py allow me to do this
> > easily?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>


-- 
@agonzalezro 
Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
and/or .pptx

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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-paypal

2010-10-25 Thread Venkatraman S
Hi,

I am using dcramer's version of django-paypal(but i think it shouldnt matter
whether it is dcramer or johnboxall's).

How can i specify multiple items in my paypal_dict(to be used in
PayPalPaymentsForm)? I need to suitably specify the shipping cost and the
individual quantities in the Summary that appears in the Paypal screen - how
do i do this? As of now, the intial_dict takes only ONE item and ONE amount.
-V

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 display image in django template

2010-10-25 Thread d
Hi all
I have been searching for solutions whole day.
How would I display image file in django template. I have already set
MEDIA_ROOT and MEDIA_URL.

Can some one show a step by step instruction as it will help a lot of
other people.

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-us...@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 display image in django template

2010-10-25 Thread Venkatraman S
On Mon, Oct 25, 2010 at 4:04 PM, d  wrote:

> I have been searching for solutions whole day.
> How would I display image file in django template. I have already set
> MEDIA_ROOT and MEDIA_URL.
>


You mean image as in static image or from Image model?
If static image, then this is the process:
- lets say image is in ProjectNameFolder/static/images/img1.jpeg
- Have this in your settings.py
import os.path
BASE_PATH = os.path.dirname(__file__)
SITE_ROOT = BASE_PATH
STATIC_DOC_ROOT = BASE_PATH+'/static'
-  In your urls.py:

if settings.DEBUG:
urlpatterns += patterns('',
(r'^static/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_DOC_ROOT}),
)

- in your template 

This should work. Note that this serves the static content from the django
dev server and should be used purely in your dev env.

-V-
http://twitter.com/venkasub

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 display image in django template

2010-10-25 Thread Kenneth Gonsalves
On Mon, 2010-10-25 at 03:34 -0700, d wrote:
> I have been searching for solutions whole day.
> How would I display image file in django template. I have already set
> MEDIA_ROOT and MEDIA_URL. 

assume a model:

Mymodel(models.Model):
photo = models.ImageField("somename",upload_to="images/")

get an instance:

myob = Mymodel.objects.get(pk=1)

in your template:


-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS at AU-KBC

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Security

2010-10-25 Thread cootetom
Hi, a firefox extension was recently released to grab session ID
cookies from a private network for the popular sites like facebook etc
You can read about it here http://goo.gl/x4Z1

I was wondering how Django sits with this type of attack. I know there
are the CSRF tokens, do they prevent this though? I thought they were
just for form posts?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 can i wsdl file in my django

2010-10-25 Thread sami nathan
Can i use RESTfull insted of SOAP service

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 can i wsdl file in my django

2010-10-25 Thread Brian Bouterse
yes

Maybe next time put a little more effort into writing your response and
you'll get a better answer.

On Mon, Oct 25, 2010 at 6:58 AM, sami nathan  wrote:

> Can i use RESTfull insted of SOAP service
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Security

2010-10-25 Thread Brian Bouterse
I'm not an expert in security, but here is how I would answer the question.
 The CSRF approach that Django 1.2 implements would prevent *most* of these
problems since the attack wouldn't be able to POST new data to the site by
stealing the cookie alone.  IBM applies CSRF tags to each step the user
interacts with on the entire site, in a technique known as
continuations.
 These techniques only prevent *most* attacks though, the session can still
be hijacked just with a reduced window of opportunity.

I say *most* because if you can snoop on the HTTP traffic, you theoretically
could capture the in-plain-text CSRF token the server handed the user once
they were generated one (from being on a user account to reset my password
page).  An attacker could form a valid POST using the CSRF just captured and
I think it would work.

Not even validating that the IP is the same for each CSRF would solve the
problem either considering these two users are probably going to be in a
coffeeshop, behind a NAT.

One possible solution would be to have some kind of hardware attestation or
browser attestation and tie session info to that.  If anyone has any
thoughts on how this could be done, please let me know.

Brian

On Mon, Oct 25, 2010 at 6:47 AM, cootetom  wrote:

> Hi, a firefox extension was recently released to grab session ID
> cookies from a private network for the popular sites like facebook etc
> You can read about it here http://goo.gl/x4Z1
>
> I was wondering how Django sits with this type of attack. I know there
> are the CSRF tokens, do they prevent this though? I thought they were
> just for form posts?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>


-- 
Brian Bouterse
ITng Services

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Security

2010-10-25 Thread Tom Evans
On Mon, Oct 25, 2010 at 1:17 PM, Brian Bouterse  wrote:
> I'm not an expert in security, but here is how I would answer the question.
>  The CSRF approach that Django 1.2 implements would prevent *most* of these
> problems since the attack wouldn't be able to POST new data to the site by
> stealing the cookie alone.  IBM applies CSRF tags to each step the user
> interacts with on the entire site, in a technique known as continuations.
>  These techniques only prevent *most* attacks though, the session can still
> be hijacked just with a reduced window of opportunity.
> I say *most* because if you can snoop on the HTTP traffic, you theoretically
> could capture the in-plain-text CSRF token the server handed the user once
> they were generated one (from being on a user account to reset my password
> page).  An attacker could form a valid POST using the CSRF just captured and
> I think it would work.
> Not even validating that the IP is the same for each CSRF would solve the
> problem either considering these two users are probably going to be in a
> coffeeshop, behind a NAT.
> One possible solution would be to have some kind of hardware attestation or
> browser attestation and tie session info to that.  If anyone has any
> thoughts on how this could be done, please let me know.
> Brian
> On Mon, Oct 25, 2010 at 6:47 AM, cootetom  wrote:

It's actually orthogonal to CSRF. CSRF protects you from a 3rd party
web site maliciously enticing a user to initiate data changing
requests to your site. It does nothing to protect a user from having
their cookies jacked by a 3rd party user, and then stopping that user
from maliciously using the credentials inferred from those cookies.

That this is even news is surprising - it's hardly a new attack
vector. The only new thing about it is it being hooked up to a web
browser and showing live feeds of what is happening, which has
probably opened the eyes of people who didn't think about it before.
It's like saying 'Oh wow, you can see in plain text peoples emails on
unsecured wifi networks' - well, durr, its a plain text protocol, and
the whole 'unsecured nework' bit should probably give it away...

If you don't want this to happen, then force the use of SSL throughout
your site, and don't hand out session cookies over HTTP.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Security

2010-10-25 Thread Brian Bouterse
Thanks for the info!

Brian

On Mon, Oct 25, 2010 at 8:44 AM, Tom Evans  wrote:

> On Mon, Oct 25, 2010 at 1:17 PM, Brian Bouterse 
> wrote:
> > I'm not an expert in security, but here is how I would answer the
> question.
> >  The CSRF approach that Django 1.2 implements would prevent *most* of
> these
> > problems since the attack wouldn't be able to POST new data to the site
> by
> > stealing the cookie alone.  IBM applies CSRF tags to each step the user
> > interacts with on the entire site, in a technique known as continuations.
> >  These techniques only prevent *most* attacks though, the session can
> still
> > be hijacked just with a reduced window of opportunity.
> > I say *most* because if you can snoop on the HTTP traffic, you
> theoretically
> > could capture the in-plain-text CSRF token the server handed the user
> once
> > they were generated one (from being on a user account to reset my
> password
> > page).  An attacker could form a valid POST using the CSRF just captured
> and
> > I think it would work.
> > Not even validating that the IP is the same for each CSRF would solve the
> > problem either considering these two users are probably going to be in a
> > coffeeshop, behind a NAT.
> > One possible solution would be to have some kind of hardware attestation
> or
> > browser attestation and tie session info to that.  If anyone has any
> > thoughts on how this could be done, please let me know.
> > Brian
> > On Mon, Oct 25, 2010 at 6:47 AM, cootetom  wrote:
>
> It's actually orthogonal to CSRF. CSRF protects you from a 3rd party
> web site maliciously enticing a user to initiate data changing
> requests to your site. It does nothing to protect a user from having
> their cookies jacked by a 3rd party user, and then stopping that user
> from maliciously using the credentials inferred from those cookies.
>
> That this is even news is surprising - it's hardly a new attack
> vector. The only new thing about it is it being hooked up to a web
> browser and showing live feeds of what is happening, which has
> probably opened the eyes of people who didn't think about it before.
> It's like saying 'Oh wow, you can see in plain text peoples emails on
> unsecured wifi networks' - well, durr, its a plain text protocol, and
> the whole 'unsecured nework' bit should probably give it away...
>
> If you don't want this to happen, then force the use of SSL throughout
> your site, and don't hand out session cookies over HTTP.
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>


-- 
Brian Bouterse
ITng Services

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Creating a common URL prefix?

2010-10-25 Thread Oliver Beattie
Hi all,

I have a bit of an conundrum for you that I'm a little stumped with…
I'm wondering whether I'm missing something painfully simple in my
search of rather complicated options. Basically, I need a prefix on
all URLs (for instance /uk/ or /us/), but I don't want each and every
view to have to accept it as a parameter. reverse_url et all would
still need to work, and I would still need to be able to redirect
users not using this prefix (links to existing URLs) to the new format
based on GeoIP [currently in use but again using separate domains].
Most of the url resolution functions have been wrapped in some custom
code anyway (so I can pass an optional country_code parameter to the
reverse function if desired), so it's not really a big deal if the
code of these needs changing.

Disclaimer: I don't want to monkey patch anything. Demanding, ain't I?

I initially thought this would be possible with the use of
process_view middleware, and this is still probably my best option,
but it's still not really all that nice, since I'd need to call
view_func directly with the modified argument list — and that looks
like it would render exception middleware unusable.

Currently, the system is set up to do this with a different domain
(domain.co.uk, domain.com.au etc), and then some process_request
middleware sets a COUNTRY_CODE variable on the request, and this is
something I'd like to continue using as a substantial codebase
(hundreds of views) already relies on this. There is a whole framework
we have built around localizing various things depending on this
variable.

Other things I thought of and have since discounted after looking at
their code are:-

* A custom request handler that can deal with this (would require
quite a bit of code duplication for a small amount of change, due to
the length of the BaseHandler.get_response function)
* A custom URL resolver/urlpatterns that can do what it will with the
parameters, but I don't think that's possible

I did also think it may also be possible with WSGI middleware, but I
don't really know where I might start with that.

To me it seems the only way to really go about this (in Django) is to
wrap each and every view in a decorator… which just feels extremely
messy. And even then I doubt all the thousands of existing calls to
reverse_url would work without modification.

I think in writing this I've almost convinced myself the best way to
go about this is to convince the powers that be to let it be a
subdomain like many other sites rather than a subdirectory… but if
anyone has any ideas I'd love to hear them.

Like I said, I'm really hoping I've missed something obvious :) Any
help would be really appreciated.

—Oliver

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



ManytoMany initial values

2010-10-25 Thread Giancarlo Razzolini

Hi all,

   I've been using django for some time now and I must say that it's my 
favorite framework. But lately I've run into a problem. Let's say I have 
the following models:


class Contact(models.Model):
   id = models.AutoField(primary_key=True)
   user = models.ForeignKey(User, editable=False)
   name = models.CharField(max_length=255, default='', null=True, 
blank=True)

   groups = models.ManyToManyField('Group', null=True, blank=True)

   class Meta:
   unique_together = ("user", "name")

   def __unicode__(self):
   return u'%s' % (self.name)

class Group(models.Model):
   id = models.AutoField(primary_key=True)
   user = models.ForeignKey(User, editable=False)
   name = models.CharField(max_length=255, null=False, blank=False)

   class Meta:
   unique_together = ("user", "name")

   def __unicode__(self):
   return u'%s' % (self.name)

   I'm using ModelForm to create the forms used to insert new instances 
of both these models into my database. But, as the models made clear, I 
want to have the contacts and the groups distinct to each user in 
django. This part is working. Now, when I'm going to add a new contact, 
for example, I want to set the initial value of the field "groups", 
which is the ManytoMany field, to be only the groups belonging to that 
user. I've searched the mail list and saw that I had to pass a list of 
group id's to be the initial value of the field:


   group_ids = []
   for group in Group.objects.filter(user=request.user):
   group_ids.append(group.id)

   And then, create the form:

   form = ContactForm(request.POST, request.FILES, initial={'groups': 
group_ids})


   When I do this, the form will render ok, but, instead of only 
showing the groups belonging to that user, it will still show all the 
groups in the model(belonging to other users too), the only difference 
being that, the groups that belong to the request.user, showing already 
selected, and the other groups(the ones that shouldn't be showing) not 
selected. I don't know if this is possible without having to override 
the queryset that the modelform make. Any ideas?


Thanks in advance,

--
Giancarlo Razzolini
http://lock.razzolini.adm.br
Linux User 172199
Red Hat Certified Engineer no:804006389722501
Verify:https://www.redhat.com/certification/rhce/current/
Moleque Sem Conteudo Numero #002
OpenBSD 4.5
Ubuntu 9.04 Jaunty Jackalope
4386 2A6F FFD4 4D5F 5842  6EA0 7ABE BBAB 9C0E 6B85

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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 can i wsdl file in my django

2010-10-25 Thread sami nathan
I think following is opt ans for my question Mr Brian Bouterse




No matter the tools you have, it's hard to make a WSDL for a RESTful
service. WSDL 1.1, after all, was specifically designed to describe
services built using SOAP. In response, the Web Application
Development Language (WADL) was created to easily describe RESTful
services. But WSDL 2.0 is more compatible with both SOAP and REST and,
with its W3C recommendation, competes stiffly with WADL for popularity
among developers.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: What does an ideal django workflow setup look like?

2010-10-25 Thread Tom Evans
When this came up another time, a better approach was explained to me.
Rather than settings.py 'under version control'*, you keep
settings_default.py as your universal settings file. This is then
imported into settings.py.

The advantage of this is that you don't need to do clever tricks in
your settings.py to update things like INSTALLED_APPS,
MIDDLEWARE_CLASSES etc.

Having said that, I still import from setting_local in all my projects.

Cheers

Tom


* This is such a misnomer - *all* your source and configuration files
should be under version control, especially local settings (I keep
mine in a separate repository, which is then externall'ed into place
in the instance's deployment repo). How else can you effectively
control change management?

On Mon, Oct 25, 2010 at 7:37 AM, Steve Holden  wrote:
> On 10/25/2010 2:02 AM, Kenneth Gonsalves wrote:
> [shacker]
>>> Another approach to this problem:
>>>
>>> settings.py IS in version control and includes settings
>>> that are universal to all environments (local dev, staging,
>>> production), but has dummy info or empty strings for
>>> passwords or paths or other information that vary between
>>> environments.
>> this is a better approach - much more professional (I *did* say I
>> am an amateur;-))
>
> A technique I use, having picked it up from Jacob Kaplan Moss, IIRC, is
> to keep settings.py under source control but have it include as its last
> statement
>
> from local_settings import *
>
> The local_settings.py file is then maintained outside source control on
> each target platform. This works very nicely, and allows you to maintain
> common settings without having to edit a file that's under code control
> to vary settings between platforms.
>
> regards
>  Steve
> --
> DjangoCon US 2010 September 7-9 http://djangocon.us/
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Embed the file system path to a template??

2010-10-25 Thread Russell Keith-Magee
On Sun, Oct 24, 2010 at 11:47 PM, Joakim Hove  wrote:
> Hello,
>
> to assist those responsible for the content of "my" site I would like
> to embed the file-system path to the template in the rendered
> template, so that when they find something they are dissatisfied with
> on a page they can do "View Source" and easily identify the correct
> template to update.
>
> I.e. I would like to embed something like this at the top of all the
> templates:
>
> 
>
> Is this possible?

Not without jumping through some hoops. The template currently being
rendered isn't exposed as a template context variable.

There are a couple of reasons for this.

Firstly, there's the issue of interpretation; as soon as you start
using {% extends %} or {% include %} tags, which any moderately
complex template will do, there are multiple template files involved.
It's not much good just printing the path to one template file when 6
files are actually involved in the rendering process.

Secondly -- you can't really answer the question of which templates
were used to render a page until all the page is rendered, by which
time, it's too late to insert content into the page.

However, if you just want to know the top-level template that started
the rendering process, you could obtain this by writing a custom
render_to_template() shortcut that inserts the loaded template name
into the context.

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-us...@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: Creating a common URL prefix?

2010-10-25 Thread Benoit
Hi,

Django-localeurl does something like this. I've successfully implemented it
in several projects.

http://bitbucket.org/carljm/django-localeurl/
http://pypi.python.org/pypi/django-localeurl/1.4

Benoit Clennett-Sirois


On Mon, Oct 25, 2010 at 8:54 AM, Oliver Beattie  wrote:

> Hi all,
>
> I have a bit of an conundrum for you that I'm a little stumped with…
> I'm wondering whether I'm missing something painfully simple in my
> search of rather complicated options. Basically, I need a prefix on
> all URLs (for instance /uk/ or /us/), but I don't want each and every
> view to have to accept it as a parameter. reverse_url et all would
> still need to work, and I would still need to be able to redirect
> users not using this prefix (links to existing URLs) to the new format
> based on GeoIP [currently in use but again using separate domains].
> Most of the url resolution functions have been wrapped in some custom
> code anyway (so I can pass an optional country_code parameter to the
> reverse function if desired), so it's not really a big deal if the
> code of these needs changing.
>
> Disclaimer: I don't want to monkey patch anything. Demanding, ain't I?
>
> I initially thought this would be possible with the use of
> process_view middleware, and this is still probably my best option,
> but it's still not really all that nice, since I'd need to call
> view_func directly with the modified argument list — and that looks
> like it would render exception middleware unusable.
>
> Currently, the system is set up to do this with a different domain
> (domain.co.uk, domain.com.au etc), and then some process_request
> middleware sets a COUNTRY_CODE variable on the request, and this is
> something I'd like to continue using as a substantial codebase
> (hundreds of views) already relies on this. There is a whole framework
> we have built around localizing various things depending on this
> variable.
>
> Other things I thought of and have since discounted after looking at
> their code are:-
>
> * A custom request handler that can deal with this (would require
> quite a bit of code duplication for a small amount of change, due to
> the length of the BaseHandler.get_response function)
> * A custom URL resolver/urlpatterns that can do what it will with the
> parameters, but I don't think that's possible
>
> I did also think it may also be possible with WSGI middleware, but I
> don't really know where I might start with that.
>
> To me it seems the only way to really go about this (in Django) is to
> wrap each and every view in a decorator… which just feels extremely
> messy. And even then I doubt all the thousands of existing calls to
> reverse_url would work without modification.
>
> I think in writing this I've almost convinced myself the best way to
> go about this is to convince the powers that be to let it be a
> subdomain like many other sites rather than a subdirectory… but if
> anyone has any ideas I'd love to hear them.
>
> Like I said, I'm really hoping I've missed something obvious :) Any
> help would be really appreciated.
>
> —Oliver
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Still Confused about Python Egg Cache

2010-10-25 Thread octopusgrabbus
I've added

PythonInterpreter amr_django
PythonImport /home/amr/django/amr/python_egg_cache.py amr_django

to /etc/init.d/conf/httpd.conf.

Here's python_egg_cache.py

import os
os.environ['PYTHON_EGG_CACHE'] = '/python_egg_cache/.python-eggs'

This was working a few days ago, after I added the configuration noted
above. So, I'm confused as to why I keep getting this egg cache
error.

Any ideas or pointers would be appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Still Confused about Python Egg Cache

2010-10-25 Thread octopusgrabbus
I'm sorry for being so bouncy about this. Fixed again, but with
different instructions.


SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
SetEnv PYTHON_EGG_CACHE /tmp
PythonOption django.root /home/amr/django/amr
PythonPath "['/home/amr/django', '/home/amr/django/amr', '/usr/
local/lib
/site-packages/django'] + sys.path"
PythonDebug On


Added second SetEnv to , but those aren't the instructions
on the django doc site.
Got instructions from here:
http://www.question-defense.com/2009/12/22/extractionerror-cant-extract-files-to-egg-cache-errno-13-permission-denied-root-python-eggs

On Oct 25, 11:58 am, octopusgrabbus  wrote:
> I've added
>
> PythonInterpreter amr_django
> PythonImport /home/amr/django/amr/python_egg_cache.py amr_django
>
> to /etc/init.d/conf/httpd.conf.
>
> Here's python_egg_cache.py
>
> import os
> os.environ['PYTHON_EGG_CACHE'] = '/python_egg_cache/.python-eggs'
>
> This was working a few days ago, after I added the configuration noted
> above. So, I'm confused as to why I keep getting this egg cache
> error.
>
> Any ideas or pointers would be appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Embed the file system path to a template??

2010-10-25 Thread Joakim Hove

> However, if you just want to know the top-level template that started
> the rendering process, you could obtain this by writing a custom
> render_to_template() shortcut that inserts the loaded template name
> into the context.

Thank you,

 I considered writing this custom render_to_template() shortcut, but
hoped maybe there was a simpler solution. I will be using this custom
shortcut quite extensively - i.e. I would like existing code which
currently calls render_to_response() to change over to my new shortcut
without updating every call. Is there a reasonably elegant way to
achieve this?

Joakim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 page cms get_absolute_url return an empty strings andURL issues.

2010-10-25 Thread tricks...@googlemail.com
I am having issues with get_absolute_url in my django templates when
using django page cms. It returns an empty string and does not link to
my required page.

I have the following Models, URLs templates and views

Models

class Body(models.Model):
...
url = models.SlugField(unique=True, help_text='---')

urls

(r'^news/', include('news.urls_news')),..

url(r'^/(?P[\w\-]+)/$', 'news_view', name='news_view'),

View

def news_view(request, url):
new = get_object_or_404(Body, url=url)
return render_to_response('news/view.html', {
'news': news
}, context_instance=RequestContext(request))

Template

   {{ news.title }}

the following code in my template returns the string I desire however
this does to direct to my html page

   {{ news.title }}

I know my everything links to the correct files because I have other
views that work correctly. Could somebody please point me in the
correct direction as to why get_absolute_url is not working correctly
and why {{ news.url }} does not direct to the correct page. I am sure
it has something to do with my urls.py however I am not certain.
Please bear with me I am new to django. All help is greatly
appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Unable to filter a query on >1 ManyToMany relationships

2010-10-25 Thread Jumpfroggy

I have a class like this:

class Node:
name = models.CharField()
parents = models.ManyToManyField('self', symmetrical=False,
related_name='child_nodes', null=True, blank=True)

This allows a basic parent(s)/children hierarchy.  A node can have >=
0 parents.  A parent can have >= 0 children.

Say I have these nodes:

A - parent node
B - parent node
C - child of both A & B

So I can do this:

Node.objects.filter(name='C')
> returns ['C' node].

Node.objects.filter(name='C', parents__name='A')
> returns ['C' node].

Node.objects.filter(name='C', parents__name='B')
> returns ['C' node].

Node.objects.filter(Q(name='C'), Q(parents__name='A'))
> returns ['C' node].

Node.objects.filter(Q(name='C'), Q(parents__name='B'))
> returns ['C' node].

Node.objects.filter(Q(name='C'), Q(parents__name='A'),
Q(parents__name='B'))
> returns []

Node.objects.filter(Q(name='C') & Q(parents__name='A') &
Q(parents__name='B'))
> returns []

Node.objects.filter(Q(parents__name='A'), Q(parents__name='B'))
> returns []


Why do those last two return an empty set?  I can even do this:

Node.objects.filter(Q(name='C'),
Q(parents__name='A')).filter(Q(parents__name='B'))
> returns ['C' node].

That works.  But filtering on two parents (AND, not OR... I want the
child nodes of both parents) returns the empty set.  It doesn't make
sense to me why using two separate filters would work, but combining
them into one statement gives different results.

Anyone have an idea about this?  Is this a bug in the django query
system, or am I looking at this wrong?  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-us...@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: What does an ideal django workflow setup look like?

2010-10-25 Thread Jumpfroggy
This is such a great thread!  I'd love to see a wiki page detailing
some good setup ideas.  It's such a leap forward from the nuts & bolts
of "How do I install django" and "How do I run a complex query" to
this... "How do I use django more effectively, end to end?"

I agree - most of these tips will be generic to project dev &
deployment, but it seems there are a few django specific ones.

My thoughts...

- Use VCS.  First step.  I use SVN, but others are probably better.
Even if you're a solo dev, even for small projects, it's worth it.

- Definitely have local, test, and prod servers.  Local is where the
development happens (on your machine).  Testing is where you can test
the latest commits.  Ideally you'd have continuous integration as
well, which would also run on the latest revision.  Prod is the live
site.  If you're a single dev on a small project, you can get away
with local & prod.

- +1 on using "settings.py" and "local_settings.py".  The problem with
keeping local settings files in the VCS is when you have multiple
servers with different settings.  You could store each file as
local_settings_test_server.py and so on.  Then you could have
something like "settings_server_name.py" that's not in VCS, and it
only has:

SERVER_NAME = 'prod'

And in your settings.py:

import * from settings_server_name

if SERVER_NAME == 'prod':
import * from settings_prod_server
elif SERVER_NAME == 'test':
...
etc

That way almost everything is in VCS, and you only have one file to
write for each server.

- Try to develop & test on servers similar to your PROD server.  It
stinks to develop and test, then realize you had python X and PROD
server is python X - 0.1, which means some features/libraries aren't
available (or syntax is wrong).

- Use "south" for database changes!  It takes just a bit to get used
to, but will make database changes (both schema and data) so much
easier to keep track of.  This is basically what Kenneth Gonsalves
described, but in reliable/convenient/automated form.  It's amazing.
Go south!  Use south!  (don't think about dmigrations.  It does not
exist.)

- Use some kind of deployment script.  I wrote my own and it's simple
and awesome.  You can also use something like fabric, which seems
complicated but is very useful.  Add things like "svn update force" to
update a repsitory, "touch *.wsgi" to reload the app, "python
manage.py migrate" to update any DB changes (using south), etc.
Anything you'd do on the server, create scripts for.  Even stuff like
"copy PROD DB to TEST server", so you have real data to play with.

That's what I can think of at the moment.  It'd be nice to have a
"best practices" page on the django site, since a lot of these
suggestions will be repeated for most users.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Connecting to Multiple MSSQL Databases... I've hit an edge case. Help, please!

2010-10-25 Thread Steven L Smith
For one of our apps, I'm using django-pyodbc to connect to an MS SQL
2005 database (not my choice...) This database contains, among other
things, rows for the Person model. I've written a function to connect
to "Lenel", an access-card system used by our campus security
department, which pulls the photos (stored as blobs in their MS SQL
2008 database).

Both the Person model queries, and the Lenel-photo-pulling function
work great... by themselves. But when they're put together, they don't
work. Basically, if I've loaded *anything* from myapp.models, the
get_photo_from_lenel function fails.

>From what I can tell, Django (or django-pyodbc) isn't cleaning up its
connection to MSSQL DB #1, and when I use pyodbc to connect to MSSQL
DB #2, it seems to be routing it somewhere else. But that's just a
guess?

I read that the connection persists as long as the object exists, so I
tried "del me" and "del Person", but the error message still shows up,
unless I restart my python shell.

This is my function:
http://dpaste.com/hold/263816/

And this is what happens when I use it:
>>> from naz.directories.getphotos import get_photo_from_lenel
>>> nazid = u'1237946'
>>> tuple(get_photo_from_lenel(naz_id=nazid))
(14439, '1234567', )


>>> from naz.directories.getphotos import get_photo_from_lenel
>>> from naz.directories.models import Person
>>> me = Person.objects.get(nazid=1234567)
>>> nazid = me.nazid
>>> nazid = u'1234567'
>>> get_photo_from_lenel(naz_id=nazid)
>>> tuple(get_photo_from_lenel(naz_id=nazid))
Traceback (most recent call last):
  File "", line 1, in 
  File "/var/django/naz/../naz/directories/getphotos.py", line 112, in
get_photo_from_lenel
cursor.execute(query)
Error: ('IM001', '[IM001] [unixODBC][Driver Manager]Driver does not
support this function (0) (SQLColAttribute)')

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Is there some way to log every SQL command sent to the DB?

2010-10-25 Thread Phlip
> You could turn on logging through your DB

Hey! Thinking outside the box is MY job!!

grumble grumble grumble thanks grumble...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ManytoMany initial values

2010-10-25 Thread Jumpfroggy
Giancarlo,

I've run into this trouble myself.  The problem here is the widget
itself.  It does exactly what you described:
-Shows all possible values for the ManyToMany field.
-Highlights the "active" or "selected" values.  These correspond to
items in that list/array/queryset.

For any more than a couple of values, it's horribly confusing.  Even
though I'm used to it, I still find myself assuming that listed values
are selected (especially when you have a few hundred options).  It's
just a bad widget for this kind of data.

Take a look at the Admin control panel widgets.  Specifically, view a
User in the django control panel and look at the permissions widget.
That's what you want.  Something where it shows all available
(unselected) options on one side, all selected options on the other
side, and a way to filter the available options for the ones you
want.  Much better than the simple SELECT MULTIPLE="" that is used by
default.

I haven't looked into it, but there  may be a way to use that admin
widget for your own forms.  This really should be the default widget
anyway.

So bottom line - you need a different widget, maybe one you have to
write yourself.  Good luck!

-James

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ManytoMany initial values

2010-10-25 Thread Jumpfroggy
On Mon, Oct 25, 2010 at 2:23 PM, Giancarlo Razzolini
 wrote:
> James,
>   First of all thank you for the fast response. I'll take a look into the 
> admin forms widgets. I'm already looking for third party applications field 
> types and widgets to see if I find one that does what I want. I was even 
> considering creating views on the underlying database to accomplish this. I 
> think that django should implement on the forms a better way to show granular 
> output. My django application is completely user dependent, and only let a 
> user to view/add/edit/remove information that belongs to him. Only the 
> superuser can deal with all objects. I was using a custom for to accomplish 
> that, but since I'm using a ManyToMany relation, it was a lot of work to 
> validate it myself and save the relationship. I guess I'll have to turn back 
> to it if I can't use the admin form you mentioned. Thank you again.
> My regards,
> Giancarlo Razzolini

No problem.  For anything user-facing, I'd recommend not using admin
forms.  You might be able to get away with it, but it seems each time
you add some business logic (permissions, validation, etc) it makes it
less and less a fit with the built-in forms.

It's relatively trivial to create your own forms, so it shouldn't be
too hard to ignore the admin pages.  It's just annoying to have to do
the work to create templates, logins, etc.

But depending on your requirements, you'll probably find that it's
easier to just create your own forms.  You'll still have to figure out
the widget issue, but at least you'll have better control over the
validation.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



dealing with BLOB field and encoding of the text.

2010-10-25 Thread Harsha Reddy
Hi All,

I have hit a road block in trying to read BLOB data {of some encoding
other than UTF-8 or any other unicode} in Django for display.

The SQLite database that I am dealing with has a table, the columns of
it which stores the command, output are of type BLOB and the data
being stored is in SHIFT_JIS encoding. this database also contain an
other table, which contains the encoding information.

>From the error I can make out that at the model level, conversion of
data to utf-8 is failing. I do not know if adding _unicode_() method
explicitly will solve this problem.

Please advice on the approach that I should take to overcome this
problem. with out compromising on changing the field type of the
database to something suitable other than blob. I do not have control
on changing the schema of the database table :(

The model code that I am using is:

class BlobField(models.Field):
def db_type(self):
return 'blob'

class VarStr(models.Field):
def db_type(self):
return 'varchar'

class Result(models.Model):
tcid = VarStr('Testcase ID')
cmd = BlobField('Command')
ec = VarStr('Status Code')
op = BlobField('Output', null=True)
mtext = BlobField('Match', null=True)
txetm = BlobField('Do Not Match', null=True)
mdiff = BlobField('Output Diff.', null=True)
gdiff = BlobField('GD Diff.', null=True)
result = VarStr()

class Meta:
db_table = 'results'

I am getting the following error:

OperationalError at /report/
Could not decode to UTF-8 column 'cmd' with text 'mkdir
folder_lazy_dog_�ӂ݈�_�I'
Request Method: POST
Request URL:http://127.0.0.1:8000/report/
Django Version: 1.3 pre-alpha SVN-14347
Exception Type: OperationalError
Exception Value:

Could not decode to UTF-8 column 'cmd' with text 'mkdir
folder_lazy_dog_�ӂ݈�_�I'

Exception Location: /usr/lib/python2.6/dist-packages/django/db/models/
sql/compiler.py in , line 744
Python Executable:  /usr/bin/python
Python Version: 2.6.6
Python Path:['/LA/src/lighthouse', '/usr/local/lib/python2.6/dist-
packages/Pygments-1.3.1-py2.6.egg', '/usr/lib/python2.6', '/usr/lib/
python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/
python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/local/lib/
python2.6/dist-packages', '/usr/lib/python2.6/dist-packages', '/usr/
lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/
gst-0.10', '/usr/lib/pymodules/python2.6', '/usr/lib/python2.6/dist-
packages/gtk-2.0', '/usr/lib/pymodules/python2.6/gtk-2.0']
Server time:Tue, 26 Oct 2010 00:39:31 +0530

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: What does an ideal django workflow setup look like?

2010-10-25 Thread Brian Bouterse
I really can't encourage the use of Hudson  (or
something like it).  It's a great tool to plug scripts into, and gives you
added features if configured properly such as running test cases
automatically, giving code coverage reports,
pylintreports, and if your build
"succeeds" can even roll out your successful
build to the staging servers.

I like to tie our VCS using git-hooks to kick off automated builds of Hudson
with each commit.

In turn, your staging servers could run some smoke tests and then do a
script based automated roll-out using fabric as suggested.  +1 for fabric

+1 on the use of South

Chaining all of these tools together bring together one powerful development
pipeline, but even using them all independently is still very powerful (and
the first step).

my 2 cents,
Brian

On Mon, Oct 25, 2010 at 2:04 PM, Jumpfroggy  wrote:

> This is such a great thread!  I'd love to see a wiki page detailing
> some good setup ideas.  It's such a leap forward from the nuts & bolts
> of "How do I install django" and "How do I run a complex query" to
> this... "How do I use django more effectively, end to end?"
>
> I agree - most of these tips will be generic to project dev &
> deployment, but it seems there are a few django specific ones.
>
> My thoughts...
>
> - Use VCS.  First step.  I use SVN, but others are probably better.
> Even if you're a solo dev, even for small projects, it's worth it.
>
> - Definitely have local, test, and prod servers.  Local is where the
> development happens (on your machine).  Testing is where you can test
> the latest commits.  Ideally you'd have continuous integration as
> well, which would also run on the latest revision.  Prod is the live
> site.  If you're a single dev on a small project, you can get away
> with local & prod.
>
> - +1 on using "settings.py" and "local_settings.py".  The problem with
> keeping local settings files in the VCS is when you have multiple
> servers with different settings.  You could store each file as
> local_settings_test_server.py and so on.  Then you could have
> something like "settings_server_name.py" that's not in VCS, and it
> only has:
>
>SERVER_NAME = 'prod'
>
> And in your settings.py:
>
>import * from settings_server_name
>
>if SERVER_NAME == 'prod':
>import * from settings_prod_server
>elif SERVER_NAME == 'test':
>...
>etc
>
> That way almost everything is in VCS, and you only have one file to
> write for each server.
>
> - Try to develop & test on servers similar to your PROD server.  It
> stinks to develop and test, then realize you had python X and PROD
> server is python X - 0.1, which means some features/libraries aren't
> available (or syntax is wrong).
>
> - Use "south" for database changes!  It takes just a bit to get used
> to, but will make database changes (both schema and data) so much
> easier to keep track of.  This is basically what Kenneth Gonsalves
> described, but in reliable/convenient/automated form.  It's amazing.
> Go south!  Use south!  (don't think about dmigrations.  It does not
> exist.)
>
> - Use some kind of deployment script.  I wrote my own and it's simple
> and awesome.  You can also use something like fabric, which seems
> complicated but is very useful.  Add things like "svn update force" to
> update a repsitory, "touch *.wsgi" to reload the app, "python
> manage.py migrate" to update any DB changes (using south), etc.
> Anything you'd do on the server, create scripts for.  Even stuff like
> "copy PROD DB to TEST server", so you have real data to play with.
>
> That's what I can think of at the moment.  It'd be nice to have a
> "best practices" page on the django site, since a lot of these
> suggestions will be repeated for most users.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>


-- 
Brian Bouterse
ITng Services

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



model forms/formset poor performance

2010-10-25 Thread SlafS
Hi there!

I'm developing a small django app with some models and modelformsets.
Using Django Debug-Toolbar I noticed the overhead (in my particular
case) which Django makes by performing extra queries to validate a
form in a formset

http://dpaste.com/hold/263886/

I know that this is needed in many cases, but in mine i would like to
reuse the objects evaluated from the queryset since performance is
crucial in my app. Can i somehow change this behaviour?

Regards

Sławek

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Connecting to Multiple MSSQL Databases... I've hit an edge case. Help, please!

2010-10-25 Thread Henrik Genssen
just use cursor.close() to close the cursor.
is leaking in the sample...

Henrik

>reply to message:
>date: 25.10.2010 13:51:12
>from: "Steven L Smith" 
>to: "Django users" 
>subject: Connecting to Multiple MSSQL Databases... I've hit an edge case. 
>Help, please!
>
>For one of our apps, I'm using django-pyodbc to connect to an MS SQL
>2005 database (not my choice...) This database contains, among other
>things, rows for the Person model. I've written a function to connect
>to "Lenel", an access-card system used by our campus security
>department, which pulls the photos (stored as blobs in their MS SQL
>2008 database).
>
>Both the Person model queries, and the Lenel-photo-pulling function
>work great... by themselves. But when they're put together, they don't
>work. Basically, if I've loaded *anything* from myapp.models, the
>get_photo_from_lenel function fails.
>
>From what I can tell, Django (or django-pyodbc) isn't cleaning up its
>connection to MSSQL DB #1, and when I use pyodbc to connect to MSSQL
>DB #2, it seems to be routing it somewhere else. But that's just a
>guess?
>
>I read that the connection persists as long as the object exists, so I
>tried "del me" and "del Person", but the error message still shows up,
>unless I restart my python shell.
>
>This is my function:
>http://dpaste.com/hold/263816/
>
>And this is what happens when I use it:
 from naz.directories.getphotos import get_photo_from_lenel
 nazid = u'1237946'
 tuple(get_photo_from_lenel(naz_id=nazid))
>(14439, '1234567', 0 at 0x1a04fb0>)
>
>
 from naz.directories.getphotos import get_photo_from_lenel
 from naz.directories.models import Person
 me = Person.objects.get(nazid=1234567)
 nazid = me.nazid
 nazid = u'1234567'
 get_photo_from_lenel(naz_id=nazid)
 tuple(get_photo_from_lenel(naz_id=nazid))
>Traceback (most recent call last):
>  File "", line 1, in 
>  File "/var/django/naz/../naz/directories/getphotos.py", line 112, in
>get_photo_from_lenel
>cursor.execute(query)
>Error: ('IM001', '[IM001] [unixODBC][Driver Manager]Driver does not
>support this function (0) (SQLColAttribute)')
>
>-- 
>You received this message because you are subscribed to the Google Groups 
>"Django users" group.
>To post to this group, send email to django-us...@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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Users table

2010-10-25 Thread miksayer
Thanx everybody.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Embed the file system path to a template??

2010-10-25 Thread Russell Keith-Magee
On Tue, Oct 26, 2010 at 1:05 AM, Joakim Hove  wrote:
>
>> However, if you just want to know the top-level template that started
>> the rendering process, you could obtain this by writing a custom
>> render_to_template() shortcut that inserts the loaded template name
>> into the context.
>
> Thank you,
>
>  I considered writing this custom render_to_template() shortcut, but
> hoped maybe there was a simpler solution. I will be using this custom
> shortcut quite extensively - i.e. I would like existing code which
> currently calls render_to_response() to change over to my new shortcut
> without updating every call. Is there a reasonably elegant way to
> achieve this?

An *elegant* way? Not that I can think of. To alter existing uses of
render_to_response you would need to get into monkeypatching, which is
never a good option :-)

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-us...@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: my first (public) app: django-requires_js_css

2010-10-25 Thread Jason Persampieri
Thanks for the feedback!  Glad to know I'm on the trail of something
that's actually needed :)

I haven't delved in to Django internals enough yet (still really just
getting started with Django) to evaluate what can be done with lower-
level changes.  And while I briefly went down the path of a separate
thread, I wrote it off as too finicky.  I think I'll continue with the
current plan, but look in to ways to making it more efficient (I
imagine I could do some intelligent caching of items that are
'required' all the time).  As it is, there should be zero overhead if
the templatetags aren't used at all.

I've recently added same-server absolute path requirements and am
considering re-working to the SETTINGS dict to be less stupid.
Anything else that would be useful right off the bat?

On Oct 24, 3:30 pm, Sam Lai  wrote:
> On 21 October 2010 16:01, Jason Persampieri  wrote:
>
> >http://github.com/pappy74/django-requires_js_css
>
> > Howdy folks,
>
> > I was hoping to get some feedback on my first public app, django-
> > requires_js_css.  The app's purpose is to allow 'sane' JavaScript and
> > CSS requirements.  That is, require from within templates, but still
> > load using 'best practices'.
>
> Another item off my to-do list. Thanks!
>
> > Definitely a work in progress, although we are using it at our
> > startup.  My questions to you:
> > - Is there another app that does this?
>
> Not that I know of.
>
> > - Do other devs find this worthwhile?
>
> Yep. My use case was to allow the addition of SyntaxHighlighter
> brushes as required by the posts on the page. (This is now moot as of
> the new version of SH, as it will now dynamically load brushes, but I
> can envision other use cases for this.)
>
> > - What's missing?
> > - I currently use a fairly gnarly hack to make this all work
> > (embedding tokens in the response content, then post-processing those
> > tokens using middleware).  Is there a better way?
>
> Other than how it is implemented now, the nicer way is what Doug has
> described. Not sure if it is possible though/might require some Django
> patches.
>
>
>
>
>
>
>
> > _jason
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Override DECIMAL_SEPARATOR in certain cases?

2010-10-25 Thread Joachim Pileborg
In my application I have LANGUAGE_CODE set to 'sv-SE', which uses
comma as decimal separator. When using a model field containing a
floating point number as argument to a Javascript function, or when
sending the number to an external site (in my case as coordinates to
get a static map from Google Maps), the model field should not be
localized.

Is there a known way to change the localization for number formating
for certain cases?

And no, the DECIMAL_SEPARATOR setting in the project settings does not
seem to be used anywhere, and the decimal fields should be localized
when showing the number to a user.

I'm using the 1.3 alpha release of Django.

Regards

/ Joachim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-25 Thread Phlip
Does anyone have a QuerySet for that?

( BTW please don't try to talk me out of it; I've been doing SQL since
1989 and am fully aware of all the alternatives there. 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-us...@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: What does an ideal django workflow setup look like?

2010-10-25 Thread Kenneth Gonsalves
On Mon, 2010-10-25 at 16:06 -0400, Brian Bouterse wrote:
> I really can't encourage the use of Hudson  (or
> something like it).  

'cant encourage'? or 'can encourage'?
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS at AU-KBC

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 get request.user when Django emails a 500 error report?

2010-10-25 Thread Sid
I wrote a middleware that adds a process_exception handler. It adds
the user info to the request.META so they show up in emails.

See http://gist.github.com/646372

You can modify that to add any info to the emails.

Sid
http://sidmitra.com


On Oct 16, 3:20 am, Margie Roginski  wrote:
> I finally turned off DEBUG on my site and got set up so that the
> django code would email me the exceptions.  This is ultra-cool!  So I
> got m first one in the mail today, and was hard-pressed to figure out
> the user that ran into the error.  I don't find request.user anywhere
> in the report.  Do I need to write the process_exception() middleware
> and add it in myself?  Anyone have an example?!
>
> Thanks!
>
> Margie

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Adding username to the 500 error emails

2010-10-25 Thread Sid
See http://gist.github.com/646372  , which also uses process_exception
handler.

-Sid
http://sidmitra.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-us...@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: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-25 Thread ankit rai
say your model name is Student, and it has a field names as marks

query set will be

Student.objects.all().aggregate(Max('marks')
this will be give you max marks

st=Student.objects.filter(marks__in=Student.objects.all().aggregate(Max('marks')))

--ankit


On Tue, Oct 26, 2010 at 9:28 AM, Phlip  wrote:

> Does anyone have a QuerySet for that?
>
> ( BTW please don't try to talk me out of it; I've been doing SQL since
> 1989 and am fully aware of all the alternatives there. 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-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.