integrity error with transaction middleware, django 1.3

2013-09-10 Thread Brian Craft
I'm getting duplicate entry integrity errors when saving an object, with transaction middleware enabled in django 1.3. I thought the point of the middleware was to rollback transaction errors and retry the view. Why would I be getting this error? The db is mysql. The save code looks like this: t

serialize field name instead of "pk"

2012-04-06 Thread Brian Craft
I have a model with a "name" field that is the primary key. When serializing, this field gets serialized as "pk" instead of "name". Is there an easy way to get django to serialize with the actual field name instead of changing it to pk? -- You received this message because you are subscribed to

Re: syncdb not creating join table

2012-01-04 Thread Brian Craft
Looks like a m2m class can be identified by the ._meta.auto_created attribute, which also holds the class with the m2m field. So the router can check for attributes on that class. On Wed, Jan 4, 2012 at 11:49 AM, Brian Craft wrote: > I strongly suspect the problem I'm having has to

Re: syncdb not creating join table

2012-01-04 Thread Brian Craft
but I don't have control of that on the generated model. On Wed, Jan 4, 2012 at 10:57 AM, Brian Craft wrote: > I have two models. The second one has a ManyToMany to the first. Both > are managed. If I drop both tables and run syncdb, only the two model > tables are created. Th

syncdb not creating join table

2012-01-04 Thread Brian Craft
I have two models. The second one has a ManyToMany to the first. Both are managed. If I drop both tables and run syncdb, only the two model tables are created. There's no join table. syncdb doesn't report any errors. "validate" shows 0 errors. Any ideas what the problem could be, or how to debug i

logging sql queries during unit test

2012-01-03 Thread Brian Craft
Is overwriting settings.DEBUG the recommended way to get connections[db].queries to work during a unit test? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from

ModelChoiceField with multiple databases

2011-12-21 Thread Brian Craft
Is there an easy way to use a ModelChoiceField with multiple databases? The only thing I've seen that looks promising is overriding the form __init__ and setting the queryset for the field. Seems kinda clunky. -- You received this message because you are subscribed to the Google Groups "Django

Re: double trailing slash in url

2011-12-01 Thread Brian Craft
I don't think so. It's not issuing a redirect. It's just serving the view, even though the url spec doesn't match. On Thu, Dec 1, 2011 at 2:42 PM, creecode wrote: > Hello Brain, > > Could it be you are seeing the results of the APPEND_SLASH setting < > https://docs.djangoproject.com/en/1.3/ref/se

double trailing slash in url

2011-12-01 Thread Brian Craft
I have a url spec like so: (r'^foo/$', 'blah') I just noted from our server logs that if someone mistakenly types two slashes ('foo//'), the page gets served, but all of the relative links are broken. It's really confusing. I believe it should be redirecting or 404ing instead. I note that foo/bar

"drop table if exists" aborts

2011-11-02 Thread Brian Craft
mysql generates an informational warning when running "drop table if exists " if the table doesn't exist. Django then throws an error and aborts. Is there a good way to avoid this? b.c. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post t

overriding widget for "group" in User model

2011-06-16 Thread Brian Craft
Is there an easy way to get checkboxes for groups in the User admin, rather than a multiselect? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, s

Re: default group for new users

2011-05-17 Thread Brian Craft
project __init__.py, but that works inconsistently, apparently because django isn't fully initialized when the project __init__.py is loaded. On Tue, May 17, 2011 at 11:07 AM, Brian Craft wrote: > Is there a good way to add new users to a default group when they are > created (e.g. vi

default group for new users

2011-05-17 Thread Brian Craft
Is there a good way to add new users to a default group when they are created (e.g. via django-registration)? I just tried binding the post_save signal for User, and adding the group in the signal handler (if "created" is true). However, I haven't found a good place (file) to put the connect() call

Re: imagefield upload_to

2011-05-11 Thread Brian Craft
solved this by moving it to the model clean() method, and using imagefield.file.open() and imagefield.file.read() to get the data for computing the other fields. On Wed, May 11, 2011 at 1:28 PM, Brian Craft wrote: > I have a model with an imagefield, and some fields that are computed > fr

