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 viewable(self, uri, ctx): if os.environ.get('PHOTO_FORCE_LOGIN', ''): agent = URIRef(os.environ['PHOTO_FORCE_LOGIN']) else: agent = webuser.getUser(ctx) return access.viewable(self.graph, uri, agent)
def publicShareButton(self): if self.desc.currentPhoto() is None: return None # not absoluteSite() here, since i didn't want to make # separate shortener entries for test sites and the real one target = self.desc.currentPhoto()+"/single" short = hasShortUrlSync(target) if short: if access.viewable(self.graph, self.desc.currentPhoto(), FOAF.Agent): return dict(hasLink=dict(short=short)) return dict(makeLink=dict(show=True))
def publicShareButton(self): if self.desc.currentPhoto() is None: return None # not absoluteSite() here, since i didn't want to make # separate shortener entries for test sites and the real one target = self.desc.currentPhoto() + "/single" short = hasShortUrlSync(target) if short: if access.viewable(self.graph, self.desc.currentPhoto(), FOAF.Agent): return dict(hasLink=dict(short=short)) return dict(makeLink=dict(show=True))
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')