Re: High, ongoing CPU consumption

2010-03-26 Thread David Christiansen
Thank you very much, Graham.  I'll do some more looking and get back
to the list.

/David Christiansen

-- 
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 Admin: Redirecting after save

2010-03-24 Thread David Christiansen
On Mar 24, 5:23 pm, mwebs  wrote:
> But it this doesnt work for me, as I definitvely need the id of the
> object that just has been saved.
> So what I need is:
> - after model save --> redirect to another view
>
> Any ideas?
>
> Thanks
> - Toni

Take a look at the UserAdmin in django.contrib.auth.  This has exactly
this behavior when making a new user.

/David Christiansen

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



High, ongoing CPU consumption

2010-03-24 Thread David Christiansen
Dear fellow Django users,

We're beginning to be at wits end with a particular problem that we're
having that I suspect has to do with server configuration issues, but
might be something else.

Our Django processes (whether it be Apache when running mod-python or
independent daemons when running mod_wsgi in daemon mode) begin to
consume CPU shortly after the server is started.  I expect to see
short spikes in CPU usage when requests occur, with some very small
amount (single-digit %) when there are no requests occurring.
Instead, we get a slowly increasing constant load on the CPU that
eventually begins to affect the performance of the site.  Restarting
the server makes the problem go away, but it returns after a few
requests have been made.

I've been unable to replicate this problem when running Django locally
on my computer, with wsgi or with manage.py runserver.

Because the CPU consumption comes from the mod_wsgi daemon processes,
I am quite sure that the problem lies somewhere in Python and not in
an Apache module or in Postgres.

As I can't replicate this problem locally, I've tried profiling the
site on our actual server by running a second instance of Apache and
mod_wsgi with the repoze.profile WSGI middleware.  This middleware
appears to work just fine, but I've not yet been able to replicate the
problem when running it.

Additionally, repoze.profile starts recording profile data when a
request begins, and stops when the request is done.  It strikes me as
possible that it may not even record data on a long-running CPU hog if
I can create it.

I have two questions for you all:

 1. Is there a good way to use cProfile or hotshot on the _entire_
WSGI application rather than as a per-request middleware while running
under mod_wsgi?  cProfile's restriction that it must be called with a
string that is eval'd seems to make this impossible, but I'm quite new
to WSGI configuration so I might be missing something obvious.
Hotshot would seem to have the same problem, even though it wants a
callable rather than a string.

 2. Has anyone else here experienced anything similar who could shed
some light on my situation?

Many thanks in advance!

/David Christiansen

-- 
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: Can I change the restriction on "username" without breaking anything?

2009-11-13 Thread David Christiansen
> Which makes me wonder if the "right" way is to use a custom user
> validation system, likely with the e-mail field dropped, or maybe just
> aliased to the username so things that expect e-mail address find one.

This is exactly how I solved this problem.  I just created an
authentication backed that compares the entered username with the
email field on the User model instead of the username field but
otherwise works just like the standard one.  I then arranged to
populate the username field with the first 30 characters of the email
address to make it easy to find the users in the admin interface and
such.

The other thing I needed to do was override the default login forms,
because they place a maximum length of 30 characters on the username
field.

Documentation for custom auth backends is at
http://docs.djangoproject.com/en/dev/topics/auth/#writing-an-authentication-backend
.

Hope this helps!

/David Christiansen

--

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




Re: OK to put app_directories before filesystem template loader?

2009-08-19 Thread David Christiansen

Well, it doesn't seem to make much sense to me.  I use the default
order so that I can place files in a site-level templates directory in
order to override the default templates in the app directory without
having to directly open it up and modify its template files.

-David Christiansen

On Aug 18, 5:43 pm, ke1g  wrote:
> I find myself wanting to place the app_directories template loader
> before the filesystem template loader in
> settings.TEMPLATE_LOADERS, so that when I clone an app to, among other
> things, modifiy its templates, I get mine instead of the default.
>
> I'm wondering if anyone knows of reasons not to change the order?
>
> [I'm actually using pinax, but this seems like a general Django
> question.]
>
> Bill
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: easy way of display an user bar?

2009-08-17 Thread David Christiansen

On Aug 16, 9:31 am, Mirat Bayrak  wrote:
> I have that problem too, is there any other solution?

Hi Mirat

I'm not sure what problem you mean.  Is the problem that you can't use
RequestContext for some reason? Or is there another reason why you
can't do it that way?


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



Re: easy way of display an user bar?

2009-07-28 Thread David Christiansen

If you're using the standard context processors, then just make sure
to use RequestContext and you'll have a user variable in your template
context.

The only downside is that this will _only_ work when you're using
RequestContext, so your template should probably do something like {%
if user %}{{ user }}'s Profile{% endif %}.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Displaying image stored in models.ImageField

