def __get__(self, obj, objtype=None): if obj is None: return self val = obj.value(self.predicate) # if we got a 'none' return as is (don't convert to "None") if val is None: return val if self.datatype is not None: val = rdflib.Literal(val, datatype=self.datatype).toPython() elif isinstance(val, rdflib.Literal): val = val.toPython() if self.normalize: val = normalize_whitespace(val) return val
def map_js(request): """Location data for places associated with the people connected to the Belfast Group or mentioned in the digitized Group sheets on the site, returned as JSON for use with :meth:`map`. """ places = find_places() markers = [] for pl in places: # lat/long should have been added in rdf data prep, but # check just in case, because missing lat/long breaks the map if not all([pl.latitude, pl.longitude]): continue tags = [] # if this place is mentioned in poems, add title/link to description texts = "" if pl.texts: texts = "<p>Mentioned in %s.</p>" % ( "; ".join('<a href="%s">%s</a>' % (t.identifier, normalize_whitespace(t.name)) for t in pl.texts) ) tags.append("text") for t in pl.texts: if t.author is not None: tags.append(unicode(t.author.identifier)) people = "" if pl.people: people = "<p>Connected people: %s.</p>" % ( "; ".join( '<a href="%s">%s</a>' % (p.identifier, p.fullname) if p.local_uri else p.fullname for p in pl.people ) ) # possibly put specific slugs here for filtering tags.append("people") tags.extend([unicode(p.identifier) for p in pl.people if p.local_uri]) # if this place is not identifiably connected to a person or place # in our data, skip it (for now at least) if not people and not texts: continue # flag to indicate the type of icon that should be used on the map if people and texts: icon = "bio-text" elif people: icon = "bio" else: icon = "text" info = { "latitude": pl.latitude, "longitude": pl.longitude, "title": pl.name, # text (html) content to be shown when clicking on a marker "content": """<b>%s</b> %s %s""" % (pl.name, people, texts), # properties to affect display "tags": tags, "icon": icon, } markers.append(info) map_data = {"markers": markers} return HttpResponse(json.dumps(map_data), content_type="application/json")