Re: Problem with memcache - very bad performance

2010-02-22 Thread Szymon
Hello,

I've turned -vv logging and sometimes it throws:

>18 ERROR
<18 ccopy_reg
>18 ERROR
<18 _reconstructor
>18 ERROR
<18 p1
>18 ERROR
<18 (cdjango.db.models.query
>18 ERROR
<18 QuerySet
>18 ERROR
<18 p2
>18 ERROR
<18 c__builtin__
>18 ERROR
<18 object
[snip - it's long]

Some problem with caching QuerySets?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Is the user member of a certain group

2010-02-22 Thread Joakim Hove
Thank you both;

it works!

Joakim

On Feb 23, 12:27 am, Andy McKay  wrote:
> On 2010-02-22, at 2:56 PM, Joakim Hove wrote:
>
> > Any tip on how to write the "user_is_member_of_admin_group()"
> > function?
>
> You can access the groups via the ManyRelatedManager, which exposes a 
> queryset: user.groups.filter(...)
>
> eg: if user.groups.filter(name="Admin")
> --
>   Andy McKay, @clearwind
>  http://clearwind.ca/djangoski

-- 
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: ContentType/GenericRelations question

2010-02-22 Thread Scott SA
Ouch, I hate the high-speed, palm-forehead interface... esp. in
public! LOL

Not sure why this didn't occur to me earlier, but I found a solution
to what I am looking for (I'm still curious to know if there is an
easier way, always like to go with the flow when possible).

In short, the related classes are, well, short of the Manager class.

Here's a cheesy example:

class CustomNotes( models.Model )
value = models.TextField()
modified = models.DateTimeField( auto_now = True )
...
# the generic-relation stuff
content_object  =  generic.GenericForeignKey()
content_type  =  models.ForeignKey( ContentType )

objects = models.Manager()

class ClassNeedingNotes( models.Model ):
index = models.IntegerField()
...
# the generic-relation stuff
notes = GenericRelation( CustomNotes )

I am fully aware that there are issues when trying to relate the
acquired list of objects back to their original class. The connections
mechanism is not the same, it's a GenericRelation after all.

My problem was, I needed to globally process what in this example is
the 'CustomNotes' class. There are a couple of other functional
reasons I wanted to be able to have direct access to the tables, but I
won't bore anyone here with it.

So, hopefully someone else will either say, 'yup, that's how', 'great,
what I needed' or, give me another reason to slap my forehead.

S

On Feb 22, 5:54 pm, Scott SA  wrote:
> Hopefully this won't be a forehead slapper of a question.
>
> Since related classes do not have an 'object' manager, what is the
> best way to get all of those objects as a set?
>
> For example, if I have a BaseClass that has a generically-related
> AttributeClass, I can get the attributes from an instance of BaseClass
> i.e. base_instance.attributeclass_set.all().
>
> But I'm looking for similar functionality to
> AttributeClass.objects.all(), kind of reverse but without having to
> have a BaseClass instance (which then limits the results).
>
> An easy way to visualize this is a contact with multiple phone
> numbers. I'm looking to get a set of all phone numbers, regardless of
> contact. Presently, I only see how to get those related to a
> particular contact-object.
>
> 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: ValidationError: ManagementForm data is missing or has been tampered with

2010-02-22 Thread DrMeers
I have the same problem -- only intermittently, only IE, can't put my
finger on what is causing it. A couple of times a month I get an
emailed error message coming through. I have not been able to
replicate it on my machine, even using IE and performing the same
operation; very odd.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to get as_sql() to work again

2010-02-22 Thread Russell Keith-Magee
On Tue, Feb 23, 2010 at 10:42 AM, felix  wrote:
>
> On Feb 23, 12:32 am, Russell Keith-Magee 
> wrote:
>
>> To reinforce my point - if you're using Django's ORM, you shouldn't
>> have to care about the underlying query. The ORM *should* be
>> abstracting these details so that you don't care. I realize that
>> inspecting query internals can be useful in practice, but from my
>> perspective, every time you need to do this Django's ORM has failed a
>> little bit.
>
> I would like my client and his clients not to care.
>
> I will need to care.  I need to know exactly what queries are being
> run and how long they took ( or would you outlaw things like debug
> footer too ? )

... and here we have yet another example of the type of hyperbole I'm
talking about.

Django provides *several* ways to find out what SQL has been (or will
be) executed. You can inspect QuerySet.query in several different ways
(str(), get_compiler().as_sql()). There is the debug query log - which
will tell you how long queries took to execute, as well as the SQL
that was used. If those options don't suit, you can go to the database
and look at the logs provided there.

I have at no point claimed that you *shouldn't* be looking at the
internals. I'm saying that the internals aren't part of the core API
that we're trying to promote, and that trying to provide a stable API
for inspecting unstable internals is a folly.

> Look, I love the Django ORM, I'm having a great time.
>
> It is not a failure of the Django ORM, please don't think of it like
> that.  If the Django ORM is to succeed and improve then it will need
> its programmers to have full access to it.  Do you think race car
> drivers don't know how their engines work ?  Do you think they don't
> know when they've changed gears?  Don't you want some smart kid to
> figure out how to optimize the queries even better ?  The more info
> and access, the better.

Sure. But to continue your analogy, what you're advocating is that a
racecar driver should have the same easy to use automatic gearbox and
simple instrument panel that my grandmother has in her 1995 Honda
Civic.

If you're a racecar driver, part of your job is to pay attention to
the internals, and to accept that in order for your car to go a little
faster, you're going to need to pay attention to what the mechanics
have done. Sometimes, this means the instrument panel will change, or
you'll need to change your style when releasing the clutch.

Besides - the internals of Django's query engine *are* completely
exposed. They're just not officially stable. That said, they've been
effectively stable since QSRF landed over two years ago. The arrival
of multi-db has shaken things up a bit, and as a result, the
anti-stall launch control that drivers like yourself have used in the
past doesn't work like it used to.

To demonstrate the scope of the problem - we could *easily* add an
as_sql() function back onto Query, so that the old
Author.objects.all().query.as_sql() trick would still work (def
as_sql(self): return __str__(self)). However, the result returned by
that call would be incorrect (or at least, potentially misleading) in
the same way that the result returned by str(queryset.query)  is
wrong. So, what is better?

 1) A consistent API entry point that provides inconsistent or
incorrect results as the internals change

 2) An inconsistent API that *occasionally* changes (and I do mean
*occasionally*), but is able to reflect the changes in internals.

Evidently, you support (1). I support (2) -- if only because a change
in interface forces people to think about the change that has
occurred, and the way that this change might affect them.

> Look, its not hyperbole to say its essential.  Getting the SQL that is
> generated is very basic and essential. These are db driven apps.

Yes, it really is hyperbole. You have always been able to get access
to the SQL. You still can. Exactly *zero* production code should need
to access or monitor the SQL that is being generated. Accessing the
generated query is *entirely* a debugging activity for medium to
advanced Django developers that are either trying to push the envelope
of what Django's query engine can produce, or debug what Django is
doing so they can patch the query engine. Neither of these activities
require a stable API. They only require that the API be *available* --
which it is.

> Can I pay the ponies no more than $3/hr ?  They can be late and
> occasionally wrong, I'll just make up some bullshit for my client.

I'd be more than happy to be paid *at all*. Remember, I'm doing this
as a volunteer.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 

Re: weird CSS behaviour

2010-02-22 Thread Josh Kersey
It would be nice to see your templates.  Post the django template code
for base, index, and register somewhere like dpaste.com and then
provide us the link.  Kind of hard to make a guess at this point but
seeing the code will help.

- Josh
cabedge.com


On Feb 22, 8:55 am, Maciek Strzelecki 
wrote:
> Hello, and straight to the point:
>
> Once upon a time there was a Base Template, called base.html:
>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;>
> http://www.w3.org/1999/xhtml; xml:lang="en" lang="en">
> 
> some title
> 
> 
> 
> 
> 
>  [... and the body continues]
>
> Please note that i put links to css in HEAD part.
>
> Now, i click between two main pages of my website - "index" and
> "register"
> The "show page source" in firefox outputs identical text (obviously
> different a bit for the container parts for register and index which
> *are* different. What *is* important tho, is that those two pages
> share the same "parent" template - "base.html", and that excerpt looks
> the same on both "sources")
>
> One of the pages - index -acts as if *there were* a "padding: 20px"
> clause in style. Except there is NOT. Index page has a grey 20px "bar"
> on the very top, register has none (and thats correct)
>
> Firebug shows me even stranger thing - as i compare using the html
> structure tool i see that:
>
> register page - links to css shown in , correctly.
> index page - links to css shown in  (why the hell there?! - they
> ARE inside head in the base template)
>
> Excuse lengthy post and not very clear "subject" but i have no idea
> whats happening here. And it seems that the gray bar (padding) is just
> a part of the problem since there seems to be a whole style to be
> inserted, messing Internet explorer up completely.
>
> im really really hoping that some one points out the obvious thing i
> missed :)
>
> (Im developing a rather simple web app - users can log in, log out,
> browse categories, make lists of their favourites stuff and so on.
> Nothing fancy.)
>
> if anything is not clear enough - please ask :)
> Thank You.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to get as_sql() to work again

2010-02-22 Thread felix


On Feb 23, 12:32 am, Russell Keith-Magee 
wrote:

> To reinforce my point - if you're using Django's ORM, you shouldn't
> have to care about the underlying query. The ORM *should* be
> abstracting these details so that you don't care. I realize that
> inspecting query internals can be useful in practice, but from my
> perspective, every time you need to do this Django's ORM has failed a
> little bit.

I would like my client and his clients not to care.

I will need to care.  I need to know exactly what queries are being
run and how long they took ( or would you outlaw things like debug
footer too ? )

Look, I love the Django ORM, I'm having a great time.

It is not a failure of the Django ORM, please don't think of it like
that.  If the Django ORM is to succeed and improve then it will need
its programmers to have full access to it.  Do you think race car
drivers don't know how their engines work ?  Do you think they don't
know when they've changed gears?  Don't you want some smart kid to
figure out how to optimize the queries even better ?  The more info
and access, the better.

We (including you) need to have basic tools to see what's going on in
the query.  Just as we need to know where exceptions happened, what
the callstack looks like when shiznitt blows up and what templates and
vars were involved.  Why is the ORM different than looking at the
context variables in a template ?  This is automatic transmission and
we need to see exactly what our high-level commands are resulting in.
That is NOT a failure of the ORM.

My point is also that you should not separate us from you.  We are not
end users.  Some of us are damned smart and we might improve something
in django's ORM, find a bug, or tune our django-ORM calls.

Look, its not hyperbole to say its essential.  Getting the SQL that is
generated is very basic and essential. These are db driven apps.

I'm just letting you know: I was stunned that I had to spend so much
time searching and that both you and James Bennet replied "oh  you
don't".  As though magical ponies would soon come and proffer the data
to us.  We'll be napping in our plush purple fields as the ponies come
bring us our query sets.

Can I pay the ponies no more than $3/hr ?  They can be late and
occasionally wrong, I'll just make up some bullshit for my client.



> > My suggestion is simply that there be a public utility function
> > somewhere that can remain stable.
>
> Point taken, but please understand that it's hard to provide a stable
> utility function for unstable internals.

But that's exactly why Y'ALL (rather than me or some snippet or blog
post) should provide said function in the django distribution, up to
date, always working for the distribution the person has dutifully
downloaded.

Internals should be free to be refactored. That's what public API
calls are for.

Its the alternative to putting the function on the QuerySet (since
QuerySets wish to remain sql-agnostic, may connect in the future to
other non-db entities and perhaps even to data sources from other
lifeforms that do not comprehend this simplistic "relational" crap of
humankind.  relational implies an illusionary separation, a division
of Godhead, lost in the realms of ignorance and needless division )

It is BECAUSE internals should be allowed to change that you offer a
public function that works as advertised.


> >> That said:
>
> >> print object.query

> It works fine - if you do what I said to do.

oh right, you said the magic word "print".  which invokes the god of
transformation  unicode ? or repr ?

IMO this is transferring what should be explicit methods and
functionality into a basic function: print or string representation.
if the desired effect is to get a SQL query string then a method
should be named that and should deliver that.

transformational functionality should not utilize unicode or repr as
means to achieve this.  this might be a python disease.

notice that I didn't even notice that "print" was REQUIRED.  my
assumption is that .query was the result and you were just printing it
for me.

print should be simply to print in whatever format makes sense for the
object involved, not to magically transform into a different creature
and print that.

and its infuriating when debugging

yesterday I was dealing with an object in a filter:
Apt.objects.filter(id__in=[1,2,3,4])

the [1,2,3,4] gets printed, but that isn't what it IS. no its ... some
kind of weird query set.  you have to constantly use obj.__class__
because you can't TRUST print or repr()

another half hour of my life wasted.  (I'm just being honest. I'm a
djangoista ! django rocks man !)


>The magic is in the __str__ function.

grrr.  Harry Potter magic shite, I tell you.

anyway, thanks very much for all your work and your reply


>
> Yours,
> Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, 

ContentType/GenericRelations question

2010-02-22 Thread Scott SA
Hopefully this won't be a forehead slapper of a question.

Since related classes do not have an 'object' manager, what is the
best way to get all of those objects as a set?

For example, if I have a BaseClass that has a generically-related
AttributeClass, I can get the attributes from an instance of BaseClass
i.e. base_instance.attributeclass_set.all().

But I'm looking for similar functionality to
AttributeClass.objects.all(), kind of reverse but without having to
have a BaseClass instance (which then limits the results).

An easy way to visualize this is a contact with multiple phone
numbers. I'm looking to get a set of all phone numbers, regardless of
contact. Presently, I only see how to get those related to a
particular contact-object.

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: Best practices for restricting media?

2010-02-22 Thread Graham Dumpleton


On Feb 23, 5:00 am, David De La Harpe Golden
 wrote:
> On 22/02/10 16:48, Brice Leroy wrote:
>
> > Hello Brett,
> > If you use nginx you can use the X-Accel-Redirect function.
>
> Minor: if you _don't_ use nginx but rather apache or lighttpd,
> similar feature is called "X-Sendfile".

If you are using mod_wsgi 3.X and use its daemon mode, you can also
use 'Location' response header with status of 200 just like in CGI and
wouldn't require mod_sendfile. Using 'Location' is like using 'X-Accel-
Redirect' in nginx in that it is a URL which is remapped on the
server. The difference is that in Apache you have to use a mod_rewrite
rule if you want to mark a part of URL namespace as not public, but
instead only accessible from an Apache subrequest.


Thus:

  # Map URL for private files.

  Alias /private/ /some/path/private/

  # Block access to private files except from an Apache sub request.

  RewriteCond %{IS_SUBREQ} !true
  RewriteRule  ^/private/ [F]

The application would then return response header:

  Location: /private/secret.txt

The status code returned for the HTTP request should be '200'.

Graham

