Re: "Great circle" using the django ORM?

2011-08-12 Thread Thomas Weholt
Thanks for your detailed reply :-) I'll try to figure it out. So far I
got a few candidates for a solution but the math functions seem to be
somewhat different on the different database platforms so I need to
experiment some more to find one that works on the three major ones (
sqlite, postgres and mysql - I often use sqlite for development and
postgres for production myself, but still want to support mysql ).

About the accuracy; my app is suppose to show photos take nearby some
location so it doesn't have to be dead on. But this should really be a
reusable app or widget. Seems like more than just me needs this
functionality. If I get something going I'll look into making it
generic and reusable. Anybody interesting in helping out making this
happen please let me know. My experience using math functions in SQL
like this is close to zero.

Thanks alot for all the replies and interest :-)

Regards,
Thomas

On Thu, Aug 11, 2011 at 7:51 PM, Bill Freeman  wrote:
> I've done this sort of thing in the past without the aid of geo-django, using 
> a
> reasonably ordinary model.
>
> I did it as a two step process, first calculating a bounding box, which is a
> rectangle in lat/long space.  It is calculated once per search, based on
> the distance and the coordinates of the distance circle's center (the point
> from which you are measuring distance).
>
> A pair of latitudes that are tangent to the distance circle are easy to come
> by because the point of tangency is at the same longitude as the circle's
> center, and because distance in linear with latitude along such a line.
>
> Bounding longitudes are harder because their points of tangency are
> closer to the pole than the circle's center (unless it's on the equator),
> as well as distance not being linear with longitude change.  But since
> a distance circle radius through the point of tangency will necessarily
> intersect the bounding line of longitude at a right angle, you can use
> one of the spherical right triangle formulas.  I like:
>   sin(a) = sin(A) * sin(c)
> where the triangle includes the pole, the point of tangency, and the center
> of the distance circle; "a" is the angle, measured as seen from the center
> of the earth, subtended by the side not involving the pole, that is of the
> distance radius (2*PI*distance/earth_radius); "c", the hypontenuse, is
> the same thing for the distance between the distance circle's center and
> the pole, that is, the compliment of the latitude of the distance circle's
> center; and A is the surface angle subtended at the pole, that is, the
> difference in longitude (what we're looking for).  Because it would be
> convenient to work in latitude, rather than compliment of latitude, change
> the formula to:
>  sin(a) = sin(A) * cos(lat)
> therefore:
>  A = asin(sin(a)/cos(lat))
> The desired bounding longitudes are then +/- A from the longitude of
> the distance circle's center's longitude.  It doesn't hurt that the use
> of cos(lat) has even symmetry, making it clear that you don't have to
> choose a pole.
>
> Now you select candidate database rows satisfying the bounding limits,
> and only have to calculate actual distance for them, discarding the
> relatively few that are too far, but within the corners of the bounding box.
> Some databases support a "BETWEEN" operator, or something like it,
> but the ORM's range lookup will work.  Be careful, though, if your circle
> can include 180 degrees of longitude, since then you want longitude to
> be outside the range, rather than within it, because the sign of longitude
> changes there.
>
> Note that if a pole is closer than your distance limit that there are no
> bounding longitudes, and only that bounding latitude that's further from
> that pole applies.
>
> In the interests of performance, note that the distance formula:
>   d = 2*PI*earth_radius*acos(sin(lat1)*sin(lat2) +
>              cos(lat1)*cos(lat2)*cos(long1 - long2))
> only needs the sin and cos of the latitudes, not the latitudes themselves.
> So that's what I stored in the database avoiding those trig operations
> on each distance calculation.  (Actually, I wound up also storing the
> latitude so that the user saw the latitude he had entered, whereas,
> given the non-infinite precision of float, or even double, doing
> asin(sin_lat) leads to some differences in less significant digits.)  Then
> we get:
>  d = 2*PI*earth_radius*acos(sin_lat1*sin_lat2 +
>              cos_lat1*cos_lat2*cos(long1 - long2))
> and we're down to just two trig functions per distance calculation, a cos
> and an acos.
>
> Further, notice that for distance less than or equal to half way around the
> globe (which is as far as you can get on the globe), acos(x) is, while not
> linear, monotonic(ly decreasing) with x.  So throwing out the candidates
> that are in the corners of the bounding box can be done using the
> the expression inside the acos, by comparing it to:
>  a = cos(d/(2*PI*earth_radius))
> and discarding points where:
> 

Re: "Great circle" using the django ORM?

2011-08-12 Thread Sam Walters
Dont know specifically about sql lite.

I have used django orm with postgres spatial db to find points within
a 'convex hull' bounding box shape:


from django.contrib.gis.geos import GEOSGeometry, Polygon, LineString,
Point, LinearRing
from django.contrib.gis.measure import D

coords_in = simplejson.loads(request.POST['coords'])
#add the first point to the end to form a loop
coords_in.append(coords_in[0])
#construct linear ring
lin_ring = LinearRing([ Point(float(item['b']),
float(item['c'])) for item in coords_in ])
#create convex hull
boundaries = lin_ring.convex_hull

#data list to return, calculate airfields in convex hull
data_list = []
for airf in Airfield.objects.filter(point__intersects=boundaries.wkt):
data_list.append([airf.airfield_name, airf.point.x,
airf.point.y, airf.ycode])

Dont take the code as gospel however for performance reasons i found
it fair to specify a segmented convex hull approximating a sphere. Set
the radius from the centre to be x units and find points within this
area. Return the queryset and order by distance from the centre with a
spheroid-arc distance formula eg: Vincenty formula.

Either way i found using forums less django-specific and more math+map
specific was a good approach




On Fri, Aug 12, 2011 at 5:51 PM, Thomas Weholt  wrote:
> Thanks for your detailed reply :-) I'll try to figure it out. So far I
> got a few candidates for a solution but the math functions seem to be
> somewhat different on the different database platforms so I need to
> experiment some more to find one that works on the three major ones (
> sqlite, postgres and mysql - I often use sqlite for development and
> postgres for production myself, but still want to support mysql ).
>
> About the accuracy; my app is suppose to show photos take nearby some
> location so it doesn't have to be dead on. But this should really be a
> reusable app or widget. Seems like more than just me needs this
> functionality. If I get something going I'll look into making it
> generic and reusable. Anybody interesting in helping out making this
> happen please let me know. My experience using math functions in SQL
> like this is close to zero.
>
> Thanks alot for all the replies and interest :-)
>
> Regards,
> Thomas
>
> On Thu, Aug 11, 2011 at 7:51 PM, Bill Freeman  wrote:
>> I've done this sort of thing in the past without the aid of geo-django, 
>> using a
>> reasonably ordinary model.
>>
>> I did it as a two step process, first calculating a bounding box, which is a
>> rectangle in lat/long space.  It is calculated once per search, based on
>> the distance and the coordinates of the distance circle's center (the point
>> from which you are measuring distance).
>>
>> A pair of latitudes that are tangent to the distance circle are easy to come
>> by because the point of tangency is at the same longitude as the circle's
>> center, and because distance in linear with latitude along such a line.
>>
>> Bounding longitudes are harder because their points of tangency are
>> closer to the pole than the circle's center (unless it's on the equator),
>> as well as distance not being linear with longitude change.  But since
>> a distance circle radius through the point of tangency will necessarily
>> intersect the bounding line of longitude at a right angle, you can use
>> one of the spherical right triangle formulas.  I like:
>>   sin(a) = sin(A) * sin(c)
>> where the triangle includes the pole, the point of tangency, and the center
>> of the distance circle; "a" is the angle, measured as seen from the center
>> of the earth, subtended by the side not involving the pole, that is of the
>> distance radius (2*PI*distance/earth_radius); "c", the hypontenuse, is
>> the same thing for the distance between the distance circle's center and
>> the pole, that is, the compliment of the latitude of the distance circle's
>> center; and A is the surface angle subtended at the pole, that is, the
>> difference in longitude (what we're looking for).  Because it would be
>> convenient to work in latitude, rather than compliment of latitude, change
>> the formula to:
>>  sin(a) = sin(A) * cos(lat)
>> therefore:
>>  A = asin(sin(a)/cos(lat))
>> The desired bounding longitudes are then +/- A from the longitude of
>> the distance circle's center's longitude.  It doesn't hurt that the use
>> of cos(lat) has even symmetry, making it clear that you don't have to
>> choose a pole.
>>
>> Now you select candidate database rows satisfying the bounding limits,
>> and only have to calculate actual distance for them, discarding the
>> relatively few that are too far, but within the corners of the bounding box.
>> Some databases support a "BETWEEN" operator, or something like it,
>> but the ORM's range lookup will work.  Be careful, though, if your circle
>> can include 180 degrees of longitude, since then you want longitude to
>> be outside the

Re: Integrating Selenium tests into Django unit tests.

2011-08-12 Thread Almad


On 3 srp, 21:56, Tom Christie  wrote:
> I just had to do the same thing. Tried to use the django-sane-testing 
> package, but didn't have much success there.

Might I ask what was the problem?

> Cheers,
>   T.

Thanks,

Almad

-- 
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: "Great circle" using the django ORM?

2011-08-12 Thread Mike Dewhirst

Thomas

Don't know if this helps but one degree of latitude is sixty nautical 
miles at the equator and slightly less at the poles. Not worth worrying 
about.


OTOH, one degree of longitude shrinks from 60 NM at the equator to zero 
at the poles - which might help you visualize the necessary math.


I bet Google has worked all this out before..

Good luck - and I'm interested in the result.

Mike

On 12/08/2011 5:51pm, Thomas Weholt wrote:

Thanks for your detailed reply :-) I'll try to figure it out. So far I
got a few candidates for a solution but the math functions seem to be
somewhat different on the different database platforms so I need to
experiment some more to find one that works on the three major ones (
sqlite, postgres and mysql - I often use sqlite for development and
postgres for production myself, but still want to support mysql ).

