src/ldt/ldt/ldt_utils/models.py
author cavaliet
Fri, 24 Aug 2012 16:39:36 +0200
changeset 744 960e4d8d8acd
parent 741 45d814511958
child 795 923429f142ea
permissions -rwxr-xr-x
small change and V01.16
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
     1
from django.conf import settings
247
f98f1a6e15f1 Add a group to contain published projects
verrierj
parents: 244
diff changeset
     2
from django.contrib.auth.models import User, Group
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
     3
from django.db import models
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
     4
from django.utils.translation import ugettext_lazy as _
560
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
     5
from guardian.shortcuts import assign, remove_perm, get_perms
128
503e365a3af7 Starting 'group_management' branch (CAUTION : STILL SOME BUGS)
cavaliet
parents: 125
diff changeset
     6
from ldt.core.models import Document
560
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
     7
from ldt.security import (get_current_user_or_admin, set_current_user, 
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
     8
    get_current_user)
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
     9
from ldt.security.manager import SafeManager
240
a46cb257d8ee Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents: 235
diff changeset
    10
from ldt.security.models import SafeModel
314
1a8620e5ebb0 Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents: 286
diff changeset
    11
from sorl.thumbnail import ImageField
560
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
    12
from tagging.models import Tag
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    13
from utils import (create_ldt, copy_ldt, create_empty_iri, update_iri, 
330
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
    14
    generate_uuid)
731
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
    15
from ldt.utils import generate_hash 
354
ecd4d57d0b40 Last annotated contents can be retrieved using the field content.last_annotated
verrierj
parents: 349
diff changeset
    16
import datetime
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    17
import lxml.etree
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    18
import mimetypes
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    19
import os.path
560
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
    20
import re
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    21
import tagging.fields
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    22
import uuid
560
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
    23
#from ldt.core.models import Document, Owner
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    24
330
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
    25
240
a46cb257d8ee Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents: 235
diff changeset
    26
