def __call__(self, **kw): data = {} context = self.context if IPlace.providedBy(context): pid = context.getId() # local id like "149492" elif ILocation.providedBy(context) or IName.providedBy(context): pid = aq_parent(aq_inner(context)).getId() else: pid = None if pid is not None: annotations = self._get_annotations(pid) if annotations is None: self.request.response.setStatus(500) annotations = [] else: self.request.response.setStatus(200) else: annotations = [] self.request.response.setStatus(404) data = dict( pid=pid, annotations=annotations) self.request.response.setHeader('Content-Type', 'application/json') return json.dumps(data)
def placeId(self): ctx = self.context if IPlace.providedBy(ctx): return ctx.getId() elif ILocation.providedBy(ctx) or IName.providedBy(ctx): return aq_parent(aq_inner(ctx)).getId() else: return None
def isPrecise(o): try: return ( ILocation.providedBy(o) and o._getGeometryRaw() and IGeoreferenced(o) ) except (ValueError, NotLocatedError): return False
def geometry(o): """Returning a mapping or None.""" if ILocation.providedBy(o) and o._getGeometryRaw(): geom = json.loads(o.getGeometryJSON()) g = shape(geom) geom.update(bbox=g.bounds) return geom else: return None
def __call__(self, **kw): data = {} context = self.context if IPlace.providedBy(context): pid = context.getId() # local id like "149492" elif ILocation.providedBy(context) or IName.providedBy(context): pid = aq_parent(aq_inner(context)).getId() else: pid = "*" tag = "pleiades:*=" + pid try: related = self._get_related_photos(pid) except FlickrResponseError: related = {} if related: total = 0 photos = related.get('photos') if photos: total = int(photos['total']) data['related'] = dict(total=total, url=FLICKR_TAGS_BASE + tag) try: pool = self._get_pool_photos(pid) except FlickrResponseError as e: pool = {} self.request.response.setStatus(e.message) if pool: total = 0 photos = pool.get('photos') if photos: total = int(photos['total']) if total < 1: data['portrait'] = None else: # Sort found photos by number of views, descending most_viewed = sorted(photos['photo'], key=lambda p: p['views'], reverse=True) if pid == "*": photo = choice(most_viewed) else: photo = most_viewed[0] title = "%s by %s." % (photo['title'].rstrip(" ."), photo['ownername']) data['portrait'] = dict(title=title, img=IMG_TMPL % photo, page=PAGE_TMPL % photo) self.request.response.setHeader('Content-Type', 'application/json') return simplejson.dumps(data)
def __call__(self, **kw): data = {} context = self.context if IPlace.providedBy(context): pid = context.getId() # local id like "149492" elif ILocation.providedBy(context) or IName.providedBy(context): pid = aq_parent(aq_inner(context)).getId() else: pid = "*" tag = "pleiades:*=" + pid try: related = self._get_related_photos(pid) except FlickrResponseError: related = {} if related: total = 0 photos = related.get('photos') if photos: total = int(photos['total']) data['related'] = dict(total=total, url=FLICKR_TAGS_BASE + tag) try: pool = self._get_pool_photos(pid) except FlickrResponseError as e: pool = {} self.request.response.setStatus(e.message) if pool: total = 0 photos = pool.get('photos') if photos: total = int(photos['total']) if total < 1: data['portrait'] = None else: # Sort found photos by number of views, descending most_viewed = sorted( photos['photo'], key=lambda p: p['views'], reverse=True ) if pid == "*": photo = choice(most_viewed) else: photo = most_viewed[0] title = "%s by %s." % ( photo['title'].rstrip(" ."), photo['ownername'] ) data['portrait'] = dict( title=title, img=IMG_TMPL % photo, page=PAGE_TMPL % photo ) self.request.response.setHeader('Content-Type', 'application/json') return simplejson.dumps(data)
def __call__(self, **kw): data = {} context = self.context if IPlace.providedBy(context): pid = context.getId() # local id like "149492" elif ILocation.providedBy(context) or IName.providedBy(context): pid = aq_parent(aq_inner(context)).getId() else: pid = None if pid is not None: try: annotations = client.annotations(pid) self.request.response.setStatus(200) except client.PelagiosAPIError, e: annotations = [] log.exception("Pelagios API Error: %s", str(e)) self.request.response.setStatus(500)
def isGridded(o): return ILocation.providedBy(o) and o.getLocation().startswith( 'http://atlantides.org/capgrids')
def isPrecise(o): try: return (ILocation.providedBy(o) and o._getGeometryRaw() and IGeoreferenced(o)) except (ValueError, NotLocatedError): return False
def isGridded(o): return ILocation.providedBy(o) and o.getLocation( ).startswith('http://atlantides.org/capgrids')