Beispiel #1
0
class MarkerView(object):
    '''
    static method MarkersUtils to manipulate markers
    '''

    def __init__(self):
        self.marker = Marker
        self.utils = Utils()

    @staticmethod
    def _parse_google_maps_bounds(bounds):
        '''
        parses the bound string and produces a list of the
        type [s, w, n, e]
        :param bounds: bounds as string from google map
        getBounds method
        '''
        characters_to_remove = ['(', ')', ' ']
        for c in characters_to_remove:
            bounds = bounds.replace(c, '')
        return map(float, bounds.split(','))

    @staticmethod
    def _parse_location(markers):
        '''
        converts point-based marker location into dict with lat, lon keys
        :param markers: markers objects to be parsed. Note that the 
        dict markers is mutated within the method
        '''
        for marker in markers:
            _location = marker['location']
            marker['location'] = {'lat': _location.x, 'lon': _location.y}

    @staticmethod
    def _parse_markers_object(markers_object):
        '''
        parse markers objects to a list of dictionaries
        :param markers_object: list of markers object from db
        '''
        markers = map(model_to_dict, markers_object)
        return markers

    def get_markers_from_db(self, bounds):
        '''
        get markers from db based on bounds
        :param bounds: bounds as string from google map
        getBounds method
        '''

        bounds_points = self._parse_google_maps_bounds(bounds)
        polygon = self.utils.generate_bounds_polygon(bounds_points)
        markers_object = self.utils.get_markers_within(polygon)
        markers = self._parse_markers_object(markers_object)
        self._parse_location(markers)
        return markers
Beispiel #2
0
 def __init__(self):
     self.marker = Marker
     self.utils = Utils()