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