editable, getFileInfo, getItem, templates
This commit is contained in:
parent
228cb1f851
commit
2bff8f8045
7 changed files with 109 additions and 60 deletions
|
@ -162,6 +162,18 @@ class Movie(models.Model):
|
||||||
return getattr(self.imdb, key)
|
return getattr(self.imdb, key)
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
def editable(user):
|
||||||
|
#FIXME: make permissions work
|
||||||
|
return False
|
||||||
|
|
||||||
|
def edit(self, data):
|
||||||
|
#FIXME: how to map the keys to the right place to write them to?
|
||||||
|
for key in data:
|
||||||
|
if key != 'id':
|
||||||
|
setattr(self.oxdb, key, data[key])
|
||||||
|
self.oxdb.save()
|
||||||
|
self.save()
|
||||||
|
|
||||||
def _manual(self, qs, f='manual'):
|
def _manual(self, qs, f='manual'):
|
||||||
if qs.filter(**{f:True}).count() > 0:
|
if qs.filter(**{f:True}).count() > 0:
|
||||||
return qs.exclude(**{f:False})
|
return qs.exclude(**{f:False})
|
||||||
|
@ -966,6 +978,10 @@ class List(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return u'%s (%s)' % (self.title, unicode(self.user))
|
return u'%s (%s)' % (self.title, unicode(self.user))
|
||||||
|
|
||||||
|
def editable(user):
|
||||||
|
#FIXME: make permissions work
|
||||||
|
return False
|
||||||
|
|
||||||
class ListItem(models.Model):
|
class ListItem(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
modified = models.DateTimeField(auto_now=True)
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
@ -1007,8 +1023,8 @@ class File(models.Model):
|
||||||
|
|
||||||
type = models.IntegerField(default=0, choices=FILE_TYPES)
|
type = models.IntegerField(default=0, choices=FILE_TYPES)
|
||||||
info = fields.DictField(default={})
|
info = fields.DictField(default={})
|
||||||
#FIMXE: why do i need those in the db? could jsut have them in info
|
|
||||||
|
|
||||||
|
#FIXME: why do i need those in the db? could just have them in info
|
||||||
path = models.CharField(blank=True, max_length=2048)
|
path = models.CharField(blank=True, max_length=2048)
|
||||||
size = models.BigIntegerField(default=-1)
|
size = models.BigIntegerField(default=-1)
|
||||||
duration = models.FloatField(default=-1)
|
duration = models.FloatField(default=-1)
|
||||||
|
@ -1117,6 +1133,10 @@ class File(models.Model):
|
||||||
#FIXME: do stuff, like create timeline or create smaller videos etc
|
#FIXME: do stuff, like create timeline or create smaller videos etc
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def editable(user):
|
||||||
|
#FIXME: make permissions work
|
||||||
|
return False
|
||||||
|
|
||||||
class Still(models.Model):
|
class Still(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
modified = models.DateTimeField(auto_now=True)
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
@ -1127,29 +1147,6 @@ class Still(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return '%s at %s' % (self.file, self.position)
|
return '%s at %s' % (self.file, self.position)
|
||||||
|
|
||||||
class Subtitle(models.Model):
|
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
|
||||||
modified = models.DateTimeField(auto_now=True)
|
|
||||||
user = models.ForeignKey(User)
|
|
||||||
|
|
||||||
file = models.ForeignKey(File, related_name="subtitles")
|
|
||||||
language = models.CharField(max_length=16)
|
|
||||||
srt = models.TextField(blank=True)
|
|
||||||
|
|
||||||
def get_or_create(model, user, oshash, language):
|
|
||||||
q = model.objects.filter(file__oshash=oshash, language=language, user=user)
|
|
||||||
if q.count() > 0:
|
|
||||||
s = q[0]
|
|
||||||
else:
|
|
||||||
f = models.File.get_or_create(oshash=oshash)
|
|
||||||
s = model.objects.create(user=user, language=language, file=f)
|
|
||||||
s.save()
|
|
||||||
return s
|
|
||||||
get_or_create = classmethod(get_or_create)
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return '%s.%s.srt' % (os.path.splitext(self.movie_file.path)[0], self.language)
|
|
||||||
|
|
||||||
class Layer(models.Model):
|
class Layer(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
modified = models.DateTimeField(auto_now=True)
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
@ -1163,8 +1160,14 @@ class Layer(models.Model):
|
||||||
type = models.CharField(blank=True, max_length=255)
|
type = models.CharField(blank=True, max_length=255)
|
||||||
value = models.TextField()
|
value = models.TextField()
|
||||||
|
|
||||||
|
#FIXME: relational layers, Locations, clips etc
|
||||||
#location = models.ForeignKey('Location', default=None)
|
#location = models.ForeignKey('Location', default=None)
|
||||||
|
|
||||||
|
def editable(user):
|
||||||
|
#FIXME: make permissions work
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class Archive(models.Model):
|
class Archive(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
modified = models.DateTimeField(auto_now=True)
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
@ -1175,6 +1178,11 @@ class Archive(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return '%s' % (self.name)
|
return '%s' % (self.name)
|
||||||
|
|
||||||
|
def editable(user):
|
||||||
|
#FIXME: make permissions work
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class ArchiveFile(models.Model):
|
class ArchiveFile(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
modified = models.DateTimeField(auto_now=True)
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
|
|
@ -18,7 +18,7 @@ try:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from django.utils import simplejson as json
|
from django.utils import simplejson as json
|
||||||
from oxdjango.shortcuts import render_to_json_response
|
from oxdjango.shortcuts import render_to_json_response, get_object_or_404_json
|
||||||
from oxdjango.decorators import login_required_json
|
from oxdjango.decorators import login_required_json
|
||||||
|
|
||||||
import models
|
import models
|
||||||
|
@ -199,35 +199,50 @@ def api_find(request):
|
||||||
|
|
||||||
def api_getItem(request):
|
def api_getItem(request):
|
||||||
'''
|
'''
|
||||||
api('getItem', id)
|
param data
|
||||||
return item with id
|
string id
|
||||||
|
|
||||||
|
return item dict
|
||||||
'''
|
'''
|
||||||
response = {'status': {'code': 200, 'text': 'ok'}}
|
response = {'status': {'code': 200, 'text': 'ok'}}
|
||||||
itemId = json.loads(request.POST['data'])
|
itemId = json.loads(request.POST['data'])
|
||||||
item = models.Movie.objects.get(movieId=itemId)
|
item = get_object_or_404_json(models.Movie, movieId=itemId)
|
||||||
response['item'] = item.json()
|
#FIXME: check permissions
|
||||||
|
response['data'] = {'item': item.json}
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
||||||
@login_required_json
|
@login_required_json
|
||||||
def api_editItem(request):
|
def api_editItem(request):
|
||||||
'''
|
'''
|
||||||
param data
|
param data
|
||||||
{key: value}
|
{id: string, key: value,..}
|
||||||
return {'status': {'code': int, 'text': string},
|
return {'status': {'code': int, 'text': string},
|
||||||
'data': {}}
|
'data': {}}
|
||||||
'''
|
'''
|
||||||
|
data = json.loads(request.POST['data'])
|
||||||
|
item = get_object_or_404_json(models.Movie, movieId=data['id'])
|
||||||
|
if item.editable(request.user):
|
||||||
response = {'status': {'code': 500, 'text': 'not implemented'}}
|
response = {'status': {'code': 500, 'text': 'not implemented'}}
|
||||||
|
item.edit(data)
|
||||||
|
else:
|
||||||
|
response = {'status': {'code': 403, 'text': 'permission denied'}}
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
||||||
@login_required_json
|
@login_required_json
|
||||||
def api_removeItem(request):
|
def api_removeItem(request):
|
||||||
'''
|
'''
|
||||||
param data
|
param data
|
||||||
{key: value}
|
string id
|
||||||
return {'status': {'code': int, 'text': string},
|
|
||||||
'data': {}}
|
return {'status': {'code': int, 'text': string}}
|
||||||
'''
|
'''
|
||||||
|
response = {'status': {'code': 200, 'text': 'ok'}}
|
||||||
|
itemId = json.loads(request.POST['data'])
|
||||||
|
item = get_object_or_404_json(models.Movie, movieId=itemId)
|
||||||
|
if item.editable(request.user):
|
||||||
response = {'status': {'code': 500, 'text': 'not implemented'}}
|
response = {'status': {'code': 500, 'text': 'not implemented'}}
|
||||||
|
else:
|
||||||
|
response = {'status': {'code': 403, 'text': 'permission denied'}}
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
||||||
@login_required_json
|
@login_required_json
|
||||||
|
@ -260,6 +275,15 @@ def api_editLayer(request):
|
||||||
return {'status': {'code': int, 'text': string},
|
return {'status': {'code': int, 'text': string},
|
||||||
'data': {}}
|
'data': {}}
|
||||||
'''
|
'''
|
||||||
|
response = {'status': {'code': 200, 'text': 'ok'}}
|
||||||
|
data = json.loads(request.POST['data'])
|
||||||
|
layer = get_object_or_404_json(models.Layer, pk=data['id'])
|
||||||
|
if layer.editable(request.user):
|
||||||
|
response = {'status': {'code': 500, 'text': 'not implemented'}}
|
||||||
|
else:
|
||||||
|
response = {'status': {'code': 403, 'text': 'permission denied'}}
|
||||||
|
return render_to_json_response(response)
|
||||||
|
|
||||||
response = {'status': {'code': 500, 'text': 'not implemented'}}
|
response = {'status': {'code': 500, 'text': 'not implemented'}}
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
||||||
|
@ -368,6 +392,10 @@ def api_upload(request): #video, timeline, frame
|
||||||
return {'status': {'code': int, 'text': string},
|
return {'status': {'code': int, 'text': string},
|
||||||
'data': {}}
|
'data': {}}
|
||||||
'''
|
'''
|
||||||
|
data = json.loads(request.POST['data'])
|
||||||
|
if data['item'] == 'timeline':
|
||||||
|
print "not implemented"
|
||||||
|
|
||||||
response = {'status': {'code': 500, 'text': 'not implemented'}}
|
response = {'status': {'code': 500, 'text': 'not implemented'}}
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
||||||
|
@ -406,33 +434,21 @@ def api_getImdbId(request):
|
||||||
response = {'status': {'code': 404, 'text': 'not found'}}
|
response = {'status': {'code': 404, 'text': 'not found'}}
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
||||||
|
def api_getFileInfo(request):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#FIXME: old stuff below...
|
|
||||||
'''
|
'''
|
||||||
GET info?oshash=a41cde31c581e11d
|
param data
|
||||||
> {
|
oshash string
|
||||||
"movie_id": 0123456, ??
|
return {'status': {'code': int, 'text': string},
|
||||||
"oshash": "a41cde31c581e11d",
|
'data': {imdbId:string }}
|
||||||
"sha1":..,
|
|
||||||
"md5":..
|
|
||||||
"duration": 5.266667,
|
|
||||||
"video": [],
|
|
||||||
"audio": [],
|
|
||||||
"path": "E/Example, The/An Example.avi",
|
|
||||||
"size": 1646274
|
|
||||||
}
|
|
||||||
'''
|
'''
|
||||||
def file_info(request):
|
if 'data' in request.POST:
|
||||||
|
oshash = json.loads(request.POST['data'])
|
||||||
|
elif 'oshash' in request.GET:
|
||||||
oshash = request.GET['oshash']
|
oshash = request.GET['oshash']
|
||||||
f = models.MovieFile.objects.get(oshash=oshash)
|
f = models.MovieFile.objects.get(oshash=oshash)
|
||||||
response = f.json()
|
response = {'data': f.json()}
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
GET subtitles?oshash=a41cde31c581e11d
|
GET subtitles?oshash=a41cde31c581e11d
|
||||||
> {
|
> {
|
||||||
|
|
|
@ -40,4 +40,3 @@ def setPreference(user, key, value):
|
||||||
else:
|
else:
|
||||||
p = Preference(user=user, key=key, value=value)
|
p = Preference(user=user, key=key, value=value)
|
||||||
p.save()
|
p.save()
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__))
|
||||||
|
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
TEMPLATE_DEBUG = DEBUG
|
TEMPLATE_DEBUG = DEBUG
|
||||||
|
JSON_DEBUG = False
|
||||||
|
|
||||||
ADMINS = (
|
ADMINS = (
|
||||||
# ('Your Name', 'your_email@domain.com'),
|
# ('Your Name', 'your_email@domain.com'),
|
||||||
|
|
2
oxdb/templates/404.html
Normal file
2
oxdb/templates/404.html
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
{'status': {'code': 404, 'text': 'not found'}}
|
||||||
|
|
1
oxdb/templates/500.html
Normal file
1
oxdb/templates/500.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
500 error
|
22
oxdb/templates/api.html
Normal file
22
oxdb/templates/api.html
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>0xdb.org API</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||||
|
<script type="text/javascript" src="/static/js/jquery/jquery.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Public API</h1>
|
||||||
|
<a href="http://code.0xdb.org/oxdb2/annotate/head%3A/oxdb/backend/views.py">look inside</a>
|
||||||
|
<div>
|
||||||
|
{% for f in api %}
|
||||||
|
<div>
|
||||||
|
<h2><a name="{{f.name}}">function: {{f.name}}</a></h2>
|
||||||
|
<pre style="padding-left: 24px">
|
||||||
|
{{f.doc|safe}}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue