Django template tag to hash/map a value to a unique web color.
Just a quick and dirty solution I needed to uniquely color code entries in a selection form list. It uses the hashlib to generate it's coloring.
- template
- django
- coloring
Just a quick and dirty solution I needed to uniquely color code entries in a selection form list. It uses the hashlib to generate it's coloring.
Unfortunately the built in Django JSON serialzer encodes GeoDjango GeometyrField as WKT text. This snippet extends django's serializer and adds support for GEOJson format. Built in JSON serializer output: [{"pk": 1, ... "geopoint": "POINT (-76.5060419999999937 44.2337040000000030)" ... }] GeoJSON serializer ouput: [{"pk": 1, ... "geopoint": {"type": "Point", "coordinates": [-76.503296000000006, 44.230956999999997], "__GEOSGeometry__": [ "__init__", [ "SRID=4326;POINT (-75.5129950000000036 44.2442360000000008)" ] ] }] Note: the "__GEOSGeometry__" is a class hint as defined by JSON-RCP and used during deserilization.
Adding this mixing to your existing class based views allows for outputting of queries into any registered serialzier format -- very handy for dynamic JS based GUI on the JSON format. This generic view mixing was created on our last project which required a fancy JS based user experience and yet also needed to be accessible through non JS enabled browsers.
**Please use the updated version http://djangosnippets.org/snippets/2596/** Unfortunately the built in Django JSON serialzer encodes GeoDjango GeometyrField as simple text. This snippet extends django's serializer and adds support for GeoJson format. Built in JSON serializer output: [{"pk": 1, ... "geopoint": "POINT (-76.5060419999999937 44.2337040000000030)" ... }] GeoJSON serializer ouput: [{"pk": 1, ... "geopoint": {"type": "Point", "coordinates": [-76.503296000000006, 44.230956999999997]}}]
Small changes to [Snippet 1694](http://djangosnippets.org/snippets/1694/) to that QueryAPI works for django 1.2 and higher. Changes: * Replaced `get_db_prep_value` with `get_prep_value`. * Replaced `get_db_prep_lookup` with modified `get_prep_lookup`.
danielsokolowski has posted 5 snippets.