2008-12-09 Thread David Christiansen

Hello Craig,

Just make sure not to use this in production.  For your production
site, you should really conifigure Apache or lighttpd or some other
dedicated web server for the static content.  The Django view isn't
that efficient at it.

-David Christiansen

On Dec 8, 10:46 pm, "Craig Spry" <[EMAIL PROTECTED]> wrote:
> Hello All,
>
> I fixed my problem I needed to add a line like this to urls.py:
> (r'^uploads/(?P.*)$', 'django.views.static.serve', {
> 'document_root': 'c:/src/webcomic/uploads' } )
>
> Thanks,
> Craig Spry
>
> On Mon, Dec 8, 2008 at 10:49 PM, Craig Spry <[EMAIL PROTECTED]> wrote:
> > Hello All,
>
> > Just to add to what I've said below, when I point the browser at the
> > image url like this:
> >http://localhost:8000/uploads/comics/john7_web.png
>
> > I get a 404.
>
> > Craig
>
> > On Mon, Dec 8, 2008 at 10:34 PM, Craig Spry <[EMAIL PROTECTED]> wrote:
> >> Hello All,
>
> >> I have an image stored in a models.ImageField that looks like this:
> >> comic = models.ImageField(upload_to='comics')
>
> >> and I have this in the settings.py
> >> MEDIA_URL = 'http://localhost:8000/uploads/'
>
> >> and in the template I have this:
> >> 
>
> >> And all I see in the rendered page is the comic.name.  Is there
> >> anything else I need to setup for this to work?
>
> >> Thanks,
> >> Craig Spry
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: serving static file via django

2008-11-20 Thread David Christiansen

Pranav,

Have you considered just writing a view that returns the data in the
file with the appropriate headers? That's very easy to do and doesn't
require loading the whole static serve method.  You can then also put
whatever tracking you wanted in that view function.

If you want, I can send you a sample of something where I do something
similar.

-David Christiansen


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



Re: Recursive function

2008-11-12 Thread David Christiansen

Hi gontran,

Why not check out using one of the two tree libraries that are out
there (django-mptt and treebeard)? They include functions for
traversing trees already, and you save yourself a lot of work dealing
with the schema stuff.  We use django-mptt where I work to do exactly
what you're describing, and it is quite effective and easy.

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



Re: saving multiple versions of an uploaded image

2008-11-05 Thread David Christiansen

It's also worth looking into the sorl.thumbnail library.  This has an
ImageWithThumbnailField that does this work for 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Migrate app from MySQL to PostgreSQL

2008-10-30 Thread David Christiansen

Why not just dump the data using manage.py dumpdata, switch your
settings file to point to the new DB, run syncdb, and then use
manage.py loaddata to get it all back?  That should be pretty easy.

-David Christiansen

On Oct 30, 2:39 am, "Naitik Shah" <[EMAIL PROTECTED]> wrote:
> I looked around but didn't find anything obvious or simple. This is a live
> Django app with data in MySQL which I want to migrate to PostgreSQL.
> Suggestions? (Before I do my own thing :))
>
> -Naitik
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Ordering in Admin Interface

2008-10-09 Thread David Christiansen

> It's not intended to work, so it seems like everything is behaving
> correctly from that respect. The admin intentionally only orders on one
> field. The reason being that the UI feedback for ordering on more than
> one column is generally going to be confusing (nobody's come up with a
> good way to represent it yet).
>
> If you have a look in
> django.contrib.admin.views.main.ChangeList.get_ordering() you will see
> where the single ordering field requirement is enforced. So you could
> somehow override that method to get what you want, I guess.
>
> Regards,
> Malcolm

Hi Malcolm,

Thanks for the explanation.  Given that the reason for only ordering
on one field is that it's hard to design a UI to order on two, why not
just allow ordering on more than one field for the default ordering,
and then revert to single-field ordering when someone clicks the
column headers?

I'll poke around and find a dirty hack.  Thanks for the pointer on the
ChangeList.get_ordering()!

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



Ordering in Admin Interface

2008-10-08 Thread David Christiansen

Hello all,

We are currently working on a project in which we would like to order
the list of model instances on the admin interface by two separate
parameters.  So far, the second has been ignored. We've tried the
following:

1. Setting the ordering attribute of the ModelAdmin subclass.  The
documentation says that this will not work, but it was worth a try.

2. Setting the ordering on the model's Meta class.  This worked in
other contexts, but not the admin interface.

3. Overriding the ModelAdmin's queryset method to look like:

def queryset(self, request):
return super(PageAdmin,
self).queryset(request).order_by('tree_id', 'lft')

