Esempio n. 1
0
        data['conditions'] = data['conditions'] + {
            'value': data['position'],
            'key': query['sort'][0]['key'],
            'operator': '^'
        }
        query = parse_query(data, request.user)
        qs = order_query(query['qs'], query['sort'])
        if qs.count() > 0:
            response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
    elif 'positions' in data:
        ids = [i.public_id for i in qs]
        response['data']['positions'] = utils.get_positions(ids, data['positions'])
    else:
        response['data']['items'] = qs.count()
    return render_to_json_response(response)
actions.register(findAnnotations)


@login_required_json
def addAnnotation(request):
    '''
        takes {
            item: itemId,
            layer: layerId,
            in: float,
            out: float,
            value: string
        }
        returns {
            id: string, //id of new annotation
            ...
Esempio n. 2
0
            name:
            text:
        }
    '''
    data = json.loads(request.POST['data'])
    if isinstance(data, basestring):
        name = data
    else:
        name = data['name']
    page, created = models.Page.objects.get_or_create(name=name)
    if created:
        page.text= ''
        page.save()
    response = json_response({'name': page.name, 'text': page.text})
    return render_to_json_response(response)
actions.register(getPage)


@login_required_json
def editPage(request):
    '''
        takes {
            name: pagename
            text: text
        }
        returns {
            name:
            text:
        }
    '''
    if request.user.get_profile().capability('canEditSitePages'):
Esempio n. 3
0
import tasks


@login_required_json
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)
actions.register(removeVolume, cache=False)


@login_required_json
def update(request):
    '''
        2 steps:
            send files
                {volume: 'Videos', files: [{oshash:, path:, mtime:, ,,}]}
            send info about changed/new files
                {volume: 'Videos', info: {oshash: {...}]}

        call volume/files first and fill in requested info after that

        takes {
            volume: '',
    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)
actions.register(addClips, cache=False)


@login_required_json
def removeClips(request):
    '''
       takes {
           edit: string
           ids: [string]
        }
        returns {
        }
    '''
    response = json_response()
    data = json.loads(request.POST['data'])
    edit = get_edit_or_404_json(data['edit'])
Esempio n. 5
0
    '''
    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)
actions.register(addDocument, cache=False)

@login_required_json
def editDocument(request):
    '''
        takes {
            id: string
            name: string
            description: string
            item(optional): edit descriptoin per item
        }
        returns {
            id:
            ...
        }
    '''
Esempio n. 6
0
                setattr(event, key, value)
        if 'nameSort' in data:
            value = ox.escape_html(data['nameSort'])
            event.set_name_sort(value)
        event.matches = 0
        event.save()
        event.update_matches()
        response = json_response(status=200, text='created')
        response['data'] = event.json()
    else:
        response = json_response(status=409, text='name exists')
        response['data']['names'] = existing_names
    return render_to_json_response(response)


actions.register(addEvent, cache=False)


