Exemplo n.º 1
0
    def get_geojson(self):
        segments = []
        for segment in self.segments.all():
            segments.append(segment.get_geojson())
        segments_string = "["+"], [".join(segments)+"]"


        c = Context({"type": get_model_name(self),
                "title": self.title,
                "creation_date": self.creation_date,
                "update_date": self.update_date,
                "distance": self.distance,
                "total_up": self.get_vertical_up(),
                "total_down": self.get_vertical_down(),
                "start_time": self.start_time,
                "end_time": self.end_time,
                "creator": self.creator,
                "self": self,
                "segments": segments_string})
        
        t = Template("""{"type": "{{type}}",\
            "id": "{{self.id}}",\
            "title": "{{title|linebreaksbr}}",\
            "creation_date": "{{creation_date}}",\
            "update_date": "{{update_date}}",\
            "distance": "{{distance}}",\
            "total_up": "{{total_up}}",\
            "total_down": "{{total_down}}",\
            "start_time": "{{start_time}}",\
            "end_time": "{{end_time}}",\
            "creator": "{{creator}}",\
            "segments":{% autoescape off %}{{segments}}{% endautoescape %}}""")
        return t.render(c)
Exemplo n.º 2
0
    def test_placing(self):
        post = Post.objects.create(title="1", slug="1sdfwere", body="sd",
                                    author=User.objects.get(pk=1))
        
        
        content_type = ContentType.objects.get_for_model(post)

        url = reverse('place_item')
        self.assertTrue(url)
        
        c = Client()
        c.login(username='******', password='******')

        resp = c.post(url, {"content_type": get_model_name(post),
                            "content_object_id": post.id,
                            "lat":"12.090", "lng":"13.99"})
        
        self.assertEquals(resp.status_code, 200)
        self.assertTrue(resp.content)

        # missing parameter
        self.assertEquals(Post.objects.get(pk=post.id).location.get_x(), 13.99)
        self.assertEquals(Post.objects.get(pk=post.id).location.get_y(), 12.090)
        
        # test searching for it
        from geo.models import GeoPointTag
        self.assertEquals(1, len(GeoPointTag.objects.search_in_area(10,10,14,13)))
        self.assertEquals(0, len(GeoPointTag.objects.search_in_area(10,10,12,12)))

        post.delete()
        
        self.assertEquals(0, len(GeoPointTag.objects.search_in_area(10,10,14,13)))
Exemplo n.º 3
0
    def get_geojson(self):
        c = Context({"type": get_model_name(self),
                     "self": self})

        t = Template("""{"type": "{{type}}",\
                "id": "{{self.id}}",\
                "location": {{self.location.geojson}}}""")
        return t.render(c)
Exemplo n.º 4
0
 def test_get_active_users_in_area(self):
     from geo.utils import get_active_users_in_area
     c = Client()
     c.login(username='******', password='******')
     track = self.create_gpx_track("/Rothaarsteig_1.gpx")
     track.tags = "one two three"
     track.save()
     
     users = get_active_users_in_area(10, 10, 13, 13)
     self.assertEqual(0, len(users))
     
     from blog.models import Post
     post = Post.objects.create(title="1", slug="1sdfwere", body="sd",
                                 author=User.objects.get(pk=1))
     post2 = Post.objects.create(title="112", slug="1sdfwere11", body="23sd",
                                 author=User.objects.get(pk=1))
     post3 = Post.objects.create(title="112234", slug="1sdfwere12341", body="23sd234",
                                 author=User.objects.get(pk=2))
     url = reverse('place_item')
     resp = c.post(url, {"content_type": get_model_name(post),
                         "content_object_id": post.id,
                             "lat":"12.090", "lng":"12.99"})
     resp = c.post(url, {"content_type": get_model_name(post2),
                         "content_object_id": post2.id,
                         "lat":"12.000", "lng":"12.00"})
     c.login(username='******', password='******')
     resp = c.post(url, {"content_type": get_model_name(post3),
                         "content_object_id": post3.id,
                         "lat":"12.000", "lng":"12.00"})
     
     users = get_active_users_in_area(10, 10, 50, 50)
     self.assertEqual(2, len(users))
     self.assertEqual(4, users[0]['counter'])
     self.assertEqual(1, users[1]['counter'])
     
     users = get_active_users_in_area(10, 10, 13, 13)
     self.assertEqual(2, len(users))
     self.assertEqual(2, users[0]['counter'])
     self.assertEqual(1, users[1]['counter'])
     
     track.delete()
Exemplo n.º 5
0
    def get_geojson(self):
        c = Context({"type": get_model_name(self),
                "self": self})

        t = Template("""{"type": "{{type}}",\
                "id": "{{self.id}}",\
                "title": "{{self.title}}",\
                "caption": "{{self.caption}}",\
                "date_added": "{{self.date_added|date}} ",\
                "marker_image": "{{self.get_50x50_url}}",\
                {% if self.has_location %}\
                    "location": {% autoescape off %}{{self.location.geojson}}{% endautoescape %},\
                {% endif %}\
                "location_name": "{{self.location_name}}" }""")
        return t.render(c)
