views.py 826 B

12345678910111213141516171819202122232425262728
  1. import uuid
  2. from django.shortcuts import render, get_object_or_404
  3. from django.http import HttpResponseRedirect
  4. from .models import File
  5. from .forms import UploadForm
  6. def index(request):
  7. return render(request, 'sharing/index.html')
  8. def upload(request):
  9. if request.method == 'POST':
  10. form = UploadForm(request.POST, request.FILES)
  11. if form.is_valid():
  12. formfile = form.save(commit=False)
  13. uid = uuid.uuid1()
  14. formfile.uid = str(uid)
  15. formfile.save()
  16. return HttpResponseRedirect('/' + formfile.uid)
  17. return render(request, 'sharing/index.html')
  18. def download(request, uid):
  19. file = get_object_or_404(File, uid=uid)
  20. return render(request, 'sharing/download.html', {'dl_url': file.file.url, 'filename': file.file.name.split('/')[-1]})