Pretty nice commit overall, made the upload mechanic much more realistic and usable. Only thing left for the upload is the user id assignment. Check new ideas in discord.
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
from django.shortcuts import render, redirect
|
||||
import os.path
|
||||
from .forms import ImageForm
|
||||
from .forms import ImageForm, VideoForm
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
|
||||
|
||||
def uploadContent(request):
|
||||
if request.method == "GET":
|
||||
return render(request, "uploadChoice.html")
|
||||
@ -24,15 +25,25 @@ def imageUpload(request):
|
||||
if request.method == 'POST':
|
||||
form = ImageForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
myfile = request.FILES['image']
|
||||
fs = FileSystemStorage(location="./static/") #defaults to MEDIA_ROOT
|
||||
filename = fs.save(myfile.name, myfile)
|
||||
file_url = fs.url(filename)
|
||||
|
||||
return render(request, 'uploadImage.html', {
|
||||
'file_url': file_url,
|
||||
'file_name': myfile.name,
|
||||
})
|
||||
form.save()
|
||||
# Get the current instance object to display in the template
|
||||
img_obj = form.instance
|
||||
return render(request, 'uploadImage.html', {'form': form, 'img_obj': img_obj})
|
||||
|
||||
else:
|
||||
form = ImageForm()
|
||||
return render(request, 'uploadImage.html', {'form': form})
|
||||
|
||||
def videoUpload(request):
|
||||
"""Process videos uploaded by users"""
|
||||
if request.method == 'POST':
|
||||
form = VideoForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
img_obj = form.instance
|
||||
return render(request, 'uploadVideo.html', {'form': form, 'img_obj': img_obj})
|
||||
|
||||
else:
|
||||
form = VideoForm()
|
||||
return render(request, 'uploadVideo.html', {'form': form})
|
||||
|
||||
|
Reference in New Issue
Block a user