def preview(request, conn=None, **kwargs): anns,names = get_user_annotations(conn) form_names = [(" "," ")] for name in names: form_names.append((name,name)) if request.POST: form = PreviewForm(options=form_names,data=request.POST) if form.is_valid(): selected = form.cleaned_data['preview_annotation'] sheet = 0 if form.cleaned_data['preview_sheet'] is not None: sheet = form.cleaned_data['preview_sheet'] annId = selected.partition(' ')[0][3:] annotation = conn.getObject("Annotation",annId) fpath = download_annotation(annotation) fname, fextension = os.path.splitext(fpath) pdata = preview_data(fpath,fextension,sheet) print len(pdata) if pdata is not None: rv = {'preview_data': pdata} data = json.dumps(rv) return HttpResponse(data, mimetype='application/json') else: rv = {'message':"Could not read file"} error = json.dumps(rv) return HttpResponseBadRequest(error, mimetype='application/json')
def add(): urlform = URLForm(request.form) pform = PreviewForm(request.form) sourceform = SourceForm(request.form) curr=True print sourceform.validate() if urlform.validate_on_submit() and not pform.validate_on_submit(): track = get_track_info(urlform.url.data) pform.songname.data = track.title pform.artist.data = track.user['username'] pform.label.data = track.label_name if pform.label.data is None: pform.label.data = '' pform.year.data = track.release_year if pform.year.data is None: pform.year.data = '' curr=False elif sourceform.validate_on_submit(): add_source(sourceform.source.data, sourceform.genre.data) return redirect(url_for("index")) elif pform.validate_on_submit(): add_track(pform.url.data, current_user.id, "user", pform.songname.data, pform.artist.data, pform.genre.data, pform.label.data, pform.year.data) return render_template("add.html", urlform=urlform, previewform=pform, sourceform=sourceform, curr=curr)