xino12 | 1 Feb 01:32
Picon

Testing

Hello, I'm doing unitTesting and I want to know if it's possible to
accept more than one value in the assetEqual method.

Maybe this works

assertEqual(first, one_value or another_value)

Sorry but I'm new programming with django.

Lots of thanks,

Rubén

--

-- 
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Furbee | 1 Feb 01:42
Picon

Re: Testing

I think you can do something like:
    assertTrue(first == one_value or first == second_value)

At the same time, when unit testing, you should really know exactly what a value returned from a method is.

Furbee

On Tue, Jan 31, 2012 at 4:32 PM, xino12 <xinatowner <at> gmail.com> wrote:
Hello, I'm doing unitTesting and I want to know if it's possible to
accept more than one value in the assetEqual method.

Maybe this works

assertEqual(first, one_value or another_value)

Sorry but I'm new programming with django.

Lots of thanks,

Rubén

--
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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Gravatar

Re: Testing


Another option, if you're using unittest2 (and if you're using Django's TestCase, you're using
unittest2) is assertIn --

    self.assertIn(first, [one_value, another_value])

Yours,
Russ Magee %-)

On 01/02/2012, at 8:42 AM, Furbee wrote:

> I think you can do something like:
>     assertTrue(first == one_value or first == second_value)
> 
> At the same time, when unit testing, you should really know exactly what a value returned from a method is.
> 
> Furbee
> 
> On Tue, Jan 31, 2012 at 4:32 PM, xino12 <xinatowner <at> gmail.com> wrote:
> Hello, I'm doing unitTesting and I want to know if it's possible to
> accept more than one value in the assetEqual method.
> 
> Maybe this works
> 
> assertEqual(first, one_value or another_value)
> 
> Sorry but I'm new programming with django.
> 
> Lots of thanks,
> 
> Rubén
> 
> --
> 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 <at> googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

richard | 1 Feb 02:34
Picon

Using Context Processor as form with HttpResponseRedirect

Hi i have seen alot of people saying to use a context processor to
include forms in multiple page. I have written a context processor
login form that just returns the django Authentication form and
everything works great including the form.errors etc except that I
cant seem to redirect from the context processor after is_valid is
called. Are context processors not supposed ot be used in this way? My
thoughts inititally were that if it seems to support a request and can
do the validation why not? Basically stuck on using
HttpResponseRedirect in a context processor. I have managed to get
this working by passing a variable called redirect in the dictionary
returned to my template and then saying if the redirect tag is
available use the browsers meta tag to redirect me but i dont think
this is the way it should work. code below please advise thanks.

context_processors.py

from django.contrib.auth.forms import AuthenticationForm
from django.http import HttpResponseRedirect

def login_form(request):
    if request.method == 'POST':
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            #return HttpResponseRedirect('/home') ONLY THING THATS NOT
WORKING
            return {'login_form': form, 'redirect': '/home'}
    else:
        form = AuthenticationForm(request)
    return {'login_form': form}

template.html
{{ form.non_field_errors}} # works fine after post with errors showing
{{ form.username}}
{{ form.password}}
{% if redirect %}
   <meta http-equiv="REFRESH" content="0;url={{ redirect }}">
 {% endif %}

--

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

Jeff Heard | 1 Feb 02:36
Picon

Re: GIS Distance from Point to Geometry Collection

You should be able to create a geometrycollection object from a queryset (you may have to use a list
comprehension for this), then calculate the centroid and take the distance from that. Taking the
distance from the edge should only be a little more
Complicated.  Check the django GEOS API docs For complete details

On Jan 31, 2012, at 6:36 PM, Loafer <loaferdtd <at> gmail.com> wrote:

> I have a model that currently stores a Geographic Point (Using Django
> GIS (GeoDjango)) and another model that has a field to store a
> geometry collection (A collection of polygons, lines, and or points).
> 
> I am trying to find the distance from the point to any one of the
> shapes in the geometry collection. Apparently the distance function
> only works on single shapes, not a collection. Are there any
> workarounds to this?
> 
> Any help is appreciated.
> 
> Thanks.
> 
> -- 
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users <at> googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Alex Kopp | 1 Feb 02:41
Picon

Re: GIS Distance from Point to Geometry Collection

Perhaps I didn't explain it well, Jeff. I am just trying to get the smallest distance from one point to any of the points, lines, or polygons inside of a queryset. The data I am receiving from the queryset is a geometrycollection already... That is how it is being stored in the database.


