| author | rougeronj |
| Thu, 11 Oct 2012 18:18:07 +0200 | |
| changeset 844 | 1f69157772a1 |
| parent 840 | b38c88bdefa2 |
| child 852 | 393bcc75d26a |
| 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 |
|
840
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
4 |
from django.db import transaction |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
5 |
from django.utils.translation import ugettext_lazy as _ |
|
560
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
6 |
from guardian.shortcuts import assign, remove_perm, get_perms |
|
128
503e365a3af7
Starting 'group_management' branch (CAUTION : STILL SOME BUGS)
cavaliet
parents:
125
diff
changeset
|
7 |
from ldt.core.models import Document |
|
560
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
8 |
from ldt.security import (get_current_user_or_admin, set_current_user, |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
9 |
get_current_user) |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
10 |
from ldt.security.manager import SafeManager |
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
11 |
from ldt.security.models import SafeModel |
|
314
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
286
diff
changeset
|
12 |
from sorl.thumbnail import ImageField |
|
560
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
13 |
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
|
14 |
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
|
15 |
generate_uuid) |
| 731 | 16 |
from ldt.utils import generate_hash |
|
354
ecd4d57d0b40
Last annotated contents can be retrieved using the field content.last_annotated
verrierj
parents:
349
diff
changeset
|
17 |
import datetime |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
18 |
import lxml.etree |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
19 |
import mimetypes |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
20 |
import os.path |
|
560
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
21 |
import re |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
22 |
import tagging.fields |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
23 |
import uuid |
|
840
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
24 |
import logging |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
25 |
from shutil import rmtree, move |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
26 |
from django.core.files.storage import default_storage |
|
560
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
27 |
#from ldt.core.models import Document, Owner |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
28 |
|
|
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
|
29 |
|
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
30 |
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
|
31 |
|
| 731 | 32 |
handle = models.CharField(max_length=255, unique=True, blank=True, null=True) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
37 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
38 |
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
|
39 |
|
| 244 | 40 |
class Meta: |
41 |
permissions = ( |
|
42 |
('view_author', 'Can view author'), |
|
43 |
) |
|
44 |
||
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
title = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('title')) |
| 731 | 58 |
src = models.CharField(max_length=1024, verbose_name=_('media.src')) |
59 |
#TODO: use a fixed length char field |
|
|
733
43c9571752f6
correct models. Add blank to generated fields
ymh <ymh.work@gmail.com>
parents:
731
diff
changeset
|
60 |
src_hash = models.CharField(max_length=128, unique=True, verbose_name=_('media.src_hash'), blank=True) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
61 |
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
|
62 |
|
| 244 | 63 |
class Meta: |
64 |
permissions = ( |
|
65 |
('view_media', 'Can view media'), |
|
66 |
) |
|
67 |
||
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
68 |
def mimetype(): #@NoSelf |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
69 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
70 |
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
|
71 |
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
|
72 |
elif self.src: |
| 150 | 73 |
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
|
74 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
75 |
return None |
|
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 fset(self, value): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
78 |
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
|
79 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
80 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
81 |
mimetype = property(**mimetype()) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
82 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
83 |
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
|
84 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
85 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
res_src = { |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
90 |
'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
|
91 |
'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
|
92 |
'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
|
93 |
'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
|
94 |
'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
|
95 |
}.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
|
96 |
return res_src |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
97 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
98 |
return locals() |
|
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 |
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
|
101 |
|
|
795
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
102 |
def is_public(): #@NoSelf |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
103 |
|
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
104 |
def fget(self): |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
105 |
if self.pk: |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
106 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
107 |
if 'view_media' in get_perms(everyone, self): |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
108 |
return True |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
109 |
return False |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
110 |
|
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
111 |
def fset(self, value): |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
112 |
if self.pk: |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
113 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
114 |
if value: |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
115 |
assign('ldt_utils.view_media', everyone, self.media_obj) |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
116 |
else: |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
117 |
remove_perm('ldt_utils.view_media', everyone, self.media_obj) |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
118 |
|
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
119 |
return locals() |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
120 |
|
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
121 |
is_public = property(**is_public()) |
|
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
122 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
123 |
def save(self, *args, **kwargs): |
| 731 | 124 |
self.src_hash = generate_hash(self.src) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
129 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
130 |
strings = [] |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
131 |
if self.title: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
132 |
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
|
133 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
return "|".join(strings) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
138 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
139 |
|
| 244 | 140 |
class ContentManager(SafeManager): |
141 |
||
142 |
def __init__(self): |
|
143 |
super(ContentManager, self).__init__(check_perm=False) |
|
144 |
||
|
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
|
145 |
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
|
146 |
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
|
147 |
|
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
148 |
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
|
149 |
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
|
150 |
|
| 731 | 151 |
iri_id = models.CharField(max_length=255, unique=True, default=generate_uuid, verbose_name=_('content.iri_id')) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
152 |
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
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
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
|
161 |
media_obj = models.ForeignKey('Media', blank=True, null=True) |
|
658
5f22830ffcd7
correct absolute path in images fields. add data migration
ymh <ymh.work@gmail.com>
parents:
570
diff
changeset
|
162 |
image = ImageField(upload_to="thumbnails/contents/", default=settings.DEFAULT_CONTENT_ICON, max_length=200) |
| 383 | 163 |
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
|
164 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
165 |
class Meta: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
166 |
ordering = ["title"] |
| 228 | 167 |
permissions = ( |
| 244 | 168 |
('view_content', 'Can view content'), |
| 228 | 169 |
) |
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
170 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
171 |
def __init__(self, *args, **kwargs): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
172 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
173 |
super(Content, self).__init__(*args, **kwargs) |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
174 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
175 |
if not hasattr(Content, 'pol_positive'): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
176 |
self.__add_polemic_attributes() |
|
840
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
177 |
|
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
178 |
def delete(self): |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
179 |
super(Content, self).delete() |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
180 |
iri_file_path = self.iri_file_path() |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
181 |
thumbnail = os.path.join(settings.MEDIA_ROOT, unicode(self.image)) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
182 |
if os.path.exists(iri_file_path): |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
183 |
dir = os.path.dirname(iri_file_path) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
184 |
temp = os.path.join(os.path.join(os.path.dirname(dir), "temp"), self.iri_id) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
185 |
try: |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
186 |
move(dir, temp) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
187 |
except Exception, e: |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
188 |
raise e |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
189 |
if os.path.exists(thumbnail): |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
190 |
if os.path.basename(thumbnail) != os.path.basename(settings.DEFAULT_CONTENT_ICON): |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
191 |
temp_thumbnail = os.path.join(os.path.dirname(thumbnail), "temp") |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
192 |
try: |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
193 |
if not os.path.exists(temp_thumbnail): |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
194 |
os.makedirs(temp_thumbnail) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
195 |
move(thumbnail, os.path.join(temp_thumbnail, os.path.basename(thumbnail))) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
196 |
except Exception, e: |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
197 |
raise e |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
198 |
|
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
199 |
#del .iri, and .png from temp directory |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
200 |
def commit(self): |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
201 |
iri_file_path=self.iri_file_path() |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
202 |
dir = os.path.dirname(iri_file_path) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
203 |
temp = os.path.join(os.path.join(os.path.dirname(dir), "temp"), self.iri_id) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
204 |
thumbnail = os.path.join(settings.MEDIA_ROOT, unicode(self.image)) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
205 |
temp_thumbnail = os.path.join(os.path.dirname(thumbnail), "temp") |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
206 |
if os.path.exists(temp): |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
207 |
default_storage.delete(os.path.join(temp, os.path.basename(self.iriurl))) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
208 |
os.rmdir(temp) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
209 |
if os.path.exists(temp_thumbnail): |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
210 |
default_storage.delete(os.path.join(temp_thumbnail, os.path.basename(thumbnail))) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
211 |
os.rmdir(temp_thumbnail) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
212 |
|
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
213 |
#move .iri, and .png to there original directory |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
214 |
def rollback(self): |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
215 |
iri_file_path=self.iri_file_path() |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
216 |
dir = os.path.dirname(iri_file_path) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
217 |
temp = os.path.join(os.path.join(os.path.dirname(dir), "temp"), self.iri_id) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
218 |
thumbnail = os.path.join(settings.MEDIA_ROOT, unicode(self.image)) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
219 |
temp_thumbnail = os.path.join(os.path.dirname(thumbnail), "temp") |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
220 |
if os.path.exists(temp): |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
221 |
move(temp, dir) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
222 |
os.rmdir(os.path.dirname(temp)) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
223 |
if os.path.exists(temp_thumbnail): |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
224 |
move(os.path.join(temp_thumbnail, os.path.basename(thumbnail)), os.path.dirname(thumbnail)) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
225 |
os.rmdir(temp_thumbnail) |
|
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
|
226 |
|
|
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
|
227 |
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
|
228 |
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
|
229 |
|
|
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
|
230 |
# 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
|
231 |
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
|
232 |
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
|
233 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
234 |
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
|
235 |
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
|
236 |
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
|
237 |
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
|
238 |
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
|
239 |
try: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
240 |
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
|
241 |
except: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
242 |
self.duration = 0 |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
243 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
244 |
self.duration = 0 |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
245 |
self.save() |
| 344 | 246 |
return self.duration |
247 |
||
|
111
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 mimetype(): #@NoSelf |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
250 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
251 |
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
|
252 |
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
|
253 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
254 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
255 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
256 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
257 |
mimetype = property(**mimetype()) |
|
718
5e27a39d3742
replace lucene by haystack, remove references to lucene
ymh <ymh.work@gmail.com>
parents:
715
diff
changeset
|
258 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
259 |
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
|
260 |
# 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
|
261 |
created = False |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
262 |
try: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
os.makedirs(dir) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
268 |
created = True |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
269 |
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
|
270 |
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
|
271 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
272 |
created = False |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
273 |
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
|
274 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
275 |
except Exception, e: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
276 |
if created: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
277 |
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
|
278 |
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
|
279 |
raise e |
|
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 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
282 |
#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
|
283 |
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
|
284 |
|
| 384 | 285 |
create_front_project = False |
286 |
||
| 844 | 287 |
# update it |
288 |
self.sync_iri_file() |
|
289 |
||
| 384 | 290 |
if not self.pk: |
| 844 | 291 |
create_front_project = True |
| 383 | 292 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
293 |
super(Content, self).save(*args, **kwargs) |
| 383 | 294 |
|
| 384 | 295 |
if create_front_project: |
296 |
# We need a primary key for self in create_project, so |
|
297 |
# save() has to be called first |
|
| 392 | 298 |
self.create_front_project() |
| 491 | 299 |
assign('ldt_utils.change_content', get_current_user(), self) |
|
840
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
300 |
|
|
232
2878499a372b
Security layer moved to middleware and ldt_utils __init__ file
verrierj
parents:
231
diff
changeset
|
301 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
302 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
303 |
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
|
304 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
305 |
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
|
306 |
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
|
307 |
return self.iriurl |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
308 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
309 |
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
|
310 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
311 |
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
|
312 |
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
|
313 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
314 |
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
|
315 |
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
|
316 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
317 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
318 |
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
|
319 |
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
|
320 |
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
|
321 |
return empty_media |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
322 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
323 |
return None |
|
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 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
326 |
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
|
327 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
328 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
329 |
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
|
330 |
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
|
331 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
332 |
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
|
333 |
if empty_media: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
334 |
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
|
335 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
336 |
return "" |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
337 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
338 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
339 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
340 |
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
|
341 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
342 |
def videopath(): #@NoSelf |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
343 |
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
|
344 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
345 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
346 |
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
|
347 |
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
|
348 |
if empty_media: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
349 |
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
|
350 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
351 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
352 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
353 |
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
|
354 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
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
|
358 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
359 |
return locals() |
|
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 |
videopath = property(**videopath()) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
362 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
363 |
def src(): #@NoSelf |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
364 |
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
|
365 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
366 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
367 |
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
|
368 |
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
|
369 |
if empty_media: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
370 |
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
|
371 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
372 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
373 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
374 |
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
|
375 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
376 |
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
|
377 |
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
|
378 |
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
|
379 |
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
|
380 |
self.save() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
381 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
382 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
383 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
384 |
src = property(**src()) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
385 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
386 |
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
|
387 |
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
|
388 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
389 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
390 |
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
|
391 |
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
|
392 |
if empty_media: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
393 |
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
|
394 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
395 |
return None |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
396 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
397 |
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
|
398 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
399 |
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
|
400 |
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
|
401 |
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
|
402 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
403 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
404 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
405 |
external_id = property(**external_id()) |
|
231
535ce952e51c
Stub of html template for project creation containing a group selection
verrierj
parents:
229
diff
changeset
|
406 |
|
| 266 | 407 |
def is_public(): #@NoSelf |
408 |
||
409 |
def fget(self): |
|
| 271 | 410 |
if self.pk: |
411 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
412 |
if 'view_content' in get_perms(everyone, self): |
|
413 |
return True |
|
| 266 | 414 |
return False |
415 |
||
416 |
def fset(self, value): |
|
| 271 | 417 |
if self.pk: |
418 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
419 |
if value: |
|
|
795
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
741
diff
changeset
|
420 |
assign('ldt_utils.view_content', everyone, self) |
| 271 | 421 |
else: |
| 458 | 422 |
remove_perm('ldt_utils.view_content', everyone, self) |
| 266 | 423 |
|
424 |
return locals() |
|
425 |
||
426 |
is_public = property(**is_public()) |
|
| 392 | 427 |
|
428 |
def create_front_project(self): |
|
| 491 | 429 |
old_user = get_current_user_or_admin() |
| 392 | 430 |
|
| 491 | 431 |
if old_user.is_superuser: |
432 |
admin = old_user |
|
| 392 | 433 |
else: |
434 |
admin = User.objects.filter(is_superuser=True)[0] |
|
435 |
||
436 |
set_current_user(admin) |
|
| 411 | 437 |
self.front_project = Project.create_project(admin, 'front project : %s' % self.title, [self], cuttings=['chapitrage', 'contributions'] ) |
| 515 | 438 |
self.front_project.publish(allow_write=True) |
439 |
self.save() |
|
| 491 | 440 |
set_current_user(old_user) |
|
741
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
441 |
|
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
442 |
|
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
443 |
def get_or_create_front_project(self): |
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
444 |
front_proj = self.front_project |
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
445 |
if front_proj: |
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
446 |
proj = front_proj |
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
447 |
else: |
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
448 |
# The main project for the content |
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
449 |
proj = Project.safe_objects.filter(contents__in=[self], state=2) |
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
450 |
if not proj: |
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
451 |
self.create_front_project() |
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
452 |
proj = self.front_project |
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
453 |
else: |
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
454 |
proj = proj[0] |
|
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
738
diff
changeset
|
455 |
return proj |
| 515 | 456 |
|
| 409 | 457 |
|
458 |
# Tag management |
|
459 |
def get_tags(self): |
|
460 |
return Tag.objects.get_for_object(self) |
|
| 458 | 461 |
|
| 468 | 462 |
|
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
463 |
# 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
|
464 |
def __add_polemic_attributes(self): |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
465 |
for element in POL_INDICES.keys(): |
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
466 |
if element.startswith('pol_'): |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
467 |
Content.add_to_class(element, property(self.__make_getter(element))) |
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
468 |
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
|
469 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
470 |
def __make_getter(self, i): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
471 |
def inner_getter(self): |
|
551
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
472 |
if self.stat_annotation is None: |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
473 |
return 0; |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
474 |
else: |
|
551
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
475 |
l = self.stat_annotation.polemics_volume |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
476 |
return l[POL_INDICES[i]] |
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
477 |
return inner_getter |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
478 |
|
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
479 |
def __make_rate(self, i): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
480 |
def inner_rate(self): |
|
551
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
481 |
if self.stat_annotation is None or self.stat_annotation.nb_annotations <= 0: |
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
482 |
return 0 |
|
551
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
483 |
return int(getattr(self, i) / float(self.stat_annotation.nb_annotations) * 100 ) |
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
484 |
return inner_rate |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
485 |
|
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
486 |
|
|
551
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
487 |
def annotation_volume(): #@NoSelf |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
488 |
def fget(self): |
|
551
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
489 |
if self.stat_annotation is None: |
|
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
490 |
return [0]*settings.DIVISIONS_FOR_STAT_ANNOTATION |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
491 |
else: |
|
551
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
492 |
return self.stat_annotation.annotation_volume |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
493 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
494 |
return locals() |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
495 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
496 |
annotation_volume = property(**annotation_volume()) |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
497 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
498 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
499 |
def nb_annotations(): #@NoSelf |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
500 |
def fget(self): |
|
551
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
501 |
if self.stat_annotation is None: |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
502 |
return 0 |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
503 |
else: |
|
551
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
504 |
return self.stat_annotation.nb_annotations |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
505 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
506 |
return locals() |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
507 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
508 |
nb_annotations = property(**nb_annotations()) |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
509 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
510 |
POL_INDICES = { |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
511 |
'pol_positive' : 0, |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
512 |
'pol_negative' : 1, |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
513 |
'pol_reference' : 2, |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
514 |
'pol_question' : 3, |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
515 |
} |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
516 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
517 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
518 |
class ContentStat(models.Model): |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
519 |
|
|
551
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
520 |
def __init__(self, *args, **kwargs): |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
521 |
super(ContentStat, self).__init__(*args, **kwargs) |
|
551
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
522 |
if self.annotation_volume_str is None and self.polemics_volume_str is None: |
|
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
523 |
self.__init_empty_stat() |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
524 |
|
|
551
c447d863b6ad
change stat_annotation to one to one field
ymh <ymh.work@gmail.com>
parents:
542
diff
changeset
|
525 |
content = models.OneToOneField(Content, blank=False, null=False, related_name='stat_annotation', verbose_name=_("content_stat.content"), unique=True, db_index=True) |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
526 |
annotation_volume_str = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content_stat.annotations_volume")) |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
527 |
polemics_volume_str = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content_stat.polemics_volume")) |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
528 |
nb_annotations = models.IntegerField(null=False, blank=False, verbose_name=_('content.nb_annotation'), default=0, db_index=True) |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
529 |
last_annotated = models.DateTimeField(default=datetime.datetime.now, verbose_name=_('content.last_annotated'), blank=True, null=True) #@UndefinedVariable |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
530 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
531 |
def __init_empty_stat(self): |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
532 |
self.annotation_volume_str = ','.join(['0']*settings.DIVISIONS_FOR_STAT_ANNOTATION) |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
533 |
self.polemics_volume_str = ','.join(['0']*len(settings.SYNTAX.keys())) |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
534 |
self.nb_annotations = 0 |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
535 |
self.last_annotated = None |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
536 |
|
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
537 |
def __list2str(self, l): |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
538 |
return ','.join([str(c) for c in l]) |
|
470
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
539 |
|
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
540 |
def __str2list(self, s): |
|
b1dd78b59750
add all polemic attributes and polemic attribute rates on contents
verrierj
parents:
468
diff
changeset
|
541 |
return [int(x) for x in s.split(',')] |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
542 |
|
| 468 | 543 |
def annotation_volume(): #@NoSelf |
544 |
||
545 |
def fget(self): |
|
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
546 |
return self.__str2list(self.annotation_volume_str) |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
547 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
548 |
def fset(self, value): |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
549 |
self.annotation_volume_str = self.__list2str(value) |
| 468 | 550 |
|
551 |
return locals() |
|
552 |
||
| 482 | 553 |
annotation_volume = property(**annotation_volume()) |
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
554 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
555 |
def polemics_volume(): #@NoSelf |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
556 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
557 |
def fget(self): |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
558 |
return self.__str2list(self.polemics_volume_str) |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
559 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
560 |
def fset(self, value): |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
561 |
self.polemics_volume_str = self.__list2str(value) |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
562 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
563 |
return locals() |
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
564 |
|
|
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
565 |
polemics_volume = property(**polemics_volume()) |
| 344 | 566 |
|
| 266 | 567 |
|
568 |
||
|
542
54dfa397baa3
export stat to extarnal object. does not fully work
ymh <ymh.work@gmail.com>
parents:
521
diff
changeset
|
569 |
|
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
570 |
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
|
571 |
STATE_CHOICES = ( |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
572 |
(1, 'edition'), |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
573 |
(2, 'published'), |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
574 |
(3, 'moderated'), |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
575 |
(4, 'rejected'), |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
576 |
(5, 'deleted') |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
577 |
) |
| 731 | 578 |
ldt_id = models.CharField(max_length=255, unique=True) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
579 |
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
|
580 |
title = models.CharField(max_length=1024) |
|
467
a1e9f5e91791
Removed object AnnotationStat + stats are computed when projects are published/unpublished
verrierj
parents:
458
diff
changeset
|
581 |
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
|
582 |
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
|
583 |
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
|
584 |
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
|
585 |
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
|
586 |
state = models.IntegerField(choices=STATE_CHOICES, default=1) |
|
342
17d615b49a91
Extend image fields size to 200 characters + minor bugs
verrierj
parents:
341
diff
changeset
|
587 |
description = models.TextField(null=True, blank=True) |
|
658
5f22830ffcd7
correct absolute path in images fields. add data migration
ymh <ymh.work@gmail.com>
parents:
570
diff
changeset
|
588 |
image = ImageField(upload_to="thumbnails/projects/", default=settings.DEFAULT_PROJECT_ICON, max_length=200) |
|
314
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
286
diff
changeset
|
589 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
590 |
class Meta: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
591 |
ordering = ["title"] |
| 228 | 592 |
permissions = ( |
|
231
535ce952e51c
Stub of html template for project creation containing a group selection
verrierj
parents:
229
diff
changeset
|
593 |
('view_project', 'Can view project'), |
| 228 | 594 |
) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
595 |
|
|
560
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
596 |
def __setattr__(self, name, value): |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
597 |
super(Project, self).__setattr__(name,value) |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
598 |
if name == "ldt" and hasattr(self, "__ldt_encoded"): |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
599 |
del self.__ldt_encoded |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
600 |
|
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
601 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
602 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
603 |
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
|
604 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
605 |
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
|
606 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
607 |
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
|
608 |
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
|
609 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
610 |
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
|
611 |
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
|
612 |
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
|
613 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
614 |
return None |
|
232
2878499a372b
Security layer moved to middleware and ldt_utils __init__ file
verrierj
parents:
231
diff
changeset
|
615 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
616 |
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
|
617 |
def fget(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
618 |
modes = [] |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
619 |
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
|
620 |
mimetype = content.mimetype |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
621 |
if mimetype: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
622 |
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
|
623 |
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
|
624 |
modes.append(mode) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
625 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
626 |
modes.append("video") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
627 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
628 |
modes.append("video") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
629 |
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
|
630 |
if not current: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
631 |
return item |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
632 |
elif current == item: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
633 |
return item |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
634 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
635 |
return "video" |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
636 |
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
|
637 |
return locals() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
638 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
639 |
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
|
640 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
641 |
@staticmethod |
| 383 | 642 |
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
|
643 |
# owner = Owner.objects.get(user=user) #@UndefinedVariable |
|
503e365a3af7
Starting 'group_management' branch (CAUTION : STILL SOME BUGS)
cavaliet
parents:
125
diff
changeset
|
644 |
owner = user |
| 178 | 645 |
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
|
646 |
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
|
647 |
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
|
648 |
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
|
649 |
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
|
650 |
project.save() |
|
231
535ce952e51c
Stub of html template for project creation containing a group selection
verrierj
parents:
229
diff
changeset
|
651 |
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
|
652 |
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
|
653 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
654 |
for content in contents: |
| 480 | 655 |
project.contents.add(content) |
|
333
4ddf8c0eeab4
Image size is checked before save + project image can be set manually
verrierj
parents:
330
diff
changeset
|
656 |
|
|
4ddf8c0eeab4
Image size is checked before save + project image can be set manually
verrierj
parents:
330
diff
changeset
|
657 |
if set_icon: |
|
4ddf8c0eeab4
Image size is checked before save + project image can be set manually
verrierj
parents:
330
diff
changeset
|
658 |
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
|
659 |
project.save() |
| 384 | 660 |
|
| 383 | 661 |
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
|
662 |
|
| 384 | 663 |
|
|
256
fd20ce3c5fbe
Project are copied in the group they are displayed in group page
verrierj
parents:
247
diff
changeset
|
664 |
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
|
665 |
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
|
666 |
project = copy_ldt(self, project, user) |
| 229 | 667 |
assign('view_project', user, project) |
668 |
assign('change_project', user, project) |
|
|
256
fd20ce3c5fbe
Project are copied in the group they are displayed in group page
verrierj
parents:
247
diff
changeset
|
669 |
if group: |
|
fd20ce3c5fbe
Project are copied in the group they are displayed in group page
verrierj
parents:
247
diff
changeset
|
670 |
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
|
671 |
for content in self.contents.all(): |
| 480 | 672 |
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
|
673 |
return project |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
674 |
|
| 384 | 675 |
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
|
676 |
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
|
677 |
self.save() |
| 247 | 678 |
self.state = 2 |
679 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
680 |
assign('ldt_utils.view_project', everyone, self) |
|
| 384 | 681 |
if allow_write: |
682 |
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
|
683 |
self.save() |
| 247 | 684 |
|
685 |
def unpublish(self): |
|
|
349
63f729155d81
Enhance search and front template : add begin and duration to searched segments.
cavaliet
parents:
344
diff
changeset
|
686 |
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
|
687 |
self.save() |
| 247 | 688 |
self.state = 1 |
689 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
690 |
remove_perm('ldt_utils.view_project', everyone, self) |
|
| 384 | 691 |
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
|
692 |
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
|
693 |
|
| 384 | 694 |
|
|
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
|
695 |
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
|
696 |
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
|
697 |
|
|
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
|
698 |
for content in self.contents.all(): |
| 458 | 699 |
add_image = False |
700 |
try: |
|
701 |
current_image = content.image.file.name |
|
702 |
except IOError: |
|
703 |
add_image = True |
|
704 |
||
705 |
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
|
706 |
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
|
707 |
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
|
708 |
|
|
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
|
709 |
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
|
710 |
return False |
| 247 | 711 |
|
|
167
fe00e7302efe
Change class and functions names to follow PEP8 formatting standards
verrierj
parents:
150
diff
changeset
|
712 |
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
|
713 |
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
|
714 |
return True |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
715 |
else: |
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
342
diff
changeset
|
716 |
return False |
|
560
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
717 |
|
|
840
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
718 |
def has_annotations(self): |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
719 |
nb_annot = 0 |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
720 |
doc = lxml.etree.fromstring(self.ldt) |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
721 |
res = doc.xpath("/iri/annotations/content/ensemble/decoupage") |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
722 |
for r in res: |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
723 |
nb_annot = nb_annot + r.find('elements').__len__() |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
724 |
if nb_annot == 0: |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
725 |
return False |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
726 |
else: |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
727 |
return True |
|
b38c88bdefa2
Creation and deletion of content, iri file, and thumbnail are now transactional
rougeronj
parents:
810
diff
changeset
|
728 |
|
|
560
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
729 |
def ldt_encoded(): #@NoSelf |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
730 |
|
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
731 |
def fget(self): |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
732 |
if self.ldt is None: |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
733 |
return None |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
734 |
if not hasattr(self, "__ldt_encoded"): |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
735 |
m = re.match("<\?xml.*?encoding\s*?=\s*?['\"]([A-Za-z][A-Za-z0-9._-]*)['\"].*?\?>", self.ldt.lstrip(), re.I|re.M|re.U) |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
736 |
if m and m.group(1): |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
737 |
encoding = m.group(1) |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
738 |
else: |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
739 |
encoding = 'utf-8' |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
740 |
self.__ldt_encoded = self.ldt.encode(encoding) |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
741 |
return self.__ldt_encoded |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
742 |
|
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
743 |
return locals() |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
744 |
|
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
745 |
ldt_encoded = property(**ldt_encoded()) |
|
1cb2a4a573e1
correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents:
551
diff
changeset
|
746 |
|
| 468 | 747 |
|
748 |
||
|
240
a46cb257d8ee
Models in ldt_utils derived from SafeModel instead of django.db.model
verrierj
parents:
235
diff
changeset
|
749 |
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
|
750 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
751 |
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
|
752 |
content = models.ForeignKey(Content) |
| 731 | 753 |
project_id = models.CharField(max_length=255, unique=False, blank=True, null=True, db_index=True) |
754 |
iri_id = models.CharField(max_length=255, unique=False, db_index=True) |
|
755 |
ensemble_id = models.CharField(max_length=512, unique=False, db_index=True) |
|
756 |
cutting_id = models.CharField(max_length=512, unique=False, db_index=True) |
|
757 |
element_id = models.CharField(max_length=512, unique=False, db_index=True) |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
758 |
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
|
759 |
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
|
760 |
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
|
761 |
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
|
762 |
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
|
763 |
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
|
764 |
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
|
765 |
polemics = models.IntegerField(null=True, blank=True, default=0) |
|
733
43c9571752f6
correct models. Add blank to generated fields
ymh <ymh.work@gmail.com>
parents:
731
diff
changeset
|
766 |
id_hash = models.CharField(max_length=128, unique=True, blank=True) |
|
810
e7546394653c
add audio annotation to segment api and correct reindex command.
cavaliet
parents:
795
diff
changeset
|
767 |
audio_src = models.CharField(max_length=255, unique=False, null=True, blank=True) |
|
e7546394653c
add audio annotation to segment api and correct reindex command.
cavaliet
parents:
795
diff
changeset
|
768 |
audio_href = models.CharField(max_length=512, unique=False, null=True, blank=True) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
769 |
|
| 468 | 770 |
|
| 570 | 771 |
# All combinations of polemic hashtags can be represented by a combination of |
772 |
# 4 bits, 1 if the hashtag is in the tweet, 0 else. We use the order OK, KO, Q, REF |
|
773 |
# and convert the resulting string into an integer to store the polemic values. |
|
774 |
# mask contains all possible polemic values |
|
| 468 | 775 |
mask = { |
776 |
'OK': set([8,9,10,11,12,13,14,15]), |
|
777 |
'KO': set([4,5,6,7,12,13,14,15]), |
|
778 |
'Q': set([2,3,6,7,10,11,14,15]), |
|
779 |
'REF': set([1,3,5,7,9,11,13,15]), |
|
780 |
} |
|
781 |
||
782 |
def is_polemic(self, polemic_keyword): # OK, KO, Q, REF |
|
783 |
if self.polemics in self.mask[polemic_keyword]: |
|
784 |
return True |
|
785 |
return False |
|
786 |
||
787 |
def get_polemic(self, polemic_keywords): |
|
788 |
value = set(range(16)) |
|
789 |
||
790 |
for keyword in self.mask.keys(): |
|
791 |
if keyword in polemic_keywords: |
|
792 |
value = value.intersection(self.mask[keyword]) |
|
793 |
else: |
|
794 |
value.difference_update(self.mask[keyword]) |
|
795 |
||
796 |
return value.pop() |
|
| 738 | 797 |
|
| 731 | 798 |
def save(self, *args, **kwargs): |
| 738 | 799 |
self.id_hash = generate_hash(self.__unicode__()) |
| 731 | 800 |
super(Segment, self).save(*args, **kwargs) |
801 |
||
| 468 | 802 |
|
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
803 |
def __unicode__(self): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
804 |
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
|
805 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
106
diff
changeset
|
806 |
class Meta: |
| 244 | 807 |
permissions = ( |
808 |
('view_segment', 'Can view segment'), |
|
809 |
) |