2011-12-19 19:41:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
from __future__ import division
|
|
|
|
|
|
|
|
import models
|
|
|
|
from ox.utils import json
|
2011-12-20 11:19:10 +00:00
|
|
|
from ox.django.shortcuts import render_to_json_response, json_response
|
2011-12-19 19:41:37 +00:00
|
|
|
|
|
|
|
from itemlist.views import get_list_or_404_json
|
2012-01-03 20:18:47 +00:00
|
|
|
from ox.django.api import actions
|
2011-12-19 19:41:37 +00:00
|
|
|
|
|
|
|
def tv(request):
|
2013-03-04 19:35:06 +00:00
|
|
|
'''
|
|
|
|
takes {
|
|
|
|
list: string
|
|
|
|
}
|
|
|
|
returns {
|
|
|
|
item: string,
|
|
|
|
position: float,
|
|
|
|
title: string,
|
|
|
|
...
|
|
|
|
}
|
|
|
|
'''
|
2011-12-19 19:41:37 +00:00
|
|
|
data = json.loads(request.POST['data'])
|
2011-12-19 21:54:53 +00:00
|
|
|
if 'list' in data and data['list']:
|
|
|
|
list = get_list_or_404_json(data['list'])
|
|
|
|
if list.accessible(request.user):
|
|
|
|
channel, created = models.Channel.objects.get_or_create(list=list)
|
|
|
|
response = json_response(status=200, text='created')
|
|
|
|
response['data'] = channel.json(request.user)
|
|
|
|
else:
|
|
|
|
response = json_response(status=404, text='list not found')
|
|
|
|
else:
|
|
|
|
channel, created = models.Channel.objects.get_or_create(list=None)
|
2013-07-11 18:07:32 +00:00
|
|
|
response = json_response(status=200, text='ok')
|
2011-12-19 21:12:23 +00:00
|
|
|
response['data'] = channel.json(request.user)
|
2011-12-19 19:41:37 +00:00
|
|
|
return render_to_json_response(response)
|
|
|
|
actions.register(tv, cache=False)
|