@login_required_json
def editEvent(request):
    '''
        takes {
            id: string,
            name: string,
            start: string,
            end: string
        }
        returns {
            id: string,
            ...
        }
Esempio n. 7
0
            value = data[key]
            if isinstance(value, list):
                value = tuple(value)
            setattr(place, key, value)
        place.matches = 0
        place.save()
        place.update_matches()
        response = json_response(place.json())
    else:
        response = json_response(status=409,
                                 text='%s exists'%(existing_names and 'Name' or 'Geoname'))
        response['data']['names'] = existing_names
        if existing_geoname:
            response['data']['geoname'] = existing_geoname
    return render_to_json_response(response)
actions.register(addPlace, cache=False)


@login_required_json
def editPlace(request):
    '''
        takes {
            id: string,
            name: string
            north: int
        }
        returns {
            names: []
        }
    '''
    data = json.loads(request.POST['data'])
        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)
actions.register(log, cache=False)


@admin_required_json
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)
actions.register(removeLogs, cache=False)
Esempio n. 9
0
        if response['data']['items']:
            if 'annotations' in keys:
                aqs = Annotation.objects.filter(layer__in=settings.CONFIG['clipLayers'],
                                                clip__in=ids)
                add_annotations('annotations',aqs , True)
            for layer in filter(lambda l: l in keys, settings.CONFIG['clipLayers']):
                aqs = Annotation.objects.filter(layer=layer, clip__in=ids)
                add_annotations(layer, aqs)
    elif 'position' in query:
        qs = order_query(qs, query['sort'])
        ids = [u'%s/%0.03f-%0.03f' % (c['item__itemId'], c['start'], c['end'])
            for c in qs.values('item__itemId', 'start', 'end')]
        data['conditions'] = data['conditions'] + {
            'value': data['position'],
            'key': query['sort'][0]['key'],
            'operator': '^'
        }
        query = parse_query(data, request.user)
        qs = order_query(query['qs'], query['sort'])
        if qs.count() > 0:
            response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
    elif 'positions' in data:
        qs = order_query(qs, query['sort'])
        ids = [u'%s/%0.03f-%0.03f' % (c['item__itemId'], c['start'], c['end'])
            for c in qs.values('item__itemId', 'start', 'end')]
        response['data']['positions'] = utils.get_positions(ids, data['positions'])
    else:
        response['data']['items'] = qs.count()
    return render_to_json_response(response)
actions.register(findClips)
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)


actions.register(tv, cache=False)
Esempio n. 11
0
from itemlist.views import get_list_or_404_json
from ox.django.api import actions

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)
actions.register(tv, cache=False)
Esempio n. 12
0
        text.save()

    if text.status == 'featured':
        pos, created = models.Position.objects.get_or_create(text=text,
                                         user=request.user, section='featured')
        qs = models.Position.objects.filter(section='featured')
    else:
        pos, created = models.Position.objects.get_or_create(text=text,
                                         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'] = text.json(user=request.user)
    return render_to_json_response(response)
actions.register(addText, cache=False)

def getText(request):
    '''
        takes {
            id: textid
        }
        returns {
            id:
            text:
            ...
        }
    '''
    response = json_response()
    data = json.loads(request.POST['data'])
    public_id = data['id']
            id: string
        }
    '''
    data = json.loads(request.POST['data'])
    title = get_object_or_404_json(models.Title, pk=ox.fromAZ(data['id']))
    response = json_response()
    if 'sorttitle' in data:
        title.sorttitle = data['sorttitle']
        title.sorttitle = unicodedata.normalize('NFKD', title.sorttitle)
        title.edited = True
    title.save()
    response['data'] = title.json()
    return render_to_json_response(response)


actions.register(editTitle, cache=False)


def parse_query(data, user):
    query = {}
    query['range'] = [0, 100]
    query['sort'] = [{'key': 'title', 'operator': '+'}]
    for key in ('keys', 'group', 'list', 'range', 'sort', 'query'):
        if key in data:
            query[key] = data[key]
    query['qs'] = models.Title.objects.find(query, user)
    #if 'itemsQuery' in data:
    #    item_query = models.Item.objects.find({'query': data['itemsQuery']}, user)
    #    query['qs'] = query['qs'].filter(items__in=item_query)
    return query
Esempio n. 14
0
    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)


actions.register(addDocument, cache=False)


@login_required_json
def editDocument(request):
    '''
        takes {
            id: string
            name: string
            description: string
            item(optional): edit descriptoin per item
        }
        returns {
            id:
            ...
        }
Esempio n. 15
0
        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)
actions.register(getNews)

@login_required_json
def addNews(request):
    '''
        takes {
            title: string,
            date: string,
            text: text,
        }
        returns {
            id: string,
            ...
        }
    '''
    data = json.loads(request.POST['data'])
Esempio n. 16
0
            id: string,
            name: string
            ...
        }
    '''
    data = json.loads(request.POST['data'])
    person = get_object_or_404_json(models.Person, pk=ox.fromAZ(data['id']))
    response = json_response()
    if 'sortname' in data:
        person.sortname = data['sortname']
        person.edited = True
    person.save()
    tasks.update_file_paths.delay(person.id)
    response['data'] = person.json()
    return render_to_json_response(response)
actions.register(editName, cache=False)