imagefield upload_to

2011-05-11 Thread Brian Craft
I have a model with an imagefield, and some fields that are computed from the image. I'm trying to override the "save" method to fill in the other fields. When I test this in the admin, there are two problems: first, the path (mymodel.image.path) doesn't honor the upload_to setting on the field. I

unit testing and file location

2011-05-10 Thread Brian Craft
I would like unit tests that do file manipulations to run with a different storage "location", so they're not manipulating real app files. Is there a good way to do this? Is there a way to override model field initializers, so I can instance a model, passing in the 'storage' parameter for an ImageF

form CharField null vs blank

2011-04-28 Thread Brian Craft
A form with a CharField seems to end up with a zero-length string in the cleaned_data if the field is not in the form data. Is there any good way to avoid this? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

object with version

2011-04-21 Thread Brian Craft
I need to create objects with version tracking, a bit like wiki content. Anyone done this in django? I could create a model with a content field and a version field. But I'm not sure how to query (for example) all the latest versions of a set of objects. I'm sure there's a raw sql method via joins

Re: how to get csrf cookie in ajax app

2011-03-21 Thread Brian Craft
No, it's not. It's a static file. On Mon, Mar 21, 2011 at 10:23 AM, Matt Robenolt wrote: > Is your main view being rendered by Django or something else? If so, you'll > have access to the cookie. > > On Mar 21, 2011, at 1:09 PM, Brian Craft wrote: > >> It&

Re: how to get csrf cookie in ajax app

2011-03-21 Thread Brian Craft
It's in a cookie once you coerce django into sending the cookie to the browser. This is less automatic for ajax apps, because django isn't serving the forms (which is when it usually sends the csrf cookie). On Mon, Mar 21, 2011 at 9:49 AM, Matt Robenolt wrote: > To get the token? It's stored in

Re: how to get csrf cookie in ajax app

2011-03-19 Thread Brian Craft
Yeah, I'm using that technique. It works fine once you have the cookie. My question was about how to get the cookie, which is not described well in the documentation. Manually calling get_token() in the view for the first ajax GET seems to be working. After that I can POST to other views. On Sat,

how to get csrf cookie in ajax app

2011-03-18 Thread Brian Craft
In an ajax-based site, where the page is static, and makes ajax calls after loading, how would one get a csrf cookie? There aren't any templates associated with the views (they just return json strings). Setting of the cookie seems to be a side effect of serving forms in django, but the client does

mysql OperationalError

2011-03-10 Thread Brian Craft
When a long-running script loses the db connection, I get this exception: _mysql_exceptions.OperationalError Is there any way to trap this in a database-agnostic way? Or must I hard-code it to mysql? -- You received this message because you are subscribed to the Google Groups "Django users" g

database connection from long lasting script

2011-03-09 Thread Brian Craft
I have a script that sits in a loop, doing occasional queries, something like while 1: wait.for.some.event() object=get.some.django.db.object() do.something.with(object) transaction.commit_unless_managed() The last line is required so the script will see updates to the database from other

Re: current recommendations for using email as username

2011-03-08 Thread Brian Craft
On Tue, Mar 8, 2011 at 12:53 PM, william ratcliff wrote: > If you look through the code in the django admin, then the limit is set in > the database schema. I've read elsewhere that it's also in all the auth form validations, so you have to subclass all of them. I haven't actually investigated th

Re: current recommendations for using email as username

2011-03-04 Thread Brian Craft
On Fri, Mar 4, 2011 at 1:34 PM, Shawn Milochik wrote: > What's wrong with writing your own auth backend? It's two piddly functions: > > http://dpaste.com/hold/473373/ > I think this has already been answered, in the comments here: http://djangosnippets.org/snippets/74/ and in the "motivation" s

current recommendations for using email as username

2011-03-04 Thread Brian Craft
I've found any number of threads on using email as username in django, but none that are both current and conclusive. "Just do ", followed by "But that breaks [the forms, the templates, the auth site, the registration, the db schema]" etc., where is something like "use email in the User username c