About the accuracy; my app is suppose to show photos take nearby some
location so it doesn't have to be dead on. But this should really be a
reusable app or widget. Seems like more than just me needs this
functionality. If I get something going I'll look into making it
generic and reusable. Anybody interesting in helping out making this
happen please let me know. My experience using math functions in SQL
like this is close to zero.

Thanks alot for all the replies and interest :-)

Regards,
Thomas

On Thu, Aug 11, 2011 at 7:51 PM, Bill Freeman  wrote:

I've done this sort of thing in the past without the aid of geo-django, using a
reasonably ordinary model.

I did it as a two step process, first calculating a bounding box, which is a
rectangle in lat/long space.  It is calculated once per search, based on
the distance and the coordinates of the distance circle's center (the point
from which you are measuring distance).

A pair of latitudes that are tangent to the distance circle are easy to come
by because the point of tangency is at the same longitude as the circle's
center, and because distance in linear with latitude along such a line.

Bounding longitudes are harder because their points of tangency are
closer to the pole than the circle's center (unless it's on the equator),
as well as distance not being linear with longitude change.  But since
a distance circle radius through the point of tangency will necessarily
intersect the bounding line of longitude at a right angle, you can use
one of the spherical right triangle formulas.  I like:
   sin(a) = sin(A) * sin(c)
