Re: HttpResponse, slow on apache

2010-03-22 Thread TheIvIaxx
i checked out the toolbar, and i have a butt load of queries.  Not for
everything on the site, but for this particular page there are 300+
queries.  They are small and are less than 1ms.  I'll try to get this
better :)

However, in regards to Xaviers point, yes I'm sure all DB stuff has
been done.  I have the rendered HTML then i call time.clock(), then
return the HttpResponse.  As far as I know, nothing else in the db
gets hit after that.

The only middlewares I have ar GZip, Common, Auth, and Session.  Im
checking out the link you sent

On Mar 22, 5:30 pm, Xavier Ordoquy  wrote:
> Hi,
>
> I'm not sure you give enough details or evidences on HttpResponse being slow.
> Are you 100% sure that DB access have been made ? Don't forget query sets are 
> lazy, ie database accesses are not done when you define your queryset.
>
> I got a website with something like 4 (small) DB queries. Without cache, I 
> get around 150 requests per second on 2GHz Pentium.
> Page wait time reported by Safari is 57ms, download take 27ms which is far 
> from your measures.
> Also notice that of 57ms, 29 are due to network latency (ping).
> On another site of mine where I have around 20 DB requests but table entries 
> are much larger (around 30 fields per row) and it take 225ms before getting 
> the first byte and another 246ms to get the full result.
>
> In either case I find it hard to say that it could be on django itself.
> What sort of server are you running your site on ? What option did you choose 
> for using apache with python ?
> I had dreadful results on a shared hosting calling python code (Django) 
> through cgi scripts (around 1 sec before the first byte is send).
>
> Xavier.
>
> Le 23 mars 2010 à 00:41, TheIvIaxx a écrit :
>
>
>
> > im not about to say my code is prefect :)  I'll check out the toolbar
> > thing.
>
> > my problem though is that timing it to the point where it's completely
> > out of my hands is .72 sec and then my browser doesn't get byte #1
> > until 1.46 sec.  There is a big discrepancy and i'm not sure what is
> > causing it.
>
> > The .72 is after all views have be ran, all DB access has been made,
> > and templates have been rendered to the HTML.  I get my last
> > time.clock() right before returning the HttpResponse object
>
> > On Mar 22, 4:37 pm, Daniel Roseman  wrote:
> >> On Mar 22, 11:25 pm, TheIvIaxx  wrote:
>
> >>> Not sure whose jurisdiction this falls under, but from my findings,
> >>> this is what i have:
>
> >>> Firebug reports 1.46/.055 sec waiting/downloading.  I need the
> >>> "waiting" part to be less than 1 sec.
>
> >>> It looks like sending the response is very fast, but preparing it is
> >>> not.
>
> >>> So i investigated as to where the slowdown is.  Using time.clock(),
> >>> from the time django received the request to the time the response
> >>> HTML is ready to ship its .72 sec.  So now i am wondering why it's
> >>> taking django or apache another ~.72 seconds to get the html ready and
> >>> fired off.
>
> >>> Chrome reports similar results.
>
> >>> Am i interpreting these times incorrectly?
>
> >>> Thanks
>
> >> Why do you think it should be faster than this? Django isn't just
> >> 'serving HTML', it's running a whole stack within which your code is
> >> presumably calling views, accessing the database, and rendering
> >> templates. Depending on the complexity of your app, .72 seconds could
> >> well be a perfectly reasonable amount of time to do all that.
>
> >> That said, there will almost certainly be areas within your code that
> >> can be made more efficient - the Django debug toolbar is a great place
> >> to start finding those slowdowns.
> >> --
> >> 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-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.



Re: HttpResponse, slow on apache

2010-03-22 Thread Xavier Ordoquy
Hi,

I'm not sure you give enough details or evidences on HttpResponse being slow.
Are you 100% sure that DB access have been made ? Don't forget query sets are 
lazy, ie database accesses are not done when you define your queryset.

I got a website with something like 4 (small) DB queries. Without cache, I get 
around 150 requests per second on 2GHz Pentium.
Page wait time reported by Safari is 57ms, download take 27ms which is far from 
your measures.
Also notice that of 57ms, 29 are due to network latency (ping).
On another site of mine where I have around 20 DB requests but table entries 
are much larger (around 30 fields per row) and it take 225ms before getting the 
first byte and another 246ms to get the full result.

In either case I find it hard to say that it could be on django itself.
What sort of server are you running your site on ? What option did you choose 
for using apache with python ?
I had dreadful results on a shared hosting calling python code (Django) through 
cgi scripts (around 1 sec before the first byte is send).

Xavier.

Le 23 mars 2010 à 00:41, TheIvIaxx a écrit :

> im not about to say my code is prefect :)  I'll check out the toolbar
> thing.
> 
> my problem though is that timing it to the point where it's completely
> out of my hands is .72 sec and then my browser doesn't get byte #1
> until 1.46 sec.  There is a big discrepancy and i'm not sure what is
> causing it.
> 
> The .72 is after all views have be ran, all DB access has been made,
> and templates have been rendered to the HTML.  I get my last
> time.clock() right before returning the HttpResponse object
> 
> On Mar 22, 4:37 pm, Daniel Roseman  wrote:
>> On Mar 22, 11:25 pm, TheIvIaxx  wrote:
>> 
>> 
>> 
>> 
>> 
>>> Not sure whose jurisdiction this falls under, but from my findings,
>>> this is what i have:
>> 
>>> Firebug reports 1.46/.055 sec waiting/downloading.  I need the
>>> "waiting" part to be less than 1 sec.
>> 
>>> It looks like sending the response is very fast, but preparing it is
>>> not.
>> 
>>> So i investigated as to where the slowdown is.  Using time.clock(),
>>> from the time django received the request to the time the response
>>> HTML is ready to ship its .72 sec.  So now i am wondering why it's
>>> taking django or apache another ~.72 seconds to get the html ready and
>>> fired off.
>> 
>>> Chrome reports similar results.
>> 
>>> Am i interpreting these times incorrectly?
>> 
>>> Thanks
>> 
>> Why do you think it should be faster than this? Django isn't just
>> 'serving HTML', it's running a whole stack within which your code is
>> presumably calling views, accessing the database, and rendering
>> templates. Depending on the complexity of your app, .72 seconds could
>> well be a perfectly reasonable amount of time to do all that.
>> 
>> That said, there will almost certainly be areas within your code that
>> can be made more efficient - the Django debug toolbar is a great place
>> to start finding those slowdowns.
>> --
>> 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-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: HttpResponse, slow on apache

2010-03-22 Thread Daniel Roseman
On Mar 22, 11:41 pm, TheIvIaxx  wrote:
> im not about to say my code is prefect :)  I'll check out the toolbar
> thing.
>
> my problem though is that timing it to the point where it's completely
> out of my hands is .72 sec and then my browser doesn't get byte #1
> until 1.46 sec.  There is a big discrepancy and i'm not sure what is
> causing it.
>
> The .72 is after all views have be ran, all DB access has been made,
> and templates have been rendered to the HTML.  I get my last
> time.clock() right before returning the HttpResponse object

Sorry, I misunderstood your first message, when you said your timing
was from 'when Django receives the request'. Sounds like you've
already done quite a bit of internal profiling.

There's still quite a bit to be done after your return the response
(presumably you're calling render separately, before your timing call,
then returning the finished response afterwards). Most particularly,
there's all the response middleware to call - do you have anything
there? James Bennett once wrote a great article[1] about exactly how
Django deals with a request - as you can see, there's lots to go
through even after the view has finished its work.

[1]:http://www.b-list.org/weblog/2006/jun/13/how-django-processes-
request/

--
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-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: Permissions for groups and users

2010-03-22 Thread Tim Shaffer
SVN diff is here:

http://code.google.com/p/django-namespace/source/diff?spec=svn3=3=side=/trunk/namespace/admin.py_path=/trunk/namespace/admin.py=2

-- 
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: Permissions for groups and users

2010-03-22 Thread Tim Shaffer
Ah, yes I see the problem. Good catch. I hadn't tested that
functionality. Luckily it is a simple change to admin.py. It's a
matter of removing line 25:

form.base_fields["namespace"].queryset =
Namespace.objects.user_can_access(request.user)

And replacing it with the following 3 lines. This basically checks to
see if any related fields are also namespaced, and limits the options
available if so.

for name,value in form.base_fields.items():
if hasattr(value,"queryset") and issubclass(value.queryset.model,
(NamespacedModel,Namespace)):
form.base_fields[name].queryset =
value.queryset.model._default_manager.user_can_access(request.user)

Let me know if you have any feedback. I'm glad this little project is
useful to someone else :)