On Tue, Jan 31, 2012 at 8:36 PM, Jeff Heard <jefferson.r.heard <at> gmail.com> wrote:
You should be able to create a geometrycollection object from a queryset (you may have to use a list comprehension for this), then calculate the centroid and take the distance from that. Taking the distance from the edge should only be a little more
Complicated.  Check the django GEOS API docs For complete details



On Jan 31, 2012, at 6:36 PM, Loafer <loaferdtd <at> gmail.com> wrote:

> I have a model that currently stores a Geographic Point (Using Django
> GIS (GeoDjango)) and another model that has a field to store a
> geometry collection (A collection of polygons, lines, and or points).
>
> I am trying to find the distance from the point to any one of the
> shapes in the geometry collection. Apparently the distance function
> only works on single shapes, not a collection. Are there any
> workarounds to this?
>
> Any help is appreciated.
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users <at> googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Alex Kopp | 1 Feb 02:45
Picon

Re: GIS Distance from Point to Geometry Collection

Here's a more concrete example, say I am storing shapes of all countries. Now, the US can't be stored in one polygon (we have hawaii and alaska), therefore I have to store the many polygons in one geometrycollection.


Now, say I have another point on the map, I would like to know how ar it is from ANY of the polygons...

On Tue, Jan 31, 2012 at 8:41 PM, Alex Kopp <loaferdtd <at> gmail.com> wrote:
Perhaps I didn't explain it well, Jeff. I am just trying to get the smallest distance from one point to any of the points, lines, or polygons inside of a queryset. The data I am receiving from the queryset is a geometrycollection already... That is how it is being stored in the database.

On Tue, Jan 31, 2012 at 8:36 PM, Jeff Heard <jefferson.r.heard <at> gmail.com> wrote:
You should be able to create a geometrycollection object from a queryset (you may have to use a list comprehension for this), then calculate the centroid and take the distance from that. Taking the distance from the edge should only be a little more
Complicated.  Check the django GEOS API docs For complete details



On Jan 31, 2012, at 6:36 PM, Loafer <loaferdtd <at> gmail.com> wrote:

> I have a model that currently stores a Geographic Point (Using Django
> GIS (GeoDjango)) and another model that has a field to store a
> geometry collection (A collection of polygons, lines, and or points).
>
> I am trying to find the distance from the point to any one of the
> shapes in the geometry collection. Apparently the distance function
> only works on single shapes, not a collection. Are there any
> workarounds to this?
>
> Any help is appreciated.
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users <at> googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Jeff Heard | 1 Feb 03:04
Picon

Re: GIS Distance from Point to Geometry Collection

Got it.  So what you want to do is a list comprehension over the geometry object, which should give you individual geometries is what it sounds like.  Then you can calculate distance() from each of these.  Something like this?


interesting_point = Point(x, y)
collection = result.geom
min_dist = min([g.distance(interesting_point) for g in collection])

or for every geometrycollection in a queryset:

result = MyModel.objects.all()
min_dist = min([min([g.distance(interesting_point) for g in coll]) for coll in result])

Brute force and thus a bit slow, but it should work if I understand you correctly...

-- Jeff


On Tue, Jan 31, 2012 at 8:45 PM, Alex Kopp <loaferdtd <at> gmail.com> wrote:
Here's a more concrete example, say I am storing shapes of all countries. Now, the US can't be stored in one polygon (we have hawaii and alaska), therefore I have to store the many polygons in one geometrycollection.

Now, say I have another point on the map, I would like to know how ar it is from ANY of the polygons...


On Tue, Jan 31, 2012 at 8:41 PM, Alex Kopp <loaferdtd <at> gmail.com> wrote:
Perhaps I didn't explain it well, Jeff. I am just trying to get the smallest distance from one point to any of the points, lines, or polygons inside of a queryset. The data I am receiving from the queryset is a geometrycollection already... That is how it is being stored in the database.

On Tue, Jan 31, 2012 at 8:36 PM, Jeff Heard <jefferson.r.heard <at> gmail.com> wrote:
You should be able to create a geometrycollection object from a queryset (you may have to use a list comprehension for this), then calculate the centroid and take the distance from that. Taking the distance from the edge should only be a little more
Complicated.  Check the django GEOS API docs For complete details



On Jan 31, 2012, at 6:36 PM, Loafer <loaferdtd <at> gmail.com> wrote:

