| author | ymh <ymh.work@gmail.com> |
| Fri, 15 Oct 2010 11:58:18 +0200 | |
| changeset 89 | 30c6e597a7de |
| parent 88 | 7f2c2d9adf58 |
| child 94 | 9927a619d2b5 |
| permissions | -rw-r--r-- |
| 32 | 1 |
from django.conf import settings |
| 0 | 2 |
from django.db import models |
| 32 | 3 |
from django.utils.translation import ugettext_lazy as _ |
| 0 | 4 |
from ldt.core.models import Document, Owner |
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
5 |
from django.contrib.auth.models import User |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
6 |
import tagging.fields |
| 41 | 7 |
from utils import create_ldt, copy_ldt, create_empty_iri, update_iri, generate_uuid |
| 32 | 8 |
import lxml.etree |
| 0 | 9 |
import os.path |
10 |
import uuid |
|
11 |
||
12 |
class Author(models.Model): |
|
13 |
||
14 |
handle = models.CharField(max_length=512, unique=True, blank=True, null=True) |
|
15 |
email = models.EmailField(unique=False, blank=True, null=True) |
|
16 |
firstname = models.CharField(max_length=512, blank=True, null=True) |
|
17 |
lastname = models.CharField(max_length=512, blank=True, null=True) |
|
18 |
||
19 |
def __unicode__(self): |
|
20 |
return unicode(self.id) + " - " + self.handle + ", " + self.email + ", " + self.firstname + " " + self.lastname |
|
21 |
||
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
22 |
class Media(models.Model): |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
23 |
external_id = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('media.external_id')) |
|
81
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
24 |
external_permalink = models.URLField(max_length=1024, verify_exists=False, null=True, blank=True, verbose_name=_('media.external_permalink')) |
| 82 | 25 |
external_publication_url = models.URLField(max_length=1024, verify_exists=True, null=True, blank=True, verbose_name=_('media.external_publication_url')) |
|
81
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
26 |
external_src_url = models.URLField(max_length=1024, verify_exists=False, null=True, blank=True, verbose_name=_('media.external_src_url')) |
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
27 |
creation_date = models.DateTimeField(auto_now_add=True, verbose_name=_('media.creation_date')) |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
28 |
media_creation_date = models.DateTimeField(null=True, blank=True, verbose_name=_('media.media_creation_date')) |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
29 |
update_date = models.DateTimeField(auto_now=True, verbose_name=_('media.update_date')) |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
30 |
videopath = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('media.videopath')) |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
31 |
duration = models.IntegerField(null=True, blank=True, verbose_name=_('media.duration')) |
| 62 | 32 |
creator = models.ForeignKey(User, blank=True, null=True, verbose_name=_('media.creator')) |
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
33 |
description = models.TextField(null=True, blank=True, verbose_name=_('description')) |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
34 |
title = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('title')) |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
35 |
src = models.CharField(max_length=1024, unique=True, verbose_name=_('media.src')) |
| 62 | 36 |
|
|
71
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
37 |
def stream_src(): |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
38 |
|
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
39 |
def fget(self): |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
40 |
res_src = self.src.rstrip() |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
41 |
if self.videopath and self.videopath.startswith("rtmp://"): |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
42 |
extension = res_src.split(".")[-1] |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
43 |
res_src = { |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
44 |
'flv': lambda s: s, |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
45 |
'mp3': lambda s: "%s:%s" %("mp3",res_src[:-4]), |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
46 |
'mp4': lambda s: "%s:%s" %("mp4",res_src[:-4]), |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
47 |
'f4v': lambda s: "%s:%s" %("mp4",res_src[:-4]), |
|
81
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
48 |
}.get(extension, lambda s:s)(res_src.lower()) |
|
71
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
49 |
return res_src |
| 72 | 50 |
|
51 |
return locals() |
|
52 |
||
|
71
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
53 |
stream_src = property(**stream_src()) |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
54 |
|
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
55 |
def save(self, *args, **kwargs): |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
56 |
super(Media, self).save(*args, **kwargs) |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
57 |
for content in self.content_set.all(): |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
58 |
content.sync_iri_file() |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
59 |
|
| 62 | 60 |
def __unicode__(self): |
61 |
strings = [] |
|
62 |
if self.title: |
|
63 |
strings.append(unicode(self.title)) |
|
64 |
else: |
|
65 |
strings.append(unicode(self.src)) |
|
66 |
if self.external_id: |
|
67 |
strings.append(unicode(self.external_id)) |
|
68 |
return "|".join(strings) |
|
| 0 | 69 |
|
|
71
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
70 |
|
| 0 | 71 |
class Content(models.Model): |
| 44 | 72 |
iri_id = models.CharField(max_length=1024, unique=True, default=generate_uuid, verbose_name=_('content.iri_id')) |
73 |
iriurl = models.CharField(max_length=1024, verbose_name=_('content.iriurl')) |
|
74 |
creation_date = models.DateTimeField(auto_now_add=True, verbose_name=_('content.creation_date')) |
|
75 |
update_date = models.DateTimeField(auto_now=True, verbose_name=_('content.update_date')) |
|
76 |
title = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('content.title')) |
|
77 |
description = models.TextField(null=True, blank=True, verbose_name=_('content.description')) |
|
78 |
authors = models.ManyToManyField(Author, blank=True, verbose_name=_('content.authors')) |
|
79 |
duration = models.IntegerField(null=True, blank=True, verbose_name=_('content.duration')) |
|
80 |
content_creation_date = models.DateTimeField(null=True, blank=True, verbose_name=_('content.content_creation_date')) |
|
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
81 |
tags = tagging.fields.TagField(max_length=2048, null=True, blank=True ) |
| 62 | 82 |
media_obj = models.ForeignKey('Media', blank=True, null=True ) |
|
81
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
83 |
|
|
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
84 |
class Meta: |
|
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
85 |
ordering = ["title"] |
| 0 | 86 |
|
87 |
def get_duration(self): |
|
88 |
if self.duration is None: |
|
| 32 | 89 |
doc = lxml.etree.parse(self.iri_file_path()) |
90 |
res = doc.xpath("/iri/body/medias/media[@id='video']/video") |
|
91 |
self.duration = int(res[0].get(u'dur') or 0) |
|
| 0 | 92 |
self.save() |
93 |
return self.duration |
|
94 |
||
95 |
def delete(self): |
|
96 |
super(Content, self).delete() |
|
97 |
writer = lucene.IndexWriter(STORE, ANALYZER, True, lucene.IndexWriter.MaxFieldLength.UNLIMITED) |
|
98 |
writer.deleteDocuments(lucene.Term("iri_id", self.iri_id)) |
|
99 |
writer.commit() |
|
100 |
||
|
71
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
101 |
def sync_iri_file(self): |
| 0 | 102 |
# create iri file if needed |
| 5 | 103 |
created = False |
| 0 | 104 |
try: |
105 |
iri_file_path = self.iri_file_path() |
|
106 |
if not os.path.exists(iri_file_path): |
|
107 |
dir = os.path.dirname(iri_file_path) |
|
108 |
if not os.path.exists(dir): |
|
109 |
os.makedirs(dir) |
|
| 5 | 110 |
created = True |
| 0 | 111 |
file = open(iri_file_path,"w") |
112 |
create_empty_iri(file, self, "IRI") |
|
| 5 | 113 |
else: |
114 |
created = False |
|
115 |
update_iri(iri_file_path, self, "IRI") |
|
116 |
||
| 0 | 117 |
except Exception, e: |
| 5 | 118 |
if created: |
119 |
if os.path.exists(iri_file_path): |
|
120 |
os.remove(iri_file_path) |
|
121 |
raise e |
|
| 41 | 122 |
|
|
71
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
123 |
|
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
124 |
#TODO: better manage the change in .iri name and error scenario (save in temp file + rename |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
125 |
def save(self, *args, **kwargs): |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
126 |
|
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
127 |
self.sync_iri_file() |
| 0 | 128 |
# update it |
| 32 | 129 |
super(Content, self).save(*args, **kwargs) |
| 0 | 130 |
|
131 |
def __unicode__(self): |
|
132 |
return str(self.id) + ": " + self.iri_id |
|
133 |
||
134 |
def iri_url(self, web_url=settings.WEB_URL): |
|
135 |
if 'http' in self.iriurl or 'https' in self.iriurl: |
|
136 |
return self.iriurl |
|
137 |
else: |
|
138 |
return unicode(web_url) + unicode(settings.MEDIA_URL)+u"media/ldt/"+unicode(self.iriurl) |
|
139 |
||
140 |
def iri_file_path(self): |
|
141 |
return os.path.join(os.path.join(os.path.join(os.path.join(settings.MEDIA_ROOT, "media"), "ldt"), self.iri_id), os.path.basename(self.iriurl)) |
|
142 |
||
143 |
def iri_url_template(self): |
|
144 |
return "${web_url}${media_url}media/ldt/" + unicode(self.iri_id) + "/" + os.path.basename(self.iriurl) |
|
| 62 | 145 |
|
146 |
||
147 |
def __get_empty_media(self): |
|
148 |
if settings.EMPTY_MEDIA_EXTERNALID: |
|
149 |
empty_media = Media.objects.get(externalid=settings.EMPTY_MEDIA_EXTERNALID) |
|
150 |
return empty_media |
|
151 |
else: |
|
152 |
return None |
|
153 |
||
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
154 |
|
|
71
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
155 |
def stream_src(): |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
156 |
|
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
157 |
def fget(self): |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
158 |
if self.media_obj is not None: |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
159 |
return self.media_obj.stream_src |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
160 |
else: |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
161 |
return None |
| 72 | 162 |
|
163 |
return locals() |
|
164 |
||
|
71
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
165 |
stream_src = property(**stream_src()) |
|
fc1210bbb854
correct translation +some bug on update
ymh <ymh.work@gmail.com>
parents:
67
diff
changeset
|
166 |
|
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
167 |
def videopath(): #@NoSelf |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
168 |
doc = """simulate videopath""" #@UnusedVariable |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
169 |
|
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
170 |
def fget(self): |
| 62 | 171 |
if self.media_obj is None: |
172 |
empty_media = self.__get_empty_media() |
|
173 |
if empty_media: |
|
174 |
return empty_media.videopath |
|
175 |
else: |
|
176 |
return None |
|
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
177 |
else: |
| 62 | 178 |
return self.media_obj.videopath |
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
179 |
|
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
180 |
def fset(self, value): |
| 62 | 181 |
if self.media_obj is not None: |
182 |
self.media_obj.videopath = value |
|
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
183 |
|
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
184 |
return locals() |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
185 |
|
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
186 |
videopath = property(**videopath()) |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
187 |
|
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
188 |
def src(): #@NoSelf |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
189 |
doc = """simulate videopath""" #@UnusedVariable |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
190 |
|
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
191 |
def fget(self): |
| 62 | 192 |
if self.media_obj is None: |
193 |
empty_media = self.__get_empty_media() |
|
194 |
if empty_media: |
|
195 |
return empty_media.src |
|
196 |
else: |
|
197 |
return None |
|
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
198 |
else: |
| 62 | 199 |
return self.media_obj.src |
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
200 |
|
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
201 |
def fset(self, value): |
| 62 | 202 |
if self.media_obj is None or self.media_obj.src != value: |
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
203 |
media, created = Media.objects.get_or_create(src=value, defaults={'src':value}) |
| 62 | 204 |
self.media_obj = media |
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
205 |
self.save() |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
206 |
|
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
207 |
return locals() |
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
208 |
|
|
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
209 |
src = property(**src()) |
| 63 | 210 |
|
| 67 | 211 |
def external_id(): #@NoSelf |
| 63 | 212 |
doc = """simulate externalid""" #@UnusedVariable |
213 |
||
214 |
def fget(self): |
|
215 |
if self.media_obj is None: |
|
216 |
empty_media = self.__get_empty_media() |
|
217 |
if empty_media: |
|
| 67 | 218 |
return empty_media.external_id |
| 63 | 219 |
else: |
220 |
return None |
|
221 |
else: |
|
| 67 | 222 |
return self.media_obj.external_id |
| 63 | 223 |
|
224 |
def fset(self, value): |
|
225 |
if self.media_obj is not None: |
|
| 67 | 226 |
self.media_obj.external_id = value |
| 63 | 227 |
|
228 |
return locals() |
|
229 |
||
| 67 | 230 |
external_id = property(**external_id()) |
| 63 | 231 |
|
| 0 | 232 |
|
233 |
||
234 |
class Project(Document): |
|
235 |
STATE_CHOICES=( |
|
236 |
(1, 'edition'), |
|
237 |
(2, 'published'), |
|
238 |
(3, 'moderated'), |
|
239 |
(4, 'rejected'), |
|
240 |
(5, 'deleted') |
|
241 |
) |
|
242 |
ldt_id = models.CharField(max_length=1024, unique=True) |
|
243 |
ldt = models.TextField(null=True) |
|
244 |
title = models.CharField(max_length=1024) |
|
245 |
contents = models.ManyToManyField(Content) |
|
246 |
creation_date = models.DateTimeField(auto_now_add=True) |
|
247 |
modification_date = models.DateTimeField(auto_now=True) |
|
248 |
created_by = models.CharField(_("created by"), max_length=70) |
|
249 |
changed_by = models.CharField(_("changed by"), max_length=70) |
|
250 |
state = models.IntegerField(choices=STATE_CHOICES, default=1) |
|
251 |
||
|
81
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
252 |
class Meta: |
|
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
253 |
ordering = ["title"] |
|
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
254 |
|
|
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
255 |
|
| 0 | 256 |
def __unicode__(self): |
257 |
return unicode(self.id) + u": " + unicode(self.ldt_id) |
|
258 |
||
259 |
def get_description(self, doc=None): |
|
260 |
||
261 |
if doc is None: |
|
| 32 | 262 |
doc = lxml.etree.fromstring(self.ldt) |
| 0 | 263 |
|
| 32 | 264 |
res = doc.xpath("/iri/project") |
| 0 | 265 |
if len(res) > 0: |
| 32 | 266 |
return res[0].get(u'abstract') |
| 0 | 267 |
else: |
268 |
return None |
|
269 |
||
270 |
||
271 |
@staticmethod |
|
272 |
def create_project(user, title, contents): |
|
273 |
owner = Owner.objects.get(user=user) |
|
274 |
project = Project(title=title, owner=owner) |
|
275 |
project.ldt_id = str(uuid.uuid1()) |
|
276 |
project.created_by=user.username |
|
277 |
project.changed_by=user.username |
|
278 |
project.state = 1 |
|
279 |
project.save() |
|
280 |
for content in contents: |
|
281 |
project.contents.add(content) |
|
282 |
project.save() |
|
283 |
return create_ldt(project, user) |
|
284 |
||
285 |
def copy_project(self, user, title): |
|
286 |
owner = Owner.objects.get(user=user) |
|
287 |
project = Project(title=title, owner=owner) |
|
288 |
project = copy_ldt(self, project, user) |
|
289 |
project.save() |
|
290 |
for content in self.contents.all(): |
|
291 |
project.contents.add(content) |
|
292 |
project.save() |
|
293 |
return project |
|
|
81
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
294 |
|
|
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
295 |
def checkAccess(self, user): |
|
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
296 |
if (user and user.is_staff) or self.state == 2: |
|
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
297 |
return True |
|
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
298 |
else: |
|
97b12f5f2c7a
first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
299 |
return False |
| 83 | 300 |
|
| 0 | 301 |
|
302 |
class Segment(models.Model): |
|
303 |
||
304 |
project_obj = models.ForeignKey(Project, null=True) |
|
305 |
content = models.ForeignKey(Content) |
|
306 |
project_id = models.CharField(max_length=1024, unique=False, blank=True, null=True) |
|
307 |
iri_id = models.CharField(max_length=1024, unique=False) |
|
308 |
ensemble_id = models.CharField(max_length=1024, unique=False) |
|
309 |
cutting_id = models.CharField(max_length=1024, unique=False) |
|
310 |
element_id = models.CharField(max_length=1024, unique=False) |
|
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
311 |
tags = tagging.fields.TagField(max_length=2048, null=True, blank=True, unique=False) |
| 0 | 312 |
title = models.CharField(max_length=2048, unique=False, null=True, blank=True) |
313 |
duration = models.IntegerField(null=True) |
|
314 |
start_ts = models.IntegerField(null=True) |
|
315 |
author = models.CharField(max_length=1024, unique=False, null=True, blank=True) |
|
316 |
date = models.CharField(max_length=128, unique=False, null=True, blank=True) |
|
317 |
abstract = models.TextField(null=True, blank=True) |
|
318 |
||
319 |
def __unicode__(self): |
|
320 |
return "/".join((unicode(self.project_id), unicode(self.iri_id), unicode(self.ensemble_id), unicode(self.cutting_id), unicode(self.element_id))) |
|
321 |
||
322 |
class Meta: |
|
323 |
unique_together = (('project_id', 'iri_id', 'ensemble_id', 'cutting_id', 'element_id'),) |
|
324 |
||
|
60
a8ad7ebf5902
various update and splitmedia from content
ymh <ymh.work@gmail.com>
parents:
44
diff
changeset
|
325 |