def file_new(request, filename): division = "new" filepath = filename.encode("utf-8") root_filepath = os.path.join(settings.NEW_PATH, filename.encode("utf-8")) if request.POST: form = AudiobookForm(request.POST) if form.is_valid(): try: form.save(path=filepath) except IOError: raise Http404 return redirect(list_new) try: tags = mutagen.File(root_filepath) except IOError: raise Http404 d = {} if tags: for tag in tags: value = tags[tag] if isinstance(value, list): d[tag] = value[0] else: d[tag] = value if tag == "project": try: d[tag] = models.Project.objects.get(name=d[tag]).pk except models.Project.DoesNotExist: d[tag] = None if not request.POST: form = AudiobookForm(d) return render(request, "archive/file_new.html", locals())
def file_managed(request, id): audiobook = get_object_or_404(models.Audiobook, id=id) if request.POST: form = AudiobookForm(request.POST, instance=audiobook) if form.is_valid(): try: form.save() except IOError: raise Http404 division = 'published' if audiobook.published() else 'unpublished' path = audiobook.source_file.path[len(settings.FILES_PATH):].lstrip('/') # for tags update tags = mutagen.File(audiobook.source_file.path.encode('utf-8')) if not tags: tags = {} form = AudiobookForm(instance=audiobook) user_can_publish = ( request.user.is_authenticated and request.user.oauthconnection_set.filter(access=True).exists()) return render(request, "archive/file_managed.html", locals())
def file_managed(request, id): audiobook = get_object_or_404(models.Audiobook, id=id) if request.POST: form = AudiobookForm(request.POST, instance=audiobook) if form.is_valid(): try: form.save() except IOError: raise Http404 division = "published" if audiobook.published() else "unpublished" path = audiobook.source_file.path[len(settings.FILES_PATH) :].lstrip("/") # for tags update tags = mutagen.File(audiobook.source_file.path) if not tags: tags = {} form = AudiobookForm(instance=audiobook) return render(request, "archive/file_managed.html", locals())