-- 
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: Problem with PIL in Mac OS X 10.4

2010-02-22 Thread piz...@gmail.com
Thank you very much, I followed your instructions and it worked  
perfectly. This is what I've done (if someone needs it):


- Download jpeg6b
- Copy the config.sub and config.guess located at ~/gtk/source/ 
libtool-2.2.6/libltdl/ (I've installed GTK+ for OSX with gtk-osx- 
build-setup.sh so I dont' have a /usr/share/libtool)
- Delete the old PIL at /Library/Frameworks/Python.framework/Versions/ 
2.6/lib/python2.6/site-packages/PIL-1.1.7-py2.6-macosx-10.3-fat.egg/

- Download PIL 1.1.7 source and install it

El 22/02/2010, a las 23:59, Tim Shaffer escribió:


You'll have to manually install libjepg to get PIL working on a Mac.

If you have MacPorts installed, you should just be able to do "sudo
port install jpeg".

Otherwise, you can download it from one of these locations:

http://dir.filewatcher.com/d/GNU/Other/jpegsrc.v6b.tar.gz.613261.html

Then follow these instructions to build and install it:

http://snippets.dzone.com/posts/show/38

IIRC, you will need to reinstall/rebuild PIL after you install
libjpeg. Installing it via easy_install might not work properly.

On Feb 22, 5:22 pm, Oscar Carballal  wrote:

Hello,

I've just installed Django CMS in my Mac OS X 10.4.11 with Python  
2.6.
One of the requisites is the PIL library, which I've installed  
through

"easy_install" and tested after installation.

Even when the Python interpreter loads the module and works fine with
it, Django and Django CMS keep saying the imaging library is not
installed. This is the message:

Error: One or more models did not validate:
picture.picture: "image": To use ImageFields, you need to install the
Python Imaging Library. Get it athttp://www.pythonware.com/ 
products/pil/

.

I have PIL 1.1.7 with Python 2.6.4 on Mac OS X 10.4.11. I have PIL
installed in: /Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/PIL-1.1.7-py2.6-macosx-10.3-fat.egg/

Any ideas?


--
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: django and ldap

2010-02-22 Thread Peter Herndon

On Feb 22, 2010, at 3:13 PM, andreas schmid wrote:

> Peter Herndon wrote:
>> On Mon, Feb 22, 2010 at 9:40 AM, andreas schmid  wrote:
>> 
>> 
>>> im experiencing strange problems now. the user is able to authenticate
>>> against ldap only if in the active directory the displayName == username
>>> why this? i dont get any error or traceback, the user only isnt able to
>>> get logged in
>>> 
>>> 
>> 
>> If users were able to authenticate, and are now not able to
>> authenticate, what changed?  
> i was thinkin the authentication over ldap group was working because i
> testet it only whith a testuser which had sAMAccountName == displayName
> but now im figuring that if thats not equal it desnt work as expected.
> the app is still in development and i didnt work on it for a few days.

Hmm.  When I get to work tomorrow, I'll take a look and see if the displayName 
is the same as the sAMAccountName in our AD.  If they are consistently the 
same, that might be a sign that some part of this operation is looking at the 
displayName.

It occurs to me, Andreas, I'd be very interested to know if someone who has a 
displayName *different* from the sAMAccountName can log in initially, but not a 
second time; or, can that person not log in at all? Is it consistent? If you 
change someone's displayName, do they instantly stop being able to log in?


>> 
> i started to log a bit today and will go on tomorrow and post what i
> will get or the solution if i will find it.

Do let me know. I'm wondering if the problem is with the bind setting on line 
81 of backends.py.  Where I work, our AD is configured to accept 
"hernd...@example" for the bind, where the "@example" is your NT4_DOMAIN 
setting.  If your AD is not configured to accept that kind of identifier, that 
might cause an issue.  We may need to mix things up a bit, and try a 
search-for-user-and-then-bind approach similar to the one in the eDirectory 
backend starting at line 157.  It also occurs to me that the "n...@domain" 
pattern might be looking at displayName -- I'm no expert on Active Directory.  
To that end, you may want to insert a logging statement of the exception that's 
caught at line 134, between 134 and 135.

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



Re: how to get as_sql() to work again

2010-02-22 Thread Russell Keith-Magee
On Tue, Feb 23, 2010 at 1:17 AM, felix  wrote:
>
> On Feb 22, 9:22 am, Russell Keith-Magee 
> wrote:
>> > However getting the SQL that will be produced is essential.  There
>> > needs to be a utility method somewhere that will give us this sql and
>> > it needs to remain stable.
>>
>> Well, no -- it isn't essential. It might be a very handy debugging
>> tool, but it isn't essential.
>
> I will again strongly disagree with that.  You might as well declare
> every other debugging tool to be non-essential.  Unless you mean to
> say that unless it involves serving web pages to actual people it
> technically isn't "essential".

Exactly. It isn't *essential*. You can serve web pages - the primary
function of Django - without ever using inspecting the internals of a
query.

My point is that hyperbole doesn't win you any extra attention.

> Working with a NoSQL ORM requires being able to see the query that it
> generates when something is going wrong. You can't fix a problem if
> you can't see what's happening.

To reinforce my point - if you're using Django's ORM, you shouldn't
have to care about the underlying query. The ORM *should* be
abstracting these details so that you don't care. I realize that
inspecting query internals can be useful in practice, but from my
perspective, every time you need to do this Django's ORM has failed a
little bit.

> My suggestion is simply that there be a public utility function
> somewhere that can remain stable.

Point taken, but please understand that it's hard to provide a stable
utility function for unstable internals.

>> That said:
>>
>> print object.query
>
> In [1]: qs = Apt.objects.all()
>
> In [2]: qs.query
> Out[2]:  0x3aede50>
>
> see, that one doesn't work.

It works fine - if you do what I said to do.

>>> User.objects.all().query


>>> print User.objects.all().query
SELECT "auth_user"."id", "auth_user"."username",
"auth_user"."first_name", "auth_user"."last_name",
"auth_user"."email", "auth_user"."password", "auth_user"."is_staff",
"auth_user"."is_active", "auth_user"."is_superuser",
"auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user"

The magic is in the __str__ function.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Is the user member of a certain group

2010-02-22 Thread Andy McKay

On 2010-02-22, at 2:56 PM, Joakim Hove wrote:
> Any tip on how to write the "user_is_member_of_admin_group()"
> function?

You can access the groups via the ManyRelatedManager, which exposes a queryset: 
user.groups.filter(...)

eg: if user.groups.filter(name="Admin")
--
  Andy McKay, @clearwind
  http://clearwind.ca/djangoski

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Is the user member of a certain group

2010-02-22 Thread Tim Shaffer
There may be a more efficient way, but you can use this for starters:

if ( "admin" in request.user.groups.values_list("name",flat=True) ):

On Feb 22, 5:56 pm, Joakim Hove  wrote:
> Hello,
>
> using the django auth framework I have created two groups called
> "admin" and "normal" and all the users are members of either of these
> groups. Now when a user is authenticated I would like to render
> different views depending on which group the user is member of,
> something like this:
>
> if user_is_member_of_admin_group():
>    render_to_response("admin_template.html", context)
> elif user_is_member_of_normal_group():
>    render_to_response("normal_template.html , context)
> else:
>    hmmm - internal applcation error!
>
> Any tip on how to write the "user_is_member_of_admin_group()"
> function?
>
> Joakim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem with PIL in Mac OS X 10.4

2010-02-22 Thread Tim Shaffer
You'll have to manually install libjepg to get PIL working on a Mac.

If you have MacPorts installed, you should just be able to do "sudo
port install jpeg".

Otherwise, you can download it from one of these locations:

http://dir.filewatcher.com/d/GNU/Other/jpegsrc.v6b.tar.gz.613261.html

Then follow these instructions to build and install it:

http://snippets.dzone.com/posts/show/38

IIRC, you will need to reinstall/rebuild PIL after you install
libjpeg. Installing it via easy_install might not work properly.

On Feb 22, 5:22 pm, Oscar Carballal  wrote:
> Hello,
>
> I've just installed Django CMS in my Mac OS X 10.4.11 with Python 2.6.
> One of the requisites is the PIL library, which I've installed through
> "easy_install" and tested after installation.
>
> Even when the Python interpreter loads the module and works fine with
> it, Django and Django CMS keep saying the imaging library is not
> installed. This is the message:
>
> Error: One or more models did not validate:
> picture.picture: "image": To use ImageFields, you need to install the
> Python Imaging Library. Get it athttp://www.pythonware.com/products/pil/
> .
>
> I have PIL 1.1.7 with Python 2.6.4 on Mac OS X 10.4.11. I have PIL
> installed in: /Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/site-packages/PIL-1.1.7-py2.6-macosx-10.3-fat.egg/
>
> Any ideas?

-- 
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 the user member of a certain group

2010-02-22 Thread Joakim Hove
Hello,

using the django auth framework I have created two groups called
"admin" and "normal" and all the users are members of either of these
groups. Now when a user is authenticated I would like to render
different views depending on which group the user is member of,
something like this:


if user_is_member_of_admin_group():
   render_to_response("admin_template.html", context)
elif user_is_member_of_normal_group():
   render_to_response("normal_template.html , context)
else:
   hmmm - internal applcation error!


Any tip on how to write the "user_is_member_of_admin_group()"
function?


Joakim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Problem with PIL in Mac OS X 10.4

2010-02-22 Thread Oscar Carballal
Hello,

I've just installed Django CMS in my Mac OS X 10.4.11 with Python 2.6.
One of the requisites is the PIL library, which I've installed through
"easy_install" and tested after installation.

Even when the Python interpreter loads the module and works fine with
it, Django and Django CMS keep saying the imaging library is not
installed. This is the message:

Error: One or more models did not validate:
picture.picture: "image": To use ImageFields, you need to install the
Python Imaging Library. Get it at http://www.pythonware.com/products/pil/
.

I have PIL 1.1.7 with Python 2.6.4 on Mac OS X 10.4.11. I have PIL
installed in: /Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/PIL-1.1.7-py2.6-macosx-10.3-fat.egg/

Any ideas?

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



Problem with restructuredtext filter

2010-02-22 Thread Gianluca Pacchiella
I have written for a personal django app (actually a blog), a new
restructured text role that allows to use TeX syntax and rendering math
formulas; the problem is that I don't want to allow this in comment. To
avoid to load the TeX related role I use the following snippet of code
where I delete the role directly by popping it from roles._role_registry
dictionary



@register.tag(name='restructuredTextWO')
def restructured_text_without(parser, token):
nodelist = parser.parse(('endrestructuredTextWO',))
parser.delete_first_token()

try:
tag_name, role_name = token.contents.split(None, 1)
except ValueError:
raise template.TemplateSyntaxError(
'%r tag requires an argument' % token.contents.split()[0])

return Without(nodelist, role_name)

class Without(template.Node):
def __init__(self, nodelist, role_name):
if settings.DEBUG:
print 'Without', role_name
self.nodelist = nodelist
self.role_name = role_name
self.role_fn = None

def render(self, context):
from docutils.parsers.rst import roles

self.role_fn = roles._role_registry.pop(self.role_name, None)

output = self.nodelist.render(context)

if self.role_fn:
roles._role_registry[self.role_name] = self.role_fn

return output



In the template I have



{{blog.title|capfirst}}

{{blog.creation_date|date:"D d M Y"}}


{{blog.content|restructuredtext}}


Comments

{% get_comment_list for blog as comments %}
{% for comment in comments %}
{% comment_entry comment %}
{% endfor %}



where comment_entry is a inclusion tag defined as



{% load markup %}
{% restructuredTextWO tex %}

posted by {{username}}
at {{date|date:"D d M Y"}}
{{content|restructuredtext}}

{% endrestructuredTextWO %}




Now, the problem is that this doesn't work if also the blog contains the
:tex: role and I don't understand why: there is something I'm missing in
how the template rendering works?

I would appreciate some hints about that.

-- 
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: Problem with memcache - very bad performance

2010-02-22 Thread Szymon
On 22 Lut, 22:50, Javier Guerra  wrote:
> are you sure you get memcached store on RAM? maybe it's being swapped out

Yes. Swap hasn't been touched yet since last reboot.

Mem: 400M Active, 2915M Inact, 354M Wired, 66M Cache, 214M Buf, 193M
Free
Swap: 4000M Total, 4000M Free

But that's strange:

# netstat | grep localhost.11211 | wc -l
652

It's ok? Almost all in "TIME_WAIT" state. Now, when there is really
small traffic.

-- 
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: Problem with memcache - very bad performance

2010-02-22 Thread Javier Guerra
On Mon, Feb 22, 2010 at 4:34 PM, Szymon  wrote:
> On 22 Lut, 21:15, Szymon  wrote:
>> 5 secs.
>
> CPU secs. of course.
>
> Now, on lighter traffic (same view).
>
> 12.1%   0.069 build/bdist.freebsd-7.1-RELEASE-amd64/egg/memcache.py
>
> Strange. Probably on higher load I will get faster response times just
> querying DB. :S Any suggestions? Maybe it's normal?

are you sure you get memcached store on RAM? maybe it's being swapped out

-- 
Javier

-- 
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: Admin screen pluralizing models inappropriately and database relations question

2010-02-22 Thread Timothy Kinney
I'm still struggling with obtaining a nice list of items for a samurai in
the admin view. I can iterate over them in a template, but I want to get
them all at once in an admin view without iteration. I have a separate model
for Inventory which has foreign keys for Samurai and Item. The trick is to
see a list of items that each samurai has in the admin view without having
to iterate. Actually, iteration would be okay as long as it fit in the items
column of the admin view.

For example, I do this:

** models.py **
class Samurai(models.Model):
   # other stuff

def items(self):
return self.inventory_set.filter(samurai = self.pk).values_list('item',
flat=True).order_by('item')

** admin.py **
class SamuraiAdmin(admin.ModelAdmin):
list_display = ('name', 'family_name', 'id', 'room', 'items')

** / code **

But in the 'items' column, it outputs:
[u'O-yoroi', u'Rice', u'Sharp Katana', u'Wakizashi']

How can I construct the query set to just print the list (without the [ ]
brackets) and without the unicode u in front of everything? Like this:
O-yoroi, Rice, Sharp Katana, Wakizashi

Thank you for your time.

-Tim





On Fri, Feb 19, 2010 at 3:48 PM, Timothy Kinney wrote:

> Thanks again for the help, and thank you very much for the links! I have
> been looking for examples of django rpgs with little success. Once I get
> something functional I plan to contribute to the open-source community as
> well.
>
> Cheers.
>
> -Tim
>
>
>
> On Fri, Feb 19, 2010 at 3:02 PM, Tim Shaffer  wrote:
>
>> You should be able to list all of a samurai's items by doing the
>> following:
>>
>> samurai = Samurai.objects.get(pk=1)
>> for inv in samurai.inventory_set.all():
>>print inv.item.name
>>
>> samurai.inventory_set returns a QuerySet the same way that
>> Inventory.objects returns a QuerySet, but it only returns inventory
>> items belonging to that specific samurai.
>>
>> So this:
>>
>> s = Samurai.objects.get(pk=1)
>> s.inventory_set.all()
>>
>> Is essentially the same as doing this:
>>
>> s = Samurai.objects.get(pk=1)
>> Inventory.objects.filter(samurai=s)
>>
>> I've actually also researched RPG-like environments in Django. Check
>> out these links, if you haven't already, for some sample code. Seems
>> to be the best I've found so far.
>>
>> http://code.google.com/p/django-mmo/
>>
>> http://www.rkblog.rk.edu.pl/w/p/code-snapshot-ice-isle-django-web-crpg-game/
>> http://github.com/batiste/django-rpg
>>
>> sounds like it could be a great project. have fun!
>>
>> On Feb 19, 2:18 pm, Timothy Kinney  wrote:
>> > Hi Tim,
>> >
>> > Thanks for the concrete examples. I actually had exactly what you had
>> coded
>> > last night, but I got rid of it because having multiple inventories for
>> a
>> > single samurai seemed counter-intuitive to me. But it sounds like it's
>> the
>> > best way to get the granularity I want.
>> >
>> > Going back to that system I have a different problem then. If I want to
>> list
>> > all of the items that a samurai has in his inventory I would like to use
>> a
>> > samurai.item_set method, but this method fails with multiple
>> inventories. It
>> > also didn't seem to work with a samurai.inventory_set method.
>> >
>> > I'm okay with having multiple inventories for one samurai, but what is
>> the
>> > best practice for accessing them all as one inventory?
>> >
>> > I apologize for the intensive questioning. I hope this discussion is
>> helping
>> > other users who are new to django. I had searched extensively for django
>> > implementations of RPG-like inventories and characters and didn't find
>> any.
>> > I'm sure there are other people in the same boat.
>> >
>> > Cheers.
>> >
>> > -Tim
>> >
>> > On Fri, Feb 19, 2010 at 7:49 AM, Tim Shaffer 
>> wrote:
>> > > Basically what you are trying to do is called a many-to-many
>> > > relationship with an intermediary table.
>> >
>> > > If it was a regular many-to-many relationship, you could just do
>> > > ManyToManyField(Item) on the samurai model, and there would be a table
>> > > with a foreign key to item, and a foreign key to samurai, and nothing
>> > > else. But since you need to specify attributes about each of those
>> > > relationships (in this case, condition), you have to use an
>> > > intermediary table (Inventory) with those foreign keys, plus your
>> > > additional attributes. It's not uncommon thing to do at all.
>> >
>> > > So if you are using an Inventory class like that, you would want to
>> > > have this:
>> >
>> > > item = models.ForeignKey(Item)
>> >
>> > > instead of this:
>> >
>> > > item_id = models.ManyToManyField(Item)
>> >
>> > > Think of one inventory record as one item belonging to one samurai,
>> > > with a condition. So if a samurai has more than one of the same same
>> > > item, he would have more than one inventory record.
>> >
>> > > If you were creating your models starting from scratch, you might come
>> > > up with 

Re: Problem with memcache - very bad performance

2010-02-22 Thread Szymon
On 22 Lut, 21:15, Szymon  wrote:
> 5 secs.

CPU secs. of course.

Now, on lighter traffic (same view).

12.1%   0.069 build/bdist.freebsd-7.1-RELEASE-amd64/egg/memcache.py

Strange. Probably on higher load I will get faster response times just
querying DB. :S Any suggestions? Maybe it's normal?

-- 
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: Problem with DateField (Rooky)

2010-02-22 Thread Shawn Milochik
DEFAULT_DATE_INPUT_FORMATS is on the deprecation timeline, just FYI.

The formatting options are for the way data can be input into a form object. 
Django always stores dates the same way (per database backend).

Are you using Django with an already-existing database full of data?

Also, your code shows you using a forms.DateField instead of a 
models.DateField. I wouldn't even think that could work.

Do you know that the formats you choose for the forms.ModelForm is irrelevant 
to the way the data is stored in the database? 

Please let us know whether you're trying to get old (pre-Django) data to work 
with Django, or new (created by Django) data to be displayed in a specific 
format in your Django application.

Shawn

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



Problem when copy django-admin templates directory

2010-02-22 Thread konatufe
I'm trying to change django templates to my own directory templates
copying the django-admin templates directory.

cp -R /usr/local/lib/python2.6/dist-packages/django/contrib/admin/
templates/admin /home/konatufe/djproyect/djapp/templates/

When do that, I can't see the change_list page of admin interface,
because appear the next error:

Template error

In template /home/konatufe/djproject/djapp/templates/admin/
change_list.html, error at line 77
Invalid block tag: 'admin_actions'

Someone can give me a tip to resolve this?

-- 
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: Slugify() and Clean form data Questions

2010-02-22 Thread Jon Loeliger
> 
> Hope this better answers your question,
> Matt

Matt,

Indeed it does.  Thank you!

I guess a bit of the frustrating part of learning Django here
is stumbling across the sites that explain how to do various
tidbits of functionality, and then slide in some variant [*1*]
of "But one would never do this on a production site." warning.

I think to myself "But this is *exactly* the functionality I need."
So, uh, what *should* I do differently then?  Or, um, OK, so,
why not take the next step in the write-up and tell me what the
best practice is so I *can* "do this in a production setting."

I read chapter 20.  And when I was done, I had an inkling that
Django escaped my user data when it went to HTML output.  Good.
And I read where "Django's API does this [escape SQL] for you".

But what wasn't clear to me was how much *more* I really should do.
How worried should I be?  Should I write better form cleaning and
validating functions?  Should I write custom save() functions to
search for SQL or script hacks?  That sort of thing.

And from the sounds of it, you are saying Django has taken large and
likely sufficient steps already.  Most excellent!  And thank you!

Thanks,
jdl

[*1*] Off hand examples:

http://lethain.com/entry/2007/dec/01/using-jquery-django-autocomplete-fields/

http://lethain.com/entry/2008/sep/21/intro-to-unintrusive-javascript-with-django/

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



Problem with DateField (Rooky)

2010-02-22 Thread anvasila
My DataBase has the dates like "2003-08-31" and the django take them
like this: "May 9, 2024".How can i change that in Django?  At first i
was trying something like this date=models.DateField(default="%Y-%m-
%d)

Next is try this:


from django import forms
from django.forms.fields import DEFAULT_DATE_INPUT_FORMATS
from django.db import models


class EuDateFormField(forms.DateField):
def __init__(self, *args, **kwargs):
kwargs.update({'input_formats': ("%Y-%m-%d")})
super(EuDateFormField, self).__init__(*args, **kwargs)

class EuDateField(models.DateField):
def formfield(self, **kwargs):
kwargs.update({'form_class': EuDateFormField})
return super(EuDateField, self).formfield(**kwargs)

class england(models.Model):
  div = models.CharField(max_length=2)
  date = EuDateField('Date Played', null=True, blank=True,
help_text="")
  hometeam = models.CharField(max_length=50)
  awayteam = models.CharField(max_length=50)
  fthgoals = models.IntegerField()
  ftagoals = models.IntegerField()
  ftresult = models.CharField(max_length=1)
  ftgoals = models.IntegerField()
  hthgoals = models.IntegerField()
  htagoals = models.IntegerField()
  htresult = models.CharField(max_length=1)
  hredcards = models.IntegerField()
  aredcards = models.IntegerField()
  htrating = models.FloatField()
  atrating = models.FloatField()
  rating_diff = models.FloatField()
  home_team_form = models.IntegerField()
  away_team_form = models.IntegerField()
  form_diff = models.IntegerField()
  htform_at_home = models.IntegerField()
  atform_at_away = models.IntegerField()
  home_away_form_diff = models.IntegerField()

  def over_under(self):
if(self.ftgoals>2):
  return('Over')
else:
  return('Under')
  over_under.short_description = 'Over/Under'
  def __unicode__(self):
return self.hometeam


I try this but nothing change... :(

What to do to make DJango read date in Y-m-d form???

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



Problem with memcache - very bad performance

2010-02-22 Thread Szymon
Hi,

I'm using latest Django trunk and have problems with memcache. For few
days my site is struggling with performance. I've blamed mod_wsgi,
I've blamed Apache, I've blamed Postgres on dedicated box, I've blamed
everything but today I've done profiling... and the winner is...

72.1%   4.862 build/bdist.freebsd-7.1-RELEASE-amd64/egg/memcache.py

5 secs. (!) 72% of execution time. Something that should boost
performance, kills my WWW box! There were about 30-40 calls.

It's not normal? What can cause problem? There are no any infos in
logs. Nothing. :S

Best regards,
Szymon Kosok

-- 
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: django and ldap

2010-02-22 Thread andreas schmid
Peter Herndon wrote:
> On Mon, Feb 22, 2010 at 9:40 AM, andreas schmid  wrote:
>
>   
>> im experiencing strange problems now. the user is able to authenticate
>> against ldap only if in the active directory the displayName == username
>> why this? i dont get any error or traceback, the user only isnt able to
>> get logged in
>>
>> 
>
> If users were able to authenticate, and are now not able to
> authenticate, what changed?  
i was thinkin the authentication over ldap group was working because i
testet it only whith a testuser which had sAMAccountName == displayName
but now im figuring that if thats not equal it desnt work as expected.
the app is still in development and i didnt work on it for a few days.

> At my place of work, I've learned to
> expect changes in Active Directory every so often -- my AD admins are
> not that great at notifying users of impending changes.  These changes
> occasionally cause breakage elsewhere.
>
> If not in AD, did something else in your environment change?
>
> The normal way ldap-groups works is that sAMAccountName is the field
> used to identify a user in AD (line 106 in
> ldap-groups/accounts/backends.py), and is used as the source of their
> django.contrib.auth.models.User username.  So, if you go changing
> someone's username via the admin, or otherwise edit the username data
> in your db, then the username won't match the sAMAccountName, and they
> won't be able to log in to that account.  
i found this problem by working with the system admin and try different
settings and we figured out what i wrote above.
> Similarly, if their
> sAMAccountName changes in AD, and they log in to your site with the
> new name, they will effectively have created a second account in your
> db.  If you have resources tied to an account in Django (saved
> bookmarks, tags, uploads, etc.), the user won't have access to those
> resources any longer, as they're on a new account.
>
> I realize that sAMAccountName is not the same as displayName.  I
> wonder if you were mistaking the occasional coincidence between
> displayName and sAMAccountName?  
nope
> Or did you edit the app to use
> displayName?  Perhaps you could post more details about your issue,
> including code.
>
> Also, you may want to instrument the LDAP code.  Either log the
> results from the LDAP calls to a file, or drop in some print
> statements and run via runserver, and see what messages your LDAP
> environment produces.  Useful bits to log will be lines 82, 106, and
> 132 in ldap-groups/accounts/backends.py.
>
>   
i started to log a bit today and will go on tomorrow and post what i
will get or the solution if i will find it.

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



Re: Slugify() and Clean form data Questions

2010-02-22 Thread Matt McCants
Django's database API does a lot of the worrying for you. It will autoescape
the more dangerous aspects of user input when executing SQL. You'd have to
be more careful if you were executing raw queries and even then you'd have
to be running those queries as literal strings instead of parameterized
ModelManager.raw()
 calls.

In short, if you're using the typical ModelManager methods ie,
Model.objects.filter(), Model.objects.get(), etc, and validating your input
with Form.is_valid(), you should be pretty well protected against SQL
Injection.

As for HTML escaping, you'd have to manually mark the string as safe or use
the safe filter in your template for it to be rendered as real HTML. If
you're trying to render user input as HTML, take a look at
django.utils.html,
there are some function in there that will be of interest.
Notably django.utils.html.escape().

Hope this better answers your question,
Matt

On Mon, Feb 22, 2010 at 2:42 PM, Peter Herndon  wrote:

> On Mon, Feb 22, 2010 at 12:32 PM, Jon Loeliger  wrote:
>
> > I get is_valid() and the notion of cleaned data.  I *think*,
> > though, that I am asking for something more robust.
> >
> > Will some_form.is_valid() will, say, remove (or identify)
> > embedded SQL hacking attempts from a plain text field input?
> >
>
> http://www.djangobook.com/en/2.0/chapter20/
>
> The part on CSRF is a bit outdated for Django 1.2, which features
> improved CSRF protection, but the rest is still on point, to my
> knowledge.
>
> --
> 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: Slugify() and Clean form data Questions

2010-02-22 Thread Peter Herndon
On Mon, Feb 22, 2010 at 12:32 PM, Jon Loeliger  wrote:

> I get is_valid() and the notion of cleaned data.  I *think*,
> though, that I am asking for something more robust.
>
> Will some_form.is_valid() will, say, remove (or identify)
> embedded SQL hacking attempts from a plain text field input?
>

http://www.djangobook.com/en/2.0/chapter20/

The part on CSRF is a bit outdated for Django 1.2, which features
improved CSRF protection, but the rest is still on point, to my
knowledge.

-- 
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: django and ldap

2010-02-22 Thread Peter Herndon
On Mon, Feb 22, 2010 at 9:40 AM, andreas schmid  wrote:

> im experiencing strange problems now. the user is able to authenticate
> against ldap only if in the active directory the displayName == username
> why this? i dont get any error or traceback, the user only isnt able to
> get logged in
>

If users were able to authenticate, and are now not able to
authenticate, what changed?  At my place of work, I've learned to
expect changes in Active Directory every so often -- my AD admins are
not that great at notifying users of impending changes.  These changes
occasionally cause breakage elsewhere.

If not in AD, did something else in your environment change?

The normal way ldap-groups works is that sAMAccountName is the field
used to identify a user in AD (line 106 in
ldap-groups/accounts/backends.py), and is used as the source of their
django.contrib.auth.models.User username.  So, if you go changing
someone's username via the admin, or otherwise edit the username data
in your db, then the username won't match the sAMAccountName, and they
won't be able to log in to that account.  Similarly, if their
sAMAccountName changes in AD, and they log in to your site with the
new name, they will effectively have created a second account in your
db.  If you have resources tied to an account in Django (saved
bookmarks, tags, uploads, etc.), the user won't have access to those
resources any longer, as they're on a new account.

I realize that sAMAccountName is not the same as displayName.  I
wonder if you were mistaking the occasional coincidence between
displayName and sAMAccountName?  Or did you edit the app to use
displayName?  Perhaps you could post more details about your issue,
including code.

Also, you may want to instrument the LDAP code.  Either log the
results from the LDAP calls to a file, or drop in some print
statements and run via runserver, and see what messages your LDAP
environment produces.  Useful bits to log will be lines 82, 106, and
132 in ldap-groups/accounts/backends.py.

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



Re: Problem

2010-02-22 Thread rennat
need more info, like a code example and the data that is causing the
validation error

On Feb 22, 6:20 am, "saurabhpres...@gmail.com"
 wrote:
> Enter a valid date/time in -MM-DD HH:MM[:ss[.uu]] format.
> Request Method: POST
> Request URL:    http://127.0.0.1:8000/book/edit/
> Exception Type: ValidationError
> Exception Value:
> Enter a valid date/time in -MM-DD HH:MM[:ss[.uu]] format.

-- 
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: pushing messages on a webapp

2010-02-22 Thread rennat
You might look at using Comet, I haven't personally used it yet but
there were some cool things done with it at PyCon this year.

I don't know if this is the best how to but it came up pretty high in
google search:
http://anirudhsanjeev.org/tutorialhow-to-django-comet-orbited-stomp-morbidq-jsio/

On Feb 22, 8:20 am, Dexter  wrote:
> Hi there,
>
> I was wondering if it is possible to push messages to client side, or is the
> only possible way polling from client to server.
>
> Grtz, Dexter

-- 
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: POST from external site

2010-02-22 Thread Tim Shaffer
What does the HTML for the Django-generated form look like?

What does the HTML for the non-Django-generated form look like?

Are you using Django Cross Site Request Forgery protection?

On Feb 22, 12:27 pm, kkerbel  wrote:
> Let me further clarify...when I post using django it works as
> expected, meaning I have another view that which processes a new form
> I submit from django.  I wrote a standalone html form on my desktop
> and tried submitting to the view and it still does not work.
>
> On Feb 22, 11:17 am, kkerbel  wrote:
>
>
>
> > I'm attempting to write a listener page which will take POST variables
> > sent from an external payment site to verify whether payment was
> > successful or not.  Here is the view:
>
> > def results(request):
> >         if request.method == 'POST':
> >                 test = request.POST.get('pmt_status')
> >                 subject = 'Jensen test values'
> >                 message = test + "\n"
> >                 emailto = '@fake.com'  <--normally my real address
> >                 try:
> >                         mail = EmailMessage(subject, message, 
> > 'do_not_re...@fake.com',
> > [emailto])
> >                         mail.send()
> >                         return 
> > render_to_response('forms/jensen/thanks.html', {'message':
> > 'Sent email to %s'%emailto})
> >                 except:
> >                         return 
> > render_to_response('forms/jensen/emailerror.html')
> >         else:
> >                 return render_to_response('forms/jensen/error.html')
>
> > No matter what I do the else block is always processed.  It never
> > detects the POST method from the external site.  When I do this from
> > internal...it works great...not so with the external site.  Is there
> > something special about processing POST from an external site?

-- 
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 REST and FILEFIELD field

2010-02-22 Thread manu.polline
Hi everyone,
my name is Manuel. I'm tryng to upload a file directly in a filefield
of Django model exposed by django-rest-interface.
It'is possible?
this is my model :

class File(models.Model):
file = models.FileField(upload_to='files',
help_text=_("file itself"))
page = models.ForeignKey(page)

and my urls.py :
json_File_resource = Collection(
queryset = File.objects.all(),
authentication = HttpBasicAuthentication(),
permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
receiver = JSONReceiver(),
responder = JSONResponder()
)

urlpatterns = patterns('',


url(r'^json/File/(.*?)/?$',json_File_resource),
...
)

The GET works and the PUT to other field too but not the POST or the
PUT on filefield Field.
How i can pass the local file to the remote Service in the JSON
string?

Please Help Me!!!

Manuel

-- 
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: Djamgo cookies

2010-02-22 Thread adamjamesdrew
Yes understood but how do other websites work? Makes no sense. I'm
going to try to create an account at a different django website to
test

On Feb 22, 12:44 pm, Timothy Kinney  wrote:
> If a user disallows cookies on their own machine, there's nothing you can do
> about it. This is why a lot of websites say: "You need to have cookies
> enabled."
>
> On Mon, Feb 22, 2010 at 10:27 AM, adamjamesdrew  wrote:
> > This is not an issue with me as I can just turn off the firewall. I'm
> > concerned with other people who have this installed who won't be able
> > to use my website.
>
> > On Feb 21, 7:20 pm, adamjamesdrew  wrote:
> > > This is a default install for a computer associates firewall. Any
> > > thoughts on why amazon would work with no url mods... Cookie domain ??
> > > Expiration type
>
> > > Dennis Kaarsemaker wrote:
> > > > On zo, 2010-02-21 at 23:51 +, theikl...@gmail.com wrote:
> > > > > I have a firewall that immediately expires cookies. [...] How can I
> > > > > fix this
>
> > > > Get a better firewall. Firewalls shouldn't mess with cookies.
> > > > --
> > > > Dennis K.
>
> > > > The universe tends towards maximum irony. Don't push it.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-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: Generate random data for Django models

2010-02-22 Thread Timothy Kinney
Okay, I got it.

There was a typo in the hard-coded url pattern. The following actually does
not work:
** code **
(r'^/1/add_random_samurai/$', self.admin_site.admin_view(
self.add_random_samurai))
** /code **

But this does:
** code **
(r'^1/add_random_samurai/$',
self.admin_site.admin_view(self.add_random_samurai))
** /code **

Basically, I added an extra slash and that's why it wasn't picking it up. So
to catch any number, I just use:
** code **
(r'^\d+/add_random_samurai/$',
self.admin_site.admin_view(self.add_random_samurai))
** / code **

I'm still not sure if this will create the samurai in the correct province.
I think I can extract this information from the request though. We shall
see.

-Tim


On Mon, Feb 22, 2010 at 12:08 AM, Timothy Kinney
wrote:

> Okay, I've got such a button and I have copied a template from admin to
> serve as a stand-in for it. I have created functions under ProvinceAdmin (in
> myapp\admin.py) that look like:
>
> ** code **
> def ProvinceAdmin(admin.ModelAdmin):
>  # other stuff
>
> def add_random_samurai(self, request):
> from django.http import HttpResponse
> # do stuff
> return HttpResponse("This is where the template will render.")
>
> def get_urls(self):
> from django.conf.urls.defaults import patterns
> urls = super(ProvinceAdmin, self).get_urls()
> my_urls = patterns('',
> (r'^/(?P\d+)/add_random_samurai/$',
> self.admin_site.admin_view(self.add_random_samurai))
> )
> return my_urls + urls
> ** / code **
>
> But I'm getting a ValueError:
> invalid literal for int() with base 10: '1/add_random_samurai'
>
> If I hardcode: (r'^/1/add_random_samurai/$',
> self.admin_site.admin_view(self.add_random_samurai))
> Then it works.
>
> So I think my regular expression is not picking up the right integer. Can
> you help me re-write the regular expression to catch the province number?
>
> Or can I ignore the province number since I am presumably calling a
> function from within the instance of the province I want to update? If so,
> how do I tell the pattern matching to ignore that?
>
> -Tim
>
>
> On Fri, Feb 19, 2010 at 5:21 PM, Peter Herndon wrote:
>
>>
>> On Feb 19, 2010, at 5:51 PM, Timothy Kinney wrote:
>>
>> > So I have a nice little database now stocked with items and provinces.
>> > I now want to generate random samurai and populate the database with
>> > them. I can think of two ways to do this:
>> >
>> > 1) Through the admin interface. But how do I install a button that
>> > will add a random samurai? Adding samurai is a built-in function on
>> > the template, but the fields are always empty. Is there a
>> > straightforward way to add another button called "Add Random Samurai"
>> > that does the same thing but with the fields randomly filled from
>> > appropriate choices?
>> >
>> > 2) Use a python script. This seems to have two possible methods:
>> > a) Randomly generate samurai desired, output a JSON flatpage, and call
>> > manage.py loaddata that_flatpage
>> >
>> > b) Randomly generate the samurai desired, access the database directly
>> > and insert them using SQL syntax. (not very Django like)
>> >
>> > I have listed these in order of preference. Can someone tell me the
>> > easiest way to implement a new admin button? I'm not even sure where
>> > the admin templates are stored. :/
>> >
>> > -Tim
>>
>> Hi Tim,
>>
>> Docs for overriding admin are here:
>> http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#overriding-admin-templates
>>
>> You will probably want to override the change_form.html template at
>> whatever level is appropriate for your needs (Province, if you are adding
>> Samurai to random rooms), and add a button "Generate Random Samurai".  That
>> button will be the submit for a form that points to a view you will write.
>>  That view should generate a random number, loop over that number, create a
>> Samurai object and assign it to a randomly-chosen Room (pick a random number
>> from 1 through the total number of rooms, get the room via "room =
>> Room.objects.get(pk=").  You will need to add a URL that will
>> tie together the view and the submit button.
>>
>> For an added bonus, add an IntegerField to your form allowing you to set
>> an upper bound on the number of Samurai generated.
>>
>> An approach similar to 2b would be to implement a custom management
>> command (skeletal docs here:
>> http://docs.djangoproject.com/en/1.1/howto/custom-management-commands/#howto-custom-management-commandsbut
>>  Google for better examples) that would allow you to run "python
>> manage.py create_samurai".  That command would use the same logic as I
>> outlined for the view, and create Samurai via the ORM and assign them to
>> random Rooms.
>>
>> ---Peter Herndon
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to 

Re: Best practices for restricting media?

2010-02-22 Thread David De La Harpe Golden

On 22/02/10 16:48, Brice Leroy wrote:

Hello Brett,
If you use nginx you can use the X-Accel-Redirect function.


Minor: if you _don't_ use nginx but rather apache or lighttpd,
similar feature is called "X-Sendfile".

--
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: Djamgo cookies

2010-02-22 Thread Timothy Kinney
If a user disallows cookies on their own machine, there's nothing you can do
about it. This is why a lot of websites say: "You need to have cookies
enabled."

On Mon, Feb 22, 2010 at 10:27 AM, adamjamesdrew  wrote:

> This is not an issue with me as I can just turn off the firewall. I'm
> concerned with other people who have this installed who won't be able
> to use my website.
>
> On Feb 21, 7:20 pm, adamjamesdrew  wrote:
> > This is a default install for a computer associates firewall. Any
> > thoughts on why amazon would work with no url mods... Cookie domain ??
> > Expiration type
> >
> > Dennis Kaarsemaker wrote:
> > > On zo, 2010-02-21 at 23:51 +, theikl...@gmail.com wrote:
> > > > I have a firewall that immediately expires cookies. [...] How can I
> > > > fix this
> >
> > > Get a better firewall. Firewalls shouldn't mess with cookies.
> > > --
> > > Dennis K.
> >
> > > The universe tends towards maximum irony. Don't push it.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-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: Slugify() and Clean form data Questions

2010-02-22 Thread Jon Loeliger
> 
> Is there a reason why you can't use Form.is_valid()? It's pretty nice.
> 
> http://docs.djangoproject.com/en/dev/ref/forms/api/#accessing-clean-data
> 
> Example:
> http://gist.github.com/311192

I get is_valid() and the notion of cleaned data.  I *think*,
though, that I am asking for something more robust.

Will some_form.is_valid() will, say, remove (or identify)
embedded SQL hacking attempts from a plain text field input?

Thanks,
jdl

-- 
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: Problem with defer

2010-02-22 Thread Dexter
Oh, I'm sorry,

no error appears, but the queryset returns the complete objects with all the
fields, not only the name field

On Mon, Feb 22, 2010 at 6:30 PM, Daniel Roseman wrote:

> On Feb 22, 5:15 pm, Dexter  wrote:
> > Hi,
> >
> > Im using django 1.1.1, and i'm trying to defer a queryset, but it doesn't
> > seem to work.
> > Here's my callback:
> >
> > def open(request, id=None):
> >
> > > """Callback to fire when a specific floor is opened."""
> > > if request.user.is_authenticated():
> > > if id:
> > > data = serializers.serialize('json',
> > > Floor.objects.filter(id=id))
> > > else:
> > > object = Floor.objects.only("name").all()
> > > print object.values()
> > > data = serializers.serialize('json', Floor.objects.all())
> > > #print data
> > > return HttpResponse(data)
> >
> > > return HttpResponse("Operation not permitted!")
> >
> > Thanks in advance.
> >
> > Grtz, Dexter
>
> What doesn't work? You didn't post the traceback, you posted the code.
> It would have been useful to have the error message, if there is one,
> or some indication of what you are seeing versus what you expected to
> see.
> --
> 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: Problem with defer

2010-02-22 Thread Daniel Roseman
On Feb 22, 5:15 pm, Dexter  wrote:
> Hi,
>
> Im using django 1.1.1, and i'm trying to defer a queryset, but it doesn't
> seem to work.
> Here's my callback:
>
> def open(request, id=None):
>
> >     """Callback to fire when a specific floor is opened."""
> >     if request.user.is_authenticated():
> >         if id:
> >             data = serializers.serialize('json',
> > Floor.objects.filter(id=id))
> >         else:
> >             object = Floor.objects.only("name").all()
> >             print object.values()
> >             data = serializers.serialize('json', Floor.objects.all())
> >         #print data
> >         return HttpResponse(data)
>
> >     return HttpResponse("Operation not permitted!")
>
> Thanks in advance.
>
> Grtz, Dexter

What doesn't work? You didn't post the traceback, you posted the code.
It would have been useful to have the error message, if there is one,
or some indication of what you are seeing versus what you expected to
see.
--
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: POST from external site

2010-02-22 Thread kkerbel
Let me further clarify...when I post using django it works as
expected, meaning I have another view that which processes a new form
I submit from django.  I wrote a standalone html form on my desktop
and tried submitting to the view and it still does not work.

On Feb 22, 11:17 am, kkerbel  wrote:
> I'm attempting to write a listener page which will take POST variables
> sent from an external payment site to verify whether payment was
> successful or not.  Here is the view:
>
> def results(request):
>         if request.method == 'POST':
>                 test = request.POST.get('pmt_status')
>                 subject = 'Jensen test values'
>                 message = test + "\n"
>                 emailto = '@fake.com'  <--normally my real address
>                 try:
>                         mail = EmailMessage(subject, message, 
> 'do_not_re...@fake.com',
> [emailto])
>                         mail.send()
>                         return render_to_response('forms/jensen/thanks.html', 
> {'message':
> 'Sent email to %s'%emailto})
>                 except:
>                         return 
> render_to_response('forms/jensen/emailerror.html')
>         else:
>                 return render_to_response('forms/jensen/error.html')
>
> No matter what I do the else block is always processed.  It never
> detects the POST method from the external site.  When I do this from
> internal...it works great...not so with the external site.  Is there
> something special about processing POST from an external site?

-- 
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: apparent bug in QuerySet

2010-02-22 Thread Marco Rogers
This is interesting.  I think the two examples you give are distinct
use cases and they should be.  But I think it's just as common to want
to do what felix is doing.  Essentially he wants to modify a queryset
as it exists by adding or overriding additional parameters.  It can be
very convenient to build this up as you go through the logic in your
app.  Felix ends up doing this manually by just holding all of his
params in a dict and adding them at the end.  But would it be a bad
thing for django to support this use case out of the box?  How about
something like

   Queryset.update(dict | **kwargs)

so this

   qs = Model.objects.filter(a__b=x)
   qs = qs.update(a__c=y)

Is equivalent to

   Model.objects.filter(a__b=x, a__c=y)

It would still return a new query set to support chaining.  But the
new one would be built with a merging the of the old and new
parameters rather than a "filter these and then filter these" type of
structure.

The name "update" conflicts with the api for dict.update which updates
in place.  Maybe that's okay or maybe it needs a new name.

:Marco

On Feb 22, 3:15 am, Russell Keith-Magee 
wrote:
> On Mon, Feb 22, 2010 at 4:48 AM, felix  wrote:
>
> > This seems so blatant that it couldn't really be a bug without someone
> > noticing. Django 1.2
>
> >        qs = Apt.objects.filter(list_on_web=True,is_available=True)
>
> >         # FastAdderStatus has Apt and Service as fk
> >        qs = qs.filter(fastadderstatus__service=self.service)
>
> >        # later on here's another filter on the same table
> >        qs = qs.filter(fastadderstatus__running_status__in= (2, 3, 4))
>
> > produces this:
>
> >  SELECT U0."id" FROM "nsproperties_apt" U0 INNER JOIN
> > "fastadder_fastadderstatus" U1 ON (U0."id" = U1."apt_id") INNER JOIN
> > "fastadder_fastadderstatus" U3 ON (U0."id" = U3."apt_id") WHERE
> > (U0."list_on_web" = True  AND U0."is_available" = True  AND
> > U1."service_id" = 4  AND U3."running_status" IN (2, 3, 4))
>
> > Note that it joins the same table twice, and the Apt is not returning
> > distinct.  Postgres is not liking the query.
>
> > count: 2837
>
> > [, ,  > #12297>, , ,  > Property #12304>, , ,
> > , ,  > #12308>, , ,  > Property #12309>, , ,
> > , ,  > #12314>, , '...(remaining elements
> > truncated)...']
>
> > what it should say (manually fixed) :
>
> >  SELECT U0."id" FROM "nsproperties_apt" U0 INNER JOIN
> > "fastadder_fastadderstatus" U1 ON (U0."id" = U1."apt_id") WHERE
> > (U0."list_on_web" = True  AND U0."is_available" = True  AND
> > U1."service_id" = 4  AND U1."running_status" IN (2, 3, 4))
>
> > count: 611, no dups
>
> > My solution:
>
> >        params = {}
> >        if self.service:
> >            params['fastadderstatus__service'] = self.service
> >        if self.agent:
> >            params['agents'] = self.agent
>
> >        if self.status:
>
> > params.update( 
> > FastAdderStatus.objects.filter_params_for_status(self.status,'fastadderstat 
> > us') )
>
> >        # a single call to filter
> >        qs = qs.filter(**params)
>
> > which avoids the (?) bug and also is vastly more efficient.
>
> You haven't found a bug - Django is returning exactly what you asked
> for. There is a difference between making the query:
>
> Model.objects.filter(a__b=x).filter(a__c=y)
>
> and the query:
>
> Model.objects.filter(a__b=x, a__c=y).
>
> In the first query, Django will use two different joins on the 'A'
> table. In the second query, the join on 'A' will be reused. It sounds
> like what you want is the second query.
>
> This behaviour is documented here [1].
>
> [1]http://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-mult...
>
> Yours,
> Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



POST from external site

2010-02-22 Thread kkerbel
I'm attempting to write a listener page which will take POST variables
sent from an external payment site to verify whether payment was
successful or not.  Here is the view:

def results(request):
if request.method == 'POST':
test = request.POST.get('pmt_status')
subject = 'Jensen test values'
message = test + "\n"
emailto = 'm...@fake.com'  <--normally my real address
try:
mail = EmailMessage(subject, message, 
'do_not_re...@fake.com',
[emailto])
mail.send()
return render_to_response('forms/jensen/thanks.html', 
{'message':
'Sent email to %s'%emailto})
except:
return 
render_to_response('forms/jensen/emailerror.html')
else:
return render_to_response('forms/jensen/error.html')


No matter what I do the else block is always processed.  It never
detects the POST method from the external site.  When I do this from
internal...it works great...not so with the external site.  Is there
something special about processing POST from an external site?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to get as_sql() to work again

2010-02-22 Thread felix


On Feb 22, 9:22 am, Russell Keith-Magee 
wrote:
> > However getting the SQL that will be produced is essential.  There
> > needs to be a utility method somewhere that will give us this sql and
> > it needs to remain stable.
>
> Well, no -- it isn't essential. It might be a very handy debugging
> tool, but it isn't essential.

I will again strongly disagree with that.  You might as well declare
every other debugging tool to be non-essential.  Unless you mean to
say that unless it involves serving web pages to actual people it
technically isn't "essential".

Working with a NoSQL ORM requires being able to see the query that it
generates when something is going wrong. You can't fix a problem if
you can't see what's happening.

I posted another thread here demonstrating an invalid SQL query.

You can also see the query I posted above.  Its joined to the same
table 3 times. Its joined to one table and then joined back to the
previous table.  I think it is essential that I have the ability to
find out that this is occurring.

My suggestion is simply that there be a public utility function
somewhere that can remain stable.

I well understand the problems of pesky external apps and users
building dependencies on your internals thus making it hard to
refactor.

That's why I suggest that since there is an obvious need to see the
SQL query (as there are several external apps and many threads and
questions [and now outdated answers]) — that there should be a public
function somewhere that is maintained.



> That said:
>
> print object.query

In [1]: qs = Apt.objects.all()

In [2]: qs.query
Out[2]: 

see, that one doesn't work.

and neither do many now outdated snippets floating around the web


> If you need the actual SQL that is guaranteed correct for a given
> backend, you need to use object.query.get_compiler(alias).as_sql()

sql,values = object.query.get_compiler(alias).as_sql()

sql % values

yes I know, I already solved it.  my point is that it might one day
break.

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



Problem with defer

2010-02-22 Thread Dexter
Hi,

Im using django 1.1.1, and i'm trying to defer a queryset, but it doesn't
seem to work.
Here's my callback:

def open(request, id=None):
> """Callback to fire when a specific floor is opened."""
> if request.user.is_authenticated():
> if id:
> data = serializers.serialize('json',
> Floor.objects.filter(id=id))
> else:
> object = Floor.objects.only("name").all()
> print object.values()
> data = serializers.serialize('json', Floor.objects.all())
> #print data
> return HttpResponse(data)
>
> return HttpResponse("Operation not permitted!")
>

Thanks in advance.

Grtz, Dexter

-- 
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: Toggle TinyMCE in admin

2010-02-22 Thread When ideas fail
Would that just do one field rather than all the text areas?

On 22 Feb, 16:41, orokusaki  wrote:
> I think you can do this by adding the exact HTML that you need into
> the label field for a form (I can't remember if you have to explicitly
> turn off HTML filtering though, check the docs to be sure). I would
> just put Toggle a> The id_tag_of_field is of course available dynamically.

-- 
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: Best practices for restricting media?

2010-02-22 Thread Brice Leroy
Actually, this snippet should be better to explain X-Accel-Redirect feature:

http://www.djangosnippets.org/snippets/491/


2010/2/22 Brice Leroy 

> Hello Brett,
> If you use nginx you can use the X-Accel-Redirect function. Technicaly, you
> get the file request on django, you check if the user should have an access
> to the file and then you send back a header with the filename inside to your
> instance of NGinx. Nginx then serve the file.
>
>
> http://stackoverflow.com/questions/263122/custom-http-headers-for-static-files-with-django
>
> Have a nice day
>
> Brice
>
> 2010/2/21 Brett Thomas 
>
> Hey, this is a pretty basic sysadmin question, but seems pretty critical
>> for django development. What's the best way to limit media on a django site
>> to certain users?
>>
>> A typical example is a photo gallery app. Suppose you are recreating
>> Flickr, and a user's photos should only be viewable by his/her friends. You
>> can restrict other users from accessing the django view that presents the
>> photo. But if the image is on a static media server, the image is still
>> publicly accessible by its direct URL.
>>
>> So, question is: can you add restrictions to a media server connected to
>> django to say "this image can only be served in a page that was rendered by
>> a django view"?
>>
>> Thanks for the help --
>> Brett
>>
>> Surprisingly (or not?) Facebook has no such permissions...here's a random
>> photo from one of my friend's private albums that apparently you can see
>> without even having a facebook account:
>> http://photos-f.ak.fbcdn.net/photos-ak-snc1/v2681/23/22/30008/n30008_36329813_2721261.jpg
>>
>>
>>
> --
> blog: http://www.debrice.com
> project: http://www.kaaloo.com http://www.djangogenerator.com
> linkedin: http://www.linkedin.com/in/bricepleroy
>



-- 
blog: http://www.debrice.com
project: http://www.kaaloo.com http://www.djangogenerator.com
linkedin: http://www.linkedin.com/in/bricepleroy

-- 
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: Best practices for restricting media?

2010-02-22 Thread Brice Leroy
Hello Brett,
If you use nginx you can use the X-Accel-Redirect function. Technicaly, you
get the file request on django, you check if the user should have an access
to the file and then you send back a header with the filename inside to your
instance of NGinx. Nginx then serve the file.

http://stackoverflow.com/questions/263122/custom-http-headers-for-static-files-with-django

Have a nice day

Brice

2010/2/21 Brett Thomas 

> Hey, this is a pretty basic sysadmin question, but seems pretty critical
> for django development. What's the best way to limit media on a django site
> to certain users?
>
> A typical example is a photo gallery app. Suppose you are recreating
> Flickr, and a user's photos should only be viewable by his/her friends. You
> can restrict other users from accessing the django view that presents the
> photo. But if the image is on a static media server, the image is still
> publicly accessible by its direct URL.
>
> So, question is: can you add restrictions to a media server connected to
> django to say "this image can only be served in a page that was rendered by
> a django view"?
>
> Thanks for the help --
> Brett
>
> Surprisingly (or not?) Facebook has no such permissions...here's a random
> photo from one of my friend's private albums that apparently you can see
> without even having a facebook account:
> http://photos-f.ak.fbcdn.net/photos-ak-snc1/v2681/23/22/30008/n30008_36329813_2721261.jpg
>
>
>
-- 
blog: http://www.debrice.com
project: http://www.kaaloo.com http://www.djangogenerator.com
linkedin: http://www.linkedin.com/in/bricepleroy

-- 
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: SAAS User and Auth situation.

2010-02-22 Thread orokusaki
@Wes The only problem with using email addresses is that a person
could have a User on multiple different accounts and this would not
allow for that, unless there was some sort of one-login-to-rule-them-
all situation, which there won't be. Imagine a hosted CMS called
"Super CMS". A single web developer who does a lot of work for Super
CMS clients, and may have a Super CMS account himself. He would then
have a User for his own account and any accounts that he does work in
as well.

-- 
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: Ajax request, json object, fields with instance of inherits class converted in regular string

2010-02-22 Thread esatterwh...@wi.rr.com
you can also use simplejson and return data the way you want it. It
isn't able to serialize date or time objects natively but this still
covers 99% of the cases.


from django.utils import simplejson
from django.http import HttpResponse

def view(request):
  return HttpResponse(simplejson.dumps([dict(monday=o.monday.name) for
o in week.objects.all()]),
 
mimetype="text/javascript")

this method is a little more flexible and will be very useful if you
have objects with more than one foreign key that you want to send
back.

On Feb 21, 11:28 am, Kev Dwyer  wrote:
> On Fri, 19 Feb 2010 07:00:36 -0800, manixor wrote:
>
> 
>
>
>
> > The very big problem is, when I loop into object on template, in the
> > monday field is not enymore the Day instance, but the string 1. How can
> > I convert to an json object the week object, and to keep the instance of
> > the inherits class, or how can I modify the ForeignField model, to point
> > to another field, like name in my case and not to the pk, which is an
> > integer in my case?
>
> Hello Maxinor,
>
> If I understand your problem correctly, I can think of two ways around this:
>
> (1) Use the development release  (1.2, the natural keys
> (http://docs.djangoproject.com/en/dev/topics/serialization/#natural-keys)
> enhancement may do what you want.
> (2) Set Day.name to have primary_key=True, that way the name will be
> serialised instead of the automatically generated primary key.  As
> you have already set Day.name to be unique making it the primary key
> shouldn't prove to be a problem.
>
> Cheers,
>
> Kev

-- 
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: SAAS User and Auth situation.

2010-02-22 Thread orokusaki
@Daniel Thanks for muaccounts. I don't know if it'll work because it
appears to be coupled to sub domains ( which I may or may not use ).
I'll have to dig more into it later tonight.

-- 
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: Toggle TinyMCE in admin

2010-02-22 Thread orokusaki
I think you can do this by adding the exact HTML that you need into
the label field for a form (I can't remember if you have to explicitly
turn off HTML filtering though, check the docs to be sure). I would
just put Toggle The id_tag_of_field is of course available dynamically.

-- 
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: Toggle TinyMCE in admin

2010-02-22 Thread When ideas fail
Oh I should mention I have already added the javascript function to
the page by including the JS file. So I really only need to include
the link next to textareas.

On 22 Feb, 16:34, When ideas fail  wrote:
> Hello, I've been using TinyMCE for a WYSIWYG editor on my admin text
> areas. However I would like to be able to toggle it on and off like
> this:
>
> http://tinymce.moxiecode.com/examples/example_01.php
>
> But I wasn't sure of the best way to do this. Does anyone have any
> suggestions?
>
> Andrew

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



Toggle TinyMCE in admin

2010-02-22 Thread When ideas fail
Hello, I've been using TinyMCE for a WYSIWYG editor on my admin text
areas. However I would like to be able to toggle it on and off like
this:

http://tinymce.moxiecode.com/examples/example_01.php

But I wasn't sure of the best way to do this. Does anyone have any
suggestions?

Andrew


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

2010-02-22 Thread adamjamesdrew
This is not an issue with me as I can just turn off the firewall. I'm
concerned with other people who have this installed who won't be able
to use my website.

On Feb 21, 7:20 pm, adamjamesdrew  wrote:
> This is a default install for a computer associates firewall. Any
> thoughts on why amazon would work with no url mods... Cookie domain ??
> Expiration type
>
> Dennis Kaarsemaker wrote:
> > On zo, 2010-02-21 at 23:51 +, theikl...@gmail.com wrote:
> > > I have a firewall that immediately expires cookies. [...] How can I
> > > fix this
>
> > Get a better firewall. Firewalls shouldn't mess with cookies.
> > --
> > Dennis K.
>
> > The universe tends towards maximum irony. Don't push it.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to make the login forms available to the entire site?

2010-02-22 Thread rennat
I have used a context processor to keep track of a global login form
and process logins before. This method and rebus_'s "submit all to a
login URL" are both valid ways to do this.


On Feb 22, 11:00 am, Josh Kersey  wrote:
> I've always done it as rebus_ explained.  Put the login options in the
> base template wrapping it in {% if user.is_authenticated %} to display
> a different mechanism for users that are already logged-in.  That form
> action is set to the login URL and and the login view handles the
> login processing, error handling, and redirects.
>
> On Feb 21, 11:44 am, Patrick  wrote:
>
>
>
> > I thought that if I put the login forms on the base template and then
> > extend all others from that base template, the login forms would be
> > available all the way through. But there is a problem: the login forms
> > are only displayed if the url is processed by the 'login' view. That
> > login view provides the forms needed for authentication, among other
> > things.
>
> > The thing is, what I want is to allow user to authenticate no matter
> > what page from the site he is visitting. How can that be done?
>
> > Many thanks in advance,
>
> > Patrick Steiger

-- 
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: Overriding widget for forms.ModelMultipleChoiceField in ModelForm

2010-02-22 Thread rennat
Here is how I accomplished this with a ModelForm

class VariationForm(forms.ModelForm):
option_values =
forms.ModelMultipleChoiceField(queryset=Value.objects.none(),
widget=CheckboxSelectMultiple(), required=False)

class Meta:
model = Variation

def __init__(self, *args, **kwargs):
super(VariationForm, self).__init__(*args, **kwargs)
if 'instance' in kwargs:
self.fields['option_values'].queryset =
kwargs['instance'].product.values.all()

-- 
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: django and its interactive shell on osx

2010-02-22 Thread rennat
This seems to be an IPython problem. at quick glance it looks like
your version of IPython is incomplete. Try reinstalling or check the
changelogs, I don't keep up with ipython but its possible a new
version had backwards incompatible changes that django needs to
account for now. hope that helps

On Feb 22, 12:39 am, Massimo Di Stefano 
wrote:
> Hi All,
>
> I'm on osx 10.6.x (system python, django trunk, ipython from bazar repository)
> tring to run the django shell i have :
>
> MacBook-Pro-15-di-Massimo-Di-Stefano:geodjango sasha$ python manage.py 
> shellTraceback (most recent call last):
>   File "manage.py", line 11, in 
>     execute_manager(settings)
>   File 
> "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 
> 438, in execute_manager
>     utility.execute()
>   File 
> "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 
> 379, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "/Library/Python/2.6/site-packages/django/core/management/base.py", 
> line 195, in run_from_argv
>     self.execute(*args, **options.__dict__)
>   File "/Library/Python/2.6/site-packages/django/core/management/base.py", 
> line 222, in execute
>     output = self.handle(*args, **options)
>   File "/Library/Python/2.6/site-packages/django/core/management/base.py", 
> line 351, in handle
>     return self.handle_noargs(**options)
>   File 
> "/Library/Python/2.6/site-packages/django/core/management/commands/shell.py 
> ", line 29, in handle_noargs
>     shell = IPython.Shell.IPShell(argv=[])
> AttributeError: 'module' object has no attribute 'Shell'
> MacBook-Pro-15-di-Massimo-Di-Stefano:geodjango sasha$
>
> Thanks for any suggestion to fix this problem!
>
> regards,
>
> Massimo.

-- 
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: Slugify() and Clean form data Questions

2010-02-22 Thread Matt McCants
Is there a reason why you can't use Form.is_valid()? It's pretty nice.

http://docs.djangoproject.com/en/dev/ref/forms/api/#accessing-clean-data

Example:
http://gist.github.com/311192

On Sat, Feb 20, 2010 at 11:25 AM, Jon Loeliger  wrote:

> > Folks,
>
> A few days ago I asked:
>
> > Is there a canonical definition or even a reference
> > implementation of a slug = slugify(str) function somewhere?
>
> Thanks for taking the time to answer that for me!  We pretty much
> beat the answer into my thick skull:  Use the slugify() function
> as per "from django.template.defaultfilters import slugify".
>
>
> What about my second question from earlier?:
>
> > Is there a standard clean_user_input() that accepts direct user
> > input from a form text field and de-gunks it so that it is later
> > acceptable to be re-emitted as HTML formatted data without worry
> > of hacking issues?  I am looking form something more clever than
> > simply validating the user's input to conform to "is a number" or
> > "is a text field" sorts of thing.  I'm specifically looking for a
> > function that strips out embedded scripting, SQL, HTML, etc hackery.
> > Sure, I'd then like to use it to verify clean form input of course.
>
> How do people ensure safe user input from their forms?
>
> Thanks,
> jdl
>
> --
> 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: How to make the login forms available to the entire site?

2010-02-22 Thread Josh Kersey
I've always done it as rebus_ explained.  Put the login options in the
base template wrapping it in {% if user.is_authenticated %} to display
a different mechanism for users that are already logged-in.  That form
action is set to the login URL and and the login view handles the
login processing, error handling, and redirects.

On Feb 21, 11:44 am, Patrick  wrote:
> I thought that if I put the login forms on the base template and then
> extend all others from that base template, the login forms would be
> available all the way through. But there is a problem: the login forms
> are only displayed if the url is processed by the 'login' view. That
> login view provides the forms needed for authentication, among other
> things.
>
> The thing is, what I want is to allow user to authenticate no matter
> what page from the site he is visitting. How can that be done?
>
> Many thanks in advance,
>
> Patrick Steiger

-- 
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: formset media

2010-02-22 Thread anentropic
{{ formset.media }} will output the script tags *and* the css link
tags


On Feb 22, 11:53 am, anentropic  wrote:
> A formset should have a 'media' attribute which should include all the
> media from the widgets in the forms which make up the formset, so in
> the template you should be able to just
> {{ name_of_formset_var.media }} in the head of your page to output the
> necessary script tags.
>
> On Feb 17, 3:13 pm, kkerbel  wrote:> Anybody?  :)
>
> > On Feb 17, 1:19 am, kkerbel  wrote:> I'm having trouble 
> > getting AdminDateWidget to show in a formset.  Is
> > > this possible?  I've read and followed every post that mentions how to
> > > do this and I even have a page working with the AdminDateWidget,
> > > however, it uses a regular form and not a formset.  I'm just having
> > > trouble getting it to show on a template using a formset.  Is there a
> > > specific way to specify formset media in the template?

-- 
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: weird problem with django admin models and webfaction

2010-02-22 Thread Simon Davies
Duh!!  yeah restarting apache did it.  How did I forget something so
simple!!

Thanks

Simon

On 22 Feb, 15:04, Shawn Milochik  wrote:
> Did you manually restart the Apache instance for this app?
>
> I had a similar problem, and it turned out that I had a bit of code in one of 
> my model that was pulling from a table that was no longer defined. Check for 
> that as well.

-- 
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: Record is saved, but no join table entry is created - weird problem

2010-02-22 Thread Tom
Ah!  Thanks Tom, that fixed it.

Tom

On Feb 22, 3:27 pm, Tom Evans  wrote:
> On Mon, Feb 22, 2010 at 3:11 PM, Tom  wrote:
> > Hi all,
>
> > I have a view that takes data from a form and saves it in the db.  One
> > of the fields is a M2M linking to another model.  The record itself
> > saves fine, but no entry in the M2M join table is created.  I am
> > passing the form initial data for the M2M in the form of a list of id
> > numbers specifying which items are to be selected.  Sure enough the
> > items are properly selected in the 'choose many' box, but the join
> > table is never made.
>
> > If anybody can provide a hint I would really appreciate it; I have
> > been going over and over this looking for an error and it is starting
> > to drive me crazy!
>
> > This is my code:
>
> > #views.py (to_form is the list of id numbers specifying the items to
> > be saved in the M2M field)
> > --
>
> > if request.method == 'POST':
> >                f = InteractionForm(request.POST)
> >                if f.is_valid():
>
> >                        interaction = f.save(commit=False)
> >                        interaction.owner = request.user
> >                        interaction.save()
> >                        return 
> > HttpResponseRedirect('http://127.0.0.1:8000/contact/%d'%
> > to_form[0])
>
> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-sav...
>
> Pay particular attention to the notes about commit=False
>
> 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: Record is saved, but no join table entry is created - weird problem

2010-02-22 Thread Tom Evans
On Mon, Feb 22, 2010 at 3:11 PM, Tom  wrote:
> Hi all,
>
> I have a view that takes data from a form and saves it in the db.  One
> of the fields is a M2M linking to another model.  The record itself
> saves fine, but no entry in the M2M join table is created.  I am
> passing the form initial data for the M2M in the form of a list of id
> numbers specifying which items are to be selected.  Sure enough the
> items are properly selected in the 'choose many' box, but the join
> table is never made.
>
> If anybody can provide a hint I would really appreciate it; I have
> been going over and over this looking for an error and it is starting
> to drive me crazy!
>
> This is my code:
>
> #views.py (to_form is the list of id numbers specifying the items to
> be saved in the M2M field)
> --
>
> if request.method == 'POST':
>                f = InteractionForm(request.POST)
>                if f.is_valid():
>
>                        interaction = f.save(commit=False)
>                        interaction.owner = request.user
>                        interaction.save()
>                        return 
> HttpResponseRedirect('http://127.0.0.1:8000/contact/%d' %
> to_form[0])

http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method

Pay particular attention to the notes about commit=False

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.



Record is saved, but no join table entry is created - weird problem

2010-02-22 Thread Tom
Hi all,

I have a view that takes data from a form and saves it in the db.  One
of the fields is a M2M linking to another model.  The record itself
saves fine, but no entry in the M2M join table is created.  I am
passing the form initial data for the M2M in the form of a list of id
numbers specifying which items are to be selected.  Sure enough the
items are properly selected in the 'choose many' box, but the join
table is never made.

If anybody can provide a hint I would really appreciate it; I have
been going over and over this looking for an error and it is starting
to drive me crazy!

This is my code:

#views.py (to_form is the list of id numbers specifying the items to
be saved in the M2M field)
--

if request.method == 'POST':
f = InteractionForm(request.POST)
if f.is_valid():

interaction = f.save(commit=False)
interaction.owner = request.user
interaction.save()
return 
HttpResponseRedirect('http://127.0.0.1:8000/contact/%d' %
to_form[0])

else:
f = InteractionForm(initial={'contacts': to_form})

return render_to_response('addinteraction.html', {'form': f})

#models.py
-

class Interaction(models.Model):
owner = models.ForeignKey(User, editable=False)
SORT_CHOICES = (
('CALL', 'Call'),
('EMAIL', 'Email'),
('MEET', 'Meeting'),
)
sort = models.CharField(choices=SORT_CHOICES, max_length=5)
contacts = models.ManyToManyField(Contact)
date = models.DateTimeField(auto_now_add=True)
notes = models.CharField(max_length=2)

def __unicode__(self):
return self.id

class InteractionForm(ModelForm):
class Meta:
model = Interaction

#addinteraction.html



Add Interaction



Add Interaction



{{ form }}








-- 
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: weird problem with django admin models and webfaction

2010-02-22 Thread Shawn Milochik
Did you manually restart the Apache instance for this app?

I had a similar problem, and it turned out that I had a bit of code in one of 
my model that was pulling from a table that was no longer defined. Check for 
that as well. 

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



weird problem with django admin models and webfaction

2010-02-22 Thread Simon Davies
Hi

I'm still developing my app and I have just refactored my models in my
django app.  I dropped most of the existing tables on my local dev
machine and then completely rebuilt everything using syncdb,
everything worked fine, including the admin, no probs at all.

Then I updated everything on my webfaction account, dropped most of
the tables and ran syncdb.  Then I accessed the admin app.  Problem!!!

Things got really weird here,  its still seeing the old models
somehow, and it falls over when I click on any of the models.  The
errors result from the fact that I updated one of the models so
abstract = True, so it won't exist as a sql table and this is causing
the error:

Caught an exception while rendering: (1146, "Table
'simondav.bikeshop_item' doesn't exist")

Original Traceback (most recent call last):
  File "/home/simondav/webapps/django/lib/python2.5/django/template/
debug.py", line 71, in render_node
result = node.render(context)
  File "/home/simondav/webapps/django/lib/python2.5/django/template/
__init__.py", line 936, in render
dict = func(*args)
  File "/home/simondav/webapps/django/lib/python2.5/django/contrib/
admin/templatetags/admin_list.py", line 253, in result_list
'results': list(results(cl))}
  File "/home/simondav/webapps/django/lib/python2.5/django/contrib/
admin/templatetags/admin_list.py", line 247, in results
for res in cl.result_list:
  File "/home/simondav/webapps/django/lib/python2.5/django/db/models/
query.py", line 106, in _result_iter
self._fill_cache()
  File "/home/simondav/webapps/django/lib/python2.5/django/db/models/
query.py", line 692, in _fill_cache
self._result_cache.append(self._iter.next())
  File "/home/simondav/webapps/django/lib/python2.5/django/db/models/
query.py", line 238, in iterator
for row in self.query.results_iter():
  File "/home/simondav/webapps/django/lib/python2.5/django/db/models/
sql/query.py", line 287, in results_iter
for rows in self.execute_sql(MULTI):
  File "/home/simondav/webapps/django/lib/python2.5/django/db/models/
sql/query.py", line 2369, in execute_sql
cursor.execute(sql, params)
  File "/home/simondav/webapps/django/lib/python2.5/django/db/backends/
util.py", line 19, in execute
return self.cursor.execute(sql, params)
  File "/home/simondav/webapps/django/lib/python2.5/django/db/backends/
mysql/base.py", line 84, in execute
return self.cursor.execute(query, args)
  File "/usr/local/lib/python2.5/site-packages/MySQLdb/cursors.py",
line 166, in execute
self.errorhandler(self, exc, value)
  File "/usr/local/lib/python2.5/site-packages/MySQLdb/
connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
ProgrammingError: (1146, "Table 'simondav.bikeshop_item' doesn't
exist")

which is correct in that the definition shouldn't exist in the
database any longer, but where is admin getting the model definition
from??

Both the models.py and admin.py files have been updated correctly, I
have completely trashed and rebuilt the whole database, yet it still
seems to be getting these ghost definitions on the webfaction server
somehow,  everything still works fine locally, so I'm puzzled.  Could
it be some kind of cache issue?, but surely anything would have been
deleted when I trashed the database.

Puzzled!!!

Thx in advance

Simon

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



weird CSS behaviour

2010-02-22 Thread Maciek Strzelecki
Hello, and straight to the point:

Once upon a time there was a Base Template, called base.html:


http://www.w3.org/1999/xhtml; xml:lang="en" lang="en">

some title





 [... and the body continues]

Please note that i put links to css in HEAD part.

Now, i click between two main pages of my website - "index" and
"register"
The "show page source" in firefox outputs identical text (obviously
different a bit for the container parts for register and index which
*are* different. What *is* important tho, is that those two pages
share the same "parent" template - "base.html", and that excerpt looks
the same on both "sources")

One of the pages - index -acts as if *there were* a "padding: 20px"
clause in style. Except there is NOT. Index page has a grey 20px "bar"
on the very top, register has none (and thats correct)

Firebug shows me even stranger thing - as i compare using the html
structure tool i see that:

register page - links to css shown in , correctly.
index page - links to css shown in  (why the hell there?! - they
ARE inside head in the base template)

Excuse lengthy post and not very clear "subject" but i have no idea
whats happening here. And it seems that the gray bar (padding) is just
a part of the problem since there seems to be a whole style to be
inserted, messing Internet explorer up completely.

im really really hoping that some one points out the obvious thing i
missed :)

(Im developing a rather simple web app - users can log in, log out,
browse categories, make lists of their favourites stuff and so on.
Nothing fancy.)

if anything is not clear enough - please ask :)
Thank You.

-- 
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: pushing messages on a webapp

2010-02-22 Thread Dexter
Hi there,

I was wondering if it is possible to push messages to client side, or is the
only possible way polling from client to server.

Grtz, Dexter

-- 
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: anybody tried web2py and gone back to Django?

2010-02-22 Thread Richard
I tried web2py and haven't gone back, though sometimes it is tempting
when I see so much Django work available!


On Feb 18, 7:48 am, snfctech  wrote:
> If so, could you provide a bullet list of things you preferred in
> Django?  Thanks.

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



Problem

2010-02-22 Thread saurabhpres...@gmail.com
Enter a valid date/time in -MM-DD HH:MM[:ss[.uu]] format.
Request Method: POST
Request URL:http://127.0.0.1:8000/book/edit/
Exception Type: ValidationError
Exception Value:
Enter a valid date/time in -MM-DD HH:MM[:ss[.uu]] format.

-- 
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: SAAS User and Auth situation.

2010-02-22 Thread Wes Turner


On Feb 21, 11:09 pm, orokusaki  wrote:
> I'm developing an SAAS which means that I will have Accounts and those
> Accounts will have Users. Each account's Users are completely
> orthogonal to the Users of another Account. When a user logs in,
> they'll supply an Account ID, a username, and a password so username
> only needs to be unique with regards to the Account in question.
> Firstly, is there an app out there or somebody who knows how to
> conquer this? If so, I would truly appreciate the help or a link.
> Problem 1 (with built-in User object), maybe there is a way around
> this:
>
> A) User of Account 'acme' might have the username "mike" and the user
> for Account "general mills" might have a user with the username
> "mike" (since "mike" is a very common name this will certainly happen
> within the first day of getting clients). I can't control what
> Accounts' Users decide to make their username and I certainly don't
> want to make it like domain registration, like if a User has to check
> if a username is available before creating it (all common names would
> be taken after the first 100 accounts if the average account had 2-3
> users).