def sortName(request):
    '''
        get sort name(s) for given name or names
        takes {
            names: [string]
            name: string
        }
        returns {
            name: sortName
        }
    '''
    data = json.loads(request.POST['data'])
    names = data.get('names', [])
    if 'name' in data:
        pos, created = models.Position.objects.get_or_create(
            text=text, user=request.user, section='featured')
        qs = models.Position.objects.filter(section='featured')
    else:
        pos, created = models.Position.objects.get_or_create(
            text=text, 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'] = text.json(user=request.user)
    return render_to_json_response(response)


actions.register(addText, cache=False)


def getText(request):
    '''
        takes {
            id: textid,
            keys: []
        }
        returns {
            id:
            text:
            ...
        }
    '''
    response = json_response()
Esempio n. 18
0
        }
    '''
    data = json.loads(request.POST['data'])
    if isinstance(data, basestring):
        name = data
    else:
        name = data['name']
    page, created = models.Page.objects.get_or_create(name=name)
    if created:
        page.text = ''
        page.save()
    response = json_response({'name': page.name, 'text': page.text})
    return render_to_json_response(response)


actions.register(getPage)


@login_required_json
def editPage(request):
    '''
        takes {
            name: pagename
            text: text
        }
        returns {
            name:
            text:
        }
    '''
    if request.user.get_profile().capability('canEditSitePages'):
Esempio n. 19
0
        response['data']['items'] = [
            l.json(data['keys'], request.user) for l in qs
        ]
    elif 'position' in data:
        #FIXME: actually implement position requests
        response['data']['position'] = 0
    elif 'positions' in data:
        ids = [i.get_id() for i in qs]
        response['data']['positions'] = utils.get_positions(
            ids, query['positions'])
    else:
        response['data']['items'] = qs.count()
    return render_to_json_response(response)


actions.register(findLists)


def getList(request):
    '''
        takes {
            id: listid
        }
        returns {
            id:
            section:
            ...
        }
    '''
    data = json.loads(request.POST['data'])
    if 'id' in data:
        if 'items' in totals:
            response['data']['items'] = items.count()
        if 'pixels' in totals:
            response['data']['pixels'] = r['pixels__sum']
        if 'runtime' in totals:
            response['data']['runtime'] = items.aggregate(
                Sum('sort__runtime'))['sort__runtime__sum'] or 0
        if 'size' in totals:
            response['data']['size'] = r['size__sum']
        for key in ('runtime', 'duration', 'pixels', 'size'):
            if key in totals and response['data'][key] == None:
                response['data'][key] = 0
    return render_to_json_response(response)


actions.register(find)


def autocomplete(request):
    '''
        takes {
            key: string,
            value: string,
            operator: string // '=', '==', '^', '$'
            query: object // item query to limit results
            range: [int, int]
        }
        returns {
            items: [string, ...] //array of matching values
        }
    '''
Esempio n. 21
0
                else:
                    response = json_response({
                        'errors': {
                            'username': '******'
                        }
                    })
            else:
                response = json_response({
                    'errors': {
                        'password': '******'
                    }
                })
    else:
        response = json_response(status=400, text='invalid data')
    return render_to_json_response(response)
actions.register(signin, cache=False)


def signout(request):
    '''
        takes {}

        returns {
            user: {
                default user
            }
        }
    '''
    response = json_response(text='ok')
    if request.user.is_authenticated():
        profile = request.user.get_profile()
Esempio n. 22
0
                if key == 'alternativeNames':
                    value = tuple([ox.escape_html(v) for v in value])
                setattr(event, key, value)
        if 'nameSort' in data:
            value = ox.escape_html(data['nameSort'])
            event.set_name_sort(value)
        event.matches = 0
        event.save()
        event.update_matches()
        response = json_response(status=200, text='created')
        response['data'] = event.json()
    else:
        response = json_response(status=409, text='name exists')
        response['data']['names'] = existing_names
    return render_to_json_response(response)
actions.register(addEvent, cache=False)


@login_required_json
def editEvent(request):
    '''
        takes {
            id: string,
            name: string,
            start: string,
            end: string
        }
        returns {
            id: string,
            ...
        }
