Example #1
0
File: story.py Project: drewp/photo
def sizeAttrs(graph, foafUser, uri, sizeName):
    # this is similar to serve.ImageSizeResponse.renderHTTP, to avoid
    # an http call
    size = sizes[sizeName]
    r = MediaResource(graph, uri)
    w, h = r.getSize(size)
    return {'width' : w, 'height' : h}
Example #2
0
    def GET(self):
        uri = URIRef(web.input()['uri'])
        r = MediaResource(graph, uri)
        size = r.getSize(sizes["screen"])

        try:
            created = photoCreated(graph, uri)
            prettyDate = created.date().isoformat()
        except ValueError:
            prettyDate = "(unknown date)"
            
        tmpl = loader.load("sharesingle.html")
        stream = tmpl.generate(
            title="photo",
            prettyDate=prettyDate,
            bestJqueryLink=networking.jqueryLink(
                web.ctx.environ.get('HTTP_X_FORWARDED_FOR', '')),
            featuredImg=Markup('<img src="%s" width="%s" height="%s"/>' %
                               (localSite(uri)+"?size=screen",
                                size[0], size[1])),
            loginWidget=Markup(networking.getLoginBarSync(
                web.ctx.environ.get('HTTP_COOKIE', ''))),
            actionsAllowed=[],
            otherSizeLinks=[],
            link="l",
            allowedToWriteMeta=False,
            pageJson="",
            )
        return (''.join(serializer(stream))).encode('utf8')
Example #3
0
File: story.py Project: drewp/photo
def sizeAttrs(graph, foafUser, uri, sizeName):
    # this is similar to serve.ImageSizeResponse.renderHTTP, to avoid
    # an http call
    size = sizes[sizeName]
    r = MediaResource(graph, uri)
    w, h = r.getSize(size)
    return {'width': w, 'height': h}
Example #4
0
    def featured(self):
        current = self.desc.currentPhoto()
        if current is None:
            return ''
        currentLocal = localSite(current)
        _, nextUri = self.prevNext()

        feat = MediaResource(self.graph, current)

        if feat.isVideo():
            progress = feat.videoProgress()
            if progress is Done:
                w, h = feat.getSize(Video2)
                return dict(video=dict(sources=[
                    dict(src=currentLocal + "?size=video2", type='video/webm'),
                    dict(src=currentLocal + "?size=video2&type=mp4",
                         type='video/mp4')
                ],
                                       width=600,
                                       height=600 / w * h))
            else:
                return dict(videoNotReady=dict(progress=progress,
                                               failed=isinstance(
                                                   progress, FailedStatus)))
        else:
            try:
                size = feat.getSize(sizes["large"])
            except (ValueError, IOError) as e:
                log.warn('current=%r', current)
                import traceback
                traceback.print_exc()
                size = (0, 0)
            marg = (602 - 2 - size[0]) // 2
            return dict(image=dict(
                nextClick=self.desc.otherImageUrl(nextUri),
                src=currentLocal + "?size=large",
                w=size[0],
                h=size[1],
                marg=marg,
                alt=self.graph.label(current),
            ))
Example #5
0
    def featured(self):
        current = self.desc.currentPhoto()
        if current is None:
            return ''
        currentLocal = localSite(current)
        _, nextUri = self.prevNext()

        feat = MediaResource(self.graph, current)

        if feat.isVideo():
            progress = feat.videoProgress()
            if progress is Done:
                w, h = feat.getSize(Video2)
                return dict(
                    video=dict(
                        sources=[
                            dict(src=currentLocal+"?size=video2", type='video/webm'),
                            dict(src=currentLocal+"?size=video2&type=mp4", type='video/mp4')
                        ],
                        width=600,
                        height=600 / w * h))
            else:
                return dict(videoNotReady=dict(
                    progress=progress,
                    failed=isinstance(progress, FailedStatus)))
        else:
            try:
                size = feat.getSize(sizes["large"])
            except (ValueError, IOError) as e:
                log.warn('current=%r', current)
                import traceback;traceback.print_exc()
                size = (0,0)
            marg = (602 - 2 - size[0]) // 2
            return dict(image=dict(
                nextClick=self.desc.otherImageUrl(nextUri),
                src=currentLocal+"?size=large",
                w=size[0], h=size[1],
                marg=marg,
                alt=self.graph.label(current),
                ))
Example #6
0
 def photosInSetPlus(self):
     """for use by other tools who want to draw some photos
     """
     out = []
     for p in self.desc.photos():
         r = MediaResource(self.graph, p)
         try:
             s = r.getSize(sizes["thumb"])
             thumbSize = {"thumbSize": dict(w=s[0], h=s[1])}
         except (ValueError, IOError, subprocess.CalledProcessError):
             thumbSize = {}
         out.append(
             dict(link=absoluteSite(self.desc.otherImageUrl(p)),
                  uri=p,
                  facts=self.facts(p),
                  thumb="%s?size=thumb" % p,
                  screen="%s?size=screen" % p,
                  isVideo=self.desc.isVideo(p)))
         out[-1].update(thumbSize)
     return out
Example #7
0
 def photosInSetPlus(self):
     """for use by other tools who want to draw some photos
     """
     out = []
     for p in self.desc.photos():
         r = MediaResource(self.graph, p)
         try:
             s = r.getSize(sizes["thumb"])
             thumbSize = {"thumbSize" : dict(w=s[0], h=s[1])}
         except (ValueError, IOError, subprocess.CalledProcessError):
             thumbSize = {}
         out.append(dict(
             link=absoluteSite(self.desc.otherImageUrl(p)),
             uri=p,
             facts=self.facts(p),
             thumb="%s?size=thumb" % p,
             screen="%s?size=screen" % p,
             isVideo=self.desc.isVideo(p)
             ))
         out[-1].update(thumbSize)
     return out