class Author(SafeModel):
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    27
731
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
    28
    handle = models.CharField(max_length=255, unique=True, blank=True, null=True)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    29
    email = models.EmailField(unique=False, blank=True, null=True)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    30
    firstname = models.CharField(max_length=512, blank=True, null=True)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    31
    lastname = models.CharField(max_length=512, blank=True, null=True)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    32
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    33
    def __unicode__(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    34
        return unicode(self.id) + " - " + self.handle + ", " + self.email + ", " + self.firstname + " " + self.lastname
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    35
244
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
    36
    class Meta:
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
    37
        permissions = (
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
    38
                       ('view_author', 'Can view author'),
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
    39
                       )
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
    40
240
a46cb257d8ee Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents: 235
diff changeset
    41
class Media(SafeModel):
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    42
    external_id = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('media.external_id'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    43
    external_permalink = models.URLField(max_length=1024, verify_exists=False, null=True, blank=True, verbose_name=_('media.external_permalink'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    44
    external_publication_url = models.URLField(max_length=1024, verify_exists=True, null=True, blank=True, verbose_name=_('media.external_publication_url'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    45
    external_src_url = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('media.external_src_url'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    46
    creation_date = models.DateTimeField(auto_now_add=True, verbose_name=_('media.creation_date'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    47
    media_creation_date = models.DateTimeField(null=True, blank=True, verbose_name=_('media.media_creation_date'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    48
    update_date = models.DateTimeField(auto_now=True, verbose_name=_('media.update_date'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    49
    videopath = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('media.videopath'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    50
    duration = models.IntegerField(null=True, blank=True, verbose_name=_('media.duration'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    51
    creator = models.ForeignKey(User, blank=True, null=True, verbose_name=_('media.creator'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    52
    description = models.TextField(null=True, blank=True, verbose_name=_('description'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    53
    title = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('title'))
731
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
    54
    src = models.CharField(max_length=1024, verbose_name=_('media.src'))
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
    55
    #TODO: use a fixed length char field
733
43c9571752f6 correct models. Add blank to generated fields
ymh <ymh.work@gmail.com>
parents: 731
diff changeset
    56
    src_hash = models.CharField(max_length=128, unique=True, verbose_name=_('media.src_hash'), blank=True)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    57
    mimetype_field = models.CharField(max_length=512, null=True, blank=True, verbose_name=_('media.mimetype'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    58
    
244
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
    59
    class Meta:
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
    60
        permissions = (
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
    61
                       ('view_media', 'Can view media'),
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
    62
                       )
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
    63
        
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    64
    def mimetype(): #@NoSelf
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    65
        def fget(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    66
            if self.mimetype_field :
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    67
                return self.mimetype_field
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    68
            elif self.src:
150
fd591c597e6d correct mimetype problem
ymh <ymh.work@gmail.com>
parents: 128
diff changeset
    69
                return mimetypes.guess_type(self.src.rstrip())[0]
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    70
            else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    71
                return None
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    72
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    73
        def fset(self, value):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    74
            self.mimetype_field = value
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    75
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    76
        return locals()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    77
    mimetype = property(**mimetype())
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    78
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    79
    def stream_src(): #@NoSelf
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    80
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    81
        def fget(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    82
            res_src = self.src.rstrip()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    83
            if self.videopath and self.videopath.startswith("rtmp://") and "mp3:" not in res_src and "mp4:" not in res_src:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    84
                extension = res_src.split(".")[-1]
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    85
                res_src = {
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    86
                    'flv': lambda s: s,
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    87
                    'mp3': lambda s: "%s:%s" % ("mp3", res_src[:-4]),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    88
                    'mp4': lambda s: "%s:%s" % ("mp4", res_src),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    89
                    'f4v': lambda s: "%s:%s" % ("mp4", res_src),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    90
                    'mov': lambda s: "%s:%s" % ("mp4", res_src),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    91
                }.get(extension, lambda s:s)(res_src)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    92
            return res_src
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    93
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    94
        return locals()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    95
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    96
    stream_src = property(**stream_src())
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    97
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
    98
    def save(self, *args, **kwargs):
731
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
    99
        self.src_hash = generate_hash(self.src)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   100
        super(Media, self).save(*args, **kwargs)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   101
        for content in self.content_set.all():
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   102
            content.sync_iri_file()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   103
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   104
    def __unicode__(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   105
        strings = []
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   106
        if self.title:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   107
            strings.append(unicode(self.title))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   108
        else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   109
            strings.append(unicode(self.src))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   110
        if self.external_id:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   111
            strings.append(unicode(self.external_id))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   112
        return "|".join(strings)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   113
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   114
244
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
   115
class ContentManager(SafeManager):
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
   116
    
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
   117
    def __init__(self):
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
   118
        super(ContentManager, self).__init__(check_perm=False)
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
   119
        
125
5c3ed9c919bb New search feature on top right corner. Advanced search included in published projects tab. Colored icons. Change css to avoid scroll on contents and projects table.
cavaliet
parents: 112
diff changeset
   120
    def get_by_natural_key(self, iri_id):
5c3ed9c919bb New search feature on top right corner. Advanced search included in published projects tab. Colored icons. Change css to avoid scroll on contents and projects table.
cavaliet
parents: 112
diff changeset
   121
        return self.get(iri_id=iri_id)
5c3ed9c919bb New search feature on top right corner. Advanced search included in published projects tab. Colored icons. Change css to avoid scroll on contents and projects table.
cavaliet
parents: 112
diff changeset
   122
240
a46cb257d8ee Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents: 235
diff changeset
   123
class Content(SafeModel):
125
5c3ed9c919bb New search feature on top right corner. Advanced search included in published projects tab. Colored icons. Change css to avoid scroll on contents and projects table.
cavaliet
parents: 112
diff changeset
   124
    objects = ContentManager()
5c3ed9c919bb New search feature on top right corner. Advanced search included in published projects tab. Colored icons. Change css to avoid scroll on contents and projects table.
cavaliet
parents: 112
diff changeset
   125
    
731
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
   126
    iri_id = models.CharField(max_length=255, unique=True, default=generate_uuid, verbose_name=_('content.iri_id'))
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   127
    iriurl = models.CharField(max_length=1024, verbose_name=_('content.iriurl'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   128
    creation_date = models.DateTimeField(auto_now_add=True, verbose_name=_('content.creation_date'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   129
    update_date = models.DateTimeField(auto_now=True, verbose_name=_('content.update_date'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   130
    title = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('content.title'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   131
    description = models.TextField(null=True, blank=True, verbose_name=_('content.description'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   132
    authors = models.ManyToManyField(Author, blank=True, verbose_name=_('content.authors'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   133
    duration = models.IntegerField(null=True, blank=True, verbose_name=_('content.duration'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   134
    content_creation_date = models.DateTimeField(null=True, blank=True, verbose_name=_('content.content_creation_date'))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   135
    tags = tagging.fields.TagField(max_length=2048, null=True, blank=True)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   136
    media_obj = models.ForeignKey('Media', blank=True, null=True)
658
5f22830ffcd7 correct absolute path in images fields. add data migration
ymh <ymh.work@gmail.com>
parents: 570
diff changeset
   137
    image = ImageField(upload_to="thumbnails/contents/", default=settings.DEFAULT_CONTENT_ICON, max_length=200)
383
a99ea8eb8b9a Front projects are created with each new content
verrierj
parents: 354
diff changeset
   138
    front_project = models.ForeignKey('Project', null=True, blank=True)
340
5f919a978f50 Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents: 333
diff changeset
   139
        
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   140
    class Meta:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   141
        ordering = ["title"]
228
94fdb72b7d56 Users can add their own groups
verrierj
parents: 178
diff changeset
   142
        permissions = (
244
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
   143
                       ('view_content', 'Can view content'),
228
94fdb72b7d56 Users can add their own groups
verrierj
parents: 178
diff changeset
   144
                       )
470
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   145
        
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   146
    def __init__(self, *args, **kwargs):
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   147
        
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   148
        super(Content, self).__init__(*args, **kwargs)
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   149
        
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   150
        if not hasattr(Content, 'pol_positive'):
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   151
            self.__add_polemic_attributes()
125
5c3ed9c919bb New search feature on top right corner. Advanced search included in published projects tab. Colored icons. Change css to avoid scroll on contents and projects table.
cavaliet
parents: 112
diff changeset
   152
    
5c3ed9c919bb New search feature on top right corner. Advanced search included in published projects tab. Colored icons. Change css to avoid scroll on contents and projects table.
cavaliet
parents: 112
diff changeset
   153
    def natural_key(self):
5c3ed9c919bb New search feature on top right corner. Advanced search included in published projects tab. Colored icons. Change css to avoid scroll on contents and projects table.
cavaliet
parents: 112
diff changeset
   154
        return self.iri_id
5c3ed9c919bb New search feature on top right corner. Advanced search included in published projects tab. Colored icons. Change css to avoid scroll on contents and projects table.
cavaliet
parents: 112
diff changeset
   155
        
5c3ed9c919bb New search feature on top right corner. Advanced search included in published projects tab. Colored icons. Change css to avoid scroll on contents and projects table.
cavaliet
parents: 112
diff changeset
   156
    # added for import
5c3ed9c919bb New search feature on top right corner. Advanced search included in published projects tab. Colored icons. Change css to avoid scroll on contents and projects table.
cavaliet
parents: 112
diff changeset
   157
    def get_by_natural_key(self, iri_id):
5c3ed9c919bb New search feature on top right corner. Advanced search included in published projects tab. Colored icons. Change css to avoid scroll on contents and projects table.
cavaliet
parents: 112
diff changeset
   158
        return self.get(iri_id=iri_id)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   159
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   160
    def get_duration(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   161
        if self.duration is None:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   162
            doc = lxml.etree.parse(self.iri_file_path())
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   163
            res = doc.xpath("/iri/body/medias/media[@id='video']/video")
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   164
            if len(res) > 0:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   165
                try:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   166
                    self.duration = int(res[0].get(u'dur', 0) or 0)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   167
                except:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   168
                    self.duration = 0
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   169
            else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   170
                self.duration = 0
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   171
            self.save()
344
76724cebff95 Merge with 631c0edee9ea995d0f2fa3b93742f715933c3800
verrierj
parents: 343 338
diff changeset
   172
        return self.duration    
76724cebff95 Merge with 631c0edee9ea995d0f2fa3b93742f715933c3800
verrierj
parents: 343 338
diff changeset
   173
    
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   174
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   175
    def mimetype(): #@NoSelf
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   176
        def fget(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   177
            if self.media_obj:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   178
                return self.media_obj.mimetype
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   179
            else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   180
                return None
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   181
        return locals()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   182
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   183
    mimetype = property(**mimetype())
718
5e27a39d3742 replace lucene by haystack, remove references to lucene
ymh <ymh.work@gmail.com>
parents: 715
diff changeset
   184
            
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   185
    def sync_iri_file(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   186
        # create iri file if needed
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   187
        created = False
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   188
        try:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   189
            iri_file_path = self.iri_file_path()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   190
            if not os.path.exists(iri_file_path):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   191
                dir = os.path.dirname(iri_file_path)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   192
                if not os.path.exists(dir):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   193
                    os.makedirs(dir)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   194
                created = True
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   195
                file = open(iri_file_path, "w")
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   196
                create_empty_iri(file, self, "IRI")
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   197
            else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   198
                created = False
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   199
                update_iri(iri_file_path, self, "IRI")
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   200
                
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   201
        except Exception, e:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   202
            if created:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   203
                if os.path.exists(iri_file_path):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   204
                    os.remove(iri_file_path)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   205
            raise e
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   206
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   207
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   208
    #TODO: better manage the change in .iri name and error scenario (save in temp file + rename
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   209
    def save(self, *args, **kwargs):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   210
        
384
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   211
        create_front_project = False
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   212
        # update it
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   213
        self.sync_iri_file()
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   214
        
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   215
        if not self.pk:
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   216
            create_front_project = True
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   217
              
383
a99ea8eb8b9a Front projects are created with each new content
verrierj
parents: 354
diff changeset
   218
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   219
        super(Content, self).save(*args, **kwargs)
383
a99ea8eb8b9a Front projects are created with each new content
verrierj
parents: 354
diff changeset
   220
        
384
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   221
        if create_front_project: 
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   222
            # We need a primary key for self in create_project, so
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   223
            # save() has to be called first
392
65c1898141da Front projects are created by admins
verrierj
parents: 384
diff changeset
   224
            self.create_front_project()
491
b0da8cecb6b3 View annot_content always finds a project
verrierj
parents: 482
diff changeset
   225
            assign('ldt_utils.change_content', get_current_user(), self)
b0da8cecb6b3 View annot_content always finds a project
verrierj
parents: 482
diff changeset
   226
232
2878499a372b Security layer moved to middleware and ldt_utils __init__ file
verrierj
parents: 231
diff changeset
   227
            
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   228
    def __unicode__(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   229
        return str(self.id) + ": " + self.iri_id
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   230
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   231
    def iri_url(self, web_url=settings.WEB_URL):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   232
        if 'http' in self.iriurl or 'https' in self.iriurl:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   233
            return self.iriurl
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   234
        else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   235
            return unicode(web_url) + unicode(settings.MEDIA_URL) + u"ldt/" + unicode(self.iriurl)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   236
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   237
    def iri_file_path(self):
112
9886ab183b09 add permalink + corrcetion config with static and media path. update urls
ymh <ymh.work@gmail.com>
parents: 111
diff changeset
   238
        return os.path.join(os.path.join(os.path.join(settings.MEDIA_ROOT, "ldt"), self.iri_id), os.path.basename(self.iriurl))
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   239
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   240
    def iri_url_template(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   241
        return "${web_url}${media_url}ldt/" + unicode(self.iri_id) + "/" + os.path.basename(self.iriurl)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   242
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   243
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   244
    def __get_empty_media(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   245
        if settings.EMPTY_MEDIA_EXTERNALID:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   246
            empty_media = Media.objects.get(external_id=settings.EMPTY_MEDIA_EXTERNALID)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   247
            return empty_media
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   248
        else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   249
            return None
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   250
            
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   251
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   252
    def stream_src(): #@NoSelf
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   253
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   254
        def fget(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   255
            if self.media_obj is not None:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   256
                return self.media_obj.stream_src
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   257
            else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   258
                empty_media = self.__get_empty_media()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   259
                if empty_media:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   260
                    return empty_media.stream_src
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   261
                else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   262
                    return ""
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   263
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   264
        return locals()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   265
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   266
    stream_src = property(**stream_src())
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   267
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   268
    def videopath(): #@NoSelf
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   269
        doc = """simulate videopath""" #@UnusedVariable
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   270
       
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   271
        def fget(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   272
            if self.media_obj is None:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   273
                empty_media = self.__get_empty_media()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   274
                if empty_media:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   275
                    return empty_media.videopath
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   276
                else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   277
                    return None
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   278
            else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   279
                return self.media_obj.videopath
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   280
           
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   281
        def fset(self, value):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   282
            if self.media_obj is not None:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   283
                self.media_obj.videopath = value
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   284
                      
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   285
        return locals()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   286
       
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   287
    videopath = property(**videopath())
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   288
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   289
    def src(): #@NoSelf
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   290
        doc = """simulate videopath""" #@UnusedVariable
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   291
       
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   292
        def fget(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   293
            if self.media_obj is None:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   294
                empty_media = self.__get_empty_media()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   295
                if empty_media:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   296
                    return empty_media.src
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   297
                else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   298
                    return None
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   299
            else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   300
                return self.media_obj.src
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   301
           
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   302
        def fset(self, value):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   303
            if self.media_obj is None or self.media_obj.src != value:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   304
                media, created = Media.objects.get_or_create(src=value, defaults={'src':value})                #@UnusedVariable
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   305
                self.media_obj = media
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   306
                self.save()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   307
                      
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   308
        return locals()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   309
       
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   310
    src = property(**src())
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   311
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   312
    def external_id(): #@NoSelf
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   313
        doc = """simulate externalid""" #@UnusedVariable
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   314
       
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   315
        def fget(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   316
            if self.media_obj is None:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   317
                empty_media = self.__get_empty_media()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   318
                if empty_media:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   319
                    return empty_media.external_id
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   320
                else: 
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   321
                    return None
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   322
            else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   323
                return self.media_obj.external_id
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   324
           
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   325
        def fset(self, value):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   326
            if self.media_obj is not None:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   327
                self.media_obj.external_id = value
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   328
                      
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   329
        return locals()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   330
       
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   331
    external_id = property(**external_id())
231
535ce952e51c Stub of html template for project creation containing a group selection
verrierj
parents: 229
diff changeset
   332
    
266
a35924820af7 Contents can be published for everyone
verrierj
parents: 264
diff changeset
   333
    def is_public(): #@NoSelf
a35924820af7 Contents can be published for everyone
verrierj
parents: 264
diff changeset
   334
        
a35924820af7 Contents can be published for everyone
verrierj
parents: 264
diff changeset
   335
        def fget(self):
271
99347d5275b6 Contents can be shared with groups
verrierj
parents: 266
diff changeset
   336
            if self.pk:
99347d5275b6 Contents can be shared with groups
verrierj
parents: 266
diff changeset
   337
                everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME)
99347d5275b6 Contents can be shared with groups
verrierj
parents: 266
diff changeset
   338
                if 'view_content' in get_perms(everyone, self):
99347d5275b6 Contents can be shared with groups
verrierj
parents: 266
diff changeset
   339
                    return True
266
a35924820af7 Contents can be published for everyone
verrierj
parents: 264
diff changeset
   340
            return False
a35924820af7 Contents can be published for everyone
verrierj
parents: 264
diff changeset
   341
        
a35924820af7 Contents can be published for everyone
verrierj
parents: 264
diff changeset
   342
        def fset(self, value):
271
99347d5275b6 Contents can be shared with groups
verrierj
parents: 266
diff changeset
   343
            if self.pk:
99347d5275b6 Contents can be shared with groups
verrierj
parents: 266
diff changeset
   344
                everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME)
99347d5275b6 Contents can be shared with groups
verrierj
parents: 266
diff changeset
   345
                if value:
458
5d35581192cb Little cleanup for migrations
verrierj
parents: 424
diff changeset
   346
                    assign('ldt_utils.view_content', everyone, self) 
5d35581192cb Little cleanup for migrations
verrierj
parents: 424
diff changeset
   347
                    assign('ldt_utils.view_media', everyone, self.media_obj)               
271
99347d5275b6 Contents can be shared with groups
verrierj
parents: 266
diff changeset
   348
                else:
458
5d35581192cb Little cleanup for migrations
verrierj
parents: 424
diff changeset
   349
                    remove_perm('ldt_utils.view_content', everyone, self)
5d35581192cb Little cleanup for migrations
verrierj
parents: 424
diff changeset
   350
                    remove_perm('ldt_utils.view_media', everyone, self.media_obj)
266
a35924820af7 Contents can be published for everyone
verrierj
parents: 264
diff changeset
   351
        
a35924820af7 Contents can be published for everyone
verrierj
parents: 264
diff changeset
   352
        return locals()
a35924820af7 Contents can be published for everyone
verrierj
parents: 264
diff changeset
   353
    
a35924820af7 Contents can be published for everyone
verrierj
parents: 264
diff changeset
   354
    is_public = property(**is_public())
392
65c1898141da Front projects are created by admins
verrierj
parents: 384
diff changeset
   355
    
65c1898141da Front projects are created by admins
verrierj
parents: 384
diff changeset
   356
    def create_front_project(self):
491
b0da8cecb6b3 View annot_content always finds a project
verrierj
parents: 482
diff changeset
   357
        old_user = get_current_user_or_admin()
392
65c1898141da Front projects are created by admins
verrierj
parents: 384
diff changeset
   358
            
491
b0da8cecb6b3 View annot_content always finds a project
verrierj
parents: 482
diff changeset
   359
        if old_user.is_superuser:
b0da8cecb6b3 View annot_content always finds a project
verrierj
parents: 482
diff changeset
   360
            admin = old_user
392
65c1898141da Front projects are created by admins
verrierj
parents: 384
diff changeset
   361
        else:
65c1898141da Front projects are created by admins
verrierj
parents: 384
diff changeset
   362
            admin = User.objects.filter(is_superuser=True)[0]
65c1898141da Front projects are created by admins
verrierj
parents: 384
diff changeset
   363
            
65c1898141da Front projects are created by admins
verrierj
parents: 384
diff changeset
   364
        set_current_user(admin)
411
d126a67897c0 Small bugfixes
verrierj
parents: 409
diff changeset
   365
        self.front_project = Project.create_project(admin, 'front project : %s' % self.title, [self], cuttings=['chapitrage', 'contributions'] )
515
d1be4a4f6639 Fix bugs in permissions
verrierj
parents: 505
diff changeset
   366
        self.front_project.publish(allow_write=True)            
d1be4a4f6639 Fix bugs in permissions
verrierj
parents: 505
diff changeset
   367
        self.save()
491
b0da8cecb6b3 View annot_content always finds a project
verrierj
parents: 482
diff changeset
   368
        set_current_user(old_user)
741
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   369
    
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   370
    
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   371
    def get_or_create_front_project(self):
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   372
        front_proj = self.front_project
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   373
        if front_proj:
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   374
            proj = front_proj
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   375
        else:
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   376
            # The main project for the content
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   377
            proj = Project.safe_objects.filter(contents__in=[self], state=2)
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   378
            if not proj:
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   379
                self.create_front_project()
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   380
                proj = self.front_project
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   381
            else:
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   382
                proj = proj[0]
45d814511958 Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents: 738
diff changeset
   383
        return proj
515
d1be4a4f6639 Fix bugs in permissions
verrierj
parents: 505
diff changeset
   384
409
e4855d669c55 First step of tag management for contents.
cavaliet
parents: 393
diff changeset
   385
    
e4855d669c55 First step of tag management for contents.
cavaliet
parents: 393
diff changeset
   386
    # Tag management
e4855d669c55 First step of tag management for contents.
cavaliet
parents: 393
diff changeset
   387
    def get_tags(self):
e4855d669c55 First step of tag management for contents.
cavaliet
parents: 393
diff changeset
   388
        return Tag.objects.get_for_object(self)
458
5d35581192cb Little cleanup for migrations
verrierj
parents: 424
diff changeset
   389
    
468
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   390
    
470
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   391
    # add polemic attributes and polemic attribute rates to class Content
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   392
    def __add_polemic_attributes(self):
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   393
        for element in POL_INDICES.keys():
470
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   394
            if element.startswith('pol_'):                    
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   395
                Content.add_to_class(element, property(self.__make_getter(element)))
470
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   396
                Content.add_to_class("%s_rate" % element, property(self.__make_rate(element)))  
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   397
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   398
    def __make_getter(self, i):
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   399
        def inner_getter(self):
551
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   400
            if self.stat_annotation is None:
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   401
                return 0;
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   402
            else:                
551
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   403
                l = self.stat_annotation.polemics_volume
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   404
                return l[POL_INDICES[i]]
470
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   405
        return inner_getter
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   406
        
470
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   407
    def __make_rate(self, i):
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   408
        def inner_rate(self):
551
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   409
            if self.stat_annotation is None or self.stat_annotation.nb_annotations <= 0:
470
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   410
                return 0
551
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   411
            return int(getattr(self, i) / float(self.stat_annotation.nb_annotations) * 100 )
470
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   412
        return inner_rate   
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   413
    
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   414
                    
551
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   415
    def annotation_volume(): #@NoSelf        
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   416
        def fget(self):
551
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   417
            if self.stat_annotation is None:
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   418
                return [0]*settings.DIVISIONS_FOR_STAT_ANNOTATION
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   419
            else:
551
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   420
                return self.stat_annotation.annotation_volume
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   421
                    
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   422
        return locals()
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   423
    
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   424
    annotation_volume = property(**annotation_volume())
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   425
    
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   426
    
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   427
    def nb_annotations(): #@NoSelf
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   428
        def fget(self):
551
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   429
            if self.stat_annotation is None:
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   430
                return 0
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   431
            else:
551
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   432
                return self.stat_annotation.nb_annotations
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   433
            
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   434
        return locals()
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   435
    
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   436
    nb_annotations = property(**nb_annotations())
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   437
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   438
POL_INDICES = {
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   439
    'pol_positive' : 0,
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   440
    'pol_negative' : 1,
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   441
    'pol_reference' : 2,
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   442
    'pol_question' : 3,               
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   443
}    
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   444
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   445
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   446
class ContentStat(models.Model):
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   447
    
551
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   448
    def __init__(self, *args, **kwargs):                
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   449
        super(ContentStat, self).__init__(*args, **kwargs)
551
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   450
        if self.annotation_volume_str is None and self.polemics_volume_str is None:
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   451
            self.__init_empty_stat()
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   452
    
551
c447d863b6ad change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents: 542
diff changeset
   453
    content = models.OneToOneField(Content, blank=False, null=False, related_name='stat_annotation', verbose_name=_("content_stat.content"), unique=True, db_index=True)
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   454
    annotation_volume_str = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content_stat.annotations_volume"))
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   455
    polemics_volume_str = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content_stat.polemics_volume"))
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   456
    nb_annotations = models.IntegerField(null=False, blank=False, verbose_name=_('content.nb_annotation'), default=0, db_index=True)
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   457
    last_annotated = models.DateTimeField(default=datetime.datetime.now, verbose_name=_('content.last_annotated'), blank=True, null=True) #@UndefinedVariable
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   458
    
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   459
    def __init_empty_stat(self):
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   460
        self.annotation_volume_str = ','.join(['0']*settings.DIVISIONS_FOR_STAT_ANNOTATION)
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   461
        self.polemics_volume_str = ','.join(['0']*len(settings.SYNTAX.keys()))
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   462
        self.nb_annotations = 0
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   463
        self.last_annotated = None
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   464
        
470
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   465
    def __list2str(self, l):
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   466
        return ','.join([str(c) for c in l])
470
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   467
        
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   468
    def __str2list(self, s):
b1dd78b59750 add all polemic attributes and polemic attribute rates on contents
verrierj
parents: 468
diff changeset
   469
        return [int(x) for x in s.split(',')] 
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   470
468
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   471
    def annotation_volume(): #@NoSelf
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   472
        
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   473
        def fget(self):
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   474
            return self.__str2list(self.annotation_volume_str)
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   475
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   476
        def fset(self, value):
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   477
            self.annotation_volume_str = self.__list2str(value)
468
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   478
            
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   479
        return locals()
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   480
    
482
c802e00c7131 Lot of bugfixes
verrierj
parents: 480
diff changeset
   481
    annotation_volume = property(**annotation_volume())
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   482
    
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   483
    def polemics_volume(): #@NoSelf
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   484
        
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   485
        def fget(self):
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   486
            return self.__str2list(self.polemics_volume_str)
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   487
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   488
        def fset(self, value):
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   489
            self.polemics_volume_str = self.__list2str(value)
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   490
            
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   491
        return locals()
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   492
    
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   493
    polemics_volume = property(**polemics_volume())
344
76724cebff95 Merge with 631c0edee9ea995d0f2fa3b93742f715933c3800
verrierj
parents: 343 338
diff changeset
   494
266
a35924820af7 Contents can be published for everyone
verrierj
parents: 264
diff changeset
   495
a35924820af7 Contents can be published for everyone
verrierj
parents: 264
diff changeset
   496
    
542
54dfa397baa3 export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents: 521
diff changeset
   497
    
240
a46cb257d8ee Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents: 235
diff changeset
   498
class Project(Document, SafeModel):  
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   499
    STATE_CHOICES = (
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   500
    (1, 'edition'),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   501
    (2, 'published'),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   502
    (3, 'moderated'),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   503
    (4, 'rejected'),
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   504
    (5, 'deleted')
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   505
    )
731
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
   506
    ldt_id = models.CharField(max_length=255, unique=True)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   507
    ldt = models.TextField(null=True)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   508
    title = models.CharField(max_length=1024)
467
a1e9f5e91791 Removed object AnnotationStat + stats are computed when projects are published/unpublished
verrierj
parents: 458
diff changeset
   509
    contents = models.ManyToManyField(Content)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   510
    creation_date = models.DateTimeField(auto_now_add=True)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   511
    modification_date = models.DateTimeField(auto_now=True)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   512
    created_by = models.CharField(_("created by"), max_length=70)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   513
    changed_by = models.CharField(_("changed by"), max_length=70)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   514
    state = models.IntegerField(choices=STATE_CHOICES, default=1)
342
17d615b49a91 Extend image fields size to 200 characters + minor bugs
verrierj
parents: 341
diff changeset
   515
    description = models.TextField(null=True, blank=True)    
658
5f22830ffcd7 correct absolute path in images fields. add data migration
ymh <ymh.work@gmail.com>
parents: 570
diff changeset
   516
    image = ImageField(upload_to="thumbnails/projects/", default=settings.DEFAULT_PROJECT_ICON, max_length=200)
314
1a8620e5ebb0 Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents: 286
diff changeset
   517
    
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   518
    class Meta:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   519
        ordering = ["title"]
228
94fdb72b7d56 Users can add their own groups
verrierj
parents: 178
diff changeset
   520
        permissions = (
231
535ce952e51c Stub of html template for project creation containing a group selection
verrierj
parents: 229
diff changeset
   521
                       ('view_project', 'Can view project'),
228
94fdb72b7d56 Users can add their own groups
verrierj
parents: 178
diff changeset
   522
                       )
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   523
560
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   524
    def __setattr__(self, name, value):
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   525
        super(Project, self).__setattr__(name,value)
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   526
        if name == "ldt" and hasattr(self, "__ldt_encoded"):
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   527
            del self.__ldt_encoded
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   528
        
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   529
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   530
    def __unicode__(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   531
        return unicode(self.id) + u"::" + unicode(self.ldt_id) + u"::" + unicode(self.title)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   532
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   533
    def get_description(self, doc=None):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   534
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   535
        if doc is None:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   536
            doc = lxml.etree.fromstring(self.ldt)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   537
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   538
        res = doc.xpath("/iri/project")
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   539
        if len(res) > 0:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   540
            return res[0].get(u'abstract')
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   541
        else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   542
            return None
232
2878499a372b Security layer moved to middleware and ldt_utils __init__ file
verrierj
parents: 231
diff changeset
   543
        
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   544
    def stream_mode(): #@NoSelf
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   545
        def fget(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   546
            modes = []
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   547
            for content in self.contents.all():
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   548
                mimetype = content.mimetype
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   549
                if mimetype:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   550
                    mode = mimetype.split("/")[0]
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   551
                    if "audio" == mode or "video" == mode:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   552
                        modes.append(mode)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   553
                    else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   554
                        modes.append("video")
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   555
                else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   556
                    modes.append("video")
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   557
            def filter_video(current, item):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   558
                if not current:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   559
                    return item
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   560
                elif current == item:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   561
                    return item
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   562
                else:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   563
                    return "video"
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   564
            return reduce(filter_video, modes)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   565
        return locals()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   566
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   567
    stream_mode = property(**stream_mode())
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   568
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   569
    @staticmethod
383
a99ea8eb8b9a Front projects are created with each new content
verrierj
parents: 354
diff changeset
   570
    def create_project(user, title, contents, description='', groups=[], set_icon=True, cuttings=[]):
128
503e365a3af7 Starting 'group_management' branch (CAUTION : STILL SOME BUGS)
cavaliet
parents: 125
diff changeset
   571
#        owner = Owner.objects.get(user=user) #@UndefinedVariable
503e365a3af7 Starting 'group_management' branch (CAUTION : STILL SOME BUGS)
cavaliet
parents: 125
diff changeset
   572
        owner = user
178
4b83c370dc8a Added project description and tooltip
verrierj
parents: 167
diff changeset
   573
        project = Project(title=title, owner=owner, description=description)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   574
        project.ldt_id = str(uuid.uuid1()) #@UndefinedVariable
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   575
        project.created_by = user.username
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   576
        project.changed_by = user.username
330
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   577
        project.state = 1                        
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   578
        project.save()
231
535ce952e51c Stub of html template for project creation containing a group selection
verrierj
parents: 229
diff changeset
   579
        assign('view_project', user, project)
330
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   580
        assign('change_project', user, project)           
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   581
                        
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   582
        for content in contents:
480
5cc5afa71d7e Minor bugs
verrierj
parents: 470
diff changeset
   583
            project.contents.add(content)        
333
4ddf8c0eeab4 Image size is checked before save + project image can be set manually
verrierj
parents: 330
diff changeset
   584
        
4ddf8c0eeab4 Image size is checked before save + project image can be set manually
verrierj
parents: 330
diff changeset
   585
        if set_icon:
4ddf8c0eeab4 Image size is checked before save + project image can be set manually
verrierj
parents: 330
diff changeset
   586
            project.set_icon()
330
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   587
        project.save()
384
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   588
               
383
a99ea8eb8b9a Front projects are created with each new content
verrierj
parents: 354
diff changeset
   589
        return create_ldt(project, user, cuttings)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   590
384
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   591
256
fd20ce3c5fbe Project are copied in the group they are displayed in group page
verrierj
parents: 247
diff changeset
   592
    def copy_project(self, user, title, description='', group=None):
fd20ce3c5fbe Project are copied in the group they are displayed in group page
verrierj
parents: 247
diff changeset
   593
        project = Project(title=title, owner=user, description=description)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   594
        project = copy_ldt(self, project, user)
229
fce9a02cc0a2 Basic access control for Projects
verrierj
parents: 228
diff changeset
   595
        assign('view_project', user, project)
fce9a02cc0a2 Basic access control for Projects
verrierj
parents: 228
diff changeset
   596
        assign('change_project', user, project)
256
fd20ce3c5fbe Project are copied in the group they are displayed in group page
verrierj
parents: 247
diff changeset
   597
        if group:
fd20ce3c5fbe Project are copied in the group they are displayed in group page
verrierj
parents: 247
diff changeset
   598
            assign('view_project', group, project)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   599
        for content in self.contents.all():
480
5cc5afa71d7e Minor bugs
verrierj
parents: 470
diff changeset
   600
            project.contents.add(content)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   601
        return project
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   602
    
384
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   603
    def publish(self, allow_write=False):
330
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   604
        if not self.pk:
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   605
            self.save()
247
f98f1a6e15f1 Add a group to contain published projects
verrierj
parents: 244
diff changeset
   606
        self.state = 2
f98f1a6e15f1 Add a group to contain published projects
verrierj
parents: 244
diff changeset
   607
        everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME)
f98f1a6e15f1 Add a group to contain published projects
verrierj
parents: 244
diff changeset
   608
        assign('ldt_utils.view_project', everyone, self)
384
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   609
        if allow_write:
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   610
            assign('ldt_utils.change_project', everyone, self)
330
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   611
        self.save()
247
f98f1a6e15f1 Add a group to contain published projects
verrierj
parents: 244
diff changeset
   612
        
f98f1a6e15f1 Add a group to contain published projects
verrierj
parents: 244
diff changeset
   613
    def unpublish(self):
349
63f729155d81 Enhance search and front template : add begin and duration to searched segments.
cavaliet
parents: 344
diff changeset
   614
        if not self.pk:
330
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   615
            self.save()
247
f98f1a6e15f1 Add a group to contain published projects
verrierj
parents: 244
diff changeset
   616
        self.state = 1
f98f1a6e15f1 Add a group to contain published projects
verrierj
parents: 244
diff changeset
   617
        everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME)
f98f1a6e15f1 Add a group to contain published projects
verrierj
parents: 244
diff changeset
   618
        remove_perm('ldt_utils.view_project', everyone, self)
384
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   619
        remove_perm('ldt_utils.change_project', everyone, self)
330
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   620
        self.save()
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   621
        
384
0e410517b311 Front projects are hidden from user interface
verrierj
parents: 383
diff changeset
   622
        
330
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   623
    def set_icon(self):
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   624
        default_image = os.path.basename(settings.DEFAULT_CONTENT_ICON)
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   625
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   626
        for content in self.contents.all():
458
5d35581192cb Little cleanup for migrations
verrierj
parents: 424
diff changeset
   627
            add_image = False
5d35581192cb Little cleanup for migrations
verrierj
parents: 424
diff changeset
   628
            try:
5d35581192cb Little cleanup for migrations
verrierj
parents: 424
diff changeset
   629
                current_image = content.image.file.name
5d35581192cb Little cleanup for migrations
verrierj
parents: 424
diff changeset
   630
            except IOError:
5d35581192cb Little cleanup for migrations
verrierj
parents: 424
diff changeset
   631
                add_image = True
5d35581192cb Little cleanup for migrations
verrierj
parents: 424
diff changeset
   632
            
5d35581192cb Little cleanup for migrations
verrierj
parents: 424
diff changeset
   633
            if add_image or current_image != default_image:
330
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   634
                self.image = content.image
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   635
                return True
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   636
            
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   637
        self.image = settings.DEFAULT_PROJECT_ICON
806188af5027 Projects have an icon identical to one of the media they contain, if this icon is different from the default icon. Icons can be set using ./manage.py setprojecticon once icons have been added to contents.
verrierj
parents: 314
diff changeset
   638
        return False
247
f98f1a6e15f1 Add a group to contain published projects
verrierj
parents: 244
diff changeset
   639
    
167
fe00e7302efe Change class and functions names to follow PEP8 formatting standards
verrierj
parents: 150
diff changeset
   640
    def check_access(self, user):
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   641
        if (user and user.is_staff) or self.state == 2: 
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   642
            return True
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   643
        else:
343
1b9b509013a7 Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents: 342
diff changeset
   644
            return False
560
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   645
        
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   646
    def ldt_encoded(): #@NoSelf
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   647
        
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   648
        def fget(self):
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   649
            if self.ldt is None:
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   650
                return None
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   651
            if not hasattr(self, "__ldt_encoded"):
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   652
                m = re.match("<\?xml.*?encoding\s*?=\s*?['\"]([A-Za-z][A-Za-z0-9._-]*)['\"].*?\?>", self.ldt.lstrip(), re.I|re.M|re.U)
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   653
                if m and m.group(1):
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   654
                    encoding = m.group(1)
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   655
                else:
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   656
                    encoding = 'utf-8'
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   657
                self.__ldt_encoded = self.ldt.encode(encoding)
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   658
            return self.__ldt_encoded
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   659
            
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   660
        return locals()
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   661
    
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   662
    ldt_encoded = property(**ldt_encoded())
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 551
diff changeset
   663
                
468
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   664
    
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   665
    
240
a46cb257d8ee Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents: 235
diff changeset
   666
class Segment(SafeModel):
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   667
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   668
    project_obj = models.ForeignKey(Project, null=True)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   669
    content = models.ForeignKey(Content)
731
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
   670
    project_id = models.CharField(max_length=255, unique=False, blank=True, null=True, db_index=True)
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
   671
    iri_id = models.CharField(max_length=255, unique=False, db_index=True)
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
   672
    ensemble_id = models.CharField(max_length=512, unique=False, db_index=True)
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
   673
    cutting_id = models.CharField(max_length=512, unique=False, db_index=True)    
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
   674
    element_id = models.CharField(max_length=512, unique=False, db_index=True)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   675
    tags = tagging.fields.TagField(max_length=2048, null=True, blank=True, unique=False)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   676
    title = models.CharField(max_length=2048, unique=False, null=True, blank=True)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   677
    duration = models.IntegerField(null=True)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   678
    start_ts = models.IntegerField(null=True)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   679
    author = models.CharField(max_length=1024, unique=False, null=True, blank=True)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   680
    date = models.CharField(max_length=128, unique=False, null=True, blank=True)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   681
    abstract = models.TextField(null=True, blank=True)
467
a1e9f5e91791 Removed object AnnotationStat + stats are computed when projects are published/unpublished
verrierj
parents: 458
diff changeset
   682
    polemics = models.IntegerField(null=True, blank=True, default=0)
733
43c9571752f6 correct models. Add blank to generated fields
ymh <ymh.work@gmail.com>
parents: 731
diff changeset
   683
    id_hash = models.CharField(max_length=128, unique=True, blank=True)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   684
    
468
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   685
    
570
361ecea621e0 Little clean up for search
verrierj
parents: 560
diff changeset
   686
    # All combinations of polemic hashtags can be represented by a combination of 
361ecea621e0 Little clean up for search
verrierj
parents: 560
diff changeset
   687
    # 4 bits, 1 if the hashtag is in the tweet, 0 else. We use the order OK, KO, Q, REF
361ecea621e0 Little clean up for search
verrierj
parents: 560
diff changeset
   688
    # and convert the resulting string into an integer to store the polemic values.
361ecea621e0 Little clean up for search
verrierj
parents: 560
diff changeset
   689
    # mask contains all possible polemic values
468
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   690
    mask = {
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   691
            'OK': set([8,9,10,11,12,13,14,15]),
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   692
            'KO': set([4,5,6,7,12,13,14,15]),
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   693
            'Q': set([2,3,6,7,10,11,14,15]),
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   694
            'REF': set([1,3,5,7,9,11,13,15]),
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   695
            }
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   696
    
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   697
    def is_polemic(self, polemic_keyword): # OK, KO, Q, REF 
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   698
        if self.polemics in self.mask[polemic_keyword]:
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   699
            return True
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   700
        return False
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   701
    
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   702
    def get_polemic(self, polemic_keywords):
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   703
        value = set(range(16))
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   704
        
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   705
        for keyword in self.mask.keys():
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   706
            if keyword in polemic_keywords:
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   707
                value = value.intersection(self.mask[keyword])
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   708
            else:
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   709
                value.difference_update(self.mask[keyword])
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   710
            
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   711
        return value.pop()
738
51294f20e8ad Correct south migrations
ymh <ymh.work@gmail.com>
parents: 733
diff changeset
   712
    
731
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
   713
    def save(self, *args, **kwargs):
738
51294f20e8ad Correct south migrations
ymh <ymh.work@gmail.com>
parents: 733
diff changeset
   714
        self.id_hash = generate_hash(self.__unicode__())
731
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
   715
        super(Segment, self).save(*args, **kwargs)
aba6c30b6d2a first step of mysql migration
ymh <ymh.work@gmail.com>
parents: 719
diff changeset
   716
468
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   717
    
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   718
    def __unicode__(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   719
        return "/".join((unicode(self.project_id), unicode(self.iri_id), unicode(self.ensemble_id), unicode(self.cutting_id), unicode(self.element_id)))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   720
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   721
    class Meta:
244
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
   722
        permissions = (
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
   723
                       ('view_segment', 'Can view segment'),
bc1dd5fea0b6 Added permissions to all objects in ldt_utils
verrierj
parents: 240
diff changeset
   724
                       )
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   725
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 106
diff changeset
   726
467
a1e9f5e91791 Removed object AnnotationStat + stats are computed when projects are published/unpublished
verrierj
parents: 458
diff changeset
   727