def renderPage(graph, topic, foafUser, cookie): isVideo = {} photos = photosWithTopic(graph, {'topic':topic}, isVideo=isVideo) filtered = starFilter(graph, 'only', foafUser, photos) if filtered: photos = filtered tmpl = loader.load("story.html") rows = [] knownFacts = set() commentJs = '1' for photo in photos: if not access.viewable(graph, photo, foafUser): log.debug("story %s NeedsMoreAccess because %s can't view %s", topic, foafUser, photo) raise access.NeedsMoreAccess() try: date = photoCreated(graph, photo).date() except ValueError: date = None else: if not rows or rows[-1]['date'] != date: rows.append(dict(type='date', date=date)) facts = json.loads(syncServiceCall('facts', photo, foafUser)) factLines = [l['line'] for l in facts['factLines'] if not l['line'].startswith("Picture taken ")] factLines = [l for l in factLines if l not in knownFacts] knownFacts.update(factLines) commentHtml = syncServiceCall('comments', photo, foafUser, js=commentJs) if commentJs == '1': commentJs = '0' rows.append(dict( type='pic', date=date, uri=photo, # more stable than the row num as pics get added and removed: anchor=hashlib.md5(photo).hexdigest()[:8], factLines=factLines, isVideo=isVideo.get(photo, False), commentHtml=Markup(commentHtml), desc=graph.value(photo, RDFS.comment), )) accessControl = pystache.render( open("template/aclwidget.mustache").read(), access.accessControlWidget(graph, foafUser, topic)) stream = tmpl.generate( rows=rows, title=graph.value(topic, RDFS.label, any=True), localSite=localSite, loginBar=Markup(networking.getLoginBarSync(cookie)), accessControl=Markup(accessControl), dateRange=findDateRange(graph, photos), sizeAttrs=lambda uri, sizeName: sizeAttrs(graph, foafUser, uri, sizeName), ) return (''.join(serializer(stream))).encode('utf8')
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')
def loginWidget(self): return networking.getLoginBarSync(self.cookie)
def renderPage(graph, topic, foafUser, cookie): isVideo = {} photos = photosWithTopic(graph, {'topic': topic}, isVideo=isVideo) filtered = starFilter(graph, 'only', foafUser, photos) if filtered: photos = filtered tmpl = loader.load("story.html") rows = [] knownFacts = set() commentJs = '1' for photo in photos: if not access.viewable(graph, photo, foafUser): log.debug("story %s NeedsMoreAccess because %s can't view %s", topic, foafUser, photo) raise access.NeedsMoreAccess() try: date = photoCreated(graph, photo).date() except ValueError: date = None else: if not rows or rows[-1]['date'] != date: rows.append(dict(type='date', date=date)) facts = json.loads(syncServiceCall('facts', photo, foafUser)) factLines = [ l['line'] for l in facts['factLines'] if not l['line'].startswith("Picture taken ") ] factLines = [l for l in factLines if l not in knownFacts] knownFacts.update(factLines) commentHtml = syncServiceCall('comments', photo, foafUser, js=commentJs) if commentJs == '1': commentJs = '0' rows.append( dict( type='pic', date=date, uri=photo, # more stable than the row num as pics get added and removed: anchor=hashlib.md5(photo).hexdigest()[:8], factLines=factLines, isVideo=isVideo.get(photo, False), commentHtml=Markup(commentHtml), desc=graph.value(photo, RDFS.comment), )) accessControl = pystache.render( open("template/aclwidget.mustache").read(), access.accessControlWidget(graph, foafUser, topic)) stream = tmpl.generate( rows=rows, title=graph.value(topic, RDFS.label, any=True), localSite=localSite, loginBar=Markup(networking.getLoginBarSync(cookie)), accessControl=Markup(accessControl), dateRange=findDateRange(graph, photos), sizeAttrs=lambda uri, sizeName: sizeAttrs(graph, foafUser, uri, sizeName), ) return (''.join(serializer(stream))).encode('utf8')