def avinfo(filename, cached=True): if cached: return cache(filename, 'info') if os.path.getsize(filename): #ffmpeg2theora = cmd('ffmpeg2theora') identify = cmd('adef_identify') '''p = subprocess.Popen([ffmpeg2theora], stdout=subprocess.PIPE, stderr=subprocess.PIPE) info, error = p.communicate() version = info.split('\n')[0].split(' - ')[0].split(' ')[-1] if version < '0.27': raise EnvironmentError('version of ffmpeg2theora needs to be 0.27 or later, found %s' % version)''' '''p = subprocess.Popen([ffmpeg2theora, '--info', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE)''' p = subprocess.Popen([identify, filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE) info, error = p.communicate() try: info = json.loads(info) except: #remove metadata, can be broken reg = re.compile('"metadata": {.*?},', re.DOTALL) info = re.sub(reg, '', info) #wafaa commented following line and added strict false to get rid of the JSONDecodeError: Invalid control characters #info = json.loads(info) info = json.loads(info, strict=False) #wafaa if 'image' in info: for v in info['image']: if not 'display_aspect_ratio' in v and 'width' in v: v['display_aspect_ratio'] = '%d:%d' % (v['width'], v['height']) v['pixel_aspect_ratio'] = '1:1' return info return {'path': filename, 'size': 0}
def avinfo(filename, cached=True): if cached: return cache(filename, 'info') if os.path.getsize(filename): ffmpeg2theora = cmd('ffmpeg2theora') p = subprocess.Popen([ffmpeg2theora], stdout=subprocess.PIPE, stderr=subprocess.PIPE) info, error = p.communicate() version = info.split('\n')[0].split(' - ')[0].split(' ')[-1] if version < '0.27': raise EnvironmentError('version of ffmpeg2theora needs to be 0.27 or later, found %s' % version) p = subprocess.Popen([ffmpeg2theora, '--info', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE) info, error = p.communicate() try: info = json.loads(info) except: #remove metadata, can be broken reg = re.compile('"metadata": {.*?},', re.DOTALL) info = re.sub(reg, '', info) info = json.loads(info) if 'video' in info: for v in info['video']: if not 'display_aspect_ratio' in v and 'width' in v: v['display_aspect_ratio'] = '%d:%d' % (v['width'], v['height']) v['pixel_aspect_ratio'] = '1:1' return info return {'path': filename, 'size': 0}
def getText(request): ''' takes { id: textid } returns { id: text: ... } ''' response = json_response() data = json.loads(request.POST['data']) public_id = data['id'] if public_id == '': qs = models.Text.objects.filter(name='') if qs.count() == 0: text = None response['data'] = { 'name': '', 'text': '', 'type': 'html', 'editable': not request.user.is_anonymous() and request.user.get_profile().capability('canEditFeaturedTexts') } else: text = qs[0] else: text = get_text_or_404_json(data['id']) if not text.accessible(request.user): text = None response['status']['code'] = 404 if text: response['data'] = text.json(user=request.user) return render_to_json_response(response)
def signin(request): data = json.loads(request.POST['data']) response = json_response({'errors': {'email': 'Failed to verify email'}}) verification_data = verify(request, data['assertion']) if verification_data: email = verification_data['email'] username = data.get('username') qs = User.objects.filter(email__iexact=email) if qs.count() == 0: if not username: response = json_response({ 'errors': { 'username': '******' } }) return response user = User() user.email = email user.username = username user.save() else: user = qs[0] if user.is_active: request.session['ui'] = '{}' #fixme. use custom backend instead? user.backend = 'django.contrib.auth.backends.ModelBackend' auth.login(request, user) user_json = models.init_user(user, request) response = json_response({'user': user_json}) else: response = json_response({'errors': {'email': 'User Disabled'}}) return response
def get_or_create(cls, request): if not request.session.session_key: request.session.save() request.session.modified = True session_key = request.session.session_key assert session_key if request.user.is_authenticated(): cls.objects.filter(user=request.user).update(session_key=session_key) data, created = cls.objects.get_or_create(session_key=session_key) if request.user.is_authenticated(): data.user = request.user if 'HTTP_X_FORWARDED_FOR' in request.META: data.ip = request.META['HTTP_X_FORWARDED_FOR'].split(',')[0] else: data.ip = request.META['REMOTE_ADDR'] if data.ip.startswith('::ffff:'): data.ip = data.ip[len('::ffff:'):] data.useragent = request.META['HTTP_USER_AGENT'] data.info = json.loads(request.POST.get('data', '{}')) screen = data.info.get('screen', {}) if screen and 'height' in screen and 'width' in screen: data.screensize = u'%s\xd7%s' % (screen['width'], screen['height']) window = data.info.get('window', {}) if window and 'outerHeight' in window and 'outerWidth' in window: data.windowsize = u'%s\xd7%s' % (window['outerWidth'], window['outerHeight']) if not data.timesseen: data.timesseen = 0 data.timesseen += 1 data.lastseen = datetime.now() data.save() tasks.parse_data.delay(data.session_key) return data
def tv(request): ''' takes { list: string } returns { item: string, position: float, title: string, ... } ''' data = json.loads(request.POST['data']) 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) response = json_response(status=200, text='ok') response['data'] = channel.json(request.user) return render_to_json_response(response)
def get_or_create(cls, request): if not request.session.session_key: request.session.save() request.session.modified = True session_key = request.session.session_key assert session_key if request.user.is_authenticated(): cls.objects.filter(user=request.user).update( session_key=session_key) data, created = cls.objects.get_or_create(session_key=session_key) if request.user.is_authenticated(): data.user = request.user if 'HTTP_X_FORWARDED_FOR' in request.META: data.ip = request.META['HTTP_X_FORWARDED_FOR'].split(',')[0] else: data.ip = request.META['REMOTE_ADDR'] if data.ip.startswith('::ffff:'): data.ip = data.ip[len('::ffff:'):] data.useragent = request.META['HTTP_USER_AGENT'] data.info = json.loads(request.POST.get('data', '{}')) screen = data.info.get('screen', {}) if screen and 'height' in screen and 'width' in screen: data.screensize = u'%s\xd7%s' % (screen['width'], screen['height']) window = data.info.get('window', {}) if window and 'outerHeight' in window and 'outerWidth' in window: data.windowsize = u'%s\xd7%s' % (window['outerWidth'], window['outerHeight']) if not data.timesseen: data.timesseen = 0 data.timesseen += 1 data.lastseen = datetime.now() data.save() tasks.parse_data.delay(data.session_key) return data
def editAnnotation(request): ''' takes { id:, in: float, out: float, value: string, } returns { id: ... } ''' response = json_response({}) data = json.loads(request.POST['data']) a = get_object_or_404_json(models.Annotation, public_id=data['id']) if a.editable(request.user): a.log() for key in ('value', 'in', 'out'): if key in data: setattr(a, { 'in': 'start', 'out': 'end' }.get(key, key), data[key]) a.save() #update sort/find tables async update_item.delay(a.id) response['data'] = a.json() response['data']['editable'] = True else: response = json_response(status=403, text='permission denied') return render_to_json_response(response)
def editNews(request): ''' takes { id: string, title: string, text: string, date: string } returns { id: string ... } ''' response = json_response({}) data = json.loads(request.POST['data']) n = get_object_or_404_json(models.News, id=ox.fromAZ(data['id'])) if n.editable(request.user): for key in ('title', 'text', 'date'): if key in data: setattr(n, key, data[key]) n.save() response['data'] = n.json() else: response = json_response(status=403, text='permission denied') return render_to_json_response(response)
def getNews(request): ''' takes { id: string } returns { id: string, ... } if not id is passed, return all news items takes {} returns { items: [object] } ''' data = json.loads(request.POST['data']) response = json_response() if 'id' in data: news = get_object_or_404_json(models.News, id=ox.fromAZ(data['id'])) response['data'] = news.json() else: qs = models.News.objects.all().order_by('-date') response['data']['items'] = [p.json() for p in qs] return render_to_json_response(response)
def addListItems(request): ''' takes { list: listId, items: [itemId], query: ... } returns { } ''' data = json.loads(request.POST['data']) list = get_list_or_404_json(data['list']) if 'items' in data: if list.editable(request.user): with transaction.commit_on_success(): for item in Item.objects.filter(itemId__in=data['items']): list.add(item) response = json_response(status=200, text='items added') else: response = json_response(status=403, text='not allowed') elif 'query' in data: response = json_response(status=501, text='not implemented') else: response = json_response(status=501, text='not implemented') return render_to_json_response(response)
def findId(request): ''' takes { 'id': string 'title': string 'director': [string] 'year': int } ''' data = json.loads(request.POST['data']) response = json_response({}) response['data']['items'] = [] if 'id' in data: qs = models.Item.objects.filter(itemId=data['id']) if qs.count() == 1: response['data']['items'] = [ i.get_json(['title', 'director', 'year', 'id']) for i in qs ] if not response['data']['items'] \ and settings.USE_IMDB \ and settings.DATA_SERVICE: r = models.external_data('getId', data) if r['status']['code'] == 200: response['data']['items'] = [r['data']] return render_to_json_response(response)
def addDocument(request): ''' add document(s) to item takes { item: string id: string or ids: [string] } returns { } ''' response = json_response() data = json.loads(request.POST['data']) if 'ids' in data: ids = data['ids'] else: ids = [data['id']] item = Item.objects.get(itemId=data['item']) if item.editable(request.user): for id in ids: document = models.Document.get(id) document.add(item) else: response = json_response(status=403, file='permission denied') return render_to_json_response(response)
def addClips(request): ''' takes { edit: string, index: int, clips: [] item: string, in: float, out: float, annotation: string } add clips with item/in/out or annotation to edit with id clips are added at index or end if index is not provided (annoation id is in the form item/annotation) returns { } ''' response = json_response() data = json.loads(request.POST['data']) edit = get_edit_or_404_json(data['edit']) clips = [] if edit.editable(request.user): index = data.get('index', edit.clips.count()) for c in data['clips']: clip = edit.add_clip(c, index) index += 1 if not clip: response = json_response(status=500, text='invalid in/out') return render_to_json_response(response) else: clips.append(clip.json(request.user)) response['data']['clips'] = clips else: response = json_response(status=403, text='permission denied') return render_to_json_response(response)
def getMediaInfo(request): ''' takes { id: oshash of stream file } returns { item: itemId, file: oshash of source file } ''' data = json.loads(request.POST['data']) f = None qs = models.Stream.objects.filter(oshash=data['id']) if qs.count() > 0: s = qs[0] f = s.file else: qs = models.File.objects.filter(oshash=data['id']) if qs.count() > 0: f = qs[0] response = json_response() if f: response['data'] = { 'file': f.oshash, 'item': f.item.itemId } return render_to_json_response(response)
def remove(request): ''' remove item with id, return status is 200/removed on sucess or 403/permission deinied. takes { id: string } returns { } ''' response = json_response({}) data = json.loads(request.POST['data']) item = get_object_or_404_json(models.Item, itemId=data['id']) user = request.user if user.get_profile().capability('canRemoveItems') == True or \ user.is_staff or \ item.user == user or \ item.groups.filter(id__in=user.groups.all()).count() > 0: item.log() #FIXME: is this cascading enough or do we end up with orphan files etc. item.delete() response = json_response(status=200, text='removed') else: response = json_response(status=403, text='permission denied') return render_to_json_response(response)
def lookup(request): ''' takes { title: string, director: [string], year: string, id: string } returns { title: string, director: [string], year: string, id: string } ''' data = json.loads(request.POST['data']) if 'id' in data: i = models.Item.objects.get(itemId=data['id']) r = {'id': i.itemId} for key in ('title', 'director', 'year'): r[key] = i.get(key) response = json_response(r) else: response = json_response(status=404, text='not found') return render_to_json_response(response)
def authors_ol(authors): r = [] for a in authors: url = 'http://openlibrary.org%s.json' % a data = json.loads(read_url(url)) r.append(data['name']) return r
def getIds(request): ''' takes { title: string, director: [string], year: int } returns { items: [{ tite: string, director: [string], year: int, originalTitle: string }] } ''' data = json.loads(request.POST['data']) response = json_response({}) if settings.DATA_SERVICE: r = models.external_data('getIds', data) if r['status']['code'] == 200: response['data']['items'] = r['data']['items'] else: response['data']['items'] return render_to_json_response(response)
def setPoster(request): ''' takes { id: string, source: string // url } returns { poster: { url: string, width: int, height: int } } ''' data = json.loads(request.POST['data']) item = get_object_or_404_json(models.Item, itemId=data['id']) response = json_response() if item.editable(request.user): valid_sources = [p['source'] for p in item.get_posters()] if data['source'] in valid_sources: item.poster_source = data['source'] if item.poster: item.poster.delete() item.save() tasks.update_poster(item.itemId) response = json_response() response['data']['posterAspect'] = item.poster_width/item.poster_height else: response = json_response(status=403, text='invalid poster url') else: response = json_response(status=403, text='permission denied') return render_to_json_response(response)
def add(request): ''' takes { title: string, //(optional) } returns { id: name: ... } ''' if not request.user.get_profile().capability('canAddItems'): response = json_response(status=403, text='permissino denied') else: data = json.loads(request.POST['data']) data['title'] = data.get('title', 'Untitled') i = models.Item() i.data['title'] = data['title'] i.user = request.user p = i.save() if p: p.wait() else: i.make_poster(True) response = json_response(status=200, text='created') response['data'] = i.get_json() return render_to_json_response(response)
def getMetadata(request): ''' takes { id: string, keys: [string] } returns { key: value .. } ''' data = json.loads(request.POST['data']) response = json_response({}) if settings.DATA_SERVICE: ''' info = {} for c in data['query']['conditions']: info[c['key']] = c['value'] r = models.external_data('getId', info) ''' r = models.external_data('getData', {'id': data['id']}) if r['status']['code'] == 200: if 'keys' in data and data['keys']: for key in data['keys']: if key in r['data']: response['data'][key] = r['data'][key] else: response['data'] = r['data'] return render_to_json_response(response)
def addAnnotations(request): ''' takes { item: itemId, layer: layerId, annotations: [{ in: float, out: float, value: string }, ...] } returns { taskId: string } ''' data = json.loads(request.POST['data']) for key in ('item', 'layer', 'annotations'): if key not in data: return render_to_json_response( json_response(status=400, text='invalid data')) item = get_object_or_404_json(Item, itemId=data['item']) layer_id = data['layer'] layer = filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers'])[0] if item.editable(request.user) \ and layer['canAddAnnotations'].get(request.user.get_profile().get_level()): response = json_response() data['user'] = request.user.username t = add_annotations.delay(data) response['data']['taskId'] = t.task_id else: response = json_response(status=403, text='permission denied') return render_to_json_response(response)
def editDocument(request): ''' takes { id: string name: string description: string item(optional): edit descriptoin per item } returns { id: ... } ''' response = json_response() data = json.loads(request.POST['data']) item = 'item' in data and Item.objects.get(itemId=data['item']) or None if data['id']: document = models.Document.get(data['id']) if document.editable(request.user): document.edit(data, request.user, item=item) document.save() response['data'] = document.json(user=request.user, item=item) else: response = json_response(status=403, text='permission denied') else: response = json_response(status=500, text='invalid request') return render_to_json_response(response)
def addAnnotations(request): ''' takes { item: itemId, layer: layerId, annotations: [{ in: float, out: float, value: string }, ...] } returns { taskId: string } ''' data = json.loads(request.POST['data']) for key in ('item', 'layer', 'annotations'): if key not in data: return render_to_json_response(json_response(status=400, text='invalid data')) item = get_object_or_404_json(Item, itemId=data['item']) layer_id = data['layer'] layer = filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers'])[0] if item.editable(request.user) \ and layer['canAddAnnotations'].get(request.user.get_profile().get_level()): response = json_response() data['user'] = request.user.username t = add_annotations.delay(data) response['data']['taskId'] = t.task_id else: response = json_response(status=403, text='permission denied') return render_to_json_response(response)
def addDocument(request): ''' add document(s) to item takes { item: string id: string or ids: [string] } returns { } ''' response = json_response() data = json.loads(request.POST['data']) if 'ids' in data: ids = data['ids'] else: ids = [data['id']] item = Item.objects.get(itemId=data['item']) if item.editable(request.user): for id in ids: document = models.Document.get(id) document.add(item) else: response = json_response(status=403, text='permission denied') return render_to_json_response(response)
def editList(request): ''' takes { id: listId, key: value, } keys: name, status, query, position, posterFrames if you change status you have to provide position of list posterFrames: array with objects that have item/position returns { id: string, ... } ''' data = json.loads(request.POST['data']) list = get_list_or_404_json(data['id']) if list.editable(request.user): response = json_response() list.edit(data, request.user) response['data'] = list.json(user=request.user) else: response = json_response(status=403, text='not allowed') return render_to_json_response(response)
def log(request): ''' takes { url: string, line: string, text: string } returns { } ''' data = json.loads(request.POST['data']) if request.user.is_authenticated(): user = request.user else: user = None url = data.get('url', '').split('/static/')[-1] if 'text' in data: if len(url) > 1000: url = url[:997] + '...' l = models.Log( text=data['text'], line=int(data.get('line', 0)), url=url ) if user: l.user = user l.save() response = json_response() return render_to_json_response(response)
def setPoster(request): ''' takes { id: string, source: string // url } returns { poster: { url: string, width: int, height: int } } ''' data = json.loads(request.POST['data']) item = get_object_or_404_json(models.Item, itemId=data['id']) response = json_response() if item.editable(request.user): valid_sources = [p['source'] for p in item.get_posters()] if data['source'] in valid_sources: item.poster_source = data['source'] if item.poster: item.poster.delete() item.save() tasks.update_poster(item.itemId) response = json_response() response['data'][ 'posterAspect'] = item.poster_width / item.poster_height else: response = json_response(status=403, text='invalid poster url') else: response = json_response(status=403, text='permission denied') return render_to_json_response(response)
def editAnnotation(request): ''' takes { id:, in: float, out: float, value: string, } returns { id: ... } ''' response = json_response({}) data = json.loads(request.POST['data']) a = get_object_or_404_json(models.Annotation, public_id=data['id']) if a.editable(request.user): a.log() for key in ('value', 'in', 'out'): if key in data: setattr(a, { 'in': 'start', 'out': 'end' }.get(key,key), data[key]) a.save() #update sort/find tables async update_item.delay(a.id) response['data'] = a.json() response['data']['editable'] = True else: response = json_response(status=403, text='permission denied') return render_to_json_response(response)
def editClip(request): ''' takes { id: string, in: float, out: float } returns { } ''' response = json_response() data = json.loads(request.POST['data']) clip = get_object_or_404_json(models.Clip, pk=ox.fromAZ(data['id'])) valid = True if clip.edit.editable(request.user): for key in ('in', 'out'): if key in data: if clip.annotation: clip.start = clip.annotation.start clip.end = clip.annotation.end clip.item = clip.annotation.item clip.annotation = None setattr(clip, {'in': 'start', 'out': 'end'}.get(key), float(data[key])) if not clip.annotation: duration = clip.item.sort.duration if clip.start >= clip.end or clip.start >= duration or clip.end > duration: response = json_response(status=500, text='invalid in/out') valid = False if valid: clip.save() response['data'] = clip.json(user=request.user) else: response = json_response(status=403, text='permission denied') return render_to_json_response(response)
def getSequence(request): ''' takes { id mode position } returns { id mode in out } ''' data = json.loads(request.POST['data']) response = json_response() position = float('%0.03f' % data['position']) i = Item.objects.get(itemId=data['id']) qs = models.Sequence.objects.filter( sort_id=i.sort.pk, mode=models.Sequence.MODE[data['mode']], start__lte=position, end__gt=position ).order_by('start', 'end') for sequence in qs: response['data'] = sequence.json() break return render_to_json_response(response)
def addList(request): ''' takes { name: value, } possible keys to create list: name description type query items view sort returns { id: string, name: string, ... } ''' data = json.loads(request.POST['data']) data['name'] = re.sub(' \[\d+\]$', '', data.get('name', 'Untitled')).strip() name = data['name'] if not name: name = "Untitled" num = 1 created = False while not created: list, created = models.List.objects.get_or_create(name=name, user=request.user) num += 1 name = data['name'] + ' [%d]' % num del data['name'] if data: list.edit(data, request.user) else: list.save() update_numberoflists.delay(request.user.username) if 'items' in data: for item in Item.objects.filter(itemId__in=data['items']): list.add(item) if list.status == 'featured': pos, created = models.Position.objects.get_or_create( list=list, user=request.user, section='featured') qs = models.Position.objects.filter(section='featured') else: pos, created = models.Position.objects.get_or_create( list=list, user=request.user, section='personal') qs = models.Position.objects.filter(user=request.user, section='personal') pos.position = qs.aggregate(Max('position'))['position__max'] + 1 pos.save() response = json_response(status=200, text='created') response['data'] = list.json() return render_to_json_response(response)
def verify(request, assertion): audience = get_audience(request) data = {'assertion': assertion, 'audience': audience} resp = requests.post('https://verifier.login.persona.org/verify', data=data, verify=True) if resp.ok: verification_data = json.loads(resp.content) if verification_data['status'] == 'okay': return verification_data return None
def addMedia(request): ''' takes { id: oshash filename: string, item: string info: {} } returns { item: id, } ''' response = json_response({}) data = json.loads(request.POST['data']) oshash = data.pop('id') if not request.user.get_profile().capability('canAddItems'): response = json_response(status=403, text='permissino denied') elif models.File.objects.filter(oshash=oshash).count() > 0: f = models.File.objects.get(oshash=oshash) if f.available: response['status']['text'] = 'file exists' response['data']['item'] = f.item.itemId response['data']['itemUrl'] = request.build_absolute_uri('/%s' % f.item.itemId) else: if 'item' in data: i = Item.objects.get(itemId=data['item']) else: title = ox.parse_movie_path(os.path.splitext( data['filename'])[0])['title'] i = Item() i.data = { 'title': title, 'director': data.get('director', []), } i.user = request.user i.save() i.make_poster(True) f = models.File(oshash=oshash, item=i) f.path = data.get('filename', 'Untitled') extension = f.path.split('.') if len(extension) > 1: extension = extension[-1] else: #wafaa #extension = 'webm' extension = 'png' f.selected = True if 'info' in data and data['info']: f.info = data['info'] f.info['extension'] = extension f.parse_info() f.save() response['data']['item'] = i.itemId response['data']['itemUrl'] = request.build_absolute_uri('/%s' % i.itemId) return render_to_json_response(response)
def only_p(m): r = {} if m: m = json.loads(m, object_hook=ox.django.fields.from_json) for p in _p: r[p] = m.get(p, '') if 'clip_qs' in query: r['clips'] = get_clips(query['clip_qs'].filter(item__itemId=m['id'])) return r
def taskStatus(request): #FIXME: should check if user has permissions to get status data = json.loads(request.POST['data']) if 'taskId' in data: task_id = data['taskId'] else: task_id = data['task_id'] response = task_status(request, task_id) return render_to_json_response(response)
def only_p(m): r = {} if m: m = json.loads(m, object_hook=ox.django.fields.from_json) for p in _p: r[p] = m.get(p, '') if 'clip_qs' in query: r['clips'] = get_clips( query['clip_qs'].filter(item__itemId=m['id'])) return r
def removeLogs(request): ''' takes { ids: [string] } returns {} ''' data = json.loads(request.POST['data']) models.Log.objects.filter(id__in=[ox.fromAZ(i) for i in data['ids']]).delete() response = json_response() return render_to_json_response(response)
def editMedia(request): ''' change file / item link takes { files: [ {id:, key1: value1, key2: value2} ... ] } possible keys: part, partTitle, language, ignore, extension, version, episodes returns { } ''' data = json.loads(request.POST['data']) ignore = [] dont_ignore = [] response = json_response(status=200, text='updated') response['data']['files'] = [] for info in data['files']: f = get_object_or_404_json(models.File, oshash=info['id']) if f.editable(request.user): if 'ignore' in info: if info['ignore']: ignore.append(info['id']) else: dont_ignore.append(info['id']) update = False for key in f.PATH_INFO: if key in info: f.info[key] = info[key] update = True if update: f.save() response['data']['files'].append(f.json()) else: response['data']['files'].append({ 'id': info['id'], 'error': 'permission denied' }) if ignore: models.Instance.objects.filter(file__oshash__in=ignore).update( ignore=True) if dont_ignore: models.Instance.objects.filter(file__oshash__in=dont_ignore).update( ignore=False) if ignore or dont_ignore: files = models.File.objects.filter(oshash__in=ignore + dont_ignore) #FIXME: is this to slow to run sync? for i in Item.objects.filter(files__in=files).distinct(): i.update_selected() i.update_wanted() return render_to_json_response(response)
def removeVolume(request): data = json.loads(request.POST['data']) user = request.user try: volume = models.Volume.objects.get(user=user, name=data['volume']) volume.files.delete() volume.delete() response = json_response() except models.Volume.DoesNotExist: response = json_response(status=404, text='volume not found') return render_to_json_response(response)
def to_python(self, value): """Convert our string value to JSON after we load it from the DB""" if isinstance(value, tuple): return value try: value = json.loads(value, object_hook=from_json) except: #this is required to load fixtures value = eval(value) assert isinstance(value, list) return tuple(value)
def get(key): user_auth = os.environ.get('oxAUTH', os.path.expanduser('~/.ox/auth.json')) auth = {} if os.path.exists(user_auth): f = open(user_auth, "r") data = f.read() f.close() auth = json.loads(data) if key in auth: return auth[key] print "please add key %s to json file '%s'" % (key, user_auth) raise Exception,"no key %s found" % key
def parsePath(request): #parse path and return info ''' takes { path: string } returns { imdb: string } ''' path = json.loads(request.POST['data'])['path'] response = json_response(ox.parse_movie_path(path)) return render_to_json_response(response)