Example #1
0
def test(request):
    try:
        lista = get_playlists()
    except Error as e:
        return error_handler(e, request)

    return HttpResponse(lista)
Example #2
0
def publicar(request, video_id):
    v = get_object_or_404(Video, pk=video_id)
    if request.method == 'POST':
        form = PublishingForm(request.POST)
        new_form = NewPlaylistForm(request.POST)
        add_form = AddToPlaylistForm(request.POST)
        try:
            add_form.fields['add_to_playlist'].choices = get_playlists()
        except Error as e:
            return error_handler(e, request)
        if form.is_valid() \
            and not (form.cleaned_data['playlist'] is 1 and not add_form.is_valid()) \
            and not (form.cleaned_data['playlist'] is 2 and not new_form.is_valid()):
            if form.cleaned_data['playlist'] is 0:
                pub_data = form.cleaned_data
            if form.cleaned_data['playlist'] is 1:
                pub_data = dict(form.cleaned_data, **add_form.cleaned_data)
            if form.cleaned_data['playlist'] is 2:
                pub_data = dict(form.cleaned_data, **new_form.cleaned_data)
            Publicacion(video = v, data = json.dumps(pub_data)).save()
            messages.success(request, u'Producción encolada para su publicación')
            return redirect('estado_video', v.id)
    else:
        form = PublishingForm()
        new_form = NewPlaylistForm()
        add_form = AddToPlaylistForm()
        metadataField = 'metadataoa' if v.objecto_aprendizaje else 'metadatagen'
        form.fields['title'].initial = getattr(v, metadataField).title
        form.fields['description'].initial = "%s\n\n---\n%s" % (getattr(v, metadataField).description, LICENSE_TEXTS[getattr(v, metadataField).license])
        form.fields['tags'].initial = "%s,%s" % (getattr(v, metadataField).keyword, getattr(v, metadataField).get_knowledge_areas_display().replace(',',''))
        try:
            add_form.fields['add_to_playlist'].choices = get_playlists()
        except Error as e:
            return error_handler(e, request)

    return render_to_response("yt_publisher/yt-section-publish.html", { 'form' : form, 'new_form' : new_form, 'add_form' : add_form }, context_instance=RequestContext(request))