There are patches for using email addresses (u...@account) as
usernames. [1]

I'm not sure how to ensure unique account usernames without checking
for uniqueness. [2]

You may be looking for something like a custom authentication backend.
[3]

Or OpenID.

[1] 
http://groups.google.com/group/django-developers/browse_thread/thread/9fcc44c5f99beb21/3420dc565df39fb1
[2] http://code.djangoproject.com/wiki/MultipleColumnPrimaryKeys
[3] 
http://docs.djangoproject.com/en/1.1/topics/auth/#other-authentication-sources

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



Using generic date_based.object_detail view without specifying a day

2010-02-22 Thread Dan Carroll
Hi all,

I am currently working on a blog for my website utilizing the
date_based generic views for a lot of the presentation.

The problem that I am running into, though, is that
date_based.object_detail requires specifying the 'day' parameter:
http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-generic-date-based-object-detail

I want my URLs to look like this:
http://127.0.0.1:8000/blog/2009/02/test-slug/

Am I missing something here?  I am about to write my own view to
handle the actual blog entry (keeping the generic ones for the
archives), but just wanted to make sure there wasn't a way to use the
generic view without specifying a day.  I could look up the object and
get the date, but that would add another database query that I
shouldn't really need.

Also, if there isn't an alternative other that writing my own view, I
can submit a patch to add this functionality.