where tree_id and lft are the fields we would like to order by.  We're
at a loss for what to do.

We can see that the second parameter to the ordering is being ignored
in one of the SQL queries shown in the Django Debug Toolbar.

Any pointers on where to look next would be appreciated.  Thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Duplicate files being created on ImageField.save

2008-09-29 Thread David Christiansen


>
> I had a similar issue.
>
> The fix i have found on the web is to wrap your action in an if
> statement to make sure you only do it once
>
> Something like
>
>       def save(self):
>          if not image_scaled:
>             scaled_name = os.path.split(self.image_original.name)[-1]
>             self.image_scaled.save(scaled_name, self.image_original,
> save=False)
>          super(Page, self).save()

See, that didn't do it, as the field needed to be filled for the first
time.  Just having the one line of code made that happen. I actually
ended up just grabbing sorl thumbnails, which does exactly what I
wanted.  But it's still funny. Perhaps if I put a timestamp on the
image and the thumbnail, and used that to check if it had been
updated.  My guess is that the admin interface was calling save()
multiple times.

Thanks for the reply!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Duplicate files being created on ImageField.save

2008-09-26 Thread David Christiansen

I'm in the process of developing a site in Django that includes the
following in the models.py:

def image_path(page, filename):
return "content_images/page/%s/original/%s" % (page.pk, filename)
def image_scaled_path(page,filename):
return "content_images/page/%s/scaled/%s" % (page.pk, filename)

class Page(models.Model):
# 
image_original = models.ImageField('Picture',
upload_to=image_path, blank=True)
image_scaled = models.ImageField(upload_to=image_scaled_path,
blank=True)
# 
def save(self):
#
scaled_name = os.path.split(self.image_original.name)[-1]
self.image_scaled.save(scaled_name, self.image_original,
save=False)
super(Page, self).save()

The idea is that image_scaled has a version that is a thumbnail of the
originally updated photo.  I've removed that code for testing
purposes, and this still happens.  What happens is that two images are
created in content_images/page/PAGE_ID/scaled/, one with an underscore
after the name.  image_scaled.path shows that the version with the
extra underscore is the current one referred to after running this.

This behavior happens on both Windows and Linux servers.  I'm running
Django 1.0.  As far as I can tell, I'm using the FileField API
correctly.  Is there something obvious that I'm missing?

Thanks in advance!

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



Re: Map API's and Django, preferences?

2008-09-16 Thread David Christiansen

On Sep 15, 5:05 pm, chiggsy <[EMAIL PROTECTED]> wrote:
> It makes a fair bit of sense.. I've heard a lot of good things about
> jquery.  If you could post the view later I think I'll be off and
> running.  Thank you for the help with this.  I find the difficulty
> with web coding is beginnings... I think that I'm getting a good idea
> on how to proceed.
>

Here's my code.  If anyone else has critique of it, I'd also love to
hear it. I'm pretty new to this myself.


#In views.py
def locations_in(request):
"Provide a JSON-encoded list of the locations within a polygon"
region = util.get_lookup_region(request.GET)
locations = [{'name':l.name, 'latitude':l.location.y,
'longitude':l.location.x, 'id':l.pk}
 for l
 in Place.objects.filter(location__within=region)]
return HttpResponse(simplejson.dumps(locations))


#In a util module
def get_lookup_region(querydict):
#Collect the provided points out of a querydict
i = 1
points = []
while "lat%s"%i in querydict and "long%s"%i in querydict:
p = "%s %s" % (querydict["long%s"%i], querydict["lat%s"%i])
points.append(p)
i += 1

#If the body of the while was never executed then there were no
points provided
if i == 1:
raise NoPointsProvidedException()

#Close the polygon if necessary
if points[0] != points[-1]:
points.append(points[0])

#Finally return the geometric region object corresponding to the
above points
lookup_region = GEOSGeometry("POLYGON(( " + ", ".join(points) +
" ))")
return lookup_region


#In models.py
class Place(models.Model):
name = models.CharField(max_length=200)
location = models.PointField()

objects = models.GeoManager()

I hope this is useful for 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Map API's and Django, preferences?

2008-09-15 Thread David Christiansen

Here's what my code looks like to get information from the server to
display on the map:

function update_locations () {
bounds = map.getBounds();
sw = bounds.getSouthWest();
ne = bounds.getNorthEast();
$.getJSON('/locations/locations/',
{'lat1':sw.lat(), 'long1':sw.lng(),
 'lat2':sw.lat(), 'long2':ne.lng(),
 'lat3':ne.lat(), 'long3':ne.lng(),
 'lat4':ne.lat(), 'long4':sw.lng()},
function(data, textStatus){
 $.each(data, function() {
 //Check if currently in set, add if not
 if (markerSet["key"+this.id]) {}
 else {
 latlng = new GLatLng(this.latitude,
this.longitude);
 marker = new GMarker(latlng,
{'title':this.name});
 marker.bindInfoWindowHtml("");
 markerSet["key"+this.id] = marker;
 markerManager.addMarker(marker, 10);
 }
 });
}
);
}