On Mar 22, 6:55 pm, Sven Richter  wrote:
> Hi Tim,
>
> I just tried your app and, wow, this is exactly what i was looking
> for. It works instantly, but, as always, there must be a but.
> One thing doesnt work. I did all as you said, and, like i wrote, it
> worked out of the box, except my ForeignKeys.
>
> In my example i have:
> class Task(NamespacedModel):
>    name = models.CharField(max_length = 250)
>    parent_task = models.ForeignKey('self',  related_name='Parent
> Task',  blank=True,  null=True)
>
> Now, when a user from GroupA with Namespace A accesses the tasks it
> only sees the tasks from namespace a. But, if he wants to add a new
> task, he can choose tasks from other namespaces as parent tasks.
>
> I tried that with a different model combination, with the same result.
> As soon as a model refers to a foreignkey the user is able to choose
> from ever other namespace.
> Can that be resolved somehow?
>
> Greetings and thanks
> Sven
>
> On Mon, Mar 22, 2010 at 10:31 PM, Tim Shaffer  wrote:
> > Django doesn't support that out of the box. I searched and couldn't
> > find anything. Self plug: I created an app that does exactly this.
>
> >http://code.google.com/p/django-namespace/
>
> > Only difference is I called the model Namespace instead of Domain.
> > Just download it, then add it to your INSTALLED_APPS.
>
> > You can then create different Namespaces in the admin, and give either
> > users or groups access to them. Then their builtin django privileges
> > apply only to those namespaces.
>
> > Then for any model that needs to be in a domain/namespace, subclass
> > the NamespacedModel like so. Basically this just adds a foreign key to
> > the Namespace model.
>
> > from django_namespace.namespace.models import NamespacedModel
>
> > class Task(NamespacedModel):
> >    name = models.CharField(max_length = 250)
> >    parent_task = models.ForeignKey('self',  related_name='Parent
> > Task',  blank=True,  null=True)
>
> > Then when you register the model for the admin, use the
> > NamespacedAdmin class (or you can subclass it). This takes care of
> > making sure users in DomainA can only see/edit/delete tasks in that
> > domain.
>
> > from django_namespace.namespace.admin import NamespacedAdmin
>
> > admin.site.register(Task, NamespacedAdmin)
>
> > See the usage for some examples. I think it's pretty straight forward
> > if you're familiar with Django. I've been using it in an internal
> > project with great success.
>
> > --
> > 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.



[bug?] using GeoManager in subqueries gives no results (Django 1.2 beta 1) + 1.1.1 bug

2010-03-22 Thread Marcin Kałuża
Hi,
I'ts my first post here, so "Hello" Everyone :)
I've got the code as shown below. The problem is that when I do a
subquery using a previously generated queryset it doesn't return any
results, if the queryset contained a geometry field (r1 here)

>>> b="49.98544839116778,19.8248291015625,50.1439061537639,20.06481170654297"
>>> bounds = Polygon.from_bbox(b.split(','))
>>> bounds

>>> r1=Report.objects.filter(location__contained=bounds)
>>> len(r1)
15
>>> Report.objects.filter(pk__in=r1).annotate(Count('incidents'), 
>>> importance=Avg('incidents__importance'), 
>>> severity=Avg('incidents__severity'))
[]

However, if I extract the id's of records from inner queryset and pass
them as array, results are correct:
>>> r2=[ x['id'] for x in r1.values('id')]
>>> r2
[55, 42, 56, 43, 44, 11, 12, 47, 48, 49, 50, 51, 52, 53, 54]
>>> Report.objects.filter(pk__in=r2).annotate(Count('incidents'), 
>>> importance=Avg('incidents__importance'), 
>>> severity=Avg('incidents__severity'))
[, , , , , , , ,
, , , , , , ]

The problem doesn't occur if the inner query has no geometry queries:
>>> r3=Report.objects.filter(creator=3)
>>> len(r3)
13
>>> Report.objects.filter(pk__in=r3).annotate(Count('incidents'), 
>>> importance=Avg('incidents__importance'), 
>>> severity=Avg('incidents__severity'))
[, , , , , , , ,
, , , , ]

Should I file it as a bug? If so - where?  Django or geodjango?
(Haven't done that before)

Moreover, running above queries on version 1.1.1 produced the
following sql:

SELECT fields_here
FROM szz."reports" LEFT OUTER JOIN szz."incidents" ON
("reports"."rep_id" = "incidents"."inc_rep_id")
WHERE "reports"."rep_id" IN
(
SELECT U0."rep_id"
FROM szz."reports" U0
WHERE "U0"."rep_location" @ ST_GeomFromWKB('\\001\\003\\000\\000\\000\
\001\\000\\000\\000\\005\\000\\000\\000\\020\\373A,#\\3...@\\000\\000\
\000\\000(\\3...@\\020\\373a,#\\3...@\\000\\000\\000\\200\\227\\0204@\
\367\\015p\\204k\\0...@\\000\\000\\000\\200\\227\\0204@\\367\\015P\
\204k\\0...@\\000\\000\\000\\000(\\3...@\\020\\373a,#\\3...@\\000\\000\
\000\\000(\\3233@', 4326)
)
GROUP BY fields_here;

SELECT fields_here
FROM szz."reports" LEFT OUTER JOIN szz."incidents" ON
("reports"."rep_id" = "incidents"."inc_rep_id")
WHERE "reports"."rep_id" IN
(
SELECT U0."rep_id" FROM "reports" U0 INNER JOIN "incidents" U1 ON
(U0."rep_id" = U1."inc_rep_id")
WHERE (U1."inc_us_id" = 3  AND U1."inc_interested" = true )
) GROUP BY fields_here;

The problem is, that in query #1 in subquery the table alias is qouted
in where and unquoted in from-list, which gives an error on postgres,
since  U0--> u0 and "U0" --> U0
Normal manager doesn't have this problem. That was my reason for
switching to 1.2. Should I post it somewhere?

Martin

-- 
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: HttpResponse, slow on apache

2010-03-22 Thread TheIvIaxx
im not about to say my code is prefect :)  I'll check out the toolbar
thing.

my problem though is that timing it to the point where it's completely
out of my hands is .72 sec and then my browser doesn't get byte #1
until 1.46 sec.  There is a big discrepancy and i'm not sure what is
causing it.

The .72 is after all views have be ran, all DB access has been made,
and templates have been rendered to the HTML.  I get my last
time.clock() right before returning the HttpResponse object

On Mar 22, 4:37 pm, Daniel Roseman  wrote:
> On Mar 22, 11:25 pm, TheIvIaxx  wrote:
>
>
>
>
>
> > Not sure whose jurisdiction this falls under, but from my findings,
> > this is what i have:
>
> > Firebug reports 1.46/.055 sec waiting/downloading.  I need the
> > "waiting" part to be less than 1 sec.
>
> > It looks like sending the response is very fast, but preparing it is
> > not.
>
> > So i investigated as to where the slowdown is.  Using time.clock(),
> > from the time django received the request to the time the response
> > HTML is ready to ship its .72 sec.  So now i am wondering why it's
> > taking django or apache another ~.72 seconds to get the html ready and
> > fired off.
>
> > Chrome reports similar results.
>
> > Am i interpreting these times incorrectly?
>
> > Thanks
>
> Why do you think it should be faster than this? Django isn't just
> 'serving HTML', it's running a whole stack within which your code is
> presumably calling views, accessing the database, and rendering
> templates. Depending on the complexity of your app, .72 seconds could
> well be a perfectly reasonable amount of time to do all that.
>
> That said, there will almost certainly be areas within your code that
> can be made more efficient - the Django debug toolbar is a great place
> to start finding those slowdowns.
> --
> 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-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: HttpResponse, slow on apache

2010-03-22 Thread Daniel Roseman
On Mar 22, 11:25 pm, TheIvIaxx  wrote:
> Not sure whose jurisdiction this falls under, but from my findings,
> this is what i have:
>
> Firebug reports 1.46/.055 sec waiting/downloading.  I need the
> "waiting" part to be less than 1 sec.
>
> It looks like sending the response is very fast, but preparing it is
> not.
>
> So i investigated as to where the slowdown is.  Using time.clock(),
> from the time django received the request to the time the response
> HTML is ready to ship its .72 sec.  So now i am wondering why it's
> taking django or apache another ~.72 seconds to get the html ready and
> fired off.
>
> Chrome reports similar results.
>
> Am i interpreting these times incorrectly?
>
> Thanks

Why do you think it should be faster than this? Django isn't just
'serving HTML', it's running a whole stack within which your code is
presumably calling views, accessing the database, and rendering
templates. Depending on the complexity of your app, .72 seconds could
well be a perfectly reasonable amount of time to do all that.

That said, there will almost certainly be areas within your code that
can be made more efficient - the Django debug toolbar is a great place
to start finding those slowdowns.
--
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-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.



HttpResponse, slow on apache

2010-03-22 Thread TheIvIaxx
Not sure whose jurisdiction this falls under, but from my findings,
this is what i have:

Firebug reports 1.46/.055 sec waiting/downloading.  I need the
"waiting" part to be less than 1 sec.

It looks like sending the response is very fast, but preparing it is
not.

So i investigated as to where the slowdown is.  Using time.clock(),
from the time django received the request to the time the response
HTML is ready to ship its .72 sec.  So now i am wondering why it's
taking django or apache another ~.72 seconds to get the html ready and
fired off.

Chrome reports similar results.

Am i interpreting these times incorrectly?

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 validation tests are applied to ImageField?

2010-03-22 Thread john2095
Thanks Tom.  I don't know where it comes from but it seems deeply
ingrained for me to expect the model to enforce the atomicity/
integrity of its objects.

Just for anyone who stumbles over this thread and wants to know how it
ends...

In this application I'm not using a form (uploadify is a flash-based
file sender) but I can still take advantage of the django.forms
validation routines by invoking ImageField without a form. This seems
to work:

def upload(request):
from django.forms import ImageField, ValidationError
try:
photo = ImageField().clean(request.FILES['Filedata'])
except ValidationError:
return HttpResponse("I don't think that's an image.")




On Mar 22, 9:04 pm, Tom Evans  wrote:
> On Mon, Mar 22, 2010 at 6:51 AM, john2095  wrote:
> > But does this all amount to an expectation that it will restrict the
> > upload to an image??
>
> > I've got this in my model:
>
> > class Photo(models.Model):
> >    image = models.ImageField(upload_to='photos')
>
> > and this in my view:
> >    try:
> >        p = Photo()
> >        p.image = request.FILES['Filedata']
> >        p.save()
> >        return HttpResponse('OK')
> > ...
>
> > Yet if I do this:
>
> > curl -F fileda...@nasty.exehttp://mysite/photo/upload/
>
> > It seems quite happy to save the .exe
>
> > Can someone please confirm the same test result?   I wouldn't like to
> > say "security advisory" prematurely.
>
> > Thanks.
>
> Models don't have validation, forms have validation. If it passed
> through a forms.ImageField it would get rejected as invalid.
>
> 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: Permissions for groups and users

2010-03-22 Thread Sven Richter
Hi Tim,

I just tried your app and, wow, this is exactly what i was looking
for. It works instantly, but, as always, there must be a but.
One thing doesnt work. I did all as you said, and, like i wrote, it
worked out of the box, except my ForeignKeys.

In my example i have:
class Task(NamespacedModel):
   name = models.CharField(max_length = 250)
   parent_task = models.ForeignKey('self',  related_name='Parent
Task',  blank=True,  null=True)

Now, when a user from GroupA with Namespace A accesses the tasks it
only sees the tasks from namespace a. But, if he wants to add a new
task, he can choose tasks from other namespaces as parent tasks.

I tried that with a different model combination, with the same result.
As soon as a model refers to a foreignkey the user is able to choose
from ever other namespace.
Can that be resolved somehow?


Greetings and thanks
Sven

On Mon, Mar 22, 2010 at 10:31 PM, Tim Shaffer  wrote:
> Django doesn't support that out of the box. I searched and couldn't
> find anything. Self plug: I created an app that does exactly this.
>
> http://code.google.com/p/django-namespace/
>
> Only difference is I called the model Namespace instead of Domain.
> Just download it, then add it to your INSTALLED_APPS.
>
> You can then create different Namespaces in the admin, and give either
> users or groups access to them. Then their builtin django privileges
> apply only to those namespaces.
>
> Then for any model that needs to be in a domain/namespace, subclass
> the NamespacedModel like so. Basically this just adds a foreign key to
> the Namespace model.
>
> from django_namespace.namespace.models import NamespacedModel
>
> class Task(NamespacedModel):
>    name = models.CharField(max_length = 250)
>    parent_task = models.ForeignKey('self',  related_name='Parent
> Task',  blank=True,  null=True)
>
> Then when you register the model for the admin, use the
> NamespacedAdmin class (or you can subclass it). This takes care of
> making sure users in DomainA can only see/edit/delete tasks in that
> domain.
>
> from django_namespace.namespace.admin import NamespacedAdmin
>
> admin.site.register(Task, NamespacedAdmin)
>
> See the usage for some examples. I think it's pretty straight forward
> if you're familiar with Django. I've been using it in an internal
> project with great success.
>
> --
> 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: Negate querysets

2010-03-22 Thread Tim Shaffer
It depends. This will only run one query, when negated_queryset is
used.

queryset = User.objects.filter(first_name='vinicius')
negated_queryset = User.objects.exclude(id__in=queryset.values("id"))

Since the first queryset is not evaluated until it's used in the
negated_queryset (as a subquery).

On Mar 22, 5:55 pm, Matt Schinckel  wrote:
> On Mar 23, 6:17 am, Phlip  wrote:
>
> > > Just create another queryset that excludes everything in your first
> > > queryset:
>
> > > negated_queryset = User.objects.exclude(id__in=queryset.values("id"))
>
> > QuerySets are already so easy to plug-n-play... Ain't there a way to
> > do it without whacking the database twice?
>
> Are you sure it hits the db twice? I seem to recall a similar case
> where I thought I was, but since the queryset evaluation is lazy, the
> ORM potentially has the ability to make this into a single query.
>
> (I can't recall if when I did this sort of thing I was using
> SQLAlchemy, but I _think_ it was pure django).
>
> Matt.

-- 
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: Issue with aggregate_select changes

2010-03-22 Thread David Cramer
I suppose I should post the full version, since my simplified attempt
didnt work :)

class ICount(Aggregate):
name = 'ICOUNT'
sql_function = 'COUNT'
sql_template = '%(function)s(LOWER(%(field)s))'
is_ordinal = True

def __init__(self, lookup, **extra):
self.lookup = lookup
self.extra = extra

def _default_alias(self):
return '%s__%s' % (self.lookup,
self.__class__.__name__.lower())
default_alias = property(_default_alias)

def add_to_query(self, query, alias, col, source, is_summary):
super(ICount, self).__init__(col, source, is_summary,
**self.extra)
query.aggregate_select[alias] = self

On Mar 22, 4:53 pm, David Cramer  wrote:
> One of the recent changes in trunk was a change to how querysets were
> cloned. Due to this, some old code we had is no longer working. This
> was a custom aggregate which relied on "aggregate_select" (see below).
> I believe the change I'm referring to is what is causing this, and I'm
> unsure of what the proper approach should be now. Should this also be
> considered a bug? If so, I'll go ahead and file a ticket.
>
> class ICount(Aggregate):
>     sql_function = 'COUNT'
>     sql_template = '%(function)s(LOWER(%(field)s))'
>     is_ordinal = True
>     name = 'ICOUNT'
>
>     def add_to_query(self, query, alias, col, source, is_summary):
>         super(ICount, self).__init__(col, source, is_summary,
> **self.extra)
>         query.aggregate_select[alias] = self

-- 
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: Remove session on browser close

2010-03-22 Thread Paulo Almeida
Maybe I'm missing something obvious, but can't you pass the user to the
template and use:

{% if user.is_authenticated %}

instead of:

{% if form.thanks %}

It doesn't solve the problem of logging out, but you don't have to handle
the session manually.

- Paulo

On Mon, Mar 22, 2010 at 9:40 PM, grimmus  wrote:

> Basically all i want to do is the following :
>
> Have a newsletter signup form. When the user signs up successfully the
> area where the form was has a thanks message instead of the form.
>
> The form or thanks message is displayed on every page of the site, so
> I thought using a session would be the best way handle whether to show
> the form or the thanks message.
>
> Here is my form
>
> 
>
>{% if form.errors %}
>Please enter a valid email address.
>{% endif %}
>{% if form.thanks %}
>Thanks for signing up
>{% endif %}
>{% if form.alreadyexists %}
>The email address already exists
>{% endif %}
>{% if not form.thanks %}
>   value="Email
> address" onfocus="this.select()" />
>   value="Go"/>
>{% endif %}
>
>  
>
> And my view
>
> if request.POST:
>form = SignUp(request.POST)
>
>if form.is_valid():
>
>email = request.POST.get('email', '')
>
>try:
>entry = MailingList.objects.get(email=email)
>
>form.alreadyexists = True
>
>except (KeyError, MailingList.DoesNotExist):
>
>entry = MailingList()
>entry.email = email
>entry.date_added = datetime.now()
>entry.save()
>
>request.session['signed_up'] = True
>form.thanks = True
>
>return HttpResponseRedirect(request.get_full_path())
>
>else:
>print form.errors
>
>else:
>
>form = SignUp()
>
>t = loader.get_template('home/page.html')
>c = RequestContext(request,{
>'form':form,
>})
>
>if request.session.get('signed_up', True):
>form.thanks = True
>
>return HttpResponse(t.render(c))
>
>
> Any help is greatly appreciated.
>
> On Mar 22, 3:13 pm, Bill Freeman  wrote:
> > And if the user disables javascript, or kills the browser without
> > normal exit, or loses
> > his connection, or pulls the ethernet cable, or has a power failure?
> >
> > On Mon, Mar 22, 2010 at 10:06 AM, Wiiboy  wrote:
> > > Couldn't you use Javascript for this? For example, on the
> > > onbeforeunload event, delete the sessionid cookie?
> >
> > > --
> > > 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.
>
>

-- 
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: Negate querysets

2010-03-22 Thread Matt Schinckel
On Mar 23, 6:17 am, Phlip  wrote:
> > Just create another queryset that excludes everything in your first
> > queryset:
>
> > negated_queryset = User.objects.exclude(id__in=queryset.values("id"))
>
> QuerySets are already so easy to plug-n-play... Ain't there a way to
> do it without whacking the database twice?

Are you sure it hits the db twice? I seem to recall a similar case
where I thought I was, but since the queryset evaluation is lazy, the
ORM potentially has the ability to make this into a single query.

(I can't recall if when I did this sort of thing I was using
SQLAlchemy, but I _think_ it was pure django).

Matt.

-- 
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.



Issue with aggregate_select changes

2010-03-22 Thread David Cramer
One of the recent changes in trunk was a change to how querysets were
cloned. Due to this, some old code we had is no longer working. This
was a custom aggregate which relied on "aggregate_select" (see below).
I believe the change I'm referring to is what is causing this, and I'm
unsure of what the proper approach should be now. Should this also be
considered a bug? If so, I'll go ahead and file a ticket.

class ICount(Aggregate):
sql_function = 'COUNT'
sql_template = '%(function)s(LOWER(%(field)s))'
is_ordinal = True
name = 'ICOUNT'

def add_to_query(self, query, alias, col, source, is_summary):
super(ICount, self).__init__(col, source, is_summary,
**self.extra)
query.aggregate_select[alias] = self

-- 
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: Remove session on browser close

2010-03-22 Thread john2095
I think the proper paradigm is to use the AnonymousUser.

Rather than trying to destroy the session - something that cannot be
reliably achieved - instead set the user of the session back to
AnonymousUser and test/react to that.


On Mar 23, 8:40 am, grimmus  wrote:
> Basically all i want to do is the following :
>
> Have a newsletter signup form. When the user signs up successfully the
> area where the form was has a thanks message instead of the form.
>
> The form or thanks message is displayed on every page of the site, so
> I thought using a session would be the best way handle whether to show
> the form or the thanks message.
>
> Here is my form
>
> 
>                 
>                     {% if form.errors %}
>                     Please enter a valid email address.
>                     {% endif %}
>                     {% if form.thanks %}
>                     Thanks for signing up
>                     {% endif %}
>                     {% if form.alreadyexists %}
>                     The email address already exists
>                     {% endif %}
>                     {% if not form.thanks %}
>                        value="Email
> address" onfocus="this.select()" />
>                        value="Go"/>
>                     {% endif %}
>                 
>               
>
> And my view
>
> if request.POST:
>         form = SignUp(request.POST)
>
>         if form.is_valid():
>
>             email = request.POST.get('email', '')
>
>             try:
>                 entry = MailingList.objects.get(email=email)
>
>                 form.alreadyexists = True
>
>             except (KeyError, MailingList.DoesNotExist):
>
>                 entry = MailingList()
>                 entry.email = email
>                 entry.date_added = datetime.now()
>                 entry.save()
>
>                 request.session['signed_up'] = True
>                 form.thanks = True
>
>             return HttpResponseRedirect(request.get_full_path())
>
>         else:
>             print form.errors
>
>     else:
>
>             form = SignUp()
>
>             t = loader.get_template('home/page.html')
>             c = RequestContext(request,{
>                 'form':form,
>             })
>
>             if request.session.get('signed_up', True):
>                 form.thanks = True
>
>             return HttpResponse(t.render(c))
>
> Any help is greatly appreciated.
>
> On Mar 22, 3:13 pm, Bill Freeman  wrote:
>
>
>
> > And if the user disables javascript, or kills the browser without
> > normal exit, or loses
> > his connection, or pulls the ethernet cable, or has a power failure?
>
> > On Mon, Mar 22, 2010 at 10:06 AM, Wiiboy  wrote:
> > > Couldn't you use Javascript for this? For example, on the
> > > onbeforeunload event, delete the sessionid cookie?
>
> > > --
> > > 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.



Re: Remove session on browser close

2010-03-22 Thread grimmus
Basically all i want to do is the following :

Have a newsletter signup form. When the user signs up successfully the
area where the form was has a thanks message instead of the form.

The form or thanks message is displayed on every page of the site, so
I thought using a session would be the best way handle whether to show
the form or the thanks message.

Here is my form



{% if form.errors %}
Please enter a valid email address.
{% endif %}
{% if form.thanks %}
Thanks for signing up
{% endif %}
{% if form.alreadyexists %}
The email address already exists
{% endif %}
{% if not form.thanks %}
  
  
{% endif %}

  

And my view

if request.POST:
form = SignUp(request.POST)

if form.is_valid():

email = request.POST.get('email', '')

try:
entry = MailingList.objects.get(email=email)

form.alreadyexists = True

except (KeyError, MailingList.DoesNotExist):

entry = MailingList()
entry.email = email
entry.date_added = datetime.now()
entry.save()

request.session['signed_up'] = True
form.thanks = True

return HttpResponseRedirect(request.get_full_path())

else:
print form.errors

else:

form = SignUp()

t = loader.get_template('home/page.html')
c = RequestContext(request,{
'form':form,
})

if request.session.get('signed_up', True):
form.thanks = True

return HttpResponse(t.render(c))


Any help is greatly appreciated.

On Mar 22, 3:13 pm, Bill Freeman  wrote:
> And if the user disables javascript, or kills the browser without
> normal exit, or loses
> his connection, or pulls the ethernet cable, or has a power failure?
>
> On Mon, Mar 22, 2010 at 10:06 AM, Wiiboy  wrote:
> > Couldn't you use Javascript for this? For example, on the
> > onbeforeunload event, delete the sessionid cookie?
>
> > --
> > 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.



Re: Permissions for groups and users

2010-03-22 Thread Tim Shaffer
Django doesn't support that out of the box. I searched and couldn't
find anything. Self plug: I created an app that does exactly this.

http://code.google.com/p/django-namespace/

Only difference is I called the model Namespace instead of Domain.
Just download it, then add it to your INSTALLED_APPS.

You can then create different Namespaces in the admin, and give either
users or groups access to them. Then their builtin django privileges
apply only to those namespaces.

Then for any model that needs to be in a domain/namespace, subclass
the NamespacedModel like so. Basically this just adds a foreign key to
the Namespace model.

from django_namespace.namespace.models import NamespacedModel

class Task(NamespacedModel):
name = models.CharField(max_length = 250)
parent_task = models.ForeignKey('self',  related_name='Parent
Task',  blank=True,  null=True)

Then when you register the model for the admin, use the
NamespacedAdmin class (or you can subclass it). This takes care of
making sure users in DomainA can only see/edit/delete tasks in that
domain.

from django_namespace.namespace.admin import NamespacedAdmin

admin.site.register(Task, NamespacedAdmin)

See the usage for some examples. I think it's pretty straight forward
if you're familiar with Django. I've been using it in an internal
project with great success.

-- 
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.



Permissions for groups and users

2010-03-22 Thread Sven Richter
Hi,

this might be offtopic, so i excuse for that in advance, but i dont
know a better place to ask for it, cause its not completely offtopic
at all.

Let's start with what i want to achieve. I am building some sort of a
groupware, and i want it to fully support different domains, and with
it different users.
So lets say i have a simple model Domain, and a model Tasks:
class Domain(models.Model):
domain = models.CharField(max_length=250)

class Task(models.Model):
name = models.CharField(max_length = 250)
parent_task = models.ForeignKey('self',  related_name='Parent
Task',  blank=True,  null=True)
domain = models.ForeignKey(Domain)

Now i create two domains DomainA and DomainB and with it two groups
GroupA and GroupB with some users for each. GroupA shall be allowed to
add new tasks to DomainA and the same goes for GroupA (add tasks only
in DomainA).

Can i achieve that with the given permission (users and groups) system
of django or do i have to extent the user and groups models from
django?


Greetings
Sven

-- 
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: Trouble installing satchmo

2010-03-22 Thread Jonathan Hayward
Thank you, Andrew and Laszlo.

On Mon, Mar 22, 2010 at 3:17 PM, Laszlo Antal  wrote:

> Hi,
>
> I use this installation and it works.
> http://bitbucket.org/chris1610/satchmo/wiki/ImprovedInstallationProcess
>
> Hope
> it helps
>
> lzantal
>
>
>
> On Mon, Mar 22, 2010 at 12:14 PM, Andrew  wrote:
>
>> Go to:
>> http://groups.google.com/group/satchmo-users
>>
>> On 15 мар, 20:10, Jonathan Hayward
>>  wrote:
>> > I'm trying to get satchmo up and running from the instructions athttp://
>> bitbucket.org/chris1610/satchmo/downloads/Satchmo.pdf, and when I
>> > get to 2.1.3 (installing PIL manually as a workaround), there is no
>> > /bin/clonesatchmo.py. After digging around, I move the scripts from the
>> > install directory to under /usr/local, and create a symlink to
>> > clonesatchmo.py. But it can't find things; my guess is that it's looking
>> in
>> > my PYTHONPATH and the same install issues that left no
>> /bin/clonesatchmo.py
>> > has left no Python files installed to the default PYTHONPATH. I get:
>> >
>> > $ python /bin/clonesatchmo.py
>> > Creating the Satchmo Application
>> > Traceback (most recent call last):
>> >   File "/bin/clonesatchmo.py", line 108, in 
>> > create_satchmo_site(opts.site_name)
>> >   File "/bin/clonesatchmo.py", line 47, in create_satchmo_site
>> > import satchmo_skeleton
>> > ImportError: No module named satchmo_skeleton
>> >
>> > Do people have suggestions, including going to a Satchmo-specific list
>> if
>> > this list is not intended to discuss Django add-ons like Satchmo or
>> Pinax?
>> >
>> > --
>> > → Jonathan Hayward, a Senior Web Developer who cares deeply about
>> usability
>> > →www.linkedin.com/in/jonathanhayward• jonathan.hayw...@pobox.com
>> > → Ajax, CGI, CMS, CSS, HTML, IA, JSON, JavaScript, LAMP, Linux, Perl,
>> PHP,
>> > Python, SQL, UI, Unix, Usability, UX, XHTML, XML
>> > → With a good interest in the human side of computing and making
>> software
>> > and websites a joy to use
>>
>> --
>> 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.
>



-- 
→ Jonathan Hayward, christos.jonathan.hayw...@gmail.com
→ An Orthodox Christian author: theology, literature, et cetera.
→ My award-winning collection is available for free reading online:
☩ I invite you to visit my main site at http://JonathansCorner.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: Negate querysets

2010-03-22 Thread Tim Shaffer
Might be possible. I'm not terribly familiar with the innards of the
QuerySet class. Seems like it could get real complex real fast,
especially if you're using Q objects.

On Mar 22, 4:17 pm, Phlip  wrote:
> > Just create another queryset that excludes everything in your first
> > queryset:
>
> > negated_queryset = User.objects.exclude(id__in=queryset.values("id"))
>
> QuerySets are already so easy to plug-n-play... Ain't there a way to
> do it without whacking the database twice?
>
> --
>   Phlip
>  http://c2.com/cgi/wiki?ZeekLand

-- 
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: Negate querysets

2010-03-22 Thread Phlip
> Just create another queryset that excludes everything in your first
> queryset:
>
> negated_queryset = User.objects.exclude(id__in=queryset.values("id"))

QuerySets are already so easy to plug-n-play... Ain't there a way to
do it without whacking the database twice?

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand

-- 
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: Trouble installing satchmo

2010-03-22 Thread Laszlo Antal
Hi,

I use this installation and it works.
http://bitbucket.org/chris1610/satchmo/wiki/ImprovedInstallationProcess

Hope
it helps

lzantal



On Mon, Mar 22, 2010 at 12:14 PM, Andrew  wrote:

> Go to:
> http://groups.google.com/group/satchmo-users
>
> On 15 мар, 20:10, Jonathan Hayward
>  wrote:
> > I'm trying to get satchmo up and running from the instructions athttp://
> bitbucket.org/chris1610/satchmo/downloads/Satchmo.pdf, and when I
> > get to 2.1.3 (installing PIL manually as a workaround), there is no
> > /bin/clonesatchmo.py. After digging around, I move the scripts from the
> > install directory to under /usr/local, and create a symlink to
> > clonesatchmo.py. But it can't find things; my guess is that it's looking
> in
> > my PYTHONPATH and the same install issues that left no
> /bin/clonesatchmo.py
> > has left no Python files installed to the default PYTHONPATH. I get:
> >
> > $ python /bin/clonesatchmo.py
> > Creating the Satchmo Application
> > Traceback (most recent call last):
> >   File "/bin/clonesatchmo.py", line 108, in 
> > create_satchmo_site(opts.site_name)
> >   File "/bin/clonesatchmo.py", line 47, in create_satchmo_site
> > import satchmo_skeleton
> > ImportError: No module named satchmo_skeleton
> >
> > Do people have suggestions, including going to a Satchmo-specific list if
> > this list is not intended to discuss Django add-ons like Satchmo or
> Pinax?
> >
> > --
> > → Jonathan Hayward, a Senior Web Developer who cares deeply about
> usability
> > →www.linkedin.com/in/jonathanhayward• jonathan.hayw...@pobox.com
> > → Ajax, CGI, CMS, CSS, HTML, IA, JSON, JavaScript, LAMP, Linux, Perl,
> PHP,
> > Python, SQL, UI, Unix, Usability, UX, XHTML, XML
> > → With a good interest in the human side of computing and making software
> > and websites a joy to use
>
> --
> 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: Negate querysets

2010-03-22 Thread Tim Shaffer
Just create another queryset that excludes everything in your first
queryset:

negated_queryset = User.objects.exclude(id__in=queryset.values("id"))

On Mar 22, 3:47 pm, Vinicius Mendes  wrote:
> Is there any way to negate a queryset? Let's supose i have this queryset:
>
> User.objects.filter(first_name='vinicius')
>
> and I want to have the queryset with the objects that is not in first
> queryset. I know I can do this:
>
> User.objects.exclude(first_name='vinicius')
>
> But we have cases where we don't know what is the queryset, we only knows
> that we want to get the elements that isn't in it, like this:
>
> queryset.negate()
>
> It's good to keep the chainable property of querysets.
>
> __
> Vinícius Mendes
> Solucione Sistemashttp://solucione.info/

-- 
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.



Negate querysets

2010-03-22 Thread Vinicius Mendes
Is there any way to negate a queryset? Let's supose i have this queryset:

User.objects.filter(first_name='vinicius')

and I want to have the queryset with the objects that is not in first
queryset. I know I can do this:

User.objects.exclude(first_name='vinicius')

But we have cases where we don't know what is the queryset, we only knows
that we want to get the elements that isn't in it, like this:

queryset.negate()

It's good to keep the chainable property of querysets.

__
Vinícius Mendes
Solucione Sistemas
http://solucione.info/

-- 
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: Trouble installing satchmo

2010-03-22 Thread Andrew
Go to:
http://groups.google.com/group/satchmo-users

On 15 мар, 20:10, Jonathan Hayward
 wrote:
> I'm trying to get satchmo up and running from the instructions 
> athttp://bitbucket.org/chris1610/satchmo/downloads/Satchmo.pdf, and when I
> get to 2.1.3 (installing PIL manually as a workaround), there is no
> /bin/clonesatchmo.py. After digging around, I move the scripts from the
> install directory to under /usr/local, and create a symlink to
> clonesatchmo.py. But it can't find things; my guess is that it's looking in
> my PYTHONPATH and the same install issues that left no /bin/clonesatchmo.py
> has left no Python files installed to the default PYTHONPATH. I get:
>
> $ python /bin/clonesatchmo.py
> Creating the Satchmo Application
> Traceback (most recent call last):
>   File "/bin/clonesatchmo.py", line 108, in 
>     create_satchmo_site(opts.site_name)
>   File "/bin/clonesatchmo.py", line 47, in create_satchmo_site
>     import satchmo_skeleton
> ImportError: No module named satchmo_skeleton
>
> Do people have suggestions, including going to a Satchmo-specific list if
> this list is not intended to discuss Django add-ons like Satchmo or Pinax?
>
> --
> → Jonathan Hayward, a Senior Web Developer who cares deeply about usability
> →www.linkedin.com/in/jonathanhayward• jonathan.hayw...@pobox.com
> → Ajax, CGI, CMS, CSS, HTML, IA, JSON, JavaScript, LAMP, Linux, Perl, PHP,
> Python, SQL, UI, Unix, Usability, UX, XHTML, XML
> → With a good interest in the human side of computing and making software
> and websites a joy to use

-- 
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.



Easily creating custom pages for django.contrib.admin

2010-03-22 Thread Grigory Javadyan

Greetings!
I had been playing around with Django for a while and eventually a 
question arised: is there any way to easily (by "easily" I mean, without 
sub-classing AdminSite) create a custom page for Django's admin site? 
Let me clarify my question by an example.


Suppose you have an app that shows you the current server metrics (like 
the CPU load, free disk space, RAM usage, etc.) and maybe even lets you 
view those metrics in a historical perspective (a a graph). And of 
course, we want this app to be accessible through Django's admin interface.


This imaginary application's objective is not to manipulate model 
instances in a database, it's monitoring the server's state and 
representing the results as a graph - and here we have a problem, 
because as far as I know, a standard use case of Django's admin is to 
create a nice interface for manipulating entities in a database.


Now I know that this example might seem a little awkward (because there 
are many sophisticated tools out there that perform the described job), 
but the question is, if I wanted to write something like that, would it 
be possible to integrate it with Django's admin interface without much 
fuss? I'd appreciate very much if anyone answered this question :)


Thanks!

--
/gj


--
Ovi Mail: Create an account directly from your phone
http://mail.ovi.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: Dynamic multi-site - running many sites from one Django instance

2010-03-22 Thread Tim Shaffer
It gives you multiple sites from one codebase with multiple settings
files. They are using the same project module. So your project would
look like this:

project
- app1
- app2
- settings.py
- settings_site1.py
- settings_site2.py
- urls.py

settings.py would contain all the settings like a normal django
project, then settings_site1 and settings_site2 could import all those
default settings and overwrite just the settings they need to (like
SITE_ID and MEDIA_ROOT).

-- 
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.



Is it possible to change the width of the boxes displayed by the filter_horizontal in Django admin interface?

2010-03-22 Thread rc
I am using the filter_horizontal in my Django admin interface and it
works great. Only problem is that some of the data that is contained
in the manytomany relationship is longer than the filter_horizontal
forms in the admin interface. How do I change the _width_ of the forms
displayed.

>From looking at the page source it is using a class called
_filtered_. From what I can tell that is generated from the contrib/
admin/media/js/SelectFilter2.js, but I don't really understand where
the size is set.

I was also able to modify the div elements that surround the actual
filter_horizontal data by editing the widgets.css, but could not find
where the actual _size_ of the filter_horizontal element is
controlled.

I guessing that I am making this to hard.

Does anyone know how to do this?

I was hoping it was as easy as adding some meta tags to the actual
filter_horizontal line in my admin.py file, but could not find much
information on filter_horizontal other than how to use it.

Any help is greatly appreciated.

rc


-- 
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: Dynamic multi-site - running many sites from one Django instance

2010-03-22 Thread Tom Evans
On Mon, Mar 22, 2010 at 5:03 PM, Tim Shaffer  wrote:
> How are you serving the Django project? Are you using Apache?
> mod_python? mod_wsgi?
>
> If you are using mod_python or mod_wsgi, you should be able to change
> the DJANGO_SETTINGS_MODULE for each site. So basically for each site,
> you would have a separate settings file in your project.
>
> So for the first site, set your settings module. This is if using
> mod_python, but it's similar for mod_wsgi.
>
> SetEnv DJANGO_SETTINGS_MODULE project.settings_site1
>
> Then for your second site, you can use a different settings module in
> the same project.
>
> SetEnv DJANGO_SETTINGS_MODULE project.settings_site2
>
> An example of settings_site1.py would look like this. Just import all
> the default settings, then overwrite what you need to.
>
> from settings import *
> SITE_ID = 1
>
> I didn't test any of this. But it should work. In theory.
>

That would give you multiple sites from mutiple instances of one
codebase, where as I think the OP is looking for multiple sites from
one instance of one codebase.

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.



Django in sub

2010-03-22 Thread Vnuce
Hi there, first post in this group and a Django newbie, so please, be
gentle :)

I have two problems I failed to solve on my own, so I'm hoping for a
help from you guys...

Problem 1:
If I go to address http://foo.com/django (without trailing slash) I
get an Internal Server Error.
Log shows this info:
File "/var/lib/python-support/python2.5/django/middleware/common.py",
line 41, in process_request
 if settings.APPEND_SLASH and (old_url1-1 != '/') and ('.' not in
old_url1.split('/')-1):
IndexError: string index out of range
If I include the trailing slash it works (at least it seems to).
APPEND_SLASH is (obviously) set to True.

Problem 2:
Let's go with urls.py that looks like this:
from django.conf.urls.defaults import *
from djangobook.views import hello

urlpatterns = patterns('',
(r'^hello/$', hello),
)

Instead of going to http://foo.com/django/hello I get redirected to
http://foo.com/hello. I presume I'm missing a setting or something to
make it relative to the project's starting URL?

Thanks for any help...

-- 
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: Dynamic multi-site - running many sites from one Django instance

2010-03-22 Thread Tim Shaffer
How are you serving the Django project? Are you using Apache?
mod_python? mod_wsgi?

If you are using mod_python or mod_wsgi, you should be able to change
the DJANGO_SETTINGS_MODULE for each site. So basically for each site,
you would have a separate settings file in your project.

So for the first site, set your settings module. This is if using
mod_python, but it's similar for mod_wsgi.

SetEnv DJANGO_SETTINGS_MODULE project.settings_site1

Then for your second site, you can use a different settings module in
the same project.

SetEnv DJANGO_SETTINGS_MODULE project.settings_site2

An example of settings_site1.py would look like this. Just import all
the default settings, then overwrite what you need to.

from settings import *
SITE_ID = 1

I didn't test any of this. But it should work. In theory.

-- 
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: hidden fields not cleaned

2010-03-22 Thread Bjunix
Django validates form data in this order when calling is_valid or
full_clean:

1. run the clean method of the form field itself. Here:
DateTimeField.clean()
2. then run the clean_() method of the form if available
3. once those two methods are run for every field, run the clean()
method of the form

Source: 
http://docs.djangoproject.com/en/1.1/ref/forms/validation/#form-and-field-validation

So I guess the cleaned_data dict has no 'some_hidden_field' key.
DateTimeField.clean() probably raised a Validation Error and did not
populate the cleaned_data dictionary.

Try the following:

def clean(self):
cleaned_data = self.cleaned_data
#cleaned_data.get(key) returns None if key does not exist
some_hidden_field = cleaned_data.get("some_hidden_field")

if some_hidden_field:
#do your custom validation here and raise ValidationError
if necessary
# Always return the full collection of cleaned data.
return cleaned_data

On Mar 22, 3:31 pm, gentlestone  wrote:
> this piece of code leads to Key error 'some_hidden_field'
>
> class XyForm(Form):
>
>     some_hidden_field =
> forms.DateTimeField(widget=forms.HiddenInput())
>
>     def clean(self):
>         some_hidden_field = self.cleaned_data['some_hidden_field']
>
> Why are hidden fields not cleaned?
> I need to validate the hidden value and raise VadiationError if the
> value is not ok.

-- 
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: Strings in page in []

2010-03-22 Thread serek
Hi

You have right.
Thanks you very mach!!!

-- 
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: Event more complicated forms / templates

2010-03-22 Thread Paulo Almeida
You could use inline formsets (have CustomerContactAnswer be a formset of
CustomerContactQuestion) and then render the Answer forms as a table in the
template.

- Paulo

On Mon, Mar 22, 2010 at 1:31 PM, ALJ  wrote:

> Is there any to have a table type form will variable rows and columns?
>
> I have events. For each event there might be several appointment days.
> And a set of questions to measure how many people the rep had contact
> with.
>
> My expected form output would be something like:
>
> Question,  Day1, Day2,
> Day3
> How many people did you see?   20, 30, 40
> How many bought stuff? 2,   1,   4
> How many samples did you give away?   15, 17, 20
>
> ... which they could fill in and submit.
>
> Has anyone else done anything like this?
>
> (Again, I think I might have bitten off more than I can chew here!)
>
> ALJ
>
>
> ..
> models.py
>
> class Appointment(models.Model):
>event = models.ForeignKey(Event)
>date = models.DateField("Date")
>time_start = models.TimeField("Start Time")
>time_end = models.TimeField("End Time")
>
>class Meta:
>ordering = ['date','time_start']
>
> class CustomerContactQuestion(models.Model):
>description = models.CharField("Question",max_length=200)
>order = models.IntegerField("Presentation Order", null=True,
> blank=True)
>
>class Meta:
>ordering = ['order','description']
>
> class CustomerContactAnswer(models.Model):
>event= models.ForeignKey(Event)
>customer_contact_question =
> models.ForeignKey(CustomerContactQuestion)
>appointment = models.ForeignKey(Appointment)
>amount = models.IntegerField()
>
>
> --
> 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.



hidden fields not cleaned

2010-03-22 Thread gentlestone
this piece of code leads to Key error 'some_hidden_field'

class XyForm(Form):

some_hidden_field =
forms.DateTimeField(widget=forms.HiddenInput())

def clean(self):
some_hidden_field = self.cleaned_data['some_hidden_field']

Why are hidden fields not cleaned?
I need to validate the hidden value and raise VadiationError if the
value is not ok.

-- 
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: Remove session on browser close

2010-03-22 Thread Bill Freeman
And if the user disables javascript, or kills the browser without
normal exit, or loses
his connection, or pulls the ethernet cable, or has a power failure?

On Mon, Mar 22, 2010 at 10:06 AM, Wiiboy  wrote:
> Couldn't you use Javascript for this? For example, on the
> onbeforeunload event, delete the sessionid cookie?
>
> --
> 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: Remove session on browser close

2010-03-22 Thread Wiiboy
Couldn't you use Javascript for this? For example, on the
onbeforeunload event, delete the sessionid cookie?

-- 
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.



Event more complicated forms / templates

2010-03-22 Thread ALJ
Is there any to have a table type form will variable rows and columns?

I have events. For each event there might be several appointment days.
And a set of questions to measure how many people the rep had contact
with.

My expected form output would be something like:

Question,  Day1, Day2,
Day3
How many people did you see?   20, 30, 40
How many bought stuff? 2,   1,   4
How many samples did you give away?   15, 17, 20

... which they could fill in and submit.

Has anyone else done anything like this?

(Again, I think I might have bitten off more than I can chew here!)

ALJ


..
models.py

class Appointment(models.Model):
event = models.ForeignKey(Event)
date = models.DateField("Date")
time_start = models.TimeField("Start Time")
time_end = models.TimeField("End Time")

class Meta:
ordering = ['date','time_start']

class CustomerContactQuestion(models.Model):
description = models.CharField("Question",max_length=200)
order = models.IntegerField("Presentation Order", null=True,
blank=True)

class Meta:
ordering = ['order','description']

class CustomerContactAnswer(models.Model):
event= models.ForeignKey(Event)
customer_contact_question =
models.ForeignKey(CustomerContactQuestion)
appointment = models.ForeignKey(Appointment)
amount = models.IntegerField()


-- 
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 sample users for testing

2010-03-22 Thread Ivan Uemlianin
Dear All

I'd like to create a bunch of sample users for testing a django
website.  I was going down the road of using an initial_data fixture,
but there seem to be a couple of problems with this:

- Can I supply partial data in initial_data, i.e. only auth.user info
(at the moment, username and password, and it seems to require last
login)?  When I do this, syncdb persists in asking me for an admin
user (even when the previously given admin user still works).

- How should I specify the password field in the fixture?  dumpdata
outputs a hash.  Do I need to write some script to generate hashes
from given passwords?

I'm now thinking a fixture might not be the right way to go: it might
be better to have a little script to add users once syncdb is done.
As well as allowing me to provide plain text passwords, I could easily
add site-specific attributes when I need them (dave.favourite_colour =
'orange'; bob.online = True, etc).

Is that second method just reinventing the fixture, or is it more
appropriate here?

Thanks and best wishes

Ivan

-- 
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: Arrays

2010-03-22 Thread bruno desthuilliers
On Mar 22, 12:19 pm, James  wrote:
> Hi,
>
> I am struggling to get a piece of code working.
> I've looked at it too much and now can't see what im doing wrong.
>
> Anyone have any ideas? The error is as follows:
> Type Error
> string indices must be integers - (if ids['m'['manufacturer__id']]

"'m'['manufacturer__id']" is trying to to an index lookup on string
"'m'" using string "'manufacturer__id'" as index - which can't work,
since strings can (of course) only be indexed by integers

> is
> not m['manufacturer__id']: )




> Code:
>
> tmp_manufacturers = Product.objects.filter(category=category).values(
>         'manufacturer__title', 'manufacturer__slug',
> 'manufacturer__id'
>     ).distinct()
>
>     manufacturers = {}
>     for m in tmp_manufacturers:
>         ids = {}
>
>         if ids['m'['manufacturer__title']] is not
> m['manufacturer__title']:

First error is the use of quotes around "m" - this should read
"ids[m['manufacturer__title']]".

Now there are two other errors in this line:

1/ you should NOT use the identity operator to test for equality -
IOW, you want to replace 'is' with '==' (or, in this case, 'is not'
with '!=')
2/ if the 'ids' dict doesn't yet have a value set for
m['manufacturer__title'], you'll get a KeyError.


>             ids.append(m['manufacturer__title'])

Looks like you're confusing dicts with lists dicts don't have an
"append" method.

>             manufacturers.append({
>                 'title': m['manufacturer__title'],
>                 'slug': m['manufacturer__slug'],
>                 'id': m['manufacturer__id'],
>                 'total_products': Product.objects.filter(
>                     category=category,
>                     manufacturer__slug=m['manufacturer__slug']
>                 ).count()
>             })

I don't know what your models looks like, but there's something wrong
IMHO - if there's to be a one2many or many2many relationship between
Products and Manufacturer, then it would better be explicit (using a
Model.ForeignKey or Model.ManyToManyField), and done on the
manufacturer *id*, not on the slug. This may also save you (and your
computer) some useless work...

> Also, does anyone have any decent documentation on arrays?

Arrays ??? This is not PHP, this is Python. Look for "list" and "dict"
in the FineManual (I mean, the fine *Python* manual). FWIW, do
yourself a favour and learn Python - at least do the official intro
tutorial. You just can't hope to do anything good in Django if you
don't know at least the most basic Python builtin types and operators.

-- 
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: Arrays

2010-03-22 Thread James
Hi,

Thanks for this, it's helped me a lot.
I will see if I can muddle through the next part.

My my had just gone completely blank with this.

Going to get some fresh air first.
Thanks again!

---

On 22 Mar, 11:38, Daniel Roseman  wrote:
> On Mar 22, 11:19 am, James  wrote:
>
>
>
> > Hi,
>
> > I am struggling to get a piece of code working.
> > I've looked at it too much and now can't see what im doing wrong.
>
> > Anyone have any ideas? The error is as follows:
> > Type Error
> > string indices must be integers - (if ids['m'['manufacturer__id']] is
> > not m['manufacturer__id']: )
>
> > Code:
>
> > tmp_manufacturers = Product.objects.filter(category=category).values(
> >         'manufacturer__title', 'manufacturer__slug',
> > 'manufacturer__id'
> >     ).distinct()
>
> >     manufacturers = {}
> >     for m in tmp_manufacturers:
> >         ids = {}
>
> >         if ids['m'['manufacturer__title']] is not
> > m['manufacturer__title']:
> >             ids.append(m['manufacturer__title'])
> >             manufacturers.append({
> >                 'title': m['manufacturer__title'],
> >                 'slug': m['manufacturer__slug'],
> >                 'id': m['manufacturer__id'],
> >                 'total_products': Product.objects.filter(
> >                     category=category,
> >                     manufacturer__slug=m['manufacturer__slug']
> >                 ).count()
> >             })
>
> > Also, does anyone have any decent documentation on arrays?
>
> Firstly, this is not an array, or even the Python equivalent (a list),
> but a dictionary. If you want documentation on these, you should look
> at the excellent Python docs (eg the reference on standard types 
> athttp://docs.python.org/library/stdtypes.htmlor the tutorial on
> datastructures athttp://docs.python.org/tutorial/datastructures.html).
>
> Secondly, your code has at least one syntax error, but even without
> those, it will always fail because of its logic errors. The initial
> syntax error should be obvious in the line of code you show: you have
> quotes around the 'm', ie referring to the string 'm', when you just
> want to refer to the dictionary m, without quotes.
>
> But even fixed, that line makes no sense. Firstly, do not use 'is' or
> 'is not' for comparisons. That checks for **identity**, which is a
> completely different thing from **equality**. You should use !=
> instead. And then ask yourself how that line could ever be True. You
> have just set ids to a blank dictionary, so there is no such thing as
> ids[anything]. That line will now always fail with an IndexError.
>
> Then, note that both 'ids.append()' and 'manufacturers.append()' will
> fail with AttributeErrors, because these are both dictionaries, not
> lists, and so have no append function.
>
> Perhaps you should explain exactly what you're trying to achieve, with
> an example of the expected output, and we should be able to help in
> more detail.
> --
> 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-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: Arrays

2010-03-22 Thread Daniel Roseman
On Mar 22, 11:19 am, James  wrote:
> Hi,
>
> I am struggling to get a piece of code working.
> I've looked at it too much and now can't see what im doing wrong.
>
> Anyone have any ideas? The error is as follows:
> Type Error
> string indices must be integers - (if ids['m'['manufacturer__id']] is
> not m['manufacturer__id']: )
>
> Code:
>
> tmp_manufacturers = Product.objects.filter(category=category).values(
>         'manufacturer__title', 'manufacturer__slug',
> 'manufacturer__id'
>     ).distinct()
>
>     manufacturers = {}
>     for m in tmp_manufacturers:
>         ids = {}
>
>         if ids['m'['manufacturer__title']] is not
> m['manufacturer__title']:
>             ids.append(m['manufacturer__title'])
>             manufacturers.append({
>                 'title': m['manufacturer__title'],
>                 'slug': m['manufacturer__slug'],
>                 'id': m['manufacturer__id'],
>                 'total_products': Product.objects.filter(
>                     category=category,
>                     manufacturer__slug=m['manufacturer__slug']
>                 ).count()
>             })
>
> Also, does anyone have any decent documentation on arrays?

Firstly, this is not an array, or even the Python equivalent (a list),
but a dictionary. If you want documentation on these, you should look
at the excellent Python docs (eg the reference on standard types at
http://docs.python.org/library/stdtypes.html or the tutorial on
datastructures at http://docs.python.org/tutorial/datastructures.html).

Secondly, your code has at least one syntax error, but even without
those, it will always fail because of its logic errors. The initial
syntax error should be obvious in the line of code you show: you have
quotes around the 'm', ie referring to the string 'm', when you just
want to refer to the dictionary m, without quotes.

But even fixed, that line makes no sense. Firstly, do not use 'is' or
'is not' for comparisons. That checks for **identity**, which is a
completely different thing from **equality**. You should use !=
instead. And then ask yourself how that line could ever be True. You
have just set ids to a blank dictionary, so there is no such thing as
ids[anything]. That line will now always fail with an IndexError.

Then, note that both 'ids.append()' and 'manufacturers.append()' will
fail with AttributeErrors, because these are both dictionaries, not
lists, and so have no append function.

Perhaps you should explain exactly what you're trying to achieve, with
an example of the expected output, and we should be able to help in
more detail.
--
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-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: Remove session on browser close

2010-03-22 Thread Tom Evans
On Mon, Mar 22, 2010 at 11:17 AM, grimmus  wrote:
> Hi,
>
> I have a simple newsletter signup form. If the user submits the form
> and there are no errors then i set the session:
>
> request.session['signed_up'] = True
>
> Then, for all other page requests i check if the session exists
>
>            if request.session.get('signed_up', True):
>                form.thanks = True
>
> form.thanks shows some HTML in the template.
>
> How can i remove the session when the user closes the site ?
>
> I tried SESSION_EXPIRE_AT_BROWSER_CLOSE = True but it does not seem to
> do anything.
>
> Thanks for any advice
>

You can't. Session cookies expire when the user closes their browser,
not your site, and there is no way to detect when a user 'closes the
site',

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: Tagging - Extending by adding a rating?

2010-03-22 Thread Paulo Almeida
I know django-tagging has the Tag model and the TaggedItem model. I wonder
if it would be possible to create the Many to Many relationship between your
Articles and this TaggedItem model, through a Ratings intermediary table. I
have no idea if that would work (and keep all the django-tagging features),
but that's something you can look into.

Best,
Paulo

On Mon, Mar 22, 2010 at 3:21 AM, Victor Hooi  wrote:

> Paolo,
>
> Thanks for the quick reply =).
>
> I did think of that, just using a M2M, however, that means I lose all
> of the inherent features of django-tagging. For our case, that would
> probably be things like helpers to do auto-complete for tags,
> automatically parsing form inputs with commas into tags, tag-clouds
> etc.
>
> Is there any way to somehow leverage off django-tagging? Or am I
> better of starting from scratch on this?
>
> Cheers,
> Victor
>
> On Mar 22, 1:54 pm, Paulo Almeida  wrote:
> > A possible solution would be to create a Many To Many relationship
> between
> > articles and companies, with an intermediary model holding the ratings:
> >
> > http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
> >
> > - Paulo
> >
> >
> >
> > On Mon, Mar 22, 2010 at 2:41 AM, Victor Hooi 
> wrote:
> > > heya,
> >
> > > I have a small Django app we're writing to hold reviews of newspaper
> > > articles.
> >
> > > With each article, there's an arbitrary number of companies or
> > > keywords associated with those articles. And for each of those
> > > companies/keywords, there's either a rating (out of 10), or possibly
> > > no rating (i.e. Null).
> >
> > > I was thinking of using django-tagging to add tags to each article,
> > > but I'm not sure how on the best way to extend it to add in the
> > > ratings. Should I somehow add a field to the tag model? I have a
> > > feeling that's a very broken/improper way of doing things. Or is there
> > > a better way of achieving what I want to do within Django?
> >
> > > Cheers,
> > > Victor
> >
> > > --
> > > 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.
>
>

-- 
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.



Arrays

2010-03-22 Thread James
Hi,

I am struggling to get a piece of code working.
I've looked at it too much and now can't see what im doing wrong.

Anyone have any ideas? The error is as follows:
Type Error
string indices must be integers - (if ids['m'['manufacturer__id']] is
not m['manufacturer__id']: )

Code:

tmp_manufacturers = Product.objects.filter(category=category).values(
'manufacturer__title', 'manufacturer__slug',
'manufacturer__id'
).distinct()

manufacturers = {}
for m in tmp_manufacturers:
ids = {}

if ids['m'['manufacturer__title']] is not
m['manufacturer__title']:
ids.append(m['manufacturer__title'])
manufacturers.append({
'title': m['manufacturer__title'],
'slug': m['manufacturer__slug'],
'id': m['manufacturer__id'],
'total_products': Product.objects.filter(
category=category,
manufacturer__slug=m['manufacturer__slug']
).count()
})


Also, does anyone have any decent documentation on arrays?

-- 
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.



Remove session on browser close

2010-03-22 Thread grimmus
Hi,

I have a simple newsletter signup form. If the user submits the form
and there are no errors then i set the session:

request.session['signed_up'] = True

Then, for all other page requests i check if the session exists

if request.session.get('signed_up', True):
form.thanks = True

form.thanks shows some HTML in the template.

How can i remove the session when the user closes the site ?

I tried SESSION_EXPIRE_AT_BROWSER_CLOSE = True but it does not seem to
do anything.

Thanks for any advice

-- 
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: Primary key in queryset even when using only()

2010-03-22 Thread Kevin Renskers
Thank you very much, this works perfectly!

On Mar 22, 12:01 pm, bruno desthuilliers
 wrote:
> On 22 mar, 11:08, Kevin Renskers  wrote:
>
> > Hi,
>
> > I am using a combination of the only() and distinct() functions on a
> > model to get the unique values of one column. Sadly, the only()
> > function also includes the primary key (even though I only give one
> > column name), which has the effect that all rows are seen as unique.
>
> only() is only (no pun) a complement to defer() - it still loads the
> Model instances, so you'll indeed have the primary key included.
>
> The method you want is values_list:
>
>
>
>
>
> >> results = YourModel.objects.values_list('power_meter', 
> >> flat=True).distinct()
> > This is the result I want:
> > power_meter
> > 1
> > 2
> > 3
>
> > This is the result I get:
> > id      power_meter
> > 80      1
> > 81      1
> > 82      1
> > 83      2
> > 84      2
> > 85      3
> > 86      3
>
> > So I am wondering why the primary key is included in the query, even
> > though I used only('power_meter') in my query.
>
> cf above. Querysets default behaviour is to yield Model instances -
> not raw data -, and Model instances neeed to have their primary key
> loaded to work correctly. If you want raw data, use either values() or
> values_list()
>
> HTH

-- 
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: Primary key in queryset even when using only()

2010-03-22 Thread bruno desthuilliers


On 22 mar, 11:08, Kevin Renskers  wrote:
> Hi,
>
> I am using a combination of the only() and distinct() functions on a
> model to get the unique values of one column. Sadly, the only()
> function also includes the primary key (even though I only give one
> column name), which has the effect that all rows are seen as unique.

only() is only (no pun) a complement to defer() - it still loads the
Model instances, so you'll indeed have the primary key included.

The method you want is values_list:

>> results = YourModel.objects.values_list('power_meter', flat=True).distinct()



> This is the result I want:
> power_meter
> 1
> 2
> 3
>
> This is the result I get:
> id      power_meter
> 80      1
> 81      1
> 82      1
> 83      2
> 84      2
> 85      3
> 86      3
>
> So I am wondering why the primary key is included in the query, even
> though I used only('power_meter') in my query.

cf above. Querysets default behaviour is to yield Model instances -
not raw data -, and Model instances neeed to have their primary key
loaded to work correctly. If you want raw data, use either values() or
values_list()

HTH

-- 
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.



Primary key in queryset even when using only()

2010-03-22 Thread Kevin Renskers
Hi,

I am using a combination of the only() and distinct() functions on a
model to get the unique values of one column. Sadly, the only()
function also includes the primary key (even though I only give one
column name), which has the effect that all rows are seen as unique.

This is the result I want:
power_meter
1
2
3

This is the result I get:
id  power_meter
80  1
81  1
82  1
83  2
84  2
85  3
86  3

So I am wondering why the primary key is included in the query, even
though I used only('power_meter') in my query. I could just do a GROUP
BY, but alas, that's impossible with the ORM...

I am not using an ORDER BY, so that should not be the reason the
primary key is included.

Thanks,
Kevin Renskers

-- 
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 validation tests are applied to ImageField?

2010-03-22 Thread Tom Evans
On Mon, Mar 22, 2010 at 6:51 AM, john2095  wrote:
> But does this all amount to an expectation that it will restrict the
> upload to an image??
>
> I've got this in my model:
>
> class Photo(models.Model):
>    image = models.ImageField(upload_to='photos')
>
> and this in my view:
>    try:
>        p = Photo()
>        p.image = request.FILES['Filedata']
>        p.save()
>        return HttpResponse('OK')
> ...
>
> Yet if I do this:
>
> curl -F fileda...@nasty.exe http://mysite/photo/upload/
>
> It seems quite happy to save the .exe
>
> Can someone please confirm the same test result?   I wouldn't like to
> say "security advisory" prematurely.
>
>
> Thanks.
>

Models don't have validation, forms have validation. If it passed
through a forms.ImageField it would get rejected as invalid.

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: Unicode problems

2010-03-22 Thread Tom Evans
On Sun, Mar 21, 2010 at 9:00 PM, Ruturaj Dhekane  wrote:
> Hi,
>
> I am designing a portal that uses Hindi language using Django.
> When I pass a hindi word from client side to server, in Unicode format, it
> gets converted to 
> type of string on server side.
>
> I want to process this string as unicode too.
> what can be done?
>
> Thanx
> Ruturaj
>
>

Make sure that the page the user is submitting from is served in
UTF-8. IE, ensure that the Content-Type header contains something
like:

'text/html; charset=UTF-8'

If it is not, your web-browser will convert any unicode characters
into HTML unicode entities before submitting.

If you can't change the content type, then any XML library will allow
you to convert unicode entities back into unicode.

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: Unicode problems

2010-03-22 Thread Daniel Roseman
On Mar 21, 9:00 pm, Ruturaj Dhekane  wrote:
> Hi,
>
> I am designing a portal that uses Hindi language using Django.
> When I pass a hindi word from client side to server, *in Unicode format*, it
> gets converted to
> **type of
> string on server side.
>
> I want to process this string as unicode too.
> what can be done?
>
> Thanx
> Ruturaj
>
> --
> [Geekru2]

What do you mean by "pass a word from client side to server"? How are
you doing that? What code are you using - on both sides? How are you
ensuring that it is "in Unicode format"?
--
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-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: Strings in page in []

2010-03-22 Thread bruno desthuilliers
On Mar 22, 12:26 am, serek  wrote:
> Hi
>
> I use djangoflashhttp://djangoflash.destaquenet.com/
> and after add message to flash
>             request.flash.add('message', 'test')
> and redirect
> i receive
> ['test']
> instead
> test


Well, that's the documented behaviour : using "flash.add('key',
value)", you get a list back for key - so you have to take care of
this in the template code. If you don't want a list, use either
"flash['key'] = value" or "flash('key', value)" - as documented, cf
http://djangoflash.destaquenet.com/usage.html

-- 
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 validation tests are applied to ImageField?

2010-03-22 Thread john2095
But does this all amount to an expectation that it will restrict the
upload to an image??

I've got this in my model:

class Photo(models.Model):
image = models.ImageField(upload_to='photos')

and this in my view:
try:
p = Photo()
p.image = request.FILES['Filedata']
p.save()
return HttpResponse('OK')
...

Yet if I do this:

curl -F fileda...@nasty.exe http://mysite/photo/upload/

It seems quite happy to save the .exe

Can someone please confirm the same test result?   I wouldn't like to
say "security advisory" prematurely.


Thanks.


On Mar 18, 9:42 pm, john2095  wrote:
> Perfect. Thanks. That's what I was chasing.
>
> On Mar 17, 11:54 pm, Karen Tracey  wrote:
>
>
>
>
>
> > Validation of image fields is done at the form field level, see:
>
> >http://code.djangoproject.com/browser/django/trunk/django/forms/field...
>
> > 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-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: Forms with read only fields

2010-03-22 Thread Margie Roginski
I implement read-only fields by using widgets that render html that
does not include any .   For example, if I have a field called
hobby in a Customer model, in my form I have something like this:

self.fields["hobby"] = CharField(widget=DisplayHobbyField(customer),
required=False)

DisplayHobbyField::__init__() saves customer in self.customer, and
then its DisplayHobbyField::render renders the value of
customer.hobby.

In order for this to work, you need to *not* put hobby into the form's
Meta.fields list (if this is a modelForm).

If this is a model form, I'm not sure if you would be able to use the
same form for your admin and your non-admin, due to the fact that in
the admin form, you would need hobby to be in Meta.fields, while in
the non-admin form you would need hobby to not be in Meta.fields.
Since Meta.fields is a static field, it seems to me that there is no
way for some versions to the form to have it set one way, and others
have it set another way.  But I am not sure about this.

The way I get around this is to always put hobby into Meta.fields  In
the case where it's a read only field, I send it as a hidden field so
that it goes out in the GET and then gets posted in the POST.  Then I
have a separate read only field that does rendering of the read-only
field  In other words, have

class Meta:
fields = ("hobby",)

if user is admin:
   self.fields["hobby"] = CharField()
else:
self.fields["displayHobby"] =
CharField(widget=DisplayHobbyField(customer), required=False)
self.fields['hobby"} = CharField(widget=HiddenInput())

I have a number of different ways of rendering forms for the same
model, and after much trial and error, I found that my code became
most maintainable when all forms always send the same set of model
fields in their get and post data.  In the case where the field needs
to be read-only, I send the data in hidden fields (by using
specialized widgets).  This allows me to reuse a lot of code (such as
my save methods) without having a lot of special case code that
understand which field are in the model.

I hope this makes sense.  I've seen a lot of people asking about read
only fields and I've found that this mechanism woks really well for
me.  The ability to use special widgets to make your forms specialized
for various purposes is very powerful.


On Mar 20, 8:05 am, Peter Reimer  wrote:
> Hi Folks,
>
> I'm looking for a way to get the following done:
> Depending on different things (user, groups, rights, etc.) I want to
> show a form with fields that can either be changed or not. For
> example, a form with two fields for name and hobby, an admin can
> change both fields, a normal user can only change hobby.
>
> One solution that came to mind: Create a form for both groups and
> exclude in the user's form the fields, he mustn't change. But I want
> two things:
> 1. Show the read-only values at the position where the admin sees the
> writeable fields because a user can be an admin (at another place) and
> it would be confusing to have different positions here and there.
> 2. Have something reusable: E.g. form = MySpecialForm(deactivated =
> [name]).
>
> I checked to docu and googled around, not only some minutes... and
> found nothing.
> Has somebody here a hint for me? I don't want a solution, I'm thankful
> for some little hints.
>
> Thanks & have a nice weekend
> Peter

-- 
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.