Beispiel #1
0
 def aclWidget(self):
     if not self.desc.currentPhoto():
         return ''
     import access
     reload(access)
     return access.accessControlWidget(self.graph, self.agent,
                                       self.desc.currentPhoto())
Beispiel #2
0
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')
Beispiel #3
0
 def aclWidget(self):
     if not self.desc.currentPhoto():
         return ''
     import access
     reload(access)
     return access.accessControlWidget(self.graph, self.agent,
                                       self.desc.currentPhoto())
Beispiel #4
0
 def setAclWidget(self):
     """
     access for the whole displayed set
     """
     try:
         setUri = self.desc.canonicalSetUri()
     except NoSetUri:
         return ''
     import access
     reload(access)
     return access.accessControlWidget(self.graph, self.agent, setUri)
Beispiel #5
0
 def setAclWidget(self):
     """
     access for the whole displayed set
     """
     try:
         setUri = self.desc.canonicalSetUri()
     except NoSetUri:
         return ''
     import access
     reload(access)
     return access.accessControlWidget(self.graph, self.agent, setUri)
Beispiel #6
0
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')