2021-02-05 14:27:58 +02:00
|
|
|
# from django.shortcuts import render, redirect
|
|
|
|
# import os
|
|
|
|
# from .models import upload_video,upload_image
|
|
|
|
#
|
|
|
|
# def imageUpload(request):
|
|
|
|
# if request.method == "GET":
|
|
|
|
# return render(request, "uploadImage.html")
|
|
|
|
# elif request.method == "POST":
|
|
|
|
# image = request.POST["image"]
|
|
|
|
# # add the id of the user, after you add in users
|
|
|
|
# savingImage = open(f"../images/{image}","w")
|
|
|
|
# for i in image:
|
|
|
|
# savingImage.write(i)
|
|
|
|
# savingImage.close()
|
|
|
|
# return redirect(f"/images/{image}")
|
|
|
|
# else:
|
|
|
|
# return
|
|
|
|
#
|
|
|
|
# def videoUpload(request):
|
|
|
|
# if request.method == "GET":
|
|
|
|
# return render(request, "uploadVideo.html")
|
|
|
|
# elif request.method == "POST":
|
|
|
|
# video = request.POST["video"]
|
|
|
|
# # add the id of the user, after you add in users
|
|
|
|
# return upload_video(video)
|
|
|
|
# else:
|
|
|
|
# return
|
|
|
|
#
|
|
|
|
# # these functions do the same thing, but i cant merge them in one, because i cant add parameters(because of request)
|
|
|
|
#
|
|
|
|
# def upload_content(request):
|
|
|
|
# if request.method == "GET":
|
|
|
|
# return render(request, "index.html")
|
|
|
|
# elif request.method == "POST":
|
|
|
|
# choice = request.POST["choices"]
|
|
|
|
# if choice == "image":
|
|
|
|
# return redirect("/upload_image/")
|
|
|
|
# elif choice == "video":
|
|
|
|
# return redirect("/upload_video/")
|
|
|
|
# else:
|
|
|
|
# return
|
|
|
|
# else:
|
|
|
|
# return
|
|
|
|
# # in conclusion - im genious, good job boyan lmao
|
2021-02-05 01:25:02 +02:00
|
|
|
|
2021-02-05 03:18:16 +02:00
|
|
|
|
2021-02-05 14:27:58 +02:00
|
|
|
from django.shortcuts import render
|
|
|
|
from .forms import UploadImage
|
|
|
|
from .models import upload_image
|
2021-02-05 03:18:16 +02:00
|
|
|
|
2021-02-05 14:27:58 +02:00
|
|
|
IMAGE_FILE_TYPES = ['png', 'jpg', 'jpeg']
|
2021-02-05 03:18:16 +02:00
|
|
|
|
2021-02-05 14:27:58 +02:00
|
|
|
def finallyUploadImage(request):
|
|
|
|
form = UploadImage()
|
|
|
|
if request.method == 'POST':
|
|
|
|
form = UploadImage(request.POST, request.FILES)
|
|
|
|
if form.is_valid():
|
|
|
|
user_pr = form.save(commit=False)
|
|
|
|
user_pr.image = request.FILES['image']
|
|
|
|
file_type = user_pr.image.url.split('.')[-1]
|
|
|
|
file_type = file_type.lower()
|
|
|
|
if file_type not in IMAGE_FILE_TYPES:
|
|
|
|
return render(request, 'error.html')
|
|
|
|
user_pr.save()
|
|
|
|
return render(request, 'details.html', {'user_pr': user_pr})
|
|
|
|
context = {"form": form,}
|
|
|
|
return render(request, 'uploadImage.html', context)
|