Thanks,
Dan

-- 
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 is up with InternalError current transaction is aborted, commands ignored until end of transaction block

2010-02-22 Thread talpay...@gmail.com
i actually found a solution. i don't know what the problem is... and
it wouldn't mater anyway. I just wanted to catch and show a message
about it. You should you something like this:

from django.db import transaction

@transaction.commit_manually
def view(request):
try:
#do something with database
transaction.commit()
except:
transaction.rollback()
#return error message.


Thank you for the 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: django and ldap

2010-02-22 Thread andreas schmid
Peter Herndon wrote:
> On Feb 5, 2010, at 5:45 AM, andreas schmid wrote:
>
>   
>> ok django-ldap-groups works perfectly now!
>>
>> 
>
> That's great to hear!  If you run into any issues, I'll be happy to help 
> troubleshoot.
>
> ---Peter
>   
im experiencing strange problems now. the user is able to authenticate
against ldap only if in the active directory the displayName == username
why this? i dont get any error or traceback, the user only isnt able to
get logged in

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Adding a new language to Django?

2010-02-22 Thread Daniel Roseman
On Feb 22, 2:16 pm, Derek  wrote:
> I'm sure I am using the wrong search terms, but I am trying to find out how
> add a new language to "skin" the entire interface.
>
> The only reference I could find was:
> Only languages listed in the
> LANGUAGESsetting
> can be selected.
> in this section of the 
> docs:http://docs.djangoproject.com/en/1.1/topics/i18n/deployment/#if-you-d...
>
> It would helpful to have a link to a page that describes how the entire
> interface (*not just your project or application*) can be translated.
>
> Thanks
> Derek