Re: csrf cookie security

2011-02-10 Thread Brian Craft
types the url and hits port 80, the MITM can create an https connection to the target site, and return it via http. I'm not certain there's a csrf attack here, but I suspect there is. On Wed, Feb 9, 2011 at 11:28 PM, Ian Clelland wrote: > On Wed, Feb 9, 2011 at 11:51 AM, Brian

Re: csrf cookie security

2011-02-09 Thread Brian Craft
in an insecure cookie, it can be sniffed. Then I don't understand what prevents the attacker from constructing a valid form. On Wed, Feb 9, 2011 at 11:36 AM, Ian Clelland wrote: > On Wed, Feb 9, 2011 at 11:23 AM, Brian Craft wrote: >> I notice that the csrf token is not secure, i.e

csrf cookie security

2011-02-09 Thread Brian Craft
I notice that the csrf token is not secure, i.e. the Set-Cookie is constructed w/o the "secure" option, so the browser will send it in-the-clear. It's trivial, then, for a 3rd party to discover the csrf token. Am I missing something? -- You received this message because you are subscribed to the

Re: caching of Models (not the cache middleware)

2011-01-31 Thread Brian Craft
explicitly commit after every select. On Fri, Jan 28, 2011 at 6:51 PM, Karen Tracey wrote: > On Fri, Jan 28, 2011 at 9:45 PM, Brian Craft > wrote: >> >> Digging into the problem I'm having with a standalone django script, >> the problem seems to be that djan

newbie question about paths

2011-01-29 Thread Brian Craft
Suppose the project is /var/www/django/project. Following the django with wsgi docs, you would add /var/www/django to the path, and DJANGO_SETTINGS_MODULE would be project.settings. However, in that case, the path scheme described in the tutorial doesn't work, e.g. setting up admin.py for Polls as

Re: caching of Models (not the cache middleware)

2011-01-28 Thread Brian Craft
n? On Fri, Jan 28, 2011 at 6:51 PM, Karen Tracey wrote: > On Fri, Jan 28, 2011 at 9:45 PM, Brian Craft > wrote: >> >> Digging into the problem I'm having with a standalone django script, >> the problem seems to be that django doesn't see updates to the >>

caching of Models (not the cache middleware)

2011-01-28 Thread Brian Craft
Digging into the problem I'm having with a standalone django script, the problem seems to be that django doesn't see updates to the database unless it writes to the database. In the following lines, ss = engine.SessionStore(session_id) session=ss.load() If session_id "abcd" has been added t

standalone session checking

2011-01-28 Thread Brian Craft
I'm trying to implement a stand-alone python script to check a session cookie for group authorization. I cribbed from the auth and session middleware, so I could take the sessionid from the cookie, look up the session, look up the user, and get the list of groups. This all basically works, except

Group methods

2011-01-13 Thread Brian Craft
Are there docs somewhere for the Group methods? E.g., I discovered through extensive googling that I can call user.groups.all(), but I can't find docs of an "all()" method, or any other method for Groups. If there aren't docs, how does one discover the methods? -- You received this message becaus

calling django auth from apache RewriteMap

2011-01-12 Thread Brian Craft
I'm interested in using RewriteMap (from mod_rewrite) to check for a django user session. That is, RewriteMap would invoke some script which would return session info, which could be used by mod_rewrite to allow or deny access. Basically, this would require writing a standalone python script that r

wsgi.file_wrapper failing silently

2010-12-17 Thread Brian Craft
I'm testing the patch for ticket 2131 (http://code.djangoproject.com/ticket/2131) on 1.2.3. I'm getting back a 500 (internal server error) sometime after returning the HttpResponseSendFile(), with nothing in the apache error log. Any suggestions on how to debug this? -- You received this message

Re: django auth for existing cgi

2010-12-07 Thread Brian Craft
Copying things from request.META to the env parameter of Popen allows me to get the cgi off the ground. Now I have the problem that the cgi is generating a cookie and content type, which django returns to the browser as page content. Is there a way to pass it back transparently? Or, failing that,