> I have a model that currently stores a Geographic Point (Using Django
> GIS (GeoDjango)) and another model that has a field to store a
> geometry collection (A collection of polygons, lines, and or points).
>
> I am trying to find the distance from the point to any one of the
> shapes in the geometry collection. Apparently the distance function
> only works on single shapes, not a collection. Are there any
> workarounds to this?
>
> Any help is appreciated.
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users <at> googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Alex Kopp | 1 Feb 03:07
Picon

Re: GIS Distance from Point to Geometry Collection

Yes Jeff, this is what I want to do. I wasn't sure if there was an easier way. What units does the distance function return? I tried this and it seems to return the distance in units of 10km, is this correct?


Thanks again!

On Tue, Jan 31, 2012 at 9:04 PM, Jeff Heard <jefferson.r.heard <at> gmail.com> wrote:
Got it.  So what you want to do is a list comprehension over the geometry object, which should give you individual geometries is what it sounds like.  Then you can calculate distance() from each of these.  Something like this?

interesting_point = Point(x, y)
collection = result.geom
min_dist = min([g.distance(interesting_point) for g in collection])

or for every geometrycollection in a queryset:

result = MyModel.objects.all()
min_dist = min([min([g.distance(interesting_point) for g in coll]) for coll in result])

Brute force and thus a bit slow, but it should work if I understand you correctly...

-- Jeff


On Tue, Jan 31, 2012 at 8:45 PM, Alex Kopp <loaferdtd <at> gmail.com> wrote:
Here's a more concrete example, say I am storing shapes of all countries. Now, the US can't be stored in one polygon (we have hawaii and alaska), therefore I have to store the many polygons in one geometrycollection.

Now, say I have another point on the map, I would like to know how ar it is from ANY of the polygons...


On Tue, Jan 31, 2012 at 8:41 PM, Alex Kopp <loaferdtd <at> gmail.com> wrote:
Perhaps I didn't explain it well, Jeff. I am just trying to get the smallest distance from one point to any of the points, lines, or polygons inside of a queryset. The data I am receiving from the queryset is a geometrycollection already... That is how it is being stored in the database.

On Tue, Jan 31, 2012 at 8:36 PM, Jeff Heard <jefferson.r.heard <at> gmail.com> wrote:
You should be able to create a geometrycollection object from a queryset (you may have to use a list comprehension for this), then calculate the centroid and take the distance from that. Taking the distance from the edge should only be a little more
Complicated.  Check the django GEOS API docs For complete details



On Jan 31, 2012, at 6:36 PM, Loafer <loaferdtd <at> gmail.com> wrote:

> I have a model that currently stores a Geographic Point (Using Django
> GIS (GeoDjango)) and another model that has a field to store a
> geometry collection (A collection of polygons, lines, and or points).
>
> I am trying to find the distance from the point to any one of the
> shapes in the geometry collection. Apparently the distance function
> only works on single shapes, not a collection. Are there any
> workarounds to this?
>
> Any help is appreciated.
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users <at> googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Stanwin Siow | 1 Feb 03:14
Picon
Gravatar

Re: Creating a hierarchy of objects in my api.py

Hello,

Any luck on this yet?

Best Regards,

Stanwin Siow



On Jan 31, 2012, at 11:39 AM, St <at> n wrote:

Hello,

I am playing around with tastypie and i want to create a hierarchy of
data.

What i currently have is this:


class keywordResource(ModelResource):
   tweets = fields.ToManyField(timelineResource, 'tweets', full=True)
   class Meta:
       queryset = Keyword.objects.all()
       resource_name = 'keyword'
       excludes = ['id', 'keyword_id']
       include_resource_uri = False

   def alter_list_data_to_serialize(self, request, data_dict):
       if isinstance(data_dict, dict):
           if 'meta' in data_dict:
               # Get rid of the "meta".
               del(data_dict['meta'])
               # Rename the objects.
               data_dict['keyword'] = copy.copy(data_dict['objects'])
               del(data_dict['objects'])
       return data_dict



Can someone explain the relationship to me in creating such a
hierarchy?

in the line tweets = fields.ToManyField(timelineResource, 'tweets',
full=True)

it means that timelineResource is a child of Keyword right? and
"tweets" would be the column name in timeline table or just a generic
name?

or must i map a matching column that appears in both tables (keyword,
timeline)?


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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> 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 <at> googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Gmane