コード例 #1
0
 def test_copy_nomulti(self):
     from ebpub.openblockapi.views import _copy_nomulti
     self.assertEqual(_copy_nomulti({}), {})
     self.assertEqual(_copy_nomulti({'a': 1}), {'a': 1})
     self.assertEqual(_copy_nomulti({'a': 1}), {'a': 1})
     self.assertEqual(_copy_nomulti({'a': [1], 'b': [1,2,3]}),
                      {'a': 1, 'b': [1,2,3]})
コード例 #2
0
ファイル: tests.py プロジェクト: horshacktest/openblock
    def test_copy_nomulti(self):
        from ebpub.openblockapi.views import _copy_nomulti

        self.assertEqual(_copy_nomulti({}), {})
        self.assertEqual(_copy_nomulti({"a": 1}), {"a": 1})
        self.assertEqual(_copy_nomulti({"a": 1}), {"a": 1})
        self.assertEqual(_copy_nomulti({"a": [1], "b": [1, 2, 3]}), {"a": 1, "b": [1, 2, 3]})
コード例 #3
0
ファイル: tests.py プロジェクト: mikef907/openblock
 def test_copy_nomulti(self):
     from ebpub.openblockapi.views import _copy_nomulti
     self.assertEqual(_copy_nomulti({}), {})
     self.assertEqual(_copy_nomulti({'a': 1}), {'a': 1})
     self.assertEqual(_copy_nomulti({'a': [1]}), {'a': 1})
     self.assertEqual(_copy_nomulti({'a': [1], 'b': [1,2,3]}),
                      {'a': 1, 'b': [1,2,3]})
     # It should work with a django Request too.
     request = RequestFactory().get('/foo/?a=1&b=2&b=3')
     self.assertEqual(_copy_nomulti(request.GET),
                      {'a': '1', 'b': ['2', '3']})
コード例 #4
0
ファイル: tests.py プロジェクト: slinkp/openblock
 def test_copy_nomulti(self):
     from ebpub.openblockapi.views import _copy_nomulti
     self.assertEqual(_copy_nomulti({}), {})
     self.assertEqual(_copy_nomulti({'a': 1}), {'a': 1})
     self.assertEqual(_copy_nomulti({'a': [1]}), {'a': 1})
     self.assertEqual(_copy_nomulti({
         'a': [1],
         'b': [1, 2, 3]
     }), {
         'a': 1,
         'b': [1, 2, 3]
     })
     # It should work with a django Request too.
     request = RequestFactory().get('/foo/?a=1&b=2&b=3')
     self.assertEqual(_copy_nomulti(request.GET), {
         'a': '1',
         'b': ['2', '3']
     })
コード例 #5
0
def map_items_json(request):
    """
    slightly briefer and less attribute-accessing 
    rendition of the api's geojson response. includes
    only attributes used by the map.
    """
    items, params = build_item_query(_copy_nomulti(request.GET))
    
    def _item_to_feature(item):
        geom = simplejson.loads(item.location.geojson)
        result = {
            'type': 'Feature',
            'geometry': geom,
            }
    
        sort_key = '%d-%d-%d-%s-%d' % (9999 - item.item_date.year,
                                    13 - item.item_date.month,
                                    32 - item.item_date.day,
                                    item.title,
                                    item.id)
        props = {'id': item.id,
                 'openblock_type': 'newsitem',
                 'icon': item.schema.map_icon_url,
                 'color': item.schema.map_color,
                 'sort': sort_key
                }
        result['properties'] = props
        return result

    items = [_item_to_feature(item) for item in items if item.location is not None]
    items_geojson_dict = {'type': 'FeatureCollection',
                          'features': items
                          }
    
    body = simplejson.dumps(items_geojson_dict)
    response = HttpResponse(body, content_type=JSON_CONTENT_TYPE)
    patch_response_headers(response, cache_timeout=3600)
    return response
コード例 #6
0
ファイル: views.py プロジェクト: peudadayusuf/openblock
def map_items_json(request):
    """
    slightly briefer and less attribute-accessing 
    rendition of the api's geojson response. includes
    only attributes used by the map.
    """
    items, params = build_item_query(_copy_nomulti(request.GET))

    def _item_to_feature(item):
        geom = simplejson.loads(item.location.geojson)
        result = {
            'type': 'Feature',
            'geometry': geom,
        }

        sort_key = '%d-%d-%d-%s-%d' % (9999 - item.item_date.year,
                                       13 - item.item_date.month, 32 -
                                       item.item_date.day, item.title, item.id)
        props = {
            'id': item.id,
            'openblock_type': 'newsitem',
            'icon': item.schema.map_icon_url,
            'color': item.schema.map_color,
            'sort': sort_key
        }
        result['properties'] = props
        return result

    items = [
        _item_to_feature(item) for item in items if item.location is not None
    ]
    items_geojson_dict = {'type': 'FeatureCollection', 'features': items}

    body = simplejson.dumps(items_geojson_dict)
    response = HttpResponse(body, content_type=JSON_CONTENT_TYPE)
    patch_response_headers(response, cache_timeout=3600)
    return response
コード例 #7
0
ファイル: views.py プロジェクト: horshacktest/openblock
def map_items_json(request):
    """
    slightly briefer and less attribute-accessing 
    rendition of the api's geojson response. includes
    only attributes used by the map.
    """
    items, params = build_item_query(_copy_nomulti(request.GET))

    def _item_to_feature(item):
        geom = simplejson.loads(item.location.geojson)
        result = {"type": "Feature", "geometry": geom}

        sort_key = "%d-%d-%d-%s-%d" % (
            9999 - item.item_date.year,
            13 - item.item_date.month,
            32 - item.item_date.day,
            item.title,
            item.id,
        )
        props = {
            "id": item.id,
            "openblock_type": "newsitem",
            "icon": item.schema.map_icon_url,
            "color": item.schema.map_color,
            "sort": sort_key,
        }
        result["properties"] = props
        return result

    items = [_item_to_feature(item) for item in items if item.location is not None]
    items_geojson_dict = {"type": "FeatureCollection", "features": items}

    body = simplejson.dumps(items_geojson_dict)
    response = HttpResponse(body, content_type=JSON_CONTENT_TYPE)
    patch_response_headers(response, cache_timeout=3600)
    return response