def test_create_sticky_notags(self): """Add sticky without tags. x=146414&y=489585.5&reporter=Jack&title=poep &description=poep+op+straat&tags=poep """ # X and Y are assumed to be in the site's projection # So we need to set one. Should be a fixture. s = Setting() s.key = 'projection' s.value = 'EPSG:28992' s.save() url = reverse('lizard_sticky.add_sticky') self.client.post( url, {'reporter': 'Jack', 'title': 'test geeltje', 'description': 'beschrijving test geeltje', 'x': '100.0', 'y': '100.0', 'tags': ''}) sticky = Sticky.objects.get(reporter='Jack') self.assertTrue(sticky) self.assertTrue(str(sticky))
def transform_point(x, y, from_proj=None, to_proj=None): """Transform x and y from from_proj to to_proj. Return a Point with the right srid set. Possible values of from_proj and to_proj are "google", "rd" and "wgs84". If from_proj or to_project aren't given, the "projection" Setting is used. It makes no sense to give neither.""" if to_proj is None: to_srs = Setting.get('projection', 'EPSG:900913') to_srid = string_to_srid[srs_to_string[to_srs]] to_proj = Proj(srs_to_mapnik_projection[to_srs]) elif to_proj not in string_to_srs: raise ValueError("Value '%s' of to_proj invalid." % to_proj) else: to_srid = string_to_srid[to_proj] to_proj = Proj(srs_to_mapnik_projection[string_to_srs[to_proj]]) if from_proj is None: from_proj = Setting.get('projection', 'EPSG:900913') from_proj = Proj(srs_to_mapnik_projection[from_proj]) elif from_proj not in string_to_srs: raise ValueError("Value '%s' of from_proj invalid." % from_proj) else: from_proj = Proj(srs_to_mapnik_projection[string_to_srs[from_proj]]) p = Point(*transform(from_proj, to_proj, x, y)) p.srid = to_srid return p
def process_request(self, request): language = None if Setting.get('show_language_picker'): # We don't want the regular lizard5 per-site configured language, # we want the user's preferred language instead. language = get_language_from_request(request) if language is None: # Look for the per-site Setting object. language = Setting.get('language_code') translation.activate(language) request.LANGUAGE_CODE = translation.get_language()
def search(self, google_x, google_y, radius=None): """Return list of dict {'distance': <float>, 'timeserie': <timeserie>} of closest fews point that matches x, y, radius. """ def distance(x1, y1, x2, y2): return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) named_locations = self._locations() result = [] for named_location in named_locations: x, y = coordinates.wgs84_to_google( named_location['longitude'], named_location['latitude']) dist = distance(google_x, google_y, x, y) if dist < radius: result.append( { 'distance': dist, 'name': self._location_plus_parameter( named_location['location']), 'shortname': named_location['location'], 'workspace_item': self.workspace_item, 'identifier': { 'location': named_location['locationid'] }, 'google_coords': (x, y), 'object': None }) result.sort(key=lambda item: item['distance']) # Default max 3. max_results = int(Setting.get('fewsjdbc_search_max_results', 3)) return result[:max_results]
def get_datasource(): """Return the datasource used for the timeseries.""" # The choices made are defined as a lizard-map setting. choices_made_json = Setting.get("neerslagradar_datasource") # Get the datasource return datasource.datasource( datasource.ChoicesMade(json=choices_made_json))
def default_symbol_mask(): return (Setting.get("FANCYLAYERS_DEFAULT_SYMBOL_MASK") or DEFAULT_SYMBOL_MASK).encode('utf8')
def default_symbol_name(): return (Setting.get("FANCYLAYERS_DEFAULT_SYMBOL_NAME") or DEFAULT_SYMBOL_NAME).encode('utf8')
def default_color(): return Setting.get("FANCYLAYERS_DEFAULT_COLOR") or DEFAULT_COLOR