예제 #1
0
    def document_to_cendari(self, doc):
        id=str(semantic_uri(doc))
        contributors = set(doc.get_all_updaters())
        contributors.add(doc.creator)
        topics=self.collect_topics(doc)
        title=xhtml_to_text(doc.description)
        if doc.has_transcript():
            text = xhtml_to_text(doc.transcript.content)
        else:
            text=''
        document = {
            'uri': id,
            'artifact': 'document',
            'application': 'nte',
            'contributor': [
                {"name": c.username, "email": c.email} for c in contributors
            ],
            'creator': {
                "name": doc.creator.username,
                "email": doc.creator.email
            },
            'created': doc.created,
            'updated': doc.last_updated,
            'format': 'application/xhtml+xml', # nothing better eg. xhtml+rdfa
            'title': title,
            'text': text,
            'project': doc.project.slug,
            'groups_allowed': doc.project.slug,
             # FIXME when I know how to test public projects
            'users_allowed': [ doc.creator.username ],
        }
        if topics['EVT']: document['date'] = topics['EVT']
        if topics['ORG']: document['org'] = topics['ORG']
        if topics['PER']: document['person'] = topics['PER']
        if topics['PLA']:
            pla = topics['PLA']
            document['place'] = map(lambda p: p['name'], pla)
            document['location'] = [l['location'] for l in pla if 'location' in l ]
        # 'publisher': publishers,
        if topics['PUB']: document['ref'] = topics['PUB']
        if topics['TAG']: document['tag'] = topics['TAG']
#        if document is not None:
#            self.es.index(self.name, 'document', document, id, refresh=True)
        return document
예제 #2
0
 def topic_to_cendari(self, topic):
     if not topic.topic_node: return
     id=str(semantic_uri(topic))
     type = topic.topic_node.type
     document = {
         'uri': id,
         'application': 'nte',
         'title': topic.preferred_name,
         'creator': topic.creator.username,
         'created': topic.created,
         'updated': topic.last_updated,
         'project': topic.project.slug,
         'groups_allowed': topic.project.slug,
     }
     if topic.summary: document['text'] = xhtml_to_text(topic.summary)
     loc = semantic_query_latlong(topic)
     if loc: document['location'] = format_location(loc)
     if type in topic_schema:
         document['class'] = topic_schema[type]
     if type in topic_field:
         document[topic_field[type]] = topic.preferred_name
     if topic.date:
         document['date'] = topic.date
     return document
예제 #3
0
def as_text(tree):
    if tree is None:
        return ''
    return utils.xhtml_to_text(tree)
 def forwards(self, orm):
     for note in orm.Note.objects.all():
         if note.title == u'':
             note.title = utils.truncate(
                 utils.xhtml_to_text(note.content), 60)
             note.save()
예제 #5
0
def as_text(tree):
    if tree is None:
        return ''
    return utils.xhtml_to_text(tree)