src/ldt/ldt/text/models.py
changeset 718 5e27a39d3742
parent 716 31dc2726ca51
child 731 aba6c30b6d2a
equal deleted inserted replaced
717:d66abfc1cb87 718:5e27a39d3742
     1 from annotindexer import AnnotIndexer
       
     2 from django.db import models
     1 from django.db import models
     3 from django.utils.translation import ugettext_lazy as _
     2 from django.utils.translation import ugettext_lazy as _
     4 from tagging.models import Tag
     3 from tagging.models import Tag
     5 from utils import generate_uuid
     4 from utils import generate_uuid
     6 import ldt.indexation
       
     7 import lxml
     5 import lxml
     8 import tagging.fields
     6 import tagging.fields
     9 #from django.core.management.validation import max_length
     7 #from django.core.management.validation import max_length
    10 
     8 
    11 def Property(func):
     9 def Property(func):
   115 
   113 
   116     @staticmethod
   114     @staticmethod
   117     def create_annotation(external_id, uri=None, tags=None, title=None, description=None, text=None, color=None, creator=None, contributor=None, creation_date=None, update_date=None):
   115     def create_annotation(external_id, uri=None, tags=None, title=None, description=None, text=None, color=None, creator=None, contributor=None, creation_date=None, update_date=None):
   118         annotation = Annotation(external_id=external_id, uri=uri, tags=tags, title=title, description=description, text=text, color=color, creator=creator, contributor=contributor, creation_date=creation_date, update_date=update_date)
   116         annotation = Annotation(external_id=external_id, uri=uri, tags=tags, title=title, description=description, text=text, color=color, creator=creator, contributor=contributor, creation_date=creation_date, update_date=update_date)
   119         annotation.save()
   117         annotation.save()
   120         annotation.index_annot()
       
   121         
   118         
   122         return annotation
   119         return annotation
   123 
   120 
   124 
       
   125     def delete(self):
       
   126         super(Annotation, self).delete()
       
   127         ldt.indexation.delete_document("external_id", self.external_id)
       
   128 
       
   129     def index_annot(self):
       
   130         writer = ldt.indexation.get_writer()
       
   131         try:
       
   132             annotl = [self, ]
       
   133             indexer = AnnotIndexer(annotl, writer)
       
   134             indexer.index_all()
       
   135         finally:
       
   136             writer.close()
       
   137 
       
   138     def update_index(self):
       
   139         ldt.indexation.delete_document("external_id", self.external_id)
       
   140         self.index_annot()
       
   141         
   121         
   142         
   122