Пример #1
0
    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)
Пример #2
0
 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
Пример #3
0
 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
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
    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)