| author | verrierj |
| Fri, 13 Jan 2012 14:25:18 +0100 | |
| changeset 383 | a99ea8eb8b9a |
| parent 354 | ecd4d57d0b40 |
| child 384 | 0e410517b311 |
| 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 _ |
| 383 | 5 |
from django.db.models.signals import post_save |
|
128
503e365a3af7
Starting 'group_management' branch (CAUTION : STILL SOME BUGS)
cavaliet
parents:
125
diff
changeset
|
6 |
#from ldt.core.models import Document, Owner |
|
503e365a3af7
Starting 'group_management' branch (CAUTION : STILL SOME BUGS)
cavaliet
parents:
125
diff
changeset
|
7 |
from ldt.core.models import Document |
| 266 | 8 |
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
|
9 |
import ldt.indexation |
|
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 |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
21 |
import uuid |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
22 |
|
|
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
|
23 |
|
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
24 |
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
|
25 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
26 |
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
|
27 |
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
|
28 |
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
|
29 |
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
|
30 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
31 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
32 |
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
|
33 |
|
| 244 | 34 |
class Meta: |
35 |
permissions = ( |
|
36 |
('view_author', 'Can view author'), |
|
37 |
) |
|
38 |
||
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
|
| 244 | 55 |
class Meta: |
56 |
permissions = ( |
|
57 |
('view_media', 'Can view media'), |
|
58 |
) |
|
59 |
||
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
60 |
def mimetype(): #@NoSelf |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
61 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
62 |
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
|
63 |
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
|
64 |
elif self.src: |
| 150 | 65 |
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
|
66 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
67 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
68 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
72 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
73 |
mimetype = property(**mimetype()) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
74 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
75 |
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
|
76 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
77 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
res_src = { |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
82 |
'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
|
83 |
'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
|
84 |
'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
|
85 |
'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
|
86 |
'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
|
87 |
}.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
|
88 |
return res_src |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
89 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
90 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
91 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
92 |
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
|
93 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
99 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
100 |
strings = [] |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
101 |
if self.title: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
102 |
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
|
103 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
return "|".join(strings) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
108 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
109 |
|
| 244 | 110 |
class ContentManager(SafeManager): |
111 |
||
112 |
def __init__(self): |
|
113 |
super(ContentManager, self).__init__(check_perm=False) |
|
114 |
||
|
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
|
115 |
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
|
116 |
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
|
117 |
|
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
stat_annotation = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content.stat_annotation")) |
| 341 | 134 |
nb_annotation = models.IntegerField(null=True, blank=True, verbose_name=_('content.nb_annotation')) |
| 383 | 135 |
last_annotated = models.DateTimeField(default=datetime.datetime.now, verbose_name=_('content.last_annotated'), blank=True, null=True) |
136 |
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
|
137 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
138 |
class Meta: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
139 |
ordering = ["title"] |
| 228 | 140 |
permissions = ( |
| 244 | 141 |
('view_content', 'Can view content'), |
| 228 | 142 |
) |
|
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
|
143 |
|
|
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
|
144 |
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
|
145 |
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
|
146 |
|
|
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
|
147 |
# 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
|
148 |
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
|
149 |
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
|
150 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
151 |
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
|
152 |
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
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
try: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
157 |
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
|
158 |
except: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
159 |
self.duration = 0 |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
160 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
161 |
self.duration = 0 |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
162 |
self.save() |
| 344 | 163 |
return self.duration |
164 |
||
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
165 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
166 |
def mimetype(): #@NoSelf |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
167 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
168 |
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
|
169 |
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
|
170 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
171 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
172 |
return locals() |
|
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 |
mimetype = property(**mimetype()) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
175 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
176 |
def delete(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
177 |
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
|
178 |
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
|
179 |
try: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
180 |
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
|
181 |
writer.commit() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
182 |
finally: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
183 |
writer.close() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
184 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
185 |
def sync_iri_file(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
186 |
# create iri file if needed |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
187 |
created = False |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
188 |
try: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
189 |
iri_file_path = self.iri_file_path() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
190 |
if not os.path.exists(iri_file_path): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
191 |
dir = os.path.dirname(iri_file_path) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
192 |
if not os.path.exists(dir): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
193 |
os.makedirs(dir) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
194 |
created = True |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
195 |
file = open(iri_file_path, "w") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
196 |
create_empty_iri(file, self, "IRI") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
197 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
198 |
created = False |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
199 |
update_iri(iri_file_path, self, "IRI") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
200 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
201 |
except Exception, e: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
202 |
if created: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
203 |
if os.path.exists(iri_file_path): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
204 |
os.remove(iri_file_path) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
205 |
raise e |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
206 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
207 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
208 |
#TODO: better manage the change in .iri name and error scenario (save in temp file + rename |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
209 |
def save(self, *args, **kwargs): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
210 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
211 |
self.sync_iri_file() |
| 383 | 212 |
# update it |
213 |
||
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
214 |
super(Content, self).save(*args, **kwargs) |
| 383 | 215 |
|
216 |
def create_front_project(sender, instance, created, **kwargs):#@NoSelf |
|
217 |
if created: |
|
218 |
admin = User.objects.filter(is_superuser=True)[0] |
|
219 |
instance.front_project = Project.create_project(admin ,'front_%s' % instance.iri_id, [instance], cuttings=['chapitrage', 'contribution'] ) |
|
220 |
instance.save() |
|
|
232
2878499a372b
Security layer moved to middleware and ldt_utils __init__ file
verrierj
parents:
231
diff
changeset
|
221 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
222 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
223 |
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
|
224 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
225 |
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
|
226 |
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
|
227 |
return self.iriurl |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
228 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
229 |
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
|
230 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
231 |
def iri_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
|
232 |
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
|
233 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
234 |
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
|
235 |
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
|
236 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
237 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
238 |
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
|
239 |
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
|
240 |
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
|
241 |
return empty_media |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
242 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
243 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
244 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
245 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
246 |
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
|
247 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
248 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
249 |
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
|
250 |
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
|
251 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
252 |
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
|
253 |
if empty_media: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
254 |
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
|
255 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
256 |
return "" |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
257 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
258 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
259 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
260 |
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
|
261 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
262 |
def videopath(): #@NoSelf |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
263 |
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
|
264 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
265 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
266 |
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
|
267 |
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
|
268 |
if empty_media: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
269 |
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
|
270 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
271 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
272 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
273 |
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
|
274 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
275 |
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
|
276 |
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
|
277 |
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
|
278 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
279 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
280 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
281 |
videopath = property(**videopath()) |
|
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 src(): #@NoSelf |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
284 |
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
|
285 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
286 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
287 |
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
|
288 |
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
|
289 |
if empty_media: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
290 |
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
|
291 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
292 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
293 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
294 |
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
|
295 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
296 |
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
|
297 |
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
|
298 |
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
|
299 |
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
|
300 |
self.save() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
301 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
302 |
return locals() |
|
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 |
src = property(**src()) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
305 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
306 |
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
|
307 |
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
|
308 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
309 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
310 |
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
|
311 |
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
|
312 |
if empty_media: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
313 |
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
|
314 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
315 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
316 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
317 |
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
|
318 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
319 |
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
|
320 |
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
|
321 |
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
|
322 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
323 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
324 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
325 |
external_id = property(**external_id()) |
|
231
535ce952e51c
Stub of html template for project creation containing a group selection
verrierj
parents:
229
diff
changeset
|
326 |
|
| 266 | 327 |
def is_public(): #@NoSelf |
328 |
||
329 |
def fget(self): |
|
| 271 | 330 |
if self.pk: |
331 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
332 |
if 'view_content' in get_perms(everyone, self): |
|
333 |
return True |
|
| 266 | 334 |
return False |
335 |
||
336 |
def fset(self, value): |
|
| 271 | 337 |
if self.pk: |
338 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
339 |
if value: |
|
| 274 | 340 |
assign('view_content', everyone, self) |
| 282 | 341 |
assign('view_media', everyone, self.media_obj) |
| 271 | 342 |
else: |
343 |
remove_perm('view_content', everyone, self) |
|
|
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
|
344 |
remove_perm('view_media', everyone, self.media_obj) |
| 266 | 345 |
|
346 |
return locals() |
|
347 |
||
348 |
is_public = property(**is_public()) |
|
| 344 | 349 |
|
| 383 | 350 |
post_save.connect(Content.create_front_project, sender=Content) |
| 266 | 351 |
|
352 |
||
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
353 |
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
|
354 |
STATE_CHOICES = ( |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
355 |
(1, 'edition'), |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
356 |
(2, 'published'), |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
357 |
(3, 'moderated'), |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
358 |
(4, 'rejected'), |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
359 |
(5, 'deleted') |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
360 |
) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
361 |
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
|
362 |
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
|
363 |
title = models.CharField(max_length=1024) |
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
364 |
contents = models.ManyToManyField(Content, through='AnnotationStat') |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
365 |
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
|
366 |
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
|
367 |
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
|
368 |
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
|
369 |
state = models.IntegerField(choices=STATE_CHOICES, default=1) |
|
342
17d615b49a91
Extend image fields size to 200 characters + minor bugs
verrierj
parents:
341
diff
changeset
|
370 |
description = models.TextField(null=True, blank=True) |
|
17d615b49a91
Extend image fields size to 200 characters + minor bugs
verrierj
parents:
341
diff
changeset
|
371 |
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
|
372 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
373 |
class Meta: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
374 |
ordering = ["title"] |
| 228 | 375 |
permissions = ( |
|
231
535ce952e51c
Stub of html template for project creation containing a group selection
verrierj
parents:
229
diff
changeset
|
376 |
('view_project', 'Can view project'), |
| 228 | 377 |
) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
378 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
379 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
380 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
381 |
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
|
382 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
383 |
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
|
384 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
385 |
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
|
386 |
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
|
387 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
388 |
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
|
389 |
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
|
390 |
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
|
391 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
392 |
return None |
|
232
2878499a372b
Security layer moved to middleware and ldt_utils __init__ file
verrierj
parents:
231
diff
changeset
|
393 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
394 |
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
|
395 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
396 |
modes = [] |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
397 |
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
|
398 |
mimetype = content.mimetype |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
399 |
if mimetype: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
400 |
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
|
401 |
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
|
402 |
modes.append(mode) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
403 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
404 |
modes.append("video") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
405 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
406 |
modes.append("video") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
407 |
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
|
408 |
if not current: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
409 |
return item |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
410 |
elif current == item: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
411 |
return item |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
412 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
413 |
return "video" |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
414 |
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
|
415 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
416 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
417 |
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
|
418 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
419 |
@staticmethod |
| 383 | 420 |
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
|
421 |
# owner = Owner.objects.get(user=user) #@UndefinedVariable |
|
503e365a3af7
Starting 'group_management' branch (CAUTION : STILL SOME BUGS)
cavaliet
parents:
125
diff
changeset
|
422 |
owner = user |
| 178 | 423 |
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
|
424 |
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
|
425 |
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
|
426 |
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
|
427 |
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
|
428 |
project.save() |
|
231
535ce952e51c
Stub of html template for project creation containing a group selection
verrierj
parents:
229
diff
changeset
|
429 |
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
|
430 |
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
|
431 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
432 |
for content in contents: |
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
433 |
project.add_contents([content]) |
|
333
4ddf8c0eeab4
Image size is checked before save + project image can be set manually
verrierj
parents:
330
diff
changeset
|
434 |
|
|
4ddf8c0eeab4
Image size is checked before save + project image can be set manually
verrierj
parents:
330
diff
changeset
|
435 |
if set_icon: |
|
4ddf8c0eeab4
Image size is checked before save + project image can be set manually
verrierj
parents:
330
diff
changeset
|
436 |
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
|
437 |
project.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
|
438 |
|
| 383 | 439 |
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
|
440 |
|
|
256
fd20ce3c5fbe
Project are copied in the group they are displayed in group page
verrierj
parents:
247
diff
changeset
|
441 |
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
|
442 |
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
|
443 |
project = copy_ldt(self, project, user) |
| 229 | 444 |
assign('view_project', user, project) |
445 |
assign('change_project', user, project) |
|
|
256
fd20ce3c5fbe
Project are copied in the group they are displayed in group page
verrierj
parents:
247
diff
changeset
|
446 |
if group: |
|
fd20ce3c5fbe
Project are copied in the group they are displayed in group page
verrierj
parents:
247
diff
changeset
|
447 |
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
|
448 |
for content in self.contents.all(): |
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
449 |
project.add_contents([content]) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
450 |
return project |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
451 |
|
| 247 | 452 |
def publish(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
|
453 |
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
|
454 |
self.save() |
| 247 | 455 |
self.state = 2 |
456 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
457 |
assign('ldt_utils.view_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
|
458 |
self.save() |
| 247 | 459 |
|
460 |
def unpublish(self): |
|
|
349
63f729155d81
Enhance search and front template : add begin and duration to searched segments.
cavaliet
parents:
344
diff
changeset
|
461 |
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
|
462 |
self.save() |
| 247 | 463 |
self.state = 1 |
464 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
465 |
remove_perm('ldt_utils.view_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
|
466 |
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
|
467 |
|
|
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
|
468 |
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
|
469 |
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
|
470 |
|
|
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
|
471 |
for content in self.contents.all(): |
|
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
|
472 |
if os.path.basename(content.image.file.name) != default_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
|
473 |
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
|
474 |
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
|
475 |
|
|
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
|
476 |
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
|
477 |
return False |
| 247 | 478 |
|
|
167
fe00e7302efe
Change class and functions names to follow PEP8 formatting standards
verrierj
parents:
150
diff
changeset
|
479 |
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
|
480 |
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
|
481 |
return True |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
482 |
else: |
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
483 |
return False |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
484 |
|
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
485 |
def add_contents(self, contents): |
|
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
486 |
for content in contents: |
|
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
487 |
contribution = AnnotationStat.objects.create(project=self, content=content) |
| 383 | 488 |
contribution.save() |
489 |
||
490 |
def remove_contents(self, contents): |
|
491 |
AnnotationStat.objects.filter(project=self, content__in=contents).delete() |
|
492 |
||
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
493 |
|
|
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
494 |
class AnnotationStat(SafeModel): |
|
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
495 |
project = models.ForeignKey(Project) |
|
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
496 |
content = models.ForeignKey(Content) |
|
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
497 |
stat = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content.stat_annotation")) |
|
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
498 |
nb_annotation = models.IntegerField(default=0, verbose_name=_("content.nb_annotation")) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
499 |
|
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
500 |
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
|
501 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
502 |
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
|
503 |
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
|
504 |
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
|
505 |
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
|
506 |
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
|
507 |
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
|
508 |
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
|
509 |
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
|
510 |
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
|
511 |
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
|
512 |
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
|
513 |
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
|
514 |
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
|
515 |
abstract = models.TextField(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
|
516 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
517 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
518 |
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
|
519 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
520 |
class Meta: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
521 |
unique_together = (('project_id', 'iri_id', 'ensemble_id', 'cutting_id', 'element_id'),) |
| 244 | 522 |
permissions = ( |
523 |
('view_segment', 'Can view segment'), |
|
524 |
) |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
525 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
526 |