where the triangle includes the pole, the point of tangency, and the center
of the distance circle; "a" is the angle, measured as seen from the center
of the earth, subtended by the side not involving the pole, that is of the
distance radius (2*PI*distance/earth_radius); "c", the hypontenuse, is
the same thing for the distance between the distance circle's center and
the pole, that is, the compliment of the latitude of the distance circle's
center; and A is the surface angle subtended at the pole, that is, the
difference in longitude (what we're looking for).  Because it would be
convenient to work in latitude, rather than compliment of latitude, change
the formula to:
  sin(a) = sin(A) * cos(lat)
therefore:
  A = asin(sin(a)/cos(lat))
The desired bounding longitudes are then +/- A from the longitude of
the distance circle's center's longitude.  It doesn't hurt that the use
of cos(lat) has even symmetry, making it clear that you don't have to
choose a pole.

Now you select candidate database rows satisfying the bounding limits,
and only have to calculate actual distance for them, discarding the
relatively few that are too far, but within the corners of the bounding box.
Some databases support a "BETWEEN" operator, or something like it,
but the ORM's range lookup will work.  Be careful, though, if your circle
can include 180 degrees of longitude, since then you want longitude to
be outside the range, rather than within it, because the sign of longitude
changes there.

Note that if a pole is closer than your distance limit that there are no
bounding longitudes, and only that bounding latitude that's further from
that pole applies.

In the interests of performance, note that the distance formula:
   d = 2*PI*earth_radius*acos(sin(lat1)*sin(lat2) +
  cos(lat1)*cos(lat2)*cos(long1 - long2))
only needs the sin and cos of the latitudes, not the latitudes themselves.
So that's what I stored in the database avoiding those trig operations
on each distance calculation.  (Actually, I wound up also storing the
latitude so that the user saw the latitude he had entered, whereas,
given the non-infinite precision of float, or even double, doing
asin(sin_lat) leads to some differences in less significant digits.)  Then
we get:
  d = 2*PI*earth_radius*acos(sin_lat1*sin_lat2 +
  cos_lat1*cos_lat2*cos(long1 - long2))
and we're down to just two trig functions per distance calculation, a cos
and an acos.

Further, notice that for distance less than or equal to half way around the
globe (which i

Use object (User and custom object) in a form

2011-08-12 Thread Suprnaturall
Hello everyone,

I'm trying to add comment to a custom object (here Article).
This is my forms.py :

from django import forms
from django.contrib.auth.models import User
from myApp.models import Article

class CommentForms (forms.Form):
cf_comment = forms.CharField()
cf_writer = forms.User()
cf_date = forms.DateField()
cf_article = forms.article()

Here the template :







and here my view :

def article(request, id):
article = Article.objects.get(id=id)
commentaires =
Commentaire.objects.filter(article=article.id).order_by("-
dateComment")
# comment form
if request.method == 'POST':
form = CommentForms(request.POST)
if form.is_valid(): #validation
cf_comment = form.cleaned_data['commentaire']
cf_writer = form.cleaned_data['user']
cf_date = datetime.datetime.now()
cf_article = form.cleaned_data['article']
else :
form = CommentForms()

c = Context({
'Article' : article,
'commentaires' : commentaires,
})
return render_to_response('myApp/article.html', c,
context_instance=RequestContext(request))

When i try to go to /myapp/myArticle/id i have this message :
Tried article in module app.myApp.views. Error was: 'module' object
has no attribute 'User'

Do you have any idea ? maybe i forge an import or maybe i can t use
object in forms ...

Thx for your 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-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: Django, Json and Android

2011-08-12 Thread Gelonida N
On 08/12/2011 03:13 AM, Kevin Anthony wrote:
> i'm trying to interface a django json page with an android application.
> it seems most json applications written for android use
> www.somepage.com/json.php?this=that&something=anotherthing
> 
> But that doesn't work with django,
> 
> Has anyone interfaced Django and Android? and if they did, is there
> any reading material on it?
> 

It might help if you were a little more specific. and gave some kind of
example.

What exactly do you mean with 'json' page?

an asynchronous get request to fetch json data or do you mean JSONRPC?

Django can well obtain the values of 'this' and of 'something'  in a get
request.

with request.GET.get('this', '-')
and
reuest.GET.get('something', '-')

( but probably this is not what you meant)




-- 
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: Django, Json and Android

2011-08-12 Thread Daniel Roseman
On Friday, 12 August 2011 02:13:13 UTC+1, Kevin Anthony wrote:
>
> i'm trying to interface a django json page with an android application.
> it seems most json applications written for android use
> www.somepage.com/json.php?this=that&something=anotherthing
>
> But that doesn't work with django,
>
> Has anyone interfaced Django and Android? and if they did, is there
> any reading material on it?
>
> -- 
> Thanks
> Kevin Anthony
> 
>

Your post is a little confusing.

Firstly, URLs of that form (without the .php, of course) work perfectly well 
in Django. GET parameters are available within the view from 
`request.GET['this']` etc.

Secondly, however, there is no correlation between the way you request a 
page and the type of content. In other words, it is just as possible to 
serve a page as JSON with the url 
somepage.com/json/this/that/something/anotherthing as it is with 
somepage.com/json?this=that&something=anotherthing. All that matters is how 
the server renders the result, and (preferably) declares the content-type 
when serving it.

Thirdly, none of this has anything to do with Android, since all you are 
doing from Android is requesting a URL and processing the result.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/NP73XrXCQtcJ.
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: "Great circle" using the django ORM?

2011-08-12 Thread Thomas Weholt
Hi all,

This is what I've come up with so far. Not tested, but I came across
an old piece of code doing the same thing ( I knew I'd done it before,
just had to look deep into my code archives ;-) ):

http://dpaste.com/592639/

Comments very welcome. Expect a pypi-release some time after the
weekend. Perhaps there's more things features we could add too, like
google maps integration, some form of widget to use in the admin etc.
Feel free to steal the code or suggest ideas.

Thomas

On Fri, Aug 12, 2011 at 10:33 AM, Mike Dewhirst  wrote:
> Thomas
>
> Don't know if this helps but one degree of latitude is sixty nautical miles
> at the equator and slightly less at the poles. Not worth worrying about.
>
> OTOH, one degree of longitude shrinks from 60 NM at the equator to zero at
> the poles - which might help you visualize the necessary math.
>
> I bet Google has worked all this out before..
>
> Good luck - and I'm interested in the result.
>
> Mike
>
> On 12/08/2011 5:51pm, Thomas Weholt wrote:
>>
>> Thanks for your detailed reply :-) I'll try to figure it out. So far I
>> got a few candidates for a solution but the math functions seem to be
>> somewhat different on the different database platforms so I need to
>> experiment some more to find one that works on the three major ones (
>> sqlite, postgres and mysql - I often use sqlite for development and
>> postgres for production myself, but still want to support mysql ).
>>
>> About the accuracy; my app is suppose to show photos take nearby some
>> location so it doesn't have to be dead on. But this should really be a
>> reusable app or widget. Seems like more than just me needs this
>> functionality. If I get something going I'll look into making it
>> generic and reusable. Anybody interesting in helping out making this
>> happen please let me know. My experience using math functions in SQL
>> like this is close to zero.
>>
>> Thanks alot for all the replies and interest :-)
>>
>> Regards,
>> Thomas
>>
>> On Thu, Aug 11, 2011 at 7:51 PM, Bill Freeman  wrote:
>>>
>>> I've done this sort of thing in the past without the aid of geo-django,
>>> using a
>>> reasonably ordinary model.
>>>
>>> I did it as a two step process, first calculating a bounding box, which
>>> is a
>>> rectangle in lat/long space.  It is calculated once per search, based on
>>> the distance and the coordinates of the distance circle's center (the
>>> point
>>> from which you are measuring distance).
>>>
>>> A pair of latitudes that are tangent to the distance circle are easy to
>>> come
>>> by because the point of tangency is at the same longitude as the circle's
>>> center, and because distance in linear with latitude along such a line.
>>>
>>> Bounding longitudes are harder because their points of tangency are
>>> closer to the pole than the circle's center (unless it's on the equator),
>>> as well as distance not being linear with longitude change.  But since
>>> a distance circle radius through the point of tangency will necessarily
>>> intersect the bounding line of longitude at a right angle, you can use
>>> one of the spherical right triangle formulas.  I like:
>>>   sin(a) = sin(A) * sin(c)
>>> where the triangle includes the pole, the point of tangency, and the
>>> center
>>> of the distance circle; "a" is the angle, measured as seen from the
>>> center
>>> of the earth, subtended by the side not involving the pole, that is of
>>> the
>>> distance radius (2*PI*distance/earth_radius); "c", the hypontenuse, is
>>> the same thing for the distance between the distance circle's center and
>>> the pole, that is, the compliment of the latitude of the distance
>>> circle's
>>> center; and A is the surface angle subtended at the pole, that is, the
>>> difference in longitude (what we're looking for).  Because it would be
>>> convenient to work in latitude, rather than compliment of latitude,
>>> change
>>> the formula to:
>>>  sin(a) = sin(A) * cos(lat)
>>> therefore:
>>>  A = asin(sin(a)/cos(lat))
>>> The desired bounding longitudes are then +/- A from the longitude of
>>> the distance circle's center's longitude.  It doesn't hurt that the use
>>> of cos(lat) has even symmetry, making it clear that you don't have to
>>> choose a pole.
>>>
>>> Now you select candidate database rows satisfying the bounding limits,
>>> and only have to calculate actual distance for them, discarding the
>>> relatively few that are too far, but within the corners of the bounding
>>> box.
>>> Some databases support a "BETWEEN" operator, or something like it,
>>> but the ORM's range lookup will work.  Be careful, though, if your circle
>>> can include 180 degrees of longitude, since then you want longitude to
>>> be outside the range, rather than within it, because the sign of
>>> longitude
>>> changes there.
>>>
>>> Note that if a pole is closer than your distance limit that there are no
>>> bounding longitudes, and only that bounding latitude that's further from
>>> that pole applies.
>>>
>>> In the interests o

Re: "Great circle" using the django ORM?

2011-08-12 Thread Thomas Weholt
Ok, now I've created an open project at bitbucket with a public issue
tracker so put any of your ideas/comments/bugs there.

https://bitbucket.org/weholt/django-locationbase

As mentioned I'll look more into this during this weekend and release
something next week if I get it working properly. The current
implementation doesn't rely on heavy math operations and seems to be
database agnostic, only using the orm. This is old code and worked
using sqlite. Not sure how well it plays against postgres or mysql.

Thanks for your attention once again.

Thomas



On Fri, Aug 12, 2011 at 12:28 PM, Thomas Weholt  wrote:
> Hi all,
>
> This is what I've come up with so far. Not tested, but I came across
> an old piece of code doing the same thing ( I knew I'd done it before,
> just had to look deep into my code archives ;-) ):
>
> http://dpaste.com/592639/
>
> Comments very welcome. Expect a pypi-release some time after the
> weekend. Perhaps there's more things features we could add too, like
> google maps integration, some form of widget to use in the admin etc.
> Feel free to steal the code or suggest ideas.
>
> Thomas
>
> On Fri, Aug 12, 2011 at 10:33 AM, Mike Dewhirst  wrote:
>> Thomas
>>
>> Don't know if this helps but one degree of latitude is sixty nautical miles
>> at the equator and slightly less at the poles. Not worth worrying about.
>>
>> OTOH, one degree of longitude shrinks from 60 NM at the equator to zero at
>> the poles - which might help you visualize the necessary math.
>>
>> I bet Google has worked all this out before..
>>
>> Good luck - and I'm interested in the result.
>>
>> Mike
>>
>> On 12/08/2011 5:51pm, Thomas Weholt wrote:
>>>
>>> Thanks for your detailed reply :-) I'll try to figure it out. So far I
>>> got a few candidates for a solution but the math functions seem to be
>>> somewhat different on the different database platforms so I need to
>>> experiment some more to find one that works on the three major ones (
>>> sqlite, postgres and mysql - I often use sqlite for development and
>>> postgres for production myself, but still want to support mysql ).
>>>
>>> About the accuracy; my app is suppose to show photos take nearby some
>>> location so it doesn't have to be dead on. But this should really be a
>>> reusable app or widget. Seems like more than just me needs this
>>> functionality. If I get something going I'll look into making it
>>> generic and reusable. Anybody interesting in helping out making this
>>> happen please let me know. My experience using math functions in SQL
>>> like this is close to zero.
>>>
>>> Thanks alot for all the replies and interest :-)
>>>
>>> Regards,
>>> Thomas
>>>
>>> On Thu, Aug 11, 2011 at 7:51 PM, Bill Freeman  wrote:

 I've done this sort of thing in the past without the aid of geo-django,
 using a
 reasonably ordinary model.

 I did it as a two step process, first calculating a bounding box, which
 is a
 rectangle in lat/long space.  It is calculated once per search, based on
 the distance and the coordinates of the distance circle's center (the
 point
 from which you are measuring distance).

 A pair of latitudes that are tangent to the distance circle are easy to
 come
 by because the point of tangency is at the same longitude as the circle's
 center, and because distance in linear with latitude along such a line.

 Bounding longitudes are harder because their points of tangency are
 closer to the pole than the circle's center (unless it's on the equator),
 as well as distance not being linear with longitude change.  But since
 a distance circle radius through the point of tangency will necessarily
 intersect the bounding line of longitude at a right angle, you can use
 one of the spherical right triangle formulas.  I like:
   sin(a) = sin(A) * sin(c)
 where the triangle includes the pole, the point of tangency, and the
 center
 of the distance circle; "a" is the angle, measured as seen from the
 center
 of the earth, subtended by the side not involving the pole, that is of
 the
 distance radius (2*PI*distance/earth_radius); "c", the hypontenuse, is
 the same thing for the distance between the distance circle's center and
 the pole, that is, the compliment of the latitude of the distance
 circle's
 center; and A is the surface angle subtended at the pole, that is, the
 difference in longitude (what we're looking for).  Because it would be
 convenient to work in latitude, rather than compliment of latitude,
 change
 the formula to:
  sin(a) = sin(A) * cos(lat)
 therefore:
  A = asin(sin(a)/cos(lat))
 The desired bounding longitudes are then +/- A from the longitude of
 the distance circle's center's longitude.  It doesn't hurt that the use
 of cos(lat) has even symmetry, making it clear that you don't have to
 choose a pole.

 Now you select candidate databas

Defunct Processes on Server

2011-08-12 Thread SixDegrees

We are running a Django-driven site using Apache. Some of our forms launch a
time-consuming process by using Popen:

   p = subprocess.Popen(my_cmd, shell=True)

which works fine, in the sense that the command gets launched in the
background and doesn't hang the website while it processes.

These processes, though, don't terminate properly. Instead, I see an
ever-growing list of processes using 'ps -A' that look like

   15576 ?00:00:00 my_cmd 
   15962 ?00:00:00 my_cmd 
   16014 ?00:00:00 my_cmd 
   ...

I get another of these each time I submit a form, and they never go away
until I restart Apache.

This seems to be a common problem with Python. All the remedies, however,
suggest calling some form of wait() on the process to ensure that it has
completed. In our case, this isn't an option, because we don't want to make
Apache wait on what ought to be a reasonably quick form submission.

How can I avoid this problem, or otherwise deal with the resulting zombies?
-- 
View this message in context: 
http://old.nabble.com/Defunct-Processes-on-Server-tp32249402p32249402.html
Sent from the django-users mailing list archive at Nabble.com.

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



Showing per-user information in admin

2011-08-12 Thread Isaac

Hi dudes,

I'm having trouble at finding a solution for my problem. All I want to 
do is tune django admin to show, for a given user an a given model, only 
instance related to that user.


my pseudocode

class User
...
class A
foreign_key User

A1 related to User1
A2 related to User1
A3 related to User2

then, I want that User1 was only be able to see A1 and A2, and User2 was 
only be able to see A3.
I know that I can create filters to allow user to filter instances, but 
all I want is not to allow user to make that decision, it will be only 
able to see what its related.


Any clue about how to use admin in this way?

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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Defunct Processes on Server

2011-08-12 Thread aledema

Probably you have to wait() for them.

The father process spawn a child process with Popen but it eventually
must wait for its termination.
Look at python doc about subprocess, wait() method.

bye

Ale

-- 
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: Defunct Processes on Server

2011-08-12 Thread Thomas Orozco
You could avoid starting the child process in your view.

If it's a long running process I would actually advocate doing so.
This might be due to limited understanding on my part, but what happens when
Apache wants to kill its child process because MaxRequests was reached?

If you don't need the job done ASAP, you could for example have a directory
where you store 'job files' and have a Cron script look at them. You could
obviously store this in a database too.

Your script could then wait on the processes to collect the returncodes and
avoid this defunct process phenomenom.

This is of course just a suggestion, although I'm pretty sure it would work,
I wouldn't say that it's the one and only way of doing what you want.
 Le 12 août 2011 13:19, "SixDegrees"  a écrit :

-- 
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: Defunct Processes on Server

2011-08-12 Thread Brian Bouterse
You should look into projects called celery and django-celery instead of
cron.

On Friday, August 12, 2011, Thomas Orozco  wrote:
> You could avoid starting the child process in your view.
>
> If it's a long running process I would actually advocate doing so.
> This might be due to limited understanding on my part, but what happens
when Apache wants to kill its child process because MaxRequests was reached?
>
> If you don't need the job done ASAP, you could for example have a
directory where you store 'job files' and have a Cron script look at them.
You could obviously store this in a database too.
>
> Your script could then wait on the processes to collect the returncodes
and avoid this defunct process phenomenom.
>
> This is of course just a suggestion, although I'm pretty sure it would
work, I wouldn't say that it's the one and only way of doing what you want.
>
> Le 12 août 2011 13:19, "SixDegrees"  a écrit :
>
> --
> 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 <
django-users%2bunsubscr...@googlegroups.com>.
> For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
>

-- 
Brian Bouterse
ITng Services

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

2011-08-12 Thread Reinout van Rees

On 12-08-11 10:24, Sam Walters wrote:

Dont know specifically about sql lite.

I have used django orm with postgres spatial db to find points within
a 'convex hull' bounding box shape:


sqlite also has a spatial version, just like postgres's postgis. It is 
called spatialite.


Sometimes there's a bit of a difference in the query language, but the 
generic idea is the same.



Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul 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-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: Use object (User and custom object) in a form

2011-08-12 Thread nicolas HERSOG
Hi everyone,

I tried few thigs more but it s still don't work.
this is my new template :
 {% csrf_token %}






And my view :
def vod(request, id):
article = Article.objects.get(id=id)
commentaires = Commentaire.objects.filter(article=article.id
).order_by("-dateComment")

c = Context({
'article' : article,
'commentaires' : commentaires,
})
 # preparation du formulaire de commentaire
if request.method == 'POST':
form = CommentForms(request.POST)
if form.is_valid(): #validation
cf_comment = form.cleaned_data['commentaire']
cf_writer = request.user
cf_date = datetime.datetime.now()
cf_article = request.article
else :
form = CommentForms()


return render_to_response('myApp/article.html', c,
context_instance=RequestContext(request))

I still have this message :

ViewDoesNotExist at /

Tried index in module app.myApp.views. Error was: 'module' object has
no attribute 'User'

Request Method:GETRequest URL:http://127.0.0.1:8000/Django Version:1.3Exception
Type:ViewDoesNotExistException Value:

Tried index in module empire.empireFront.views. Error was: 'module'
object has no attribute 'User'



could the problem from my forms.py ?
Thx

On Fri, Aug 12, 2011 at 10:38 AM,  wrote:

> I am out of office right now and will get back to you when I return. If you
> don't hear from me, my assistant should contact you shortly. I.m on sick
> leave because of some news from my Dr., please check out this diet product
> he recommended..Click 
> Here
>
> Enable images or click 
> here
>
> 
> Let me know what you think after you have a chance to review.
> Cheers!
>
> If you no longer wish to receive emails, please 
> unsubscribe
>
> 866-288-1880
> 5150 yarmouth ave, Encino, CA 91316
> On Fri, 12 Aug 2011 01:37:56 -0700 (PDT), Suprnaturall ** wrote:
>

-- 
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: Use object (User and custom object) in a form

2011-08-12 Thread Daniel Roseman
Your error has nothing to do with your form. There is an import problem in 
your empireFront.views module which is preventing it from being imported.

Somewhere you are trying to import something called "User" from a place that 
doesn't have any such class. It would help if you posted the imports in that 
file.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/OeT67jgufvoJ.
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: Defunct Processes on Server

2011-08-12 Thread SixDegrees

Yes, I'm familiar with celery, and eventually we would like to migrate to
that, or some other task scheduler. Right now, though, that's not in the
cards, and folks are griping about these zombies.


Brian Bouterse wrote:
> 
> You should look into projects called celery and django-celery instead of
> cron.
> 
> On Friday, August 12, 2011, Thomas Orozco 
> wrote:
>> You could avoid starting the child process in your view.
>>
>> If it's a long running process I would actually advocate doing so.
>> This might be due to limited understanding on my part, but what happens
> when Apache wants to kill its child process because MaxRequests was
> reached?
>>
>> If you don't need the job done ASAP, you could for example have a
> directory where you store 'job files' and have a Cron script look at them.
> You could obviously store this in a database too.
>>
>> Your script could then wait on the processes to collect the returncodes
> and avoid this defunct process phenomenom.
>>
>> This is of course just a suggestion, although I'm pretty sure it would
> work, I wouldn't say that it's the one and only way of doing what you
> want.
>>
>> Le 12 août 2011 13:19, "SixDegrees"  a écrit :
>>
>> --
>> 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 <
> django-users%2bunsubscr...@googlegroups.com>.
>> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>>
> 
> -- 
> Brian Bouterse
> ITng Services
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Defunct-Processes-on-Server-tp32249402p32250150.html
Sent from the django-users mailing list archive at Nabble.com.

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

2011-08-12 Thread raj
This is wayyy over my head. Thanks for the project files, but I don't
even know where to begin with all of this. I wish there was more of an
orbited support site. Anyway, I was trying to use orbited to create a
chat system on my website and I followed this tutorial:
http://www.rkblog.rk.edu.pl/w/p/django-and-comet/. But I couldn't
figure out what to do at the end of it. The html file requires
something called orbited.js, and the tutorial never talks about where
to get this file. So ya I'm stumped, I don't even know what path I
should take to make a django chat system. I even tried impletementing
a polling chat from the django-jchat tutorial, but that didn't work
either. :(. Ideas?

On Aug 12, 12:59 am, william ratcliff 
wrote:
> You may also want to look at some of the projects 
> at:https://github.com/mcarter
>
> On Fri, Aug 12, 2011 at 12:58 AM, william ratcliff <
>
>
>
>
>
>
>
> william.ratcl...@gmail.com> wrote:
> > Can't write much now, but you may look at my students' prototype of a web
> > based system for data reduction at:
> >https://github.com/pjreddie/WRed
>
> > Here, we were updating the client every time a new datapoint came off of
> > our instrument.  The README tells you how to start orbited, what to do with
> > STOMP, etc.    However, I've also had problems with orbited.org--at some
> > point, I think the project forked into orbited2 and hookbox.   I'd be really
> > curious to know what other people are using for Comet--are they still using
> > django, or did they move on to using something else?
>
> > Best,
> > William
> > (btw. for our app, it's big and you'd have to fake the data stream to run
> > the live data part, but it should give you an idea where to put things and
> > what goes in a cfg file)
>
> > On Thu, Aug 11, 2011 at 10:24 PM, raj  wrote:
>
> >> Odd question, but I'm trying to follow this tutorial which explains
> >> how to set up comet with django. I'm just confused about some stuff
> >> when I'm trying to do the tutorial.
>
> >> Firstly, where does the orbited.cfg file go? I just placed it at the
> >> root of my application (where the settings.py file etc. is). Also, in
> >> the cfg, It says to use the localhost address as the http, but I'm not
> >> running a development server, can I just put the url I'm using there?
> >> What about the port issue?
>
> >> Secondly, at the end of the tutorial, it says to run the orbited
> >> server. How do I do this? Do I need to install orbited beforehand? I
> >> ask this also because the html file requires an orbited.js file, and I
> >> have no clue where to find that. orbited.org doesn't seem to work. I
> >> found some github distros, but I dunno exactly how to make all the
> >> pieces fit. Currently I have pyorbited installed. 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-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.

-- 
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: Running the orbited server?

2011-08-12 Thread raj
Oh, and I found that first app interesting. What exactly did that do?

On Aug 12, 9:32 am, raj  wrote:
> This is wayyy over my head. Thanks for the project files, but I don't
> even know where to begin with all of this. I wish there was more of an
> orbited support site. Anyway, I was trying to use orbited to create a
> chat system on my website and I followed this 
> tutorial:http://www.rkblog.rk.edu.pl/w/p/django-and-comet/. But I couldn't
> figure out what to do at the end of it. The html file requires
> something called orbited.js, and the tutorial never talks about where
> to get this file. So ya I'm stumped, I don't even know what path I
> should take to make a django chat system. I even tried impletementing
> a polling chat from the django-jchat tutorial, but that didn't work
> either. :(. Ideas?
>
> On Aug 12, 12:59 am, william ratcliff 
> wrote:
>
>
>
>
>
>
>
> > You may also want to look at some of the projects 
> > at:https://github.com/mcarter
>
> > On Fri, Aug 12, 2011 at 12:58 AM, william ratcliff <
>
> > william.ratcl...@gmail.com> wrote:
> > > Can't write much now, but you may look at my students' prototype of a web
> > > based system for data reduction at:
> > >https://github.com/pjreddie/WRed
>
> > > Here, we were updating the client every time a new datapoint came off of
> > > our instrument.  The README tells you how to start orbited, what to do 
> > > with
> > > STOMP, etc.    However, I've also had problems with orbited.org--at some
> > > point, I think the project forked into orbited2 and hookbox.   I'd be 
> > > really
> > > curious to know what other people are using for Comet--are they still 
> > > using
> > > django, or did they move on to using something else?
>
> > > Best,
> > > William
> > > (btw. for our app, it's big and you'd have to fake the data stream to run
> > > the live data part, but it should give you an idea where to put things and
> > > what goes in a cfg file)
>
> > > On Thu, Aug 11, 2011 at 10:24 PM, raj  wrote:
>
> > >> Odd question, but I'm trying to follow this tutorial which explains
> > >> how to set up comet with django. I'm just confused about some stuff
> > >> when I'm trying to do the tutorial.
>
> > >> Firstly, where does the orbited.cfg file go? I just placed it at the
> > >> root of my application (where the settings.py file etc. is). Also, in
> > >> the cfg, It says to use the localhost address as the http, but I'm not
> > >> running a development server, can I just put the url I'm using there?
> > >> What about the port issue?
>
> > >> Secondly, at the end of the tutorial, it says to run the orbited
> > >> server. How do I do this? Do I need to install orbited beforehand? I
> > >> ask this also because the html file requires an orbited.js file, and I
> > >> have no clue where to find that. orbited.org doesn't seem to work. I
> > >> found some github distros, but I dunno exactly how to make all the
> > >> pieces fit. Currently I have pyorbited installed. 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-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.

-- 
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: Defunct Processes on Server

2011-08-12 Thread SixDegrees

Calling wait() on the processes freezes the form page until the process
completes. Since the process may take several minutes to run, this is not
acceptable. We need the process to run in the background and detach from the
server process, but when it is finished we need it to truly finish and not
become zombified.


aledema wrote:
> 
> 
> Probably you have to wait() for them.
> 
> The father process spawn a child process with Popen but it eventually
> must wait for its termination.
> Look at python doc about subprocess, wait() method.
> 
> bye
> 
> Ale
> 
> -- 
> 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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Defunct-Processes-on-Server-tp32249402p32250402.html
Sent from the django-users mailing list archive at Nabble.com.

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

2011-08-12 Thread Derek
On Aug 12, 1:29 pm, Isaac  wrote:
> Hi dudes,
>
> I'm having trouble at finding a solution for my problem. All I want to
> do is tune django admin to show, for a given user an a given model, only
> instance related to that user.
>
> my pseudocode
>
> class User
>      ...
> class A
>      foreign_key User
>
> A1 related to User1
> A2 related to User1
> A3 related to User2
>
> then, I want that User1 was only be able to see A1 and A2, and User2 was
> only be able to see A3.
> I know that I can create filters to allow user to filter instances, but
> all I want is not to allow user to make that decision, it will be only
> able to see what its related.
>
> Any clue about how to use admin in this way?
>
> Thanks in advance

See:
http://lincolnloop.com/static/slides/2010-djangocon/customizing-the-admin.html#slide45
for an example of this. Note how the default queryset is now filtered
per user.

-- 
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: Running the orbited server?

2011-08-12 Thread william ratcliff
Sorry--I'm in the middle of an experiment and the project I pointed you at
is rather large.  For the orbited.js (version 0.7) file, you may use the one
in:
https://github.com/scattering/WRed/tree/master/media/JavaScript/orbited-0.7

In the main directory:
https://github.com/scattering/WRed

In the readme file, it tells you how to start the stomp server, and orbited,
which rely on relay.py and orbited.cfg...These may help you.  Again, I'm not
sure what the future is for orbited, so it might be best to email the
creators...

Best,
William


On Fri, Aug 12, 2011 at 9:32 AM, raj  wrote:

> This is wayyy over my head. Thanks for the project files, but I don't
> even know where to begin with all of this. I wish there was more of an
> orbited support site. Anyway, I was trying to use orbited to create a
> chat system on my website and I followed this tutorial:
> http://www.rkblog.rk.edu.pl/w/p/django-and-comet/. But I couldn't
> figure out what to do at the end of it. The html file requires
> something called orbited.js, and the tutorial never talks about where
> to get this file. So ya I'm stumped, I don't even know what path I
> should take to make a django chat system. I even tried impletementing
> a polling chat from the django-jchat tutorial, but that didn't work
> either. :(. Ideas?
>
> On Aug 12, 12:59 am, william ratcliff 
> wrote:
> > You may also want to look at some of the projects at:
> https://github.com/mcarter
> >
> > On Fri, Aug 12, 2011 at 12:58 AM, william ratcliff <
> >
> >
> >
> >
> >
> >
> >
> > william.ratcl...@gmail.com> wrote:
> > > Can't write much now, but you may look at my students' prototype of a
> web
> > > based system for data reduction at:
> > >https://github.com/pjreddie/WRed
> >
> > > Here, we were updating the client every time a new datapoint came off
> of
> > > our instrument.  The README tells you how to start orbited, what to do
> with
> > > STOMP, etc.However, I've also had problems with orbited.org--at
> some
> > > point, I think the project forked into orbited2 and hookbox.   I'd be
> really
> > > curious to know what other people are using for Comet--are they still
> using
> > > django, or did they move on to using something else?
> >
> > > Best,
> > > William
> > > (btw. for our app, it's big and you'd have to fake the data stream to
> run
> > > the live data part, but it should give you an idea where to put things
> and
> > > what goes in a cfg file)
> >
> > > On Thu, Aug 11, 2011 at 10:24 PM, raj  wrote:
> >
> > >> Odd question, but I'm trying to follow this tutorial which explains
> > >> how to set up comet with django. I'm just confused about some stuff
> > >> when I'm trying to do the tutorial.
> >
> > >> Firstly, where does the orbited.cfg file go? I just placed it at the
> > >> root of my application (where the settings.py file etc. is). Also, in
> > >> the cfg, It says to use the localhost address as the http, but I'm not
> > >> running a development server, can I just put the url I'm using there?
> > >> What about the port issue?
> >
> > >> Secondly, at the end of the tutorial, it says to run the orbited
> > >> server. How do I do this? Do I need to install orbited beforehand? I
> > >> ask this also because the html file requires an orbited.js file, and I
> > >> have no clue where to find that. orbited.org doesn't seem to work. I
> > >> found some github distros, but I dunno exactly how to make all the
> > >> pieces fit. Currently I have pyorbited installed. 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-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.
>
> --
> 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.
>
>

-- 
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: Defunct Processes on Server

2011-08-12 Thread Alexey Luchko

On 12.08.2011 16:48, SixDegrees wrote:

Calling wait() on the processes freezes the form page until the process
completes.


The poll() also exists.

You can also start a thread that will wait() for the child.  One per child 
or one per all of the children.


The other way is to fork() twice as daemons do, but this is a bit more 
expensive.



--
Regards,
Alexey.

--
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: Use object (User and custom object) in a form

2011-08-12 Thread nicolas HERSOG
Humm, maybe you should right, here is my views.py :

from django.template import Context, loader, RequestContext
from myApp.models import Article, Commentaire
from django.http import HttpResponse
from django.contrib import auth
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User
from django.http import HttpResponseRedirect
from django.contrib.sessions.models import Session
from django.shortcuts import get_object_or_404, render_to_response
from myApp.forms import CommentForms

and here the view which don t work :
def article(request, id):
article = Article.objects.get(id=id)
commentaires = Commentaire.objects.filter(video=video.id
).order_by("-dateComment")

c = Context({
'article' : article,
'commentaires' : commentaires,
})
 # preparation du formulaire de commentaire
if request.method == 'POST':
form = CommentForms(request.POST)
if form.is_valid(): #validation
cf_comment = form.cleaned_data['commentaire']
cf_writer = request.user
cf_date = datetime.datetime.now()
cf_article = request.article
#return render_to_response('myApp/article.html', c,
context_instance=RequestContext(request))
else :
form = CommentForms()


return render_to_response('myApp/article.html', c,
context_instance=RequestContext(request))

and finally my forms.py :

from django import forms
from django.contrib.auth.models import User
from myApp.models import Article

class CommentForms (forms.Form):
cf_comment = forms.CharField()
cf_writer = forms.User()
cf_date = forms.DateField()
cf_video = forms.Article()

This one don't work, i can't launch my webApp, when i hit it I have this
error :
ViewDoesNotExist at /

Tried index in module empire.myApp.views. Error was: 'module' object
has no attribute 'User'

Request Method:GETRequest URL:http://127.0.0.1:8000/Django Version:1.3Exception
Type:ViewDoesNotExistException Value:

Tried index in module app.myApp.views. Error was: 'module' object has
no attribute 'User'



Now i delete the object attribute of my form (ie : User and Article ) :
my forms.py :
from django import forms
from django.contrib.auth.models import User
from myApp.models import Article

class CommentForms (forms.Form):
cf_comment = forms.CharField()
#cf_writer = forms.User()
cf_date = forms.DateField()
#cf_video = forms.Video()

and my view (i keep the same import ) :
def article(request, id):
article = Article.objects.get(id=id)
commentaires = Commentaire.objects.filter(video=video.id
).order_by("-dateComment")

c = Context({
'article' : article,
'commentaires' : commentaires,
})
 # preparation du formulaire de commentaire
if request.method == 'POST':
form = CommentForms(request.POST)
if form.is_valid(): #validation
cf_comment = form.cleaned_data['commentaire']
#cf_writer = request.user
cf_date = datetime.datetime.now()
#cf_article = request.article
#return render_to_response('myApp/article.html', c,
context_instance=RequestContext(request))
print 'IF'

else :
form = CommentForms()
print 'ELSE'

The application launch fine but when i submit the form (obviously) i go in
the ELSE.

Any idea ?

Thx for your help :)


return render_to_response('myApp/article.html', c,
context_instance=RequestContext(request))



On Fri, Aug 12, 2011 at 3:16 PM, Daniel Roseman wrote:

> Your error has nothing to do with your form. There is an import problem in
> your empireFront.views module which is preventing it from being imported.
>
> Somewhere you are trying to import something called "User" from a place
> that doesn't have any such class. It would help if you posted the imports in
> that file.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/OeT67jgufvoJ.
>
> 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.
>

-- 
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: Defunct Processes on Server

2011-08-12 Thread Reinout van Rees

On 12-08-11 13:18, SixDegrees wrote:

This seems to be a common problem with Python. All the remedies, however,
suggest calling some form of wait() on the process to ensure that it has
completed. In our case, this isn't an option, because we don't want to make
Apache wait on what ought to be a reasonably quick form submission.


Well, that's the web for you! Not really a problem with python, but more 
with the way the web works. At least as far as I see it.


The solution is basically celery: http://celeryproject.org/

You off-load long running processes to celery's task queue and continue 
with your form submission. Behind the scenes, celery will take care of 
your task.



Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul 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-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: Use object (User and custom object) in a form

2011-08-12 Thread bruno desthuilliers
On Aug 12, 10:37 am, Suprnaturall  wrote:
>
> from django.contrib.auth.models import User
>
> class CommentForms (forms.Form):
>     cf_writer = forms.User()
>
> Error was: 'module' object
> has no attribute 'User'
>
> Do you have any idea ?

cf above...

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



Django 1.3 admin added methods login requirement

2011-08-12 Thread Chris Fraschetti
I believe that in earlier versions of django if you added a view
method to an admin, and extended the get_urls method that because it
was under the admin it would automatically require at least a log in
(user.is_authenticated()=True.  I have been working with Django 1.3
and have noticed that this is no longer the case?  Has anyone
experienced this and is there a solution such as a decorator to use
since login_required will not work with methods.

-- 
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: Django 1.3 admin added methods login requirement

2011-08-12 Thread Jacob Kaplan-Moss
On Fri, Aug 12, 2011 at 10:32 AM, Chris Fraschetti
 wrote:
> I believe that in earlier versions of django if you added a view
> method to an admin, and extended the get_urls method that because it
> was under the admin it would automatically require at least a log in
> (user.is_authenticated()=True.  I have been working with Django 1.3
> and have noticed that this is no longer the case?  Has anyone
> experienced this and is there a solution such as a decorator to use
> since login_required will not work with methods.

I don't believe admin views have ever been automatically protected. In
any case, you'll need to use the admin site's ``admin_view``
decorator. See 
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_urls
for details.

Jacob

-- 
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: Use object (User and custom object) in a form

2011-08-12 Thread Landy Chapman
> class CommentForms (forms.Form):
> cf_writer = forms.User()
>
> Error was: 'module' object
> has no attribute 'User'
>
> Do you have any idea ?

Normal forms don't include/automatically create 'User' as a field...
The built-in comment app may be what you need:

https://docs.djangoproject.com/en/1.3/ref/contrib/comments/models/#django.contrib.comments.models.Comment

-- 
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: Use object (User and custom object) in a form

2011-08-12 Thread Landy Chapman
I think you have a *namespace* problem.

> and finally my forms.py :
>
>from django import forms
>from django.contrib.auth.models import User
>
> > Error was: 'module' object
> > has no attribute 'User'
#--

You are importing everything in "django/forms/" into your namespace as
"forms.*", which comes from the installed files
  django/forms/
 widgets.py
 fields.py
 forms.py
 models.py
None of those define 'User'

> my forms.py
>class CommentForms (forms.Form):
>cf_comment = forms.CharField()
>cf_writer = forms.User() <- problem

That line says "make a new object called cf_writer using the User
class defined in the django forms module.

-- 
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: "Great circle" using the django ORM?

2011-08-12 Thread Bill Freeman
1. In calculate_minmax_radius(), because cos is non-negative over the range -90
degrees to +90 degrees (and there are no points on the earth outside of that
range of latitudes), the abs() function would be unnecessary.  But if
round off error
made the pole look like beyond the pole, that would be a good thing, since you
want to include the pole in this case, which using the abs() will cause it to be
excluded.

2. Also in calculate_minmax_radius(), while 69 is being used to convert statute
miles to degrees.  If you reorder the equations you will find that it is always
actually divided into radius:  For example, you can rewrite lng_min as

  lng_min = long - (radius / 69)  / abs(math.cos(math.radians(lat)))

or, eliminating abs() as in point 1:

  lng_min = long - (radius / 69)  / math.cos(math.radians(lat))

Therefore, calculate radius/69 once and have done with it.  Local variables are
cheaper than divides (or multiplies)

  degradius = radius / 69
  lng_min = long - degradius/math.cos(math.radians(lat))
...
  lat_max = lat + degradius

3. Also in calculate_minmax_radius(), note that you are calculating
the exact same
thing to respectively subtract from and add to long in the
calculations of lng_min
and lng_max.  Certainly call cos() only once:

  deltalong = degradius/math.cos(math.radians(lat))
  lng_min = long - deltalong
  lng_max = long + deltalong

4. Also in calculate_minmax_radius(), 69 is a pretty good approximation to the
number of statute miles in a degree (within 0.1%, I was surprised),
but obfuscates
the code.  The code would be easier to follow if you calculated the
necessary values
as symbolic constants in the module global space, and use them:

EARTH_RADIUS_KM = 6371.0  # "Mean" radius, you have to choose something
EARTH_RADIUS_MI = 3959.0 # About the same

DEGREES_PER_KM = 180 / (EARTH_RADIUS_KM * math.pi)
DEGREES_PER_MI = 180 / (EARTH_RADIUS_MI * math.pi)

Then, in calculate_minmax_radius():

   degradius = radius * (use_km and DEGREES_PER_KM or DEGREES_PER_MI)

5. Sadly, when lat isn't zero, lng_min <= long <= lng_max will exclude
points that
are within radius.  To test this, calculate lng_min for, say, lat = 60 degrees,
long = 0, and radius = 1000 km, then use either the haversine formula or the law
of cosines formula to calculate the distance between lat, long and
lat, lng_min.  You
will find that it is well less than radius.  Therefore there are
points beyond lng_min
at latitue lat which are within radius.  The error does shrink with
smaller radius, so
it may not be important for you.  But you can get a better deltalong:

  radianradius = radius / (use_km and EARTH_RADIUS_KM or EARTH_RADIUS_MI)
  deltalong = degradius *
math.asin(math.sin(radianradius)/math.cos(math.radians(lat)))

6. In items_in_radius(), beware that if long is close to 180 degrees,
then lng_max may
be greater than 180, or if long is close to -180 degrees, then lng_min
may be less
than -180.  You need to detect these cases and subtract 360 from lng_max or add
360 to lng_min to be sure that they are both within the range from -180 to 180
inclusive.  Then lng_max will be less than lng_min, and your test must be that
the longitude is outside the range lng_max to lng_min, rather than
inside the range
lng_min to lng_max.

You might also like the "range" query set lookup:

  q = cls.objects.filter(latitude__range=(lat_min, lat_max))
  if lng_min < -180.0:
lng_min += 360.0
  elif lng_max > 180.0:
lng_max -= 360.0
  else:
return q.filter(longitude__range=(lng_min, lng_max))
  return q.exclude(longitude__range=(lng_max, lng_min))

7. items_in_radius() and locations_in_radius() appear to be exactly
the same classmethod,
except that radius is a require argument for one, but defaluts to 10
in the other.

On Fri, Aug 12, 2011 at 6:28 AM, Thomas Weholt  wrote:
> Hi all,
>
> This is what I've come up with so far. Not tested, but I came across
> an old piece of code doing the same thing ( I knew I'd done it before,
> just had to look deep into my code archives ;-) ):
>
> http://dpaste.com/592639/
>
> Comments very welcome. Expect a pypi-release some time after the
> weekend. Perhaps there's more things features we could add too, like
> google maps integration, some form of widget to use in the admin etc.
> Feel free to steal the code or suggest ideas.
>
> Thomas
>
> On Fri, Aug 12, 2011 at 10:33 AM, Mike Dewhirst  wrote:
>> Thomas
>>
>> Don't know if this helps but one degree of latitude is sixty nautical miles
>> at the equator and slightly less at the poles. Not worth worrying about.
>>
>> OTOH, one degree of longitude shrinks from 60 NM at the equator to zero at
>> the poles - which might help you visualize the necessary math.
>>
>> I bet Google has worked all this out before..
>>
>> Good luck - and I'm interested in the result.
>>
>> Mike
>>
>> On 12/08/2011 5:51pm, Thomas Weholt wrote:
>>>
>>> Thanks for your detailed reply :-) I'll try to figure it out. So far I
>>> got a few candidates for a solution but the math 

Re: same form model with separate admins and data

2011-08-12 Thread brian
I've figured a way that I think will work best for me for the model
and form but I'm having trouble with writing the view.  Here is my
pseudo code

models.py
-
class baseModel(models.Model):
first_name   = models.CharField( max_length=100,
verbose_name='first')

class form1Model( baseModel):
pass

class form2Model( baseModel):
pass
-


forms.py
-
class baseForm(ModelForm):


class form1( baseForm ):
class Meta(baseForm.Meta):
model = models.form1Model

class form2( baseForm ):
class Meta(baseForm.Meta):
model = models.form2Model

-


view.py
-
def form1View(request):

if request.method == 'POST':
form = form1(request.POST)

if form.is_valid():
form.save()

return HttpResponseRedirect('/thanksForm1/')

else:
form = form1()


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

-

I'm not sure how to create a view that can be reused.  The only
difference is the form name and the 'thank you' page.  I thought about
a Decorators but it doesn't seem like that is the right tool to use.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: same form model with separate admins and data

2011-08-12 Thread Landy Chapman
I apologize since I tried to reply via gmail.  Reposting & expanding
part of a solution .

> I've figured a way that I think will work best for me for the model
> and form but I'm having trouble with writing the view.  Here is my
> pseudo code
>
> models.py
> -
> class baseModel(models.Model):
>    first_name   = models.CharField( max_length=100,
> verbose_name='first')
>
> class form1Model( baseModel):
>    pass
>
> class form2Model( baseModel):
>    pass
> -

The problem with the above definitions is that form2Model and
form1Model would point to the *same* database table; that's what you
do_not_want.
[of course, no table is specified above.]  You'd need, at a minimum,
something like this:

class BaseModel(models.Model):
class Meta:
abstract = True

class Form1Model(BaseModel):
# Specify the table to use for Form1Model
class Meta(BaseModel.Meta):
db_table = 'table1'

class Form2Model(BaseModel):
# Specify the db table to use for Form2Model
class Meta(BaseModel.Meta):
db_table = 'table2' #<--- table in db specified here


The following should then work for you (after db_sync):

> forms.py
> -
> class baseForm(ModelForm):
>    
>
> class form1( baseForm ):
>    class Meta(baseForm.Meta):
>        model = models.Form1Model
>
> class form2( baseForm ):
>    class Meta(baseForm.Meta):
>        model = models.Form2Model
> -

> I'm not sure how to create a view that can be reused.  The only
> difference is the form name and the 'thank you' page.  I thought about
> a Decorators but it doesn't seem like that is the right tool to use.
>
> view.py
> -
> def form1View(request):
>
>    if request.method == 'POST':
>        form = form1(request.POST)
>
>        if form.is_valid():
>            form.save()
>            return HttpResponseRedirect('/thanksForm1/')
# --->#  you're missing code for NOT (form.is_valid())
>    else:
>            form = form1()
>    return render_to_response('form_template.html', {'form': form} )
>

I'm guessing here that you want both forms to be processed with the
same view function?   If the forms are submitted from different pages
there are a few ways to do this.

1. (sloppy) Pass a variable from urls.py  this will also require
rewriting the  view:
  def formView(request, which_form=None):
      if request.method == 'POST':
  if not [1, 2].__contains__(which_form):
   pass #  <--- iNone or nvalid form specified
  else:
  if which_form==1:
  form = form1(request.POST)
  redirect_url='/thanksForm2/'
  if which_form==2:
  form = form2(request.POST)
  redirect_url='/thanksForm2/'
         if form.is_valid():
            form.save()
            return HttpResponseRedirect(redirect_url)

  def Form1View(request):
   formView(request, which_form=1)

  def Form2View(request):
   formView(request, which_form=2)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Use object (User and custom object) in a form

2011-08-12 Thread Landy Chapman
I apologize since I tried to reply via gmail.  Reposting & expanding
part of a solution .

> I've figured a way that I think will work best for me for the model
> and form but I'm having trouble with writing the view.  Here is my
> pseudo code
>
> models.py
> -
> class baseModel(models.Model):
>first_name   = models.CharField( max_length=100,
> verbose_name='first')
>
> class form1Model( baseModel):
>pass
>
> class form2Model( baseModel):
>pass
> -

The problem with the above definitions is that form2Model and
form1Model would point to the *same* database table; that's what you
do_not_want.
[of course, no table is specified above.]  You'd need, at a minimum,
something like this:

class BaseModel(models.Model):
   class Meta:
   abstract = True

class Form1Model(BaseModel):
# Specify the table to use for Form1Model
   class Meta(BaseModel.Meta):
   db_table = 'table1'

class Form2Model(BaseModel):
# Specify the db table to use for Form2Model
   class Meta(BaseModel.Meta):
   db_table = 'table2' #<--- table in db specified here


The following should then work for you (after db_sync):

> forms.py
> -
> class baseForm(ModelForm):
>
>
> class form1( baseForm ):
>class Meta(baseForm.Meta):
>model = models.Form1Model
>
> class form2( baseForm ):
>class Meta(baseForm.Meta):
>model = models.Form2Model
> -

> I'm not sure how to create a view that can be reused.  The only
> difference is the form name and the 'thank you' page.  I thought about
> a Decorators but it doesn't seem like that is the right tool to use.
>
> view.py
> -
> def form1View(request):
>
>if request.method == 'POST':
>form = form1(request.POST)
>
>if form.is_valid():
>form.save()
>return HttpResponseRedirect('/thanksForm1/')
# --->#  you're missing code for NOT (form.is_valid())
>else:
>form = form1()
>return render_to_response('form_template.html', {'form': form} )
>

I'm guessing here that you want both forms to be processed with the
same view function?   If the forms are submitted from different pages
there are a few ways to do this.

--Pass a variable from urls.py  and rewrite the  view:
 def formView(request, which_form=None):
 if request.method == 'POST':
 if not [1, 2].__contains__(which_form):
  pass #  <--- iNone or nvalid form specified
 else:
 if which_form==1:
 form = form1(request.POST)
 redirect_url='/thanksForm2/'
 if which_form==2:
 form = form2(request.POST)
 redirect_url='/thanksForm2/'
if form.is_valid():
   form.save()
   return HttpResponseRedirect(redirect_url)

--Pass a variable from separate views:

 def Form1View(request):
  formView(request, which_form=1)

 def Form2View(request):
  formView(request, which_form=2)

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



didn't return an HttpResponse object

2011-08-12 Thread Harrison
I'm going through the tutorial, about views right now. I have this
code:

def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
t = loader.get_template('polls/index.html')
c = Context({
'latest_poll_list': latest_poll_list
})
HttpResponse(t.render(c))

But it's saying that it didn't return an HttpResponse object when I go
to the page. I tried everything I could think of, but it won't work.
Am I doing something wrong?


Sorry if this has been asked before, but I didn't see anything quite
like it in my searching.

-- 
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: didn't return an HttpResponse object

2011-08-12 Thread Karen Tracey
On Fri, Aug 12, 2011 at 10:04 PM, Harrison wrote:

> I'm going through the tutorial, about views right now. I have this
> code:
>
> def index(request):
>latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
>t = loader.get_template('polls/index.html')
>c = Context({
>'latest_poll_list': latest_poll_list
>})
>HttpResponse(t.render(c))
>
> But it's saying that it didn't return an HttpResponse object when I go
> to the page. I tried everything I could think of, but it won't work.
> Am I doing something wrong?
>

The last line needs to be:

   return HttpResponse(t.render(c))

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: didn't return an HttpResponse object

2011-08-12 Thread Harrison Morgan
Thanks, I just noticed that. I overlook the simplest things sometimes. =/

On Fri, Aug 12, 2011 at 10:07 PM, Karen Tracey  wrote:

> On Fri, Aug 12, 2011 at 10:04 PM, Harrison wrote:
>
>> I'm going through the tutorial, about views right now. I have this
>> code:
>>
>> def index(request):
>>latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
>>t = loader.get_template('polls/index.html')
>>c = Context({
>>'latest_poll_list': latest_poll_list
>>})
>>HttpResponse(t.render(c))
>>
>> But it's saying that it didn't return an HttpResponse object when I go
>> to the page. I tried everything I could think of, but it won't work.
>> Am I doing something wrong?
>>
>
> The last line needs to be:
>
>return HttpResponse(t.render(c))
>
> Karen
> --
> http://tracey.org/kmt/
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-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.
>

-- 
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: Use object (User and custom object) in a form

2011-08-12 Thread Landy Chapman
copy/paste typo, sorry.  It should have read/been:

def formView(request, which_form=None):
if request.method == 'POST':
if not [1, 2].__contains__(which_form):
pass #  <--- iNone or nvalid form specified
else:
 if which_form==1:
  form = form1(request.POST)
  redirect_url='/thanksForm1/'#was typo
 if which_form==2:
  form = form2(request.POST)
  redirect_url='/thanksForm2/'

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



ANN: django-socketio 0.1.0 released

2011-08-12 Thread Stephen McDonald
Hi all,

Our Django Dash entry http://drawnby.jupo.org made extensive use of
Socket.IO (cross-browser websockets) and born out of that I've created a new
django-socketio package which is now available:

Github: https://github.com/stephenmcd/django-socketio
Bitbucket: https://bitbucket.org/stephenmcd/django-socketio
PyPI: http://pypi.python.org/pypi/django-socketio/

Here's an overview from the docs:

django-socketio is a BSD licensed Django application that brings together a
variety of features that allow you to use WebSockets seamlessly with any
Django project. django-socketio was inspired by Cody Soyland's introductory
blog post on using Socket.IO and gevent with Django, and made possible by
the work of Jeffrey Gelens' gevent-websocket and gevent-socketio
packages. The features provided by django-socketio are:

- Installation of required packages from PyPI
- A management command for running gevent's pywsgi server with
auto-reloading capabilities
- A channel subscription and broadcast system that extends Socket.IO
allowing WebSockets and events to be partitioned into separate concerns
- A signals-like event system that abstracts away the various stages of a
Socket.IO request
- The required views, urlpatterns, templatetags and tests for all the above

Cheers,
Steve

-- 
Stephen McDonald
http://jupo.org

-- 
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: Redisplay form with different field value?

2011-08-12 Thread Karen Tracey
On Thu, Aug 11, 2011 at 7:03 AM, Jonas H.  wrote:

> On 08/09/2011 12:45 AM, Jonas H. wrote:
>
>> Hello list!
>>
>> Is there any way to use a different value for a field when re-displaying
>> a form? I.e. if a user enters '42' into an IntegerField but made the
>> other fields not validate, how could that IntegerField be re-displayed
>> with '43'?
>>
>>
Change the value in the form's data dictionary.

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Re: RedirectView with query_string = True and urlencoded unicode string

2011-08-12 Thread Karen Tracey
On Thu, Aug 11, 2011 at 10:48 AM, Slafs  wrote:

> Should i report a ticket?
>

Yes please, that's a bug in Django.

Karen
-- 
http://tracey.org/kmt/

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

2011-08-12 Thread Karen Tracey
On Thu, Aug 11, 2011 at 2:58 PM, Federico Capoano
wrote:

> Hi all,
>
> i'm using the new GenericIPAddressField and validation errors are not
> translated to the language of my project.
>
> Pheraps this field hasn't been internationalized yet?
>
>
Correct. Updating translations are done as part of the release process. If
you're pulling new code out of the repo, it won't have translations.

Karen
-- 
http://tracey.org/kmt/

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

2011-08-12 Thread Karen Tracey
On Wed, Aug 10, 2011 at 12:45 PM, RoyWilliams wrote:

> My problem is that POST data is not being copied into the request
> object that my Django code is getting, but the problem only happens
> with WSGI.
>
> When I fill in the web form with a browser, the POST data comes
> through correctly: request.method is POST and the QueryDict has my
> parameters. But when I use code (python urllib) to POST the data, it
> does not come through: request.method is set to GET and there are no
> parameters (QueryDict). I have checked that this client is really
> sending a POST request.
>
> I have done this with CSRF switched on and off, and it makes no
> difference.
>
> I have found this to be a WSGI problem, because there is another
> installation of the same application that uses mod_python, and that
> works perfectly.
>
>
You haven't shown any code, nor config information, nor how you have checked
that the client is really sending a POST, so it's rather hard to help. All I
can say is really, it's quite possible to use python urllib to successfully
POST data to a Django server using Apache/mod_wsgi (I assume that is what
you mean by WSGI since you mention mod_python as an alternative).

Karen
-- 
http://tracey.org/kmt/

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