| author | ymh <ymh.work@gmail.com> |
| Tue, 01 Jun 2010 19:07:23 +0200 | |
| changeset 35 | 8b65c9054eac |
| parent 29 | cc9b7e14412b |
| child 36 | bbe6f42d42b2 |
| permissions | -rw-r--r-- |
| 0 | 1 |
import os |
| 29 | 2 |
import xml |
3 |
import Ft.Xml |
|
| 0 | 4 |
|
5 |
from django.db import models |
|
6 |
from django.contrib import admin |
|
7 |
import lucene |
|
|
3
526ebd3988b0
replace pocketfilms occurence by blinkster
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
8 |
from blinkster.ldt import STORE |
|
526ebd3988b0
replace pocketfilms occurence by blinkster
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
9 |
from blinkster.ldt import ANALYZER |
|
526ebd3988b0
replace pocketfilms occurence by blinkster
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
10 |
from blinkster import settings |
| 0 | 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) |
|
| 35 | 16 |
firstname = models.CharField(max_length=512, blank=True, null=True) |
17 |
lastname = models.CharField(max_length=512, blank=True, null=True) |
|
| 0 | 18 |
|
19 |
def __unicode__(self): |
|
20 |
return unicode(self.id) + " - " + self.handle + ", " + self.email + ", " + self.firstname + " " + self.lastname |
|
21 |
||
22 |
class Content(models.Model): |
|
23 |
||
24 |
def uploadTo(self, filename): |
|
| 35 | 25 |
return "media/ldt/" + self.iri_id + "/" + filename |
| 0 | 26 |
|
27 |
iri_id = models.CharField(max_length=1024, unique=True) |
|
28 |
iri = models.FileField(upload_to=uploadTo, null=True) |
|
29 |
creation_date = models.DateTimeField(auto_now_add=True) |
|
30 |
update_date = models.DateTimeField(auto_now=True) |
|
31 |
title = models.CharField(max_length=1024, null=True) |
|
32 |
description = models.TextField(null=True) |
|
33 |
external_id = models.CharField(max_length=1024, null=True, blank=True) |
|
34 |
authors = models.ManyToManyField(Author) |
|
| 29 | 35 |
duration = models.IntegerField(null=True, blank=True) |
36 |
||
37 |
def get_duration(self): |
|
38 |
if self.duration is None: |
|
39 |
doc = xml.dom.minidom.parse(self.iri_file_path()) |
|
40 |
doc = Ft.Xml.Domlette.ConvertDocument(doc) |
|
41 |
con = xml.xpath.Context.Context(doc, 1, 1, None) |
|
42 |
res = xml.xpath.Evaluate("/iri/body/medias/media[@id='video']/video", context=con) |
|
43 |
self.duration = int(res[0].getAttributeNS(None, 'dur')) |
|
44 |
self.save() |
|
45 |
return self.duration |
|
| 0 | 46 |
|
47 |
def delete(self): |
|
48 |
super(Content, self).delete() |
|
49 |
writer = lucene.IndexModifier(STORE, ANALYZER, True) |
|
50 |
writer.deleteDocuments(lucene.Term("iri_id", self.iri_id)) |
|
51 |
writer.flush() |
|
52 |
||
53 |
def iri_file_path(self): |
|
| 35 | 54 |
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.iri.path)) |
| 0 | 55 |
|
56 |
def iri_url(self, web_url=""): |
|
| 35 | 57 |
return unicode(web_url) + unicode(settings.MEDIA_URL) + u"media/ldt/" + unicode(self.iri_id) + "/" + os.path.basename(self.iri.path) |
| 0 | 58 |
|
59 |
def iri_url_template(self): |
|
| 35 | 60 |
return "${web_url}${media_url}media/ldt/" + unicode(self.iri_id) + "/" + os.path.basename(self.iri.path) |
| 0 | 61 |
|
62 |
def __unicode__(self): |
|
63 |
return str(self.id) + ": " + self.iri_id |
|
| 16 | 64 |
|
| 0 | 65 |
|
66 |
class LdtProject(models.Model): |
|
67 |
||
68 |
ldt_id = models.CharField(max_length=1024, unique=True) |
|
69 |
ldt = models.TextField(null=True) |
|
70 |
authors = models.ManyToManyField(Author) |
|
71 |
contents = models.ManyToManyField(Content) |
|
72 |
creation_date = models.DateTimeField(auto_now_add=True) |
|
73 |
modification_date = models.DateTimeField(auto_now=True) |
|
74 |
||
75 |
def __unicode__(self): |
|
76 |
return unicode(self.id) + u": " + unicode(self.ldt_id) |
|
| 16 | 77 |
|
78 |
class Segment(models.Model): |
|
79 |
||
80 |
project_obj = models.ForeignKey(LdtProject, null=True) |
|
81 |
content = models.ForeignKey(Content) |
|
| 35 | 82 |
project_id = models.CharField(max_length=1024, unique=False, blank=True, null=True) |
| 16 | 83 |
iri_id = models.CharField(max_length=1024, unique=False) |
84 |
ensemble_id = models.CharField(max_length=1024, unique=False) |
|
85 |
cutting_id = models.CharField(max_length=1024, unique=False) |
|
86 |
element_id = models.CharField(max_length=1024, unique=False) |
|
| 35 | 87 |
tags = models.CharField(max_length=2048, unique=False, null=True, blank=True) |
| 16 | 88 |
title = models.CharField(max_length=2048, unique=False, null=True, blank=True) |
89 |
duration = models.IntegerField(null=True) |
|
90 |
start_ts = models.IntegerField(null=True) |
|
91 |
author = models.CharField(max_length=1024, unique=False, null=True, blank=True) |
|
92 |
date = models.CharField(max_length=128, unique=False, null=True, blank=True) |
|
93 |
abstract = models.TextField(null=True, blank=True) |
|
94 |
||
95 |
def __unicode__(self): |
|
96 |
return "/".join((unicode(self.project_id), unicode(self.iri_id), unicode(self.ensemble_id), unicode(self.cutting_id), unicode(self.element_id))) |
|
97 |
||
98 |
class Meta: |
|
| 35 | 99 |
unique_together = (('project_id', 'iri_id', 'ensemble_id', 'cutting_id', 'element_id'),) |
| 0 | 100 |
|
101 |
||
102 |
admin.site.register(Content) |
|
103 |
admin.site.register(Author) |
|
104 |
admin.site.register(LdtProject) |
|
| 16 | 105 |
admin.site.register(Segment) |
| 0 | 106 |