In my onload event handler for the page, I have this:

GEvent.addListener(map, 'moveend', update_locations);

I don't have access to the Django view that responds to the request
right now, but I could post it later if it would be helpful.  It
basically just creates a polygon from the lat/long GET parameters and
then does a GeoDjango query for the points inside that polygon.  It
then iterates over them and constructs a JSON-encoded list of
JavaScript objects, which it puts into the HTTPResponse.

The code uses JQuery, which I've found really helpful in reducing the
pain of Javascript. That's what all the funny $ variables are.  Does
this make sense?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Map API's and Django, preferences?

2008-09-15 Thread David Christiansen

I've had good luck with using GeoDjango and a custom Google Maps
interface.  The one included with GeoDjango was a bit sparse in
features, but it did work.  An easy way to get started might be to
have GeoDjango generate you a map, and then take the generated code
and use it as a starting point and put your own information in it.

What I do is I connect the 'move' event of the Google map to a little
function that makes a GET request to a Django view with the lat/long
of the four corners of the map as parameters.  This returns a list of
points inside the polygon formed by the four points, along with
metadata, and I then iterate over that list and create GMarker
instances on the map.  It's a little more complicated, as it uses a
MarkerManager to hide points that are off the map and a table of
already-seen points to avoid adding them twice, but that's the general
method.  It seems to be working pretty well so far, though I could
decrease server load by only querying the polygons that haven't been
queried before.

Have you written Javascript before?

-David



On Sep 13, 4:15 pm, TiNo <[EMAIL PROTECTED]> wrote:
> I wanted to do the same. I decided not to user GIS because of all the new
> stuff I needed to install. Two Coordinates are good enough for the google
> maps api.
> I plan on using geopy (http://exogen.case.edu/projects/geopy/) for
> translating addresses to coordinates.
>
> I also found these articles that should help you in the right 
> direction:http://www.developer.com/java/web/article.php/10935_3528381http://ajaxian.com/archives/geocoding-with-googles-maps-apihttp://www.instantdjango.com/chapter1.html
>
> Good luck, and please backpost when you build a cool app!
>
> TiNo
>
> On Sat, Sep 13, 2008 at 3:02 AM, chiggsy <[EMAIL PROTECTED]> wrote:
>
> > I'm working on a little idea.  I need to display data on a map.  Now,
> > I have been reading over the gis stuff in django, I've set up
> > PostGIS , and now i'm trying to work out how do display the data.
> > What are some opinons on Google maps vs yahoo maps, for ease of django
> > development ? (I am brand new to this, so if i missed a handy map api
> > pls lmk)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Include django views in other web sites

2008-07-03 Thread David Christiansen

Just a thought, but can you put this information in an iframe?

On Jul 3, 1:28 pm, Alessandro <[EMAIL PROTECTED]> wrote:
> I need to include some django output in other web pages. The problem
> is that Sometimes I cannot use server side includes on the other side,
> and I don't know how to do.
>
> I thought maybe some javascript or ajax to include with a 

URL pre-processing middleware

2008-07-02 Thread David Christiansen

Hi everyone,

I'm in the process of using Django to develop a CMS for our Web site,
and one thing that I'd like to do is to find a way to maintain
compatibility with the old URLs on the site. These old URLs are,
however, somewhat crufty. In particular, I'd like to be able to do the
following to URLs:

1. Strip certain file extensions, such as ".php" and ".asp"

2. Change them from mixed case to all lower case

Doing this will allow the majority of our legacy URLs to work well in
the new system.  It should probably be done by returning a permanent
redirect status code pointing at the new URL.

It seems to me that the best way to do this would be to write a
middleware class that works similarly to CommonMiddleware.  However,
I'm having a hard time creating one that I'm satisfied with. The
problem is that anything I create will have to essentially replicate
those URL rewrites performed by CommonMiddleware, such as adding the
trailing slash.  This is because only one middleware can return a new
response for a request.

My first plan of attack was to write a middleware class whose __init__
method took a list of functions as parameters which it would then use
as rewriters.  But it doesn't seem to look as though one can provide
init arguments to middleware classes.  I suppose it could be in a
settings.py variable though.  In any case, this middleware would also
have to reimplement the rewrites found in CommonMiddleware.

Is there somewhere I should be looking where I'm not? Some kind of
built in rewriter?

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