remove debug, use action since function causes parsing errors in safari

This commit is contained in:
j 2010-01-30 12:26:10 +05:30
parent 21f8710b38
commit 6f18e50b8b
3 changed files with 69 additions and 21 deletions

View file

@ -163,7 +163,7 @@ class Movie(models.Model):
return getattr(self.imdb, key)
return default
def editable(user):
def editable(self, user):
#FIXME: make permissions work
return False
@ -977,7 +977,7 @@ class List(models.Model):
def __unicode__(self):
return u'%s (%s)' % (self.title, unicode(self.user))
def editable(user):
def editable(self, user):
#FIXME: make permissions work
return False
@ -1132,7 +1132,7 @@ class File(models.Model):
#FIXME: do stuff, like create timeline or create smaller videos etc
return
def editable(user):
def editable(self, user):
#FIXME: make permissions work
return False
@ -1162,7 +1162,7 @@ class Layer(models.Model):
#FIXME: relational layers, Locations, clips etc
#location = models.ForeignKey('Location', default=None)
def editable(user):
def editable(self, user):
#FIXME: make permissions work
return False
@ -1177,9 +1177,8 @@ class Archive(models.Model):
def __unicode__(self):
return '%s' % (self.name)
def editable(user):
#FIXME: make permissions work
return False
def editable(self, user):
return self.users.filter(id=user.id).count() > 0
class ArchiveFile(models.Model):

View file

@ -35,9 +35,9 @@ def api(request):
#response = render_to_json_response({'status': {'code': 200, 'text': 'please use POST'}})
#response['Access-Control-Allow-Origin'] = '*'
return response
if not 'function' in request.POST:
if not 'action' in request.POST:
return apidoc(request)
function = request.POST['function']
function = request.POST['action']
#FIXME: possible to do this in f
#data = json.loads(request.POST['data'])
@ -347,6 +347,64 @@ def api_removeList(request):
response = {'status': {'code': 501, 'text': 'not implemented'}}
return render_to_json_response(response)
@login_required_json
def api_addArchive(request):
'''
ARCHIVE API NEED CLEANUP
param data
{name: string}
return {'status': {'code': int, 'text': string},
'data': {}}
'''
data = json.loads(request.POST['data'])
try:
archive = models.Archive.objects.get(name=data['name'])
response = {'status': {'code': 403, 'text': 'archive with this name exists'}}
except models.Archive.DoesNotExist:
archive = models.Archive(name=data['name'])
archive.save()
archive.users.add(request.user)
response = {'status': {'code': 200, 'text': 'archive created'}}
return render_to_json_response(response)
@login_required_json
def api_editArchive(request):
'''
ARCHIVE API NEED CLEANUP
param data
{id: string, key: value,..}
return {'status': {'code': int, 'text': string},
'data': {}}
'''
data = json.loads(request.POST['data'])
item = get_object_or_404_json(models.Archive, name=data['name'])
if item.editable(request.user):
response = {'status': {'code': 501, 'text': 'not implemented'}}
item.edit(data)
else:
response = {'status': {'code': 403, 'text': 'permission denied'}}
return render_to_json_response(response)
@login_required_json
def api_removeArchive(request):
'''
ARCHIVE API NEED CLEANUP
param data
string id
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.Archive, movieId=itemId)
if item.editable(request.user):
response = {'status': {'code': 501, 'text': 'not implemented'}}
else:
response = {'status': {'code': 403, 'text': 'permission denied'}}
return render_to_json_response(response)
#@login_required_json
def api_update(request):
'''
@ -363,11 +421,10 @@ def api_update(request):
needs_data = []
rename = {}
for oshash in files:
print 'checking', oshash
data = files[oshash]
q = models.ArchiveFile.objects.filter(archive=archive, file__oshash=oshash)
if q.count() == 0:
print "adding file", oshash, data['path']
#print "adding file", oshash, data['path']
f = models.ArchiveFile.get_or_create(archive, oshash)
f.update(data)
if not f.file.movie:
@ -382,7 +439,7 @@ def api_update(request):
needs_data.append(oshash)
if f.path != f.file.path:
rename[oshash] = f.file.path
print "processed files for", archive.name
#print "processed files for", archive.name
#remove all files not in files.keys() from ArchiveFile
response = {'status': {'code': 200, 'text': 'ok'}, 'data': {}}
response['data']['info'] = needs_data
@ -401,7 +458,7 @@ def api_upload(request): #video, timeline, frame
'''
data = json.loads(request.POST['data'])
if data['item'] == 'timeline':
print "not implemented"
#print "not implemented"
response = {'status': {'code': 501, 'text': 'not implemented'}}
return render_to_json_response(response)

View file

@ -24,8 +24,6 @@ def api_login(request):
return {'status': {'code': int, 'text': string}}
'''
print "lgin"
response = {'status': {'code': 403, 'text': 'login failed'}}
data = json.loads(request.POST['data'])
form = LoginForm(data, request.FILES)
@ -38,7 +36,6 @@ def api_login(request):
response = {'status': {'code': 200, 'message': 'You are logged in.', 'user': user_json}}
else:
response = {'status': {'code': 403, 'text': 'Your account is disabled.'}}
print "Your account has been disabled!"
else:
response = {'status': {'code': 403, 'text': 'Your username and password were incorrect.'}}
else:
@ -70,15 +67,12 @@ def api_register(request):
return {'status': {'code': int, 'text': string}}
'''
print "register"
data = json.loads(request.POST['data'])
form = RegisterForm(data, request.FILES)
if form.is_valid():
if models.User.objects.filter(username=form.data['username']).count() > 0:
print "username taken", form.data['username']
response = {'status': {'code':422, 'text': 'username or email exists'}}
elif models.User.objects.filter(email=form.data['email']).count() > 0:
print "username taken", form.data['email']
response = {'status': {'code':422, 'text': 'username or email exists'}}
else:
user = models.User(username=form.data['username'], email=form.data['email'])
@ -89,8 +83,6 @@ def api_register(request):
login(request, user)
response = {'status': {'code':200, 'text': 'account created'}}
else:
print "form invalid"
print form.errors
response = {'status': {'code':422, 'text': 'username exists'}}
return render_to_json_response(response)