Exemplo n.º 6
0
def generate_clusterable_items():
    from blog.models import Post
    c = Client()
    c.login(username='******', password='******')
    count = 0
    for point in cluster_points:
        post = Post.objects.create(title="1", slug="1sdfwere_%s"%count,
                                   body="sd", author=User.objects.get(pk=1))
   
        url = reverse('place_item')
        resp = c.post(url, {"content_type": get_model_name(post),
                            "content_object_id": post.id,
                            "tags": "one two three",
                                "lat":point[0], "lng":point[1]})
        count = count+1
Exemplo n.º 7
0
    def get_geojson(self):
        timestamps = "''"
        altitudes = "''"
        if self.raw_track:
            try:
                timestamps = []
                for point in self.raw_track:
                    if (point["timestamp"]):
                        timestamps.append(point["timestamp"])
                    else:
                        timestamps.append(point.time.strftime("%b %d, %Y %H:%M:%S"))
                timestamps = simplejson.dumps(timestamps)
                altitudes = simplejson.dumps([ point.elevation
                                              for point in self.raw_track])
            except:
                pass
        c = Context({"type": get_model_name(self),
                "title":self.title,
                "creation_date": self.creation_date,
                "update_date": self.update_date,
                "distance": self.distance,
                "start_time": self.start_time,
                "end_time": self.end_time,
                "creator": self.creator,
                "timestamps": timestamps,
                "altitudes": altitudes,
                "total_up": self.get_vertical_up(),
                "total_down": self.get_vertical_down(),
                "self": self,
                "track": self.track.geojson})

        t = Template("""{"type": "{{type}}",\
            "id": "{{self.id}}",\
            "parent_id": "{{self.parent.id}}",\
            "title": "{{title|linebreaksbr}}",\
            "description": "{{self.description|linebreaksbr}}",\
            "creation_date": "{{creation_date}}",\
            "update_date": "{{update_date}}",\
            "distance": "{{distance}}",\
            "total_up": "{{total_up}}", \
            "total_down": "{{total_down}}",\
            "start_time": "{{start_time}}",\
            "end_time": "{{end_time}}",\
            "altitudes": {% autoescape off %}{{altitudes}}{% endautoescape %},\
            "timestamps":{% autoescape off %}{{timestamps}}{% endautoescape %},\
            "creator": "{{creator}}",\
            "track": {% autoescape off %}{{track}}{% endautoescape %} }""")
        return t.render(c)
Exemplo n.º 8
0
    def get_geojson(self):
        c = Context({"type": get_model_name(self),
                "self": self})

        t = Template("""{"type": "{{type}}",\
                "id": "{{self.id}}",\
                "title": "{{self.title}}",\
                "body": "{{self.body}}",\
                "publish": "{{self.publish|date}} ",\
                "slug": "{{self.slug}}",\
                "marker_image": "{{self.videoimage.get_50x50_url}}",\
                {% if self.has_location %}\
                    "location": {% autoescape off %}{{self.location.geojson}}{% endautoescape %},\
                {% endif %}\
                "location_name": "{{self.location_name}}" }""")
        return t.render(c)
Exemplo n.º 9
0
    def get_geojson(self):
        c = Context({"type": get_model_name(self),
                "story":self.story,
                "self": self,
                "position": self.position})

        t = Template("""{"type": "{{type}}",\
                "id": {{self.id}},\
                "storyId": {{story.id}},\
                "text": "{{self.text|linebreaksbr}}",\
                "marker_image": "{{self.get_image.0.content_object.get_50x50_url}}",\
                {% if self.has_location %}\
                    "location": {% autoescape off %}{{self.location.geojson}}{% endautoescape %},\
                {% endif %}\
                "position": {{position}} }""")
        return t.render(c)
Exemplo n.º 10
0
 def test_adding_and_updating_line_to_story(self):
     c = Client()
     c.login(username='******', password='******')
     url = reverse('geo_create_line')
     story = Story.objects.create(title='To Do', slug="to-do",
                                  creator=User.objects.get(pk=1))
     
     resp = c.post(url, {"points": "0 0, 1 1, 2 2, 3 3, 4 4",
                         "content_type":get_model_name(story),
                         "content_object_id":story.pk})
     
     self.assertEquals(resp.status_code, 200)
     
     self.assertTrue(resp.content)
     
     #test output
     from django.utils import simplejson
     obj = simplejson.loads( resp.content )
     line = simplejson.loads( obj["line"] )
     
     print resp.content
     
     self.assertTrue(obj)
     self.assertEquals(line["type"], "geo.geo_line_tag")
     self.assertEquals(len(line["line"]["coordinates"]), 5)
     self.assertEquals(line["line"]["coordinates"][0][0], 0)
     self.assertEquals(line["line"]["coordinates"][0][1], 0)
     self.assertEquals(line["line"]["coordinates"][1][0], 1)
     self.assertEquals(line["line"]["coordinates"][1][1], 1)
     self.assertEquals(len(story.lines), 1)
     
     url = reverse('geo_update_line', args=(line["id"],))
     resp = c.post(url, {"points": "1 1, 1 1, 2 2, 3 3, 0 0"})
     
     self.assertEquals(resp.status_code, 200)
     
     self.assertTrue(resp.content)
     
     obj = simplejson.loads( resp.content )
     line = simplejson.loads( obj["line"] )
     self.assertTrue(obj)
     self.assertEquals(line["type"], "geo.geo_line_tag")
     self.assertEquals(len(line["line"]["coordinates"]), 5)
     self.assertEquals(line["line"]["coordinates"][0][0], 1)
     self.assertEquals(line["line"]["coordinates"][0][1], 1)
     self.assertEquals(line["line"]["coordinates"][4][0], 0)
     self.assertEquals(line["line"]["coordinates"][4][1], 0)
Exemplo n.º 11
0
    def get_geojson(self):
        c = Context({"type": get_model_name(self),
                "self": self,
                "STATIC_URL": settings.STATIC_URL})

        t = Template("""{"type": "{{type}}",\
                "id": "{{self.id}}",\
                "title": "{{self.title}}",\
                "body": "{{self.body}}",\
                "publish": "{{self.publish|date}} ",\
                "marker_image": "{{STATIC_URL}}/images/post-75-75.gif",\
                "slug": "{{self.slug}}",\
                {% if self.has_location %}\
                    "location": {% autoescape off %}{{self.location.geojson}}{% endautoescape %},\
                {% endif %}\
                "location_name": "{{self.location.location_name}}" }""")
        return t.render(c)
Exemplo n.º 12
0
    def get_geojson(self):
        c = Context({"type": get_model_name(self),
                "title":self.title,
                "creation_date": self.creation_date,
                "update_date": self.update_date,
                "distance": self.distance,
                "creator": self.creator,
                "self": self,
                "line": self.line.geojson})

        t = Template("""{"type": "{{type}}",\
                "id": "{{self.id}}",\
                "title": "{{title|linebreaksbr}}",\
                "description": "{{self.description|linebreaksbr}}",\
                "creation_date": "{{creation_date}}",\
                "update_date": "{{update_date}}",\
                "creator": "{{creator}}",\
                "track": {% autoescape off %}{{line}}{% endautoescape %} }""")
        
        return t.render(c)
def object_to_model_name(object):
    try:
        return get_model_name(object)
    except:
        return ""
Exemplo n.º 14
0
    def test_placing(self):
        photo = Image.objects.create(title="1", title_slug="1")
        photo.image.save(os.path.basename('ph.jpg'),
                         ContentFile(open(self.file_path+'/photo.jpg', "r")
                                                                    .read()))
        photo.save()
        
        self.assertTrue(photo)
        content_type = ContentType.objects.get_for_model(photo)
    
        self.assertFalse(photo.has_location())
        url = reverse('place_item')
        self.assertTrue(url)
        
        c = Client()
        
        #test without login
        resp = c.post(url, {"content_type": get_model_name(photo),
                            "content_object_id": photo.id,
                            "lat":"12.090", "lng":"13.99"})
        self.assertEquals(resp.status_code, 302)
        
        c.login(username='******', password='******')
        
        #test without lat
        resp = c.post(url, {"content_type": get_model_name(photo),
                            "content_object_id": photo.id,
                            "lng":"13.99"})
        self.assertEquals(resp.status_code, 400)
        
        #test without content_type
        resp = c.post(url, {"content_object_id": photo.id,
                            "lat":"12.090", "lng":"13.99"})
        self.assertEquals(resp.status_code, 400)
        
        #test outside of valid area
        resp = c.post(url, {"content_object_id": photo.id,
                            "lat":"199.090", "lng":"13.99"})
        self.assertEquals(resp.status_code, 400)
        
        #test correct post
        resp = c.post(url, {"content_type": get_model_name(photo),
                            "content_object_id": photo.id,
                            "lat":"12.090", "lng":"13.99"})
        
        self.assertEquals(resp.status_code, 200)
        self.assertTrue(resp.content)

        # missing parameter
        self.assertEquals(Image.objects.get(pk=photo.id).location.get_x(),
                                                                        13.99)
        self.assertEquals(Image.objects.get(pk=photo.id).location.get_y(),
                                                                        12.090)
        
        # test searching for it
        from geo.models import GeoPointTag
        self.assertEquals(1,
                          len(GeoPointTag.objects.search_in_area(10,10,14,13)))
        self.assertEquals(0,
                          len(GeoPointTag.objects.search_in_area(10,10,12,12)))
        
        # test editing the 
        resp = c.post(url, {"content_type": get_model_name(photo),
                            "content_object_id": photo.id,
                            "lat":"24.090", "lng":"26.99"})
        
        self.assertEquals(resp.status_code, 200)
        self.assertTrue(photo.has_location())
        self.assertEquals(Image.objects.get(pk=photo.id).location.get_x(),
                                                                        26.99)
        self.assertEquals(Image.objects.get(pk=photo.id).location.get_y(),
                                                                        24.090)
        
        self.assertEquals(1,
                          len(GeoPointTag.objects.search_in_area(20,20,30,30)))
        
        photo.delete()
        
        self.assertEquals(0,
                          len(GeoPointTag.objects.search_in_area(10,10,14,13)))