Esempio n. 23
0
            response['data']['duration'] = r['duration__sum']
        if 'files' in totals:
            response['data']['files'] = files.count()
        if 'items' in totals:
            response['data']['items'] = items.count()
        if 'pixels' in totals:
            response['data']['pixels'] = r['pixels__sum']
        if 'runtime' in totals:
            response['data']['runtime'] = items.aggregate(Sum('sort__runtime'))['sort__runtime__sum'] or 0
        if 'size' in totals:
            response['data']['size'] = r['size__sum']
        for key in ('runtime', 'duration', 'pixels', 'size'):
            if key in totals and response['data'][key] == None:
                response['data'][key] = 0 
    return render_to_json_response(response)
actions.register(find)


def autocomplete(request):
    '''
        takes {
            key: string,
            value: string,
            operator: string // '=', '==', '^', '$'
            query: object // item query to limit results
            range: [int, int]
        }
        returns {
            items: [string, ...] //array of matching values
        }
    '''
            'value': data['position'],
            'key': query['sort'][0]['key'],
            'operator': '^'
        }
        query = parse_query(data, request.user)
        qs = order_query(query['qs'], query['sort'])
        if qs.count() > 0:
            response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
    elif 'positions' in data:
        qs = order_query(qs, query['sort'])
        ids = [i['public_id'] for i in qs.values('public_id')]
        response['data']['positions'] = utils.get_positions(ids, data['positions'])
    else:
        response['data']['items'] = qs.count()
    return render_to_json_response(response)
actions.register(findSequences)

def getSequence(request):
    '''
        takes {
            id
            mode 
            position
        }

        returns {
            id
            mode
            in
            out
        }
                else:
                    response = json_response(
                        {'errors': {
                            'username': '******'
                        }})
            else:
                response = json_response(
                    {'errors': {
                        'password': '******'
                    }})
    else:
        response = json_response(status=400, text='invalid data')
    return render_to_json_response(response)


actions.register(signin, cache=False)


def signout(request):
    '''
        takes {}

        returns {
            user: {
                default user
            }
        }
    '''
    response = json_response(text='ok')
    if request.user.is_authenticated():
        profile = request.user.get_profile()
Esempio n. 26
0
@login_required_json
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)


actions.register(removeVolume, cache=False)


@login_required_json
def update(request):
    '''
        2 steps:
            send files
                {volume: 'Videos', files: [{oshash:, path:, mtime:, ,,}]}
            send info about changed/new files
                {volume: 'Videos', info: {oshash: {...}]}

        call volume/files first and fill in requested info after that

        takes {
            volume: '',
Esempio n. 27
0
            ...
        }
    '''
    data = json.loads(request.POST['data'])
    person = get_object_or_404_json(models.Person, pk=ox.fromAZ(data['id']))
    response = json_response()
    if 'sortname' in data:
        person.sortname = data['sortname']
        person.edited = True
    person.save()
    tasks.update_file_paths.delay(person.id)
    response['data'] = person.json()
    return render_to_json_response(response)


actions.register(editName, cache=False)


def sortName(request):
    '''
        get sort name(s) for given name or names
        takes {
            names: [string]
            name: string
        }
        returns {
            name: sortName
        }
    '''
    data = json.loads(request.POST['data'])
    names = data.get('names', [])
Esempio n. 28
0
        }
        query = parse_query(data, request.user)
        qs = order_query(query['qs'], query['sort'])
        if qs.count() > 0:
            response['data']['position'] = utils.get_positions(
                ids, [qs[0].itemId])[0]
    elif 'positions' in data:
        ids = [i.public_id for i in qs]
        response['data']['positions'] = utils.get_positions(
            ids, data['positions'])
    else:
        response['data']['items'] = qs.count()
    return render_to_json_response(response)


actions.register(findAnnotations)


@login_required_json
def addAnnotation(request):
    '''
        takes {
            item: itemId,
            layer: layerId,
            in: float,
            out: float,
            value: string
        }
        returns {
            id: string, //id of new annotation
            ...
        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)


actions.register(getNews)


@login_required_json
def addNews(request):
    '''
        takes {
            title: string,
            date: string,
            text: text,
        }
        returns {
            id: string,
            ...
        }
    '''