1 import datetime |
1 import datetime |
|
2 from ldt.core.models import Document |
|
3 from ldt.security import get_current_user_or_admin, set_current_user, \ |
|
4 get_current_user |
|
5 from ldt.security.manager import SafeManager |
|
6 from ldt.security.models import SafeModel |
|
7 from ldt.utils import generate_hash, url as url_utils |
|
8 from ldt.utils.web_url_management import get_web_url |
2 import logging |
9 import logging |
3 import lxml.etree # @UnresolvedImport |
|
4 import mimetypes |
10 import mimetypes |
5 import os.path |
11 import os.path |
6 import re |
12 import re |
7 from shutil import move |
13 from shutil import move |
8 import uuid |
14 import uuid |
12 from django.contrib.auth.models import Group |
18 from django.contrib.auth.models import Group |
13 from django.core.files.storage import default_storage |
19 from django.core.files.storage import default_storage |
14 from django.db import models |
20 from django.db import models |
15 from django.utils.translation import ugettext_lazy as _ |
21 from django.utils.translation import ugettext_lazy as _ |
16 from guardian.shortcuts import assign_perm, remove_perm, get_perms |
22 from guardian.shortcuts import assign_perm, remove_perm, get_perms |
|
23 import lxml.etree # @UnresolvedImport |
17 from sorl.thumbnail import ImageField |
24 from sorl.thumbnail import ImageField |
18 from taggit.managers import TaggableManager |
25 from taggit.managers import TaggableManager |
19 |
26 |
20 from ldt.core.models import Document |
|
21 from ldt.security import get_current_user_or_admin, set_current_user, \ |
|
22 get_current_user |
|
23 from ldt.security.manager import SafeManager |
|
24 from ldt.security.models import SafeModel |
|
25 from ldt.utils import generate_hash, url as url_utils |
|
26 from ldt.utils.web_url_management import get_web_url |
|
27 from utils import create_ldt, copy_ldt, create_empty_iri, update_iri, \ |
27 from utils import create_ldt, copy_ldt, create_empty_iri, update_iri, \ |
28 generate_uuid |
28 generate_uuid |
29 |
29 |
30 from .events import post_project_save |
30 from .events import post_project_save |
|
31 |
31 |
32 |
32 logger = logging.getLogger(__name__); |
33 logger = logging.getLogger(__name__); |
33 |
34 |
34 class Author(SafeModel): |
35 class Author(SafeModel): |
35 |
36 |
178 title = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('content.title')) |
179 title = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('content.title')) |
179 description = models.TextField(null=True, blank=True, verbose_name=_('content.description')) |
180 description = models.TextField(null=True, blank=True, verbose_name=_('content.description')) |
180 authors = models.ManyToManyField("Author", blank=True, verbose_name=_('content.authors')) |
181 authors = models.ManyToManyField("Author", blank=True, verbose_name=_('content.authors')) |
181 duration = models.IntegerField(null=True, blank=True, verbose_name=_('content.duration')) |
182 duration = models.IntegerField(null=True, blank=True, verbose_name=_('content.duration')) |
182 content_creation_date = models.DateTimeField(null=True, blank=True, verbose_name=_('content.content_creation_date')) |
183 content_creation_date = models.DateTimeField(null=True, blank=True, verbose_name=_('content.content_creation_date')) |
183 tags = TaggableManager() |
184 tags = TaggableManager(blank=True) |
184 media_obj = models.ForeignKey("Media", blank=True, null=True) |
185 media_obj = models.ForeignKey("Media", blank=True, null=True) |
185 image = ImageField(upload_to="thumbnails/contents/", default=get_content_image_default, max_length=200) |
186 image = ImageField(upload_to="thumbnails/contents/", default=get_content_image_default, max_length=200) |
186 front_project = models.ForeignKey("Project", null=True, blank=True) |
187 front_project = models.ForeignKey("Project", null=True, blank=True) |
187 |
188 |
188 class Meta: |
189 class Meta: |
530 return self.stat_annotation.nb_annotations |
531 return self.stat_annotation.nb_annotations |
531 |
532 |
532 return locals() |
533 return locals() |
533 |
534 |
534 nb_annotations = property(**nb_annotations()) |
535 nb_annotations = property(**nb_annotations()) |
|
536 |
|
537 def get_tags(self): |
|
538 return ",".join([t.name for t in self.tags.all()]) |
535 |
539 |
536 POL_INDICES = { |
540 POL_INDICES = { |
537 'pol_positive' : 0, |
541 'pol_positive' : 0, |
538 'pol_negative' : 1, |
542 'pol_negative' : 1, |
539 'pol_reference' : 2, |
543 'pol_reference' : 2, |
540 'pol_question' : 3, |
544 'pol_question' : 3, |
541 } |
545 } |
542 |
546 |
543 |
547 |
544 class ContentStat(models.Model): |
548 class ContentStat(models.Model): |
545 |
549 |
546 def __init__(self, *args, **kwargs): |
550 def __init__(self, *args, **kwargs): |
547 super(ContentStat, self).__init__(*args, **kwargs) |
551 super(ContentStat, self).__init__(*args, **kwargs) |
548 if self.annotation_volume_str is None and self.polemics_volume_str is None: |
552 if self.annotation_volume_str is None and self.polemics_volume_str is None: |
549 self.__init_empty_stat() |
553 self.__init_empty_stat() |
550 |
554 |
551 content = models.OneToOneField("Content", blank=False, null=False, related_name='stat_annotation', verbose_name=_("content_stat.content"), unique=True, db_index=True) |
555 content = models.OneToOneField("Content", blank=False, null=False, related_name='stat_annotation', verbose_name=_("content_stat.content"), unique=True, db_index=True) |
552 annotation_volume_str = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content_stat.annotations_volume")) |
556 annotation_volume_str = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content_stat.annotations_volume")) |
553 polemics_volume_str = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content_stat.polemics_volume")) |
557 polemics_volume_str = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content_stat.polemics_volume")) |
554 nb_annotations = models.IntegerField(null=False, blank=False, verbose_name=_('content.nb_annotation'), default=0, db_index=True) |
558 nb_annotations = models.IntegerField(null=False, blank=False, verbose_name=_('content.nb_annotation'), default=0, db_index=True) |
555 last_annotated = models.DateTimeField(default=datetime.datetime.now, verbose_name=_('content.last_annotated'), blank=True, null=True) #@UndefinedVariable |
559 last_annotated = models.DateTimeField(default=datetime.datetime.now, verbose_name=_('content.last_annotated'), blank=True, null=True) #@UndefinedVariable |
806 project_id = models.CharField(max_length=255, unique=False, blank=True, null=True, db_index=True) |
810 project_id = models.CharField(max_length=255, unique=False, blank=True, null=True, db_index=True) |
807 iri_id = models.CharField(max_length=255, unique=False, db_index=True) |
811 iri_id = models.CharField(max_length=255, unique=False, db_index=True) |
808 ensemble_id = models.CharField(max_length=512, unique=False, db_index=True) |
812 ensemble_id = models.CharField(max_length=512, unique=False, db_index=True) |
809 cutting_id = models.CharField(max_length=512, unique=False, db_index=True) |
813 cutting_id = models.CharField(max_length=512, unique=False, db_index=True) |
810 element_id = models.CharField(max_length=512, unique=False, db_index=True) |
814 element_id = models.CharField(max_length=512, unique=False, db_index=True) |
811 tags = TaggableManager() |
815 tags = TaggableManager(blank=True) |
812 title = models.CharField(max_length=2048, unique=False, null=True, blank=True) |
816 title = models.CharField(max_length=2048, unique=False, null=True, blank=True) |
813 duration = models.IntegerField(null=True) |
817 duration = models.IntegerField(null=True) |
814 start_ts = models.IntegerField(null=True) |
818 start_ts = models.IntegerField(null=True) |
815 author = models.CharField(max_length=1024, unique=False, null=True, blank=True) |
819 author = models.CharField(max_length=1024, unique=False, null=True, blank=True) |
816 date = models.CharField(max_length=128, unique=False, null=True, blank=True) |
820 date = models.CharField(max_length=128, unique=False, null=True, blank=True) |