http://docs.djangoproject.com/en/1.1/topics/i18n/localization/ seems
to be the page you need.
--
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: allowing other chars in User.username

2010-02-22 Thread Aljosa Mohorovic
On Feb 22, 1:58 pm, Dougal Matthews  wrote:
> I'm not sure what your reason if for using such characters?

enabling non-english names to be used (with chars like čćžđš),
separating first and last name with other chars (like
"first.last_name" or "first-last_name" or "first last_name").
especially since large number of users authorize via facebook or
openid and username is more like a nick.

Aljosa

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



Adding a new language to Django?

2010-02-22 Thread Derek
I'm sure I am using the wrong search terms, but I am trying to find out how
add a new language to "skin" the entire interface.

The only reference I could find was:
Only languages listed in the
LANGUAGESsetting
can be selected.
in this section of the docs:
http://docs.djangoproject.com/en/1.1/topics/i18n/deployment/#if-you-do-need-internationalization

It would helpful to have a link to a page that describes how the entire
interface (*not just your project or application*) can be translated.

Thanks
Derek

-- 
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: NoReverseMatch is making me crazy

2010-02-22 Thread andreas schmid
Tom Evans wrote:
> On Mon, Feb 22, 2010 at 11:01 AM, andreas schmid  wrote:
>   
>> im experiencing a problem since today:
>>
>> my model :
>>
>>class Technology(models.Model):
>> title= models.CharField(max_length=250,
>>help_text=_('Type in the technology title'))
>> body   = models.TextField(help_text=_('Type in the
>>description of the technology'))
>> slug= models.SlugField()
>>
>> ...
>>
>> @models.permalink
>> def get_absolute_url(self):
>>return ('my_technology_detail', (), { 'slug': self.slug })
>>
>> my view:
>>
>>def technology_detail(request, slug):
>>technology = get_object_or_404(Technology, slug=slug)
>>return render_to_response( 'techn_detail.html',
>>{'technology': technology})
>>
>> my url:
>>...
>>
>>url(r'^/technlogies/(?P[-\w]+])/$',
>> 
> ^^^
> Remove the extraneous square bracket and everything should be golden.
>   
right... i got it a second after i wrote to the list :)
>   
>>technology_detail,
>>name='my_technology_detail'),
>>...
>>
>> whatever i try to do with the detailview of this model i get a:
>> Exception Type: NoReverseMatch
>> Exception Value:
>>
>> Reverse for 'my_technology_detail' with arguments '()' and keyword arguments 
>> '{'slug': u'whatever-slug'}' not found.
>>
>>
>> but the technology is saved in the db and the slug is the right slug and
>> i have other models written the same way but they are working. what am i
>> missing?
>>
>> 
>
>   

-- 
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 is up with InternalError current transaction is aborted, commands ignored until end of transaction block

2010-02-22 Thread Shawn Milochik
The problems is that some part of your code is screwing up something with your 
database connection. Then, some other part of your code tries to use the 
database and it can't, so it breaks. Find out where the error is coming from 
(from your traceback), then figure out what code executes before that code.

Shawn

-- 
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: have trouble with safe and linebreaks together

2010-02-22 Thread Tom Coote
It wouldn't really matter if you needed to use something like html2pdf in
the future because you can always run a context through a template to get
the modified string including all the html before then using html2pdf. Also
keeping that kind of display logic in templates means its easily modified in
the future.

On Feb 22, 2010 12:27 PM, "Ali Rıza Keleş"  wrote:

On Sun, 2010-02-21 at 15:27 -0800, Benjamin wrote: > If you still want to
give your users quite a bi...
Yes maybe, but I do not know how it would be if I'd want to reuse them
by some other applications like html2pdf or another etc..

Wolud it be better to add some code in linebreak filter?

if not startswith(('', '',..)):

something like that.

> On Feb 21, 4:41 pm, Ali Rıza Keleş  wrote: > > Hi
all, > > > > I have a p...

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



IP address and NetScaler application delivery device

2010-02-22 Thread jfine
I'm running a Django/Pinax website (www.mathtran.org) whose host
wishes to move it to the NetScaler application delivery device.

This will change the IP address from which the applications appear to
come from (to the NetScaler device).  The (real) client IP address is
available in a HTTP header called X-Forwarded-For.

I don't expect this to make any difference, but does any know for
sure?

Here's a URL for NetScaler: 
http://www.citrix.com/English/ps2/products/feature.asp?contentID=1683490

--
Jonathan

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



Admin: 1364, "Field 'id' doesn't have a default value"

2010-02-22 Thread Jonathan Sutcliffe
Hi,

I wonder if anyone can help me. I am trying to use the admin to create
a new group and assign permisisions. When I try to save the object I
see the fllowing error message.

OperationalError at /admin/auth/group/add/

(1364, "Field 'id' doesn't have a default value")

Request Method: POST
Request URL:http://localhost:8000/admin/auth/group/add/
Exception Type: OperationalError
Exception Value:

(1364, "Field 'id' doesn't have a default value")

Would anyone have any suggestions or debugging tips?

I am missing something at the database level. I have mysql database.

Many Thanks.
Jono

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



Custom button for imagefield form

2010-02-22 Thread CrabbyPete
I have form with where users can upload an image. All works well but I
want a graphic instead of the default browse button that shows up. Can
I change it and if so how do you change it in the form field or
template?


class ProfileForm(SignUpForm):

mugshot = forms.ImageField  (required = False)

-- 
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: allowing other chars in User.username

2010-02-22 Thread Dougal Matthews
On 22 February 2010 11:56, Aljosa Mohorovic wrote:

> what are security concerns if username is allowed to contain chars
> like ".,;-() " and non-ascii alphabet letters?
> will orm still properly escape string before querying the database?
>
> Aljosa
>
>
In short, yes it will. All strings passed through the ORM are correctly
escaped (this applies to any and all models).

I'm not sure what your reason if for using such characters?

Dougal

-- 
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: have trouble with safe and linebreaks together

2010-02-22 Thread Ali Rıza Keleş
On Sun, 2010-02-21 at 15:27 -0800, Benjamin wrote:
> If you still want to give your users quite a bit of formatting power
> (other than just 'title' and 'body' fields), consider letting them use
> something like markdown, restructured test, or something similar. This
> way your application is safe from running arbitrary HTML, but your
> users get to make things look pretty.
> 
> Django-markup is a great reusable app that enables this sort of thing.
> Take a look at its documentation for use in templates here:
> http://docs.mahner.org/django-markup/usage_templates.html
> 
Yes maybe, but I do not know how it would be if I'd want to reuse them
by some other applications like html2pdf or another etc.. 

Wolud it be better to add some code in linebreak filter? 

if not startswith(('', '',..)): 

something like that.


> On Feb 21, 4:41 pm, Ali Rıza Keleş  wrote:
> > Hi all,
> >
> > I have a problem about template language.
> >
> > In my model there is a text field for body text of entries. And I markup
> > my text with some html. Like below:
> >
> > Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
> > tempor incididunt ut labore et dolore magna aliqua. "Ut enim ad
> > minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
> > ex ea commodo consequat."
> >
> > Section 1.10.32 of "de Finibus Bonorum et Malorum"
> >
> > Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
> > dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
> > proident, sunt in culpa qui officia deserunt.
> >
> > Sed ut perspiciatis unde omnis iste natus error sit voluptatem
> > accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
> > illo inventore veritatis et quasi architecto beatae vitae dicta sunt
> > explicabo.
> >
> > and in my templates use this text like that:
> >
> > {{ body|safe|linebreaks }}
> >
> > and the result is:
> >
> > Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
> > eiusmod tempor incididunt ut labore et dolore magna aliqua. "Ut
> > enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
> > aliquip ex ea commodo consequat."
> >
> > Section 1.10.32 of "de Finibus Bonorum et Malorum"
> >
> > Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
> > dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
> > proident, sunt in culpa qui officia deserunt.
> >
> > Sed ut perspiciatis unde omnis iste natus error sit voluptatem
> > accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
> > illo inventore veritatis et quasi architecto beatae vitae dicta sunt
> > explicabo.
> >
> > As you see, h2 tag is inside p tag. And this is not a valid usage for
> > xhtml which is my document's type.
> >
> > I need paragraphs because their styles are applied by css. Also h2s are
> > same.
> >
> > I don't want users-editors- do paragraphs manually, because many of
> > texts are quite long, this is not efficient, so I use linebreaks. Users
> > have some capability of writing html as much as they need. So they can
> > markup h2, strong etc, if it is necessary in text.
> >
> > How can I fix this?
> >
> > Thanks.
> >
> > --
> > Ali Rıza Keleş
> 

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



TextField in BaseCommentAbstractModel

2010-02-22 Thread kioopi
Hi,

contrib.comments.models.BaseCommentAbstractModel's field object_pk is
a TextField to allow for models without integer-ids to be commented.
This manifests as a longtext field in the (mysql) DB.  This leads to a
lot of full-table-scans, which turn out to be a performance problem.

So far i'm only using models with intergers as PKs.  Could i just
change the Field in the database to an integer and index it, or would
that lead to trouble down the road.

Alternatively, i could monkeypatch  BaseCommentAbstractModel, coudn't
i?  Is that recommendable?

Thanks for your thoughts.

Cheers
k

-- 
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: have trouble with safe and linebreaks together

2010-02-22 Thread Ali Rıza Keleş
On Sun, 2010-02-21 at 14:24 -0800, cootetom wrote:
> You have a mix of techniques here. You are allowing markup to be saved
> into the database and then when being displayed in a template you are
> again adding mark up there to! Why don't you have a model which has a
> "title" field and a "body" field. That way the user doesn't have to
yes I have titles marked h1 .. but I need some subtitles in body
section. 

> get involved with entering in any markup at all. Then you template can
> do the following:
> 
> {{ heading }}
> 
> {{ body|linebreaks }}
> 
thanks.. 

> 
> 
> 
> On Feb 21, 9:41 pm, Ali Rıza Keleş  wrote:
> > Hi all,
> >
> > I have a problem about template language.
> >
> > In my model there is a text field for body text of entries. And I markup
> > my text with some html. Like below:
> >
> > Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
> > tempor incididunt ut labore et dolore magna aliqua. "Ut enim ad
> > minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
> > ex ea commodo consequat."
> >
> > Section 1.10.32 of "de Finibus Bonorum et Malorum"
> >
> > Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
> > dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
> > proident, sunt in culpa qui officia deserunt.
> >
> > Sed ut perspiciatis unde omnis iste natus error sit voluptatem
> > accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
> > illo inventore veritatis et quasi architecto beatae vitae dicta sunt
> > explicabo.
> >
> > and in my templates use this text like that:
> >
> > {{ body|safe|linebreaks }}
> >
> > and the result is:
> >
> > Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
> > eiusmod tempor incididunt ut labore et dolore magna aliqua. "Ut
> > enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
> > aliquip ex ea commodo consequat."
> >
> > Section 1.10.32 of "de Finibus Bonorum et Malorum"
> >
> > Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
> > dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
> > proident, sunt in culpa qui officia deserunt.
> >
> > Sed ut perspiciatis unde omnis iste natus error sit voluptatem
> > accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
> > illo inventore veritatis et quasi architecto beatae vitae dicta sunt
> > explicabo.
> >
> > As you see, h2 tag is inside p tag. And this is not a valid usage for
> > xhtml which is my document's type.
> >
> > I need paragraphs because their styles are applied by css. Also h2s are
> > same.
> >
> > I don't want users-editors- do paragraphs manually, because many of
> > texts are quite long, this is not efficient, so I use linebreaks. Users
> > have some capability of writing html as much as they need. So they can
> > markup h2, strong etc, if it is necessary in text.
> >
> > How can I fix this?
> >
> > Thanks.
> >
> > --
> > Ali Rıza Keleş
> 

-- 
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: NoReverseMatch is making me crazy

2010-02-22 Thread Tom Evans
On Mon, Feb 22, 2010 at 11:01 AM, andreas schmid  wrote:
> im experiencing a problem since today:
>
> my model :
>
>    class Technology(models.Model):
>         title        = models.CharField(max_length=250,
>    help_text=_('Type in the technology title'))
>         body       = models.TextField(help_text=_('Type in the
>    description of the technology'))
>         slug        = models.SlugField()
>
>         ...
>
>         @models.permalink
>         def get_absolute_url(self):
>            return ('my_technology_detail', (), { 'slug': self.slug })
>
> my view:
>
>        def technology_detail(request, slug):
>            technology = get_object_or_404(Technology, slug=slug)
>            return render_to_response( 'techn_detail.html',
>    {'technology': technology})
>
> my url:
>        ...
>
>        url(r'^/technlogies/(?P[-\w]+])/$',
^^^
Remove the extraneous square bracket and everything should be golden.

>            technology_detail,
>            name='my_technology_detail'),
>        ...
>
> whatever i try to do with the detailview of this model i get a:
> Exception Type:         NoReverseMatch
> Exception Value:
>
> Reverse for 'my_technology_detail' with arguments '()' and keyword arguments 
> '{'slug': u'whatever-slug'}' not found.
>
>
> but the technology is saved in the db and the slug is the right slug and
> i have other models written the same way but they are working. what am i
> missing?
>

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



allowing other chars in User.username

2010-02-22 Thread Aljosa Mohorovic
what are security concerns if username is allowed to contain chars
like ".,;-() " and non-ascii alphabet letters?
will orm still properly escape string before querying the database?

Aljosa

-- 
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: formset media

2010-02-22 Thread anentropic
A formset should have a 'media' attribute which should include all the
media from the widgets in the forms which make up the formset, so in
the template you should be able to just
{{ name_of_formset_var.media }} in the head of your page to output the
necessary script tags.

On Feb 17, 3:13 pm, kkerbel  wrote:
> Anybody?  :)
>
> On Feb 17, 1:19 am, kkerbel  wrote:> I'm having trouble 
> getting AdminDateWidget to show in a formset.  Is
> > this possible?  I've read and followed every post that mentions how to
> > do this and I even have a page working with the AdminDateWidget,
> > however, it uses a regular form and not a formset.  I'm just having
> > trouble getting it to show on a template using a formset.  Is there a
> > specific way to specify formset media in the template?

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



NoReverseMatch is making me crazy

2010-02-22 Thread andreas schmid
im experiencing a problem since today:

my model :

class Technology(models.Model):   
 title= models.CharField(max_length=250,
help_text=_('Type in the technology title'))
 body   = models.TextField(help_text=_('Type in the
description of the technology'))
 slug= models.SlugField()

 ...

 @models.permalink
 def get_absolute_url(self):
return ('my_technology_detail', (), { 'slug': self.slug })

my view:

def technology_detail(request, slug):
technology = get_object_or_404(Technology, slug=slug)
return render_to_response( 'techn_detail.html',
{'technology': technology})

my url:
...

url(r'^/technlogies/(?P[-\w]+])/$',
technology_detail,
name='my_technology_detail'),
...

whatever i try to do with the detailview of this model i get a:
Exception Type: NoReverseMatch
Exception Value:

Reverse for 'my_technology_detail' with arguments '()' and keyword arguments 
'{'slug': u'whatever-slug'}' not found.

 
but the technology is saved in the db and the slug is the right slug and
i have other models written the same way but they are working. what am i
missing?

-- 
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: Othogonal aspects to models

2010-02-22 Thread klaasvanschel...@gmail.com
Thanks Shawn - but James' talk is exactly what got me into this
mess :-)
I'm aware of the possibility of specifying the model to be used as a
default kw arg in views etc. But I want all my models to become 'owner
aware'.

http://code.google.com/p/django-granular-permissions/ approaches the
model's extension from the other side: it has a Permission class with
content_type/id pointers to the relevant object. Unfortunately
permissions are not checked/handed out automatically, but at least
this solves the model problem to some extend.

Will keep everyone posted, I'm not quite there yet... help is very
welcome.

On Feb 22, 2:36 am, Shawn Milochik  wrote:
> Check out James Bennett's DjangoCon 2008 talk on reusable apps. He goes into 
> some detail on how he made django-registration in such a way that it wasn't 
> necessary to require a specific model in order for it to work. I haven't 
> implemented anything this reusable myself so I can't really give you much, 
> but you could do worse than checking out the work of one of the core 
> developers of Django.
>
> http://www.youtube.com/watch?v=A-S0tqpPga4
>
> In addition, the actual app is here, for your reading pleasure:
>
> http://bitbucket.org/ubernostrum/django-registration/
>
> Shawn

-- 
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: SAAS User and Auth situation.

2010-02-22 Thread Daniel Hilton
On 22 February 2010 05:09, orokusaki  wrote:
> I'm developing an SAAS which means that I will have Accounts and those
> Accounts will have Users. Each account's Users are completely
> orthogonal to the Users of another Account. When a user logs in,
> they'll supply an Account ID, a username, and a password so username
> only needs to be unique with regards to the Account in question.
> Firstly, is there an app out there or somebody who knows how to
> conquer this? If so, I would truly appreciate the help or a link.
>
>
> Problem 1 (with built-in User object), maybe there is a way around
> this:

You could look at this app:

http://github.com/saas-kit/django-muaccounts

The rest of the saas-kit might be helpful too - I'm really loking
forward to the payment stuff coming from satchmo as well to help with
saas payments.


HTH
Dan

>
> A) User of Account 'acme' might have the username "mike" and the user
> for Account "general mills" might have a user with the username
> "mike" (since "mike" is a very common name this will certainly happen
> within the first day of getting clients). I can't control what
> Accounts' Users decide to make their username and I certainly don't
> want to make it like domain registration, like if a User has to check
> if a username is available before creating it (all common names would
> be taken after the first 100 accounts if the average account had 2-3
> users).






>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>



-- 
Dan Hilton

www.twitter.com/danhilton
www.DanHilton.co.uk


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



what is up with InternalError current transaction is aborted, commands ignored until end of transaction block

2010-02-22 Thread talpay...@gmail.com
I have search far and wide for some help regarding the Internal Error
and i can't find any help. I have absolutely no idea why this is
showing it doesn't make any sens. I just want a way to catch it but
that is impossible. I would appreciate any help.


Traceback:
File "C:\Python26\Lib\site-packages\django\core\handlers\base.py" in
get_response
  99. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Python26\Lib\site-packages\iitcms\auth\decorators.py" in
_checklogin
  18. return view_func(request, *args, **kwargs)
File "C:\Python26\Lib\site-packages\iitcms\products\my_admin\views.py"
in import_excel
  1312. msg = prepare_products(request)
File "C:\Python26\Lib\site-packages\iitcms\products\utils.py" in
prepare_products
  115. error_list, ignored_list_number, new_list_number,
edited_list_number = create_products(products, category)
File "C:\Python26\Lib\site-packages\iitcms\products\utils.py" in
create_products
  164. rezult = create_product(category, product, cat_poz,
name_poz, description_poz, price_poz, codes_poz, stoc_poz, um_poz)
File "C:\Python26\Lib\site-packages\iitcms\products\utils.py" in
create_product
  305. new_product =
Product.objects.get(product_name__iexact = product_name)
File "C:\Python26\Lib\site-packages\django\db\models\manager.py" in
get
  119. return self.get_query_set().get(*args, **kwargs)
File "C:\Python26\Lib\site-packages\django\db\models\query.py" in get
  293. num = len(clone)
File "C:\Python26\Lib\site-packages\django\db\models\query.py" in
__len__
  74. self._result_cache = list(self.iterator())
File "C:\Python26\Lib\site-packages\django\db\models\query.py" in
iterator
  231. for row in self.query.results_iter():
File "C:\Python26\Lib\site-packages\django\db\models\sql\query.py" in
results_iter
  281. for rows in self.execute_sql(MULTI):
File "C:\Python26\Lib\site-packages\django\db\models\sql\query.py" in
execute_sql
  2373. cursor.execute(sql, params)
File "C:\Python26\Lib\site-packages\django\db\backends\util.py" in
execute
  19. return self.cursor.execute(sql, params)

Exception Type: InternalError at /products/admin/import/
Exception Value: current transaction is aborted, commands ignored
until end of transaction block

-- 
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: A Query question about Many-to-many relationships

2010-02-22 Thread Jason
Hi Atamert,

Thank you so much!

The following statement works! This is really simple but fantastic!!!
Publication.objects.filter(article__in =
article_qs).annotate(Count('article'))

Sincerely,
Jason

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to get as_sql() to work again

2010-02-22 Thread Russell Keith-Magee
On Mon, Feb 22, 2010 at 2:41 AM, felix  wrote:
> As of 1.2 and multi-db how do I get the sql that will be produced from
> a query set ?
>
> Since 1.2 and multi-db, the previous methods are no longer working.
> Its been said here that we shouldn't depend on internal functions as
> they may change.
>
> However getting the SQL that will be produced is essential.  There
> needs to be a utility method somewhere that will give us this sql and
> it needs to remain stable.

Well, no -- it isn't essential. It might be a very handy debugging
tool, but it isn't essential.

That said:

print object.query

will give you the result you are looking for, with one caveat.

If you only have one database, then you don't need to worry about the
caveat. However, if you have multiple databases, you should be aware
that "print object.query" will return the query for the 'default'
database. If you have a heterogenous database environment, then the
SQL that is returned won't be 100% correct.

If you need the actual SQL that is guaranteed correct for a given
backend, you need to use object.query.get_compiler(alias).as_sql()
(where alias is the database alias that you want to generate SQL for).

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: apparent bug in QuerySet

2010-02-22 Thread Russell Keith-Magee
On Mon, Feb 22, 2010 at 4:48 AM, felix  wrote:
>
> This seems so blatant that it couldn't really be a bug without someone
> noticing. Django 1.2
>
>        qs = Apt.objects.filter(list_on_web=True,is_available=True)
>
>         # FastAdderStatus has Apt and Service as fk
>        qs = qs.filter(fastadderstatus__service=self.service)
>
>        # later on here's another filter on the same table
>        qs = qs.filter(fastadderstatus__running_status__in= (2, 3, 4))
>
> produces this:
>
>  SELECT U0."id" FROM "nsproperties_apt" U0 INNER JOIN
> "fastadder_fastadderstatus" U1 ON (U0."id" = U1."apt_id") INNER JOIN
> "fastadder_fastadderstatus" U3 ON (U0."id" = U3."apt_id") WHERE
> (U0."list_on_web" = True  AND U0."is_available" = True  AND
> U1."service_id" = 4  AND U3."running_status" IN (2, 3, 4))
>
> Note that it joins the same table twice, and the Apt is not returning
> distinct.  Postgres is not liking the query.
>
> count: 2837
>
> [, ,  #12297>, , ,  Property #12304>, , ,
> , ,  #12308>, , ,  Property #12309>, , ,
> , ,  #12314>, , '...(remaining elements
> truncated)...']
>
> what it should say (manually fixed) :
>
>  SELECT U0."id" FROM "nsproperties_apt" U0 INNER JOIN
> "fastadder_fastadderstatus" U1 ON (U0."id" = U1."apt_id") WHERE
> (U0."list_on_web" = True  AND U0."is_available" = True  AND
> U1."service_id" = 4  AND U1."running_status" IN (2, 3, 4))
>
> count: 611, no dups
>
>
> My solution:
>
>        params = {}
>        if self.service:
>            params['fastadderstatus__service'] = self.service
>        if self.agent:
>            params['agents'] = self.agent
>
>        if self.status:
>
> params.update( 
> FastAdderStatus.objects.filter_params_for_status(self.status,'fastadderstatus')
>  )
>
>        # a single call to filter
>        qs = qs.filter(**params)
>
> which avoids the (?) bug and also is vastly more efficient.

You haven't found a bug - Django is returning exactly what you asked
for. There is a difference between making the query:

Model.objects.filter(a__b=x).filter(a__c=y)

and the query:

Model.objects.filter(a__b=x, a__c=y).

In the first query, Django will use two different joins on the 'A'
table. In the second query, the join on 'A' will be reused. It sounds
like what you want is the second query.

This behaviour is documented here [1].

[1] 
http://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-multi-valued-relationships

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



  1   2   >