def pick(request): message = None basic_form = BasicFilesForm() form = FileForm() if request.method == "POST": post = request.POST.dict() basic_form = BasicFilesForm(post) if basic_form.is_valid(): f = basic_form.save() post['mid_id'] = f.id else: message = 'Invalid form' files_links = request.POST['fpfile'].split(',') if post.get('mid_id', None): for i, f in enumerate(request.FILES.getlist("fpfile")): form = FileForm(post) if form.is_valid(): fp = form.save(commit=False) fp.fpfile = f fp.fpurl = files_links[i] fp.mid_id = post.get('mid_id') fp.save() else: message = "Invalid form" files = ", ".join([str(f) for f in request.FILES.getlist("fpfile")]) message = "Save successful. URL for {0}: {1}".format( files, request.POST["fpfile"]) if not message else message return render(request, "home.html", {'form': form, 'message': message, 'basic_form': basic_form})
def list_files(request, url): url, _ = canonicalize_url(url) p = get_object_or_404(Page, url=url) if request.method == 'POST' and request.user.has_perm('podstakannik.add_file'): form = FileForm(request.POST, request.FILES) if form.is_valid(): m = form.save(commit=False) m.owner = request.user m.parent = p m.save() return HttpResponseRedirect(p.files_url) else: form = FileForm() files = p.file_set.all() return render_to_response('podstakannik/list_files.html', {'page' : p, 'files' : files, 'form' : form}, context_instance=RequestContext(request))
def upload(request): if request.method == 'POST': form = FileForm(request.POST, request.FILES) if form.is_valid(): m = form.save(commit=False) if request.user.is_anonymous(): m.owner = None else: m.owner = request.user m.save() else: m = None else: m = None form = FileForm() return render_to_response('uploader/upload.html', {'file' : m, 'form' : form}, context_instance=RequestContext(request))