| author | verrierj |
| Tue, 31 Jan 2012 15:40:42 +0100 | |
| changeset 491 | b0da8cecb6b3 |
| parent 482 | c802e00c7131 |
| child 504 | 32a878a71a80 |
| permissions | -rwxr-xr-x |
|
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 | 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 _ |
|
128
503e365a3af7
Starting 'group_management' branch (CAUTION : STILL SOME BUGS)
cavaliet
parents:
125
diff
changeset
|
5 |
#from ldt.core.models import Document, Owner |
|
503e365a3af7
Starting 'group_management' branch (CAUTION : STILL SOME BUGS)
cavaliet
parents:
125
diff
changeset
|
6 |
from ldt.core.models import Document |
| 266 | 7 |
from guardian.shortcuts import assign, remove_perm, get_perms |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
8 |
import ldt.indexation |
| 491 | 9 |
from ldt.security import get_current_user_or_admin, set_current_user, get_current_user |
|
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 |
|
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
11 |
from ldt.security.manager import SafeManager |
|
314
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
286
diff
changeset
|
12 |
from sorl.thumbnail import ImageField |
|
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) |
|
354
ecd4d57d0b40
Last annotated contents can be retrieved using the field content.last_annotated
verrierj
parents:
349
diff
changeset
|
15 |
import datetime |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
16 |
import lucene |
|
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 |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
20 |
import tagging.fields |
| 409 | 21 |
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
|
22 |
import uuid |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
23 |
|
|
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
|
24 |
|
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
25 |
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
|
26 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
27 |
handle = models.CharField(max_length=512, unique=True, 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
|
28 |
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
|
29 |
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
|
30 |
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
|
31 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
32 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
33 |
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
|
34 |
|
| 244 | 35 |
class Meta: |
36 |
permissions = ( |
|
37 |
('view_author', 'Can view author'), |
|
38 |
) |
|
39 |
||
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
title = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('title')) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
53 |
src = models.CharField(max_length=1024, unique=True, verbose_name=_('media.src')) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
54 |
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
|
55 |
|
| 244 | 56 |
class Meta: |
57 |
permissions = ( |
|
58 |
('view_media', 'Can view media'), |
|
59 |
) |
|
60 |
||
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
61 |
def mimetype(): #@NoSelf |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
62 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
elif self.src: |
| 150 | 66 |
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
|
67 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
68 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
69 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
70 |
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
|
71 |
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
|
72 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
73 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
74 |
mimetype = property(**mimetype()) |
|
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 |
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
|
77 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
78 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
res_src = { |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
83 |
'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
|
84 |
'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
|
85 |
'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
|
86 |
'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
|
87 |
'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
|
88 |
}.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
|
89 |
return res_src |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
90 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
91 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
92 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
93 |
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
|
94 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
100 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
101 |
strings = [] |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
102 |
if self.title: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
103 |
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
|
104 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
return "|".join(strings) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
109 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
110 |
|
| 244 | 111 |
class ContentManager(SafeManager): |
112 |
||
113 |
def __init__(self): |
|
114 |
super(ContentManager, self).__init__(check_perm=False) |
|
115 |
||
|
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
|
116 |
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
|
117 |
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
|
118 |
|
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
119 |
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
|
120 |
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
|
121 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
122 |
iri_id = models.CharField(max_length=1024, unique=True, default=generate_uuid, verbose_name=_('content.iri_id')) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
media_obj = models.ForeignKey('Media', blank=True, null=True) |
|
342
17d615b49a91
Extend image fields size to 200 characters + minor bugs
verrierj
parents:
341
diff
changeset
|
133 |
image = ImageField(upload_to=settings.MEDIA_ROOT+"thumbnails/contents/", default=settings.DEFAULT_CONTENT_ICON, max_length=200) |
|
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
|
134 |
stat_annotation = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content.stat_annotation")) |
| 341 | 135 |
nb_annotation = models.IntegerField(null=True, blank=True, verbose_name=_('content.nb_annotation')) |
| 383 | 136 |
last_annotated = models.DateTimeField(default=datetime.datetime.now, verbose_name=_('content.last_annotated'), blank=True, null=True) |
137 |
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
|
138 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
139 |
class Meta: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
140 |
ordering = ["title"] |
| 228 | 141 |
permissions = ( |
| 244 | 142 |
('view_content', 'Can view content'), |
| 228 | 143 |
) |
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
144 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
145 |
def __init__(self, *args, **kwargs): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
146 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
147 |
super(Content, self).__init__(*args, **kwargs) |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
148 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
149 |
if not hasattr(Content, 'pol_positive'): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
150 |
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
|
151 |
|
|
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 |
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
|
153 |
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
|
154 |
|
|
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 |
# 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
|
156 |
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
|
157 |
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
|
158 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
159 |
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
|
160 |
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
|
161 |
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
|
162 |
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
|
163 |
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
|
164 |
try: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
165 |
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
|
166 |
except: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
167 |
self.duration = 0 |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
168 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
169 |
self.duration = 0 |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
170 |
self.save() |
| 344 | 171 |
return self.duration |
172 |
||
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
173 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
174 |
def mimetype(): #@NoSelf |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
175 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
176 |
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
|
177 |
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
|
178 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
179 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
180 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
181 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
182 |
mimetype = property(**mimetype()) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
183 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
184 |
def delete(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
185 |
super(Content, self).delete() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
186 |
writer = ldt.indexation.get_writer() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
187 |
try: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
188 |
writer.deleteDocuments(lucene.Term("iri_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
|
189 |
writer.commit() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
190 |
finally: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
191 |
writer.close() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
192 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
193 |
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
|
194 |
# 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
|
195 |
created = False |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
196 |
try: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
197 |
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
|
198 |
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
|
199 |
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
|
200 |
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
|
201 |
os.makedirs(dir) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
202 |
created = True |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
203 |
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
|
204 |
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
|
205 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
206 |
created = False |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
207 |
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
|
208 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
209 |
except Exception, e: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
210 |
if created: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
211 |
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
|
212 |
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
|
213 |
raise e |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
214 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
215 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
216 |
#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
|
217 |
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
|
218 |
|
| 384 | 219 |
create_front_project = False |
220 |
# update it |
|
221 |
self.sync_iri_file() |
|
222 |
||
223 |
if not self.pk: |
|
224 |
create_front_project = True |
|
225 |
||
226 |
if not self.nb_annotation: |
|
227 |
self.nb_annotation = 0 |
|
228 |
if not self.stat_annotation: |
|
| 424 | 229 |
self.stat_annotation = ('0,' * settings.DIVISIONS_FOR_STAT_ANNOTATION)[:-1] |
| 383 | 230 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
231 |
super(Content, self).save(*args, **kwargs) |
| 383 | 232 |
|
| 384 | 233 |
if create_front_project: |
234 |
# We need a primary key for self in create_project, so |
|
235 |
# save() has to be called first |
|
| 392 | 236 |
self.create_front_project() |
| 491 | 237 |
assign('ldt_utils.change_content', get_current_user(), self) |
238 |
||
|
232
2878499a372b
Security layer moved to middleware and ldt_utils __init__ file
verrierj
parents:
231
diff
changeset
|
239 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
240 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
241 |
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
|
242 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
243 |
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
|
244 |
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
|
245 |
return self.iriurl |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
246 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
247 |
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
|
248 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
249 |
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
|
250 |
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
|
251 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
252 |
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
|
253 |
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
|
254 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
255 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
return empty_media |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
260 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
261 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
262 |
|
|
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 |
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
|
265 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
266 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
267 |
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
|
268 |
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
|
269 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
270 |
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
|
271 |
if empty_media: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
272 |
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
|
273 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
274 |
return "" |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
275 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
276 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
277 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
278 |
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
|
279 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
280 |
def videopath(): #@NoSelf |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
281 |
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
|
282 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
283 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
284 |
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
|
285 |
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
|
286 |
if empty_media: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
287 |
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
|
288 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
289 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
290 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
291 |
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
|
292 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
293 |
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
|
294 |
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
|
295 |
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
|
296 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
297 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
298 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
299 |
videopath = property(**videopath()) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
300 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
301 |
def src(): #@NoSelf |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
302 |
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
|
303 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
304 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
305 |
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
|
306 |
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
|
307 |
if empty_media: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
308 |
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
|
309 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
310 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
311 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
312 |
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
|
313 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
314 |
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
|
315 |
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
|
316 |
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
|
317 |
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
|
318 |
self.save() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
319 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
320 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
321 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
322 |
src = property(**src()) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
323 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
324 |
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
|
325 |
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
|
326 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
327 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
328 |
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
|
329 |
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
|
330 |
if empty_media: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
331 |
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
|
332 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
333 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
334 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
335 |
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
|
336 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
337 |
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
|
338 |
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
|
339 |
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
|
340 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
341 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
342 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
343 |
external_id = property(**external_id()) |
|
231
535ce952e51c
Stub of html template for project creation containing a group selection
verrierj
parents:
229
diff
changeset
|
344 |
|
| 266 | 345 |
def is_public(): #@NoSelf |
346 |
||
347 |
def fget(self): |
|
| 271 | 348 |
if self.pk: |
349 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
350 |
if 'view_content' in get_perms(everyone, self): |
|
351 |
return True |
|
| 266 | 352 |
return False |
353 |
||
354 |
def fset(self, value): |
|
| 271 | 355 |
if self.pk: |
356 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
357 |
if value: |
|
| 458 | 358 |
assign('ldt_utils.view_content', everyone, self) |
359 |
assign('ldt_utils.view_media', everyone, self.media_obj) |
|
| 271 | 360 |
else: |
| 458 | 361 |
remove_perm('ldt_utils.view_content', everyone, self) |
362 |
remove_perm('ldt_utils.view_media', everyone, self.media_obj) |
|
| 266 | 363 |
|
364 |
return locals() |
|
365 |
||
366 |
is_public = property(**is_public()) |
|
| 392 | 367 |
|
368 |
def create_front_project(self): |
|
| 491 | 369 |
old_user = get_current_user_or_admin() |
| 392 | 370 |
|
| 491 | 371 |
if old_user.is_superuser: |
372 |
admin = old_user |
|
| 392 | 373 |
else: |
374 |
admin = User.objects.filter(is_superuser=True)[0] |
|
375 |
||
376 |
set_current_user(admin) |
|
| 411 | 377 |
self.front_project = Project.create_project(admin, 'front project : %s' % self.title, [self], cuttings=['chapitrage', 'contributions'] ) |
| 392 | 378 |
self.front_project.publish(allow_write=True) |
| 491 | 379 |
set_current_user(old_user) |
| 392 | 380 |
|
381 |
self.save() |
|
| 409 | 382 |
|
383 |
# Tag management |
|
384 |
def get_tags(self): |
|
385 |
return Tag.objects.get_for_object(self) |
|
| 458 | 386 |
|
| 468 | 387 |
|
| 482 | 388 |
__pol_indices = { |
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
389 |
'annotation_volume_begin' : 0, |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
390 |
'annotation_volume_end' : settings.DIVISIONS_FOR_STAT_ANNOTATION, |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
391 |
'pol_positive' : settings.DIVISIONS_FOR_STAT_ANNOTATION, |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
392 |
'pol_negative' : settings.DIVISIONS_FOR_STAT_ANNOTATION + 1, |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
393 |
'pol_reference' : settings.DIVISIONS_FOR_STAT_ANNOTATION + 2, |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
394 |
'pol_question' : settings.DIVISIONS_FOR_STAT_ANNOTATION + 3, |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
395 |
} |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
396 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
397 |
# 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
|
398 |
def __add_polemic_attributes(self): |
| 482 | 399 |
for element in self.__pol_indices.keys(): |
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
400 |
if element.startswith('pol_'): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
401 |
Content.add_to_class(element, property(self.__make_getter(element), self.__make_setter(element))) |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
402 |
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
|
403 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
404 |
def __make_getter(self, i): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
405 |
def inner_getter(self): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
406 |
l = self.__str2list(self.stat_annotation) |
| 482 | 407 |
return l[Content.__pol_indices[i]] |
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
408 |
return inner_getter |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
409 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
410 |
def __make_setter(self, i): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
411 |
def inner_setter(self, value): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
412 |
l = self.__str2list(self.stat_annotation) |
| 482 | 413 |
l[Content.__pol_indices[i]] = value |
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
414 |
self.stat_annotation = self.__list2str(l) |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
415 |
return inner_setter |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
416 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
417 |
def __make_rate(self, i): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
418 |
def inner_rate(self): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
419 |
if self.nb_annotation <= 0: |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
420 |
return 0 |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
421 |
return int(getattr(self, i) / float(self.nb_annotation) * 100 ) |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
422 |
return inner_rate |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
423 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
424 |
def __list2str(self, l): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
425 |
return ("%s" % l)[1:-1].replace(' ','') |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
426 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
427 |
def __str2list(self, s): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
428 |
return [int(x) for x in s.split(',')] |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
429 |
|
| 468 | 430 |
def annotation_volume(): #@NoSelf |
431 |
||
432 |
def fget(self): |
|
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
433 |
l = self.__str2list(self.stat_annotation) |
| 482 | 434 |
return l[Content.__pol_indices['annotation_volume_begin']:Content.__pol_indices['annotation_volume_end']] |
| 468 | 435 |
|
436 |
def fset(self, value): # value is a list |
|
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
437 |
l = self.__str2list(self.stat_annotation) |
| 482 | 438 |
l[Content.__pol_indices['annotation_volume_begin']:Content.__pol_indices['annotation_volume_end']] = value |
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
439 |
self.stat_annotation = self.__list2str(l) |
| 468 | 440 |
|
441 |
return locals() |
|
442 |
||
| 482 | 443 |
annotation_volume = property(**annotation_volume()) |
| 344 | 444 |
|
| 266 | 445 |
|
446 |
||
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
447 |
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
|
448 |
STATE_CHOICES = ( |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
449 |
(1, 'edition'), |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
450 |
(2, 'published'), |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
451 |
(3, 'moderated'), |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
452 |
(4, 'rejected'), |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
453 |
(5, 'deleted') |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
454 |
) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
455 |
ldt_id = models.CharField(max_length=1024, unique=True) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
456 |
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
|
457 |
title = models.CharField(max_length=1024) |
|
467
a1e9f5e91791
Removed object AnnotationStat + stats are computed when projects are published/unpublished
verrierj
parents:
458
diff
changeset
|
458 |
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
|
459 |
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
|
460 |
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
|
461 |
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
|
462 |
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
|
463 |
state = models.IntegerField(choices=STATE_CHOICES, default=1) |
|
342
17d615b49a91
Extend image fields size to 200 characters + minor bugs
verrierj
parents:
341
diff
changeset
|
464 |
description = models.TextField(null=True, blank=True) |
|
17d615b49a91
Extend image fields size to 200 characters + minor bugs
verrierj
parents:
341
diff
changeset
|
465 |
image = ImageField(upload_to=settings.MEDIA_ROOT+"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
|
466 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
467 |
class Meta: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
468 |
ordering = ["title"] |
| 228 | 469 |
permissions = ( |
|
231
535ce952e51c
Stub of html template for project creation containing a group selection
verrierj
parents:
229
diff
changeset
|
470 |
('view_project', 'Can view project'), |
| 228 | 471 |
) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
472 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
473 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
474 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
475 |
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
|
476 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
477 |
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
|
478 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
479 |
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
|
480 |
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
|
481 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
482 |
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
|
483 |
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
|
484 |
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
|
485 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
486 |
return None |
|
232
2878499a372b
Security layer moved to middleware and ldt_utils __init__ file
verrierj
parents:
231
diff
changeset
|
487 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
488 |
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
|
489 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
490 |
modes = [] |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
491 |
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
|
492 |
mimetype = content.mimetype |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
493 |
if mimetype: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
494 |
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
|
495 |
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
|
496 |
modes.append(mode) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
497 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
498 |
modes.append("video") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
499 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
500 |
modes.append("video") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
501 |
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
|
502 |
if not current: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
503 |
return item |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
504 |
elif current == item: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
505 |
return item |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
506 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
507 |
return "video" |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
508 |
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
|
509 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
510 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
511 |
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
|
512 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
513 |
@staticmethod |
| 383 | 514 |
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
|
515 |
# owner = Owner.objects.get(user=user) #@UndefinedVariable |
|
503e365a3af7
Starting 'group_management' branch (CAUTION : STILL SOME BUGS)
cavaliet
parents:
125
diff
changeset
|
516 |
owner = user |
| 178 | 517 |
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
|
518 |
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
|
519 |
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
|
520 |
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
|
521 |
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
|
522 |
project.save() |
|
231
535ce952e51c
Stub of html template for project creation containing a group selection
verrierj
parents:
229
diff
changeset
|
523 |
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
|
524 |
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
|
525 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
526 |
for content in contents: |
| 480 | 527 |
project.contents.add(content) |
|
333
4ddf8c0eeab4
Image size is checked before save + project image can be set manually
verrierj
parents:
330
diff
changeset
|
528 |
|
|
4ddf8c0eeab4
Image size is checked before save + project image can be set manually
verrierj
parents:
330
diff
changeset
|
529 |
if set_icon: |
|
4ddf8c0eeab4
Image size is checked before save + project image can be set manually
verrierj
parents:
330
diff
changeset
|
530 |
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
|
531 |
project.save() |
| 384 | 532 |
|
| 383 | 533 |
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
|
534 |
|
| 384 | 535 |
|
|
256
fd20ce3c5fbe
Project are copied in the group they are displayed in group page
verrierj
parents:
247
diff
changeset
|
536 |
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
|
537 |
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
|
538 |
project = copy_ldt(self, project, user) |
| 229 | 539 |
assign('view_project', user, project) |
540 |
assign('change_project', user, project) |
|
|
256
fd20ce3c5fbe
Project are copied in the group they are displayed in group page
verrierj
parents:
247
diff
changeset
|
541 |
if group: |
|
fd20ce3c5fbe
Project are copied in the group they are displayed in group page
verrierj
parents:
247
diff
changeset
|
542 |
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
|
543 |
for content in self.contents.all(): |
| 480 | 544 |
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
|
545 |
return project |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
546 |
|
| 384 | 547 |
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
|
548 |
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
|
549 |
self.save() |
| 247 | 550 |
self.state = 2 |
551 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
552 |
assign('ldt_utils.view_project', everyone, self) |
|
| 384 | 553 |
if allow_write: |
554 |
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
|
555 |
self.save() |
| 247 | 556 |
|
557 |
def unpublish(self): |
|
|
349
63f729155d81
Enhance search and front template : add begin and duration to searched segments.
cavaliet
parents:
344
diff
changeset
|
558 |
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
|
559 |
self.save() |
| 247 | 560 |
self.state = 1 |
561 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
562 |
remove_perm('ldt_utils.view_project', everyone, self) |
|
| 384 | 563 |
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
|
564 |
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
|
565 |
|
| 384 | 566 |
|
|
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
|
567 |
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
|
568 |
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
|
569 |
|
|
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
|
570 |
for content in self.contents.all(): |
| 458 | 571 |
add_image = False |
572 |
try: |
|
573 |
current_image = content.image.file.name |
|
574 |
except IOError: |
|
575 |
add_image = True |
|
576 |
||
577 |
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
|
578 |
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
|
579 |
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
|
580 |
|
|
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 |
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
|
582 |
return False |
| 247 | 583 |
|
|
167
fe00e7302efe
Change class and functions names to follow PEP8 formatting standards
verrierj
parents:
150
diff
changeset
|
584 |
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
|
585 |
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
|
586 |
return True |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
587 |
else: |
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
588 |
return False |
| 468 | 589 |
|
590 |
||
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
591 |
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
|
592 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
593 |
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
|
594 |
content = models.ForeignKey(Content) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
595 |
project_id = models.CharField(max_length=1024, 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
|
596 |
iri_id = models.CharField(max_length=1024, unique=False) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
597 |
ensemble_id = models.CharField(max_length=1024, unique=False) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
598 |
cutting_id = models.CharField(max_length=1024, unique=False) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
599 |
element_id = models.CharField(max_length=1024, unique=False) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
600 |
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
|
601 |
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
|
602 |
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
|
603 |
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
|
604 |
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
|
605 |
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
|
606 |
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
|
607 |
polemics = models.IntegerField(null=True, blank=True, default=0) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
608 |
|
| 468 | 609 |
|
610 |
# Mask is 0000, representing OK|KO|Q|REF |
|
611 |
mask = { |
|
612 |
'OK': set([8,9,10,11,12,13,14,15]), |
|
613 |
'KO': set([4,5,6,7,12,13,14,15]), |
|
614 |
'Q': set([2,3,6,7,10,11,14,15]), |
|
615 |
'REF': set([1,3,5,7,9,11,13,15]), |
|
616 |
} |
|
617 |
||
618 |
def is_polemic(self, polemic_keyword): # OK, KO, Q, REF |
|
619 |
if self.polemics in self.mask[polemic_keyword]: |
|
620 |
return True |
|
621 |
return False |
|
622 |
||
623 |
def get_polemic(self, polemic_keywords): |
|
624 |
value = set(range(16)) |
|
625 |
||
626 |
for keyword in self.mask.keys(): |
|
627 |
if keyword in polemic_keywords: |
|
628 |
value = value.intersection(self.mask[keyword]) |
|
629 |
else: |
|
630 |
value.difference_update(self.mask[keyword]) |
|
631 |
||
632 |
return value.pop() |
|
633 |
||
634 |
||
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
635 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
636 |
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
|
637 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
638 |
class Meta: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
639 |
unique_together = (('project_id', 'iri_id', 'ensemble_id', 'cutting_id', 'element_id'),) |
| 244 | 640 |
permissions = ( |
641 |
('view_segment', 'Can view segment'), |
|
642 |
) |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
643 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
644 |
|
|
467
a1e9f5e91791
Removed object AnnotationStat + stats are computed when projects are published/unpublished
verrierj
parents:
458
diff
changeset
|
645 |