Ejemplo n.º 1
0
Archivo: ajax.py Proyecto: alx/acabed
def add(request, animation):
    dajax = Dajax()
    dajax.remove_css_class('#movie-inspector label', 'error')

    animation = json.loads(animation)
    animation.update({
        'type': 'm',
        'user': request.user is None and '' or request.user.id,
    })

    if int(animation['max_duration']) > 60:
        animation['max_duration'] = 60

    movie_duration = 0
    for frame in animation['data']:
        frame['duration'] = int(frame['duration'])
        if frame['duration'] > 2000:
            frame['duration'] = 2000
        movie_duration += frame['duration']

    if movie_duration > 60000:
        dajax.script('MessageWidget.msg("Animation darf insgesamt nicht laenger als 60 Sekunden sein! Bitte Frames loeschen oder kuerzer anzeigen lassen!")')
        return dajax.json()
    
    form = AnimationForm(animation)

    if form.is_valid():
        a = form.save()

        p = Playlist(
            title = 'stub \'%s\' playlist' % form.cleaned_data['title'],
            user = User.objects.all()[0]
        )
        p.save()
        
        ai = AnimationInstance(
            playlist = p,
            animation = a
        )
        ai.save()

        # queue playlist
        sj = SpoolJob(
            playlist = p,
            priority = 2,
            added = datetime.now()
        )
        sj.save()

        dajax.script('MessageWidget.msg("Great success! Animootion mit ID %s gespeichert!")' % p.id)
    else:
        for error in form.errors:
            dajax.add_css_class('#movie-inspector label[for="%s"]' % error, 'error')
        dajax.script('MessageWidget.msg("Bitte fehlende Felder ausfuellen.")')

    return dajax.json()
Ejemplo n.º 2
0
def add(request, animation):
    dajax = Dajax()
    dajax.remove_css_class('#movie-inspector label', 'error')

    animation = json.loads(animation)
    animation.update({
        'type': 'm',
        'user': request.user is None and '' or request.user.id,
    })

    if int(animation['max_duration']) > 60:
        animation['max_duration'] = 60

    movie_duration = 0
    for frame in animation['data']:
        frame['duration'] = int(frame['duration'])
        if frame['duration'] > 2000:
            frame['duration'] = 2000
        movie_duration += frame['duration']

    if movie_duration > 60000:
        dajax.script(
            'MessageWidget.msg("Animation darf insgesamt nicht laenger als 60 Sekunden sein! Bitte Frames loeschen oder kuerzer anzeigen lassen!")'
        )
        return dajax.json()

    form = AnimationForm(animation)

    if form.is_valid():
        a = form.save()

        p = Playlist(title='stub \'%s\' playlist' % form.cleaned_data['title'],
                     user=User.objects.all()[0])
        p.save()

        ai = AnimationInstance(playlist=p, animation=a)
        ai.save()

        # queue playlist
        sj = SpoolJob(playlist=p, priority=2, added=datetime.now())
        sj.save()

        dajax.script(
            'MessageWidget.msg("Great success! Animootion mit ID %s gespeichert!")'
            % p.id)
    else:
        for error in form.errors:
            dajax.add_css_class('#movie-inspector label[for="%s"]' % error,
                                'error')
        dajax.script('MessageWidget.msg("Bitte fehlende Felder ausfuellen.")')

    return dajax.json()
Ejemplo n.º 3
0
Archivo: ajax.py Proyecto: C3MA/acabed
def add(request, animation):
    dajax = Dajax()
    dajax.remove_css_class('#movie-inspector label', 'error')

    animation = json.loads(animation)
    animation.update({
        'type': 'm',
        'user': request.user is None and '' or request.user.id,
    })

    if int(animation['max_duration']) > 60:
        animation['max_duration'] = 60

    movie_duration = 0
    for frame in animation['data']:
        frame['duration'] = int(frame['duration'])
        if frame['duration'] > 2000:
            frame['duration'] = 2000
        movie_duration += frame['duration']

    if movie_duration > 60000:
        dajax.script('MessageWidget.msg("The maximal duration of 60 seconds has been reached! Either delete frames or shoten the movie duration!")')
        return dajax.json()
    

    initial = {'title': datetime.now().strftime("%Y-%m-%d %H:%M"),
                                               'description':"created at terminal",
                                               'author': "random hacker",
                                               'email': "*****@*****.**"}

    form = AnimationForm(animation, initial = initial )
    if request.user.is_authenticated():
        for key in initial:
            if not form.data[key]:
                form.data[key]=initial[key]
            
    if form.is_valid():
        a = form.save()

        p = Playlist(
            title = 'stub \'%s\' playlist' % form.cleaned_data['title'],
            user = User.objects.all()[0]
        )
        p.save()
        
        ai = AnimationInstance(
            playlist = p,
            animation = a
        )
        ai.save()

        # queue playlist
        sj = SpoolJob(
            playlist = p,
            priority = 2,
            added = datetime.now()
        )
        sj.save()

        dajax.script('MessageWidget.msg("Great success! Animootion ID %s saved!")' % p.id)
    else:
        for error in form.errors:
            dajax.add_css_class('#movie-inspector label[for="%s"]' % error, 'error')
        dajax.script('MessageWidget.msg("Please fill out marked fields.")')

    return dajax.json()