diff --git a/website/db.sqlite3 b/website/db.sqlite3 index 1b69019e..862d5b37 100644 Binary files a/website/db.sqlite3 and b/website/db.sqlite3 differ diff --git a/website/home/__pycache__/admin.cpython-36.pyc b/website/home/__pycache__/admin.cpython-36.pyc index c7725463..6a1beeb2 100644 Binary files a/website/home/__pycache__/admin.cpython-36.pyc and b/website/home/__pycache__/admin.cpython-36.pyc differ diff --git a/website/home/__pycache__/models.cpython-36.pyc b/website/home/__pycache__/models.cpython-36.pyc index 089fc763..e80a12af 100644 Binary files a/website/home/__pycache__/models.cpython-36.pyc and b/website/home/__pycache__/models.cpython-36.pyc differ diff --git a/website/home/__pycache__/views.cpython-36.pyc b/website/home/__pycache__/views.cpython-36.pyc index 9640f227..c7e2c6b7 100644 Binary files a/website/home/__pycache__/views.cpython-36.pyc and b/website/home/__pycache__/views.cpython-36.pyc differ diff --git a/website/static/2021/02/09/Screenshot_at_2021-01-19_03-15-00.png b/website/static/2021/02/09/Screenshot_at_2021-01-19_03-15-00.png deleted file mode 100644 index 6d58ac0b..00000000 Binary files a/website/static/2021/02/09/Screenshot_at_2021-01-19_03-15-00.png and /dev/null differ diff --git a/website/static/Screenshot at 2021-01-19 03-15-00.png b/website/static/Screenshot at 2021-01-19 03-15-00.png deleted file mode 100644 index e69de29b..00000000 diff --git a/website/static/Screenshot at 2021-01-19 03-15-00_5jYNLfq.png b/website/static/Screenshot at 2021-01-19 03-15-00_5jYNLfq.png deleted file mode 100644 index 6d58ac0b..00000000 Binary files a/website/static/Screenshot at 2021-01-19 03-15-00_5jYNLfq.png and /dev/null differ diff --git a/website/static/Screenshot at 2021-01-19 03-15-00_HzSfOyh.png b/website/static/Screenshot at 2021-01-19 03-15-00_HzSfOyh.png deleted file mode 100644 index 6d58ac0b..00000000 Binary files a/website/static/Screenshot at 2021-01-19 03-15-00_HzSfOyh.png and /dev/null differ diff --git a/website/static/Screenshot at 2021-01-19 03-15-00_Wukng9o.png b/website/static/Screenshot at 2021-01-19 03-15-00_Wukng9o.png deleted file mode 100644 index 6d58ac0b..00000000 Binary files a/website/static/Screenshot at 2021-01-19 03-15-00_Wukng9o.png and /dev/null differ diff --git a/website/static/Screenshot at 2021-01-19 03-15-00_p1gRbJ7.png b/website/static/Screenshot at 2021-01-19 03-15-00_p1gRbJ7.png deleted file mode 100644 index 6d58ac0b..00000000 Binary files a/website/static/Screenshot at 2021-01-19 03-15-00_p1gRbJ7.png and /dev/null differ diff --git a/website/static/Screenshot_at_2021-01-19_03-15-00.png b/website/static/Screenshot_at_2021-01-19_03-15-00.png deleted file mode 100644 index 6d58ac0b..00000000 Binary files a/website/static/Screenshot_at_2021-01-19_03-15-00.png and /dev/null differ diff --git a/website/static/Screenshot_at_2021-01-19_03-15-00_nSTujQE.png b/website/static/Screenshot_at_2021-01-19_03-15-00_nSTujQE.png deleted file mode 100644 index 6d58ac0b..00000000 Binary files a/website/static/Screenshot_at_2021-01-19_03-15-00_nSTujQE.png and /dev/null differ diff --git a/website/static/Screenshot_at_2021-01-19_03-15-00_nnpFyZr.png b/website/static/Screenshot_at_2021-01-19_03-15-00_nnpFyZr.png deleted file mode 100644 index 6d58ac0b..00000000 Binary files a/website/static/Screenshot_at_2021-01-19_03-15-00_nnpFyZr.png and /dev/null differ diff --git a/website/static/akmddGB.png b/website/static/akmddGB.png deleted file mode 100644 index e69de29b..00000000 diff --git a/website/templates/uploadImage.html b/website/templates/uploadImage.html index 6eee37a2..68c26c7e 100644 --- a/website/templates/uploadImage.html +++ b/website/templates/uploadImage.html @@ -5,16 +5,16 @@ {% block content %} {% if user.is_authenticated %} Hi {{ user.username }}!
-
- {% csrf_token %} - {{ form.as_p }} - -
- - {% if file_url %} -

Succesfully uploaded

- connect - {% endif %} +
+ {% csrf_token %} + {{ form.as_p }} + +
+ + {% if img_obj %} +

Succesfully uploaded : {{img_obj.title}}

+ connect + {% endif %} {% else %}

You are not logged in

Log In diff --git a/website/templates/uploadVideo.html b/website/templates/uploadVideo.html new file mode 100644 index 00000000..f3aefc41 --- /dev/null +++ b/website/templates/uploadVideo.html @@ -0,0 +1,22 @@ +{% extends 'base.html' %} + +{% block title %} Home {% endblock %} + +{% block content %} +{% if user.is_authenticated %} + Hi {{ user.username }}!
+
+ {% csrf_token %} + {{ form.as_p }} + +
+ + {% if img_obj %} +

Succesfully uploaded : {{img_obj.title}}

+ + {% endif %} + {% else %} +

You are not logged in

+ Log In +{% endif %} +{% endblock %} diff --git a/website/upload/__pycache__/__init__.cpython-36.pyc b/website/upload/__pycache__/__init__.cpython-36.pyc index fb5f5ec8..49b605ea 100644 Binary files a/website/upload/__pycache__/__init__.cpython-36.pyc and b/website/upload/__pycache__/__init__.cpython-36.pyc differ diff --git a/website/upload/__pycache__/admin.cpython-36.pyc b/website/upload/__pycache__/admin.cpython-36.pyc index 882cca75..b44cbe26 100644 Binary files a/website/upload/__pycache__/admin.cpython-36.pyc and b/website/upload/__pycache__/admin.cpython-36.pyc differ diff --git a/website/upload/__pycache__/forms.cpython-36.pyc b/website/upload/__pycache__/forms.cpython-36.pyc index e68e9b9b..6c148c01 100644 Binary files a/website/upload/__pycache__/forms.cpython-36.pyc and b/website/upload/__pycache__/forms.cpython-36.pyc differ diff --git a/website/upload/__pycache__/models.cpython-36.pyc b/website/upload/__pycache__/models.cpython-36.pyc index 395154f7..17a7d67c 100644 Binary files a/website/upload/__pycache__/models.cpython-36.pyc and b/website/upload/__pycache__/models.cpython-36.pyc differ diff --git a/website/upload/__pycache__/validators.cpython-36.pyc b/website/upload/__pycache__/validators.cpython-36.pyc new file mode 100644 index 00000000..b40e8bc6 Binary files /dev/null and b/website/upload/__pycache__/validators.cpython-36.pyc differ diff --git a/website/upload/__pycache__/views.cpython-36.pyc b/website/upload/__pycache__/views.cpython-36.pyc index eb7181fd..49f28d75 100644 Binary files a/website/upload/__pycache__/views.cpython-36.pyc and b/website/upload/__pycache__/views.cpython-36.pyc differ diff --git a/website/upload/forms.py b/website/upload/forms.py index d168e15a..0235a029 100644 --- a/website/upload/forms.py +++ b/website/upload/forms.py @@ -1,9 +1,15 @@ from django import forms -from .models import Image +from .models import Image, Videos class ImageForm(forms.ModelForm): """Form for the image model""" class Meta: model = Image - fields = ('image',) + fields = ('title', 'image') + +class VideoForm(forms.ModelForm): + """Form for the image model""" + class Meta: + model = Videos + fields = ('title', 'video') diff --git a/website/upload/migrations/0004_auto_20210217_0041.py b/website/upload/migrations/0004_auto_20210217_0041.py new file mode 100644 index 00000000..8ca66b80 --- /dev/null +++ b/website/upload/migrations/0004_auto_20210217_0041.py @@ -0,0 +1,25 @@ +# Generated by Django 3.1.6 on 2021-02-16 22:41 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('upload', '0003_auto_20210209_1806'), + ] + + operations = [ + migrations.AddField( + model_name='image', + name='title', + field=models.CharField(default=django.utils.timezone.now, max_length=200), + preserve_default=False, + ), + migrations.AlterField( + model_name='image', + name='image', + field=models.ImageField(upload_to='images'), + ), + ] diff --git a/website/upload/migrations/0005_videos.py b/website/upload/migrations/0005_videos.py new file mode 100644 index 00000000..38e798f8 --- /dev/null +++ b/website/upload/migrations/0005_videos.py @@ -0,0 +1,25 @@ +# Generated by Django 3.1.6 on 2021-02-16 22:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('upload', '0004_auto_20210217_0041'), + ] + + operations = [ + migrations.CreateModel( + name='Videos', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=100)), + ('video', models.FileField(upload_to='videos/')), + ], + options={ + 'verbose_name': 'video', + 'verbose_name_plural': 'videos', + }, + ), + ] diff --git a/website/upload/migrations/__pycache__/0001_initial.cpython-36.pyc b/website/upload/migrations/__pycache__/0001_initial.cpython-36.pyc index dbd6bcbd..217b0afc 100644 Binary files a/website/upload/migrations/__pycache__/0001_initial.cpython-36.pyc and b/website/upload/migrations/__pycache__/0001_initial.cpython-36.pyc differ diff --git a/website/upload/migrations/__pycache__/0002_auto_20210209_1803.cpython-36.pyc b/website/upload/migrations/__pycache__/0002_auto_20210209_1803.cpython-36.pyc index edf7ffd2..9da3b562 100644 Binary files a/website/upload/migrations/__pycache__/0002_auto_20210209_1803.cpython-36.pyc and b/website/upload/migrations/__pycache__/0002_auto_20210209_1803.cpython-36.pyc differ diff --git a/website/upload/migrations/__pycache__/0003_auto_20210209_1806.cpython-36.pyc b/website/upload/migrations/__pycache__/0003_auto_20210209_1806.cpython-36.pyc index a6db6103..b7fd6b74 100644 Binary files a/website/upload/migrations/__pycache__/0003_auto_20210209_1806.cpython-36.pyc and b/website/upload/migrations/__pycache__/0003_auto_20210209_1806.cpython-36.pyc differ diff --git a/website/upload/migrations/__pycache__/0004_auto_20210217_0041.cpython-36.pyc b/website/upload/migrations/__pycache__/0004_auto_20210217_0041.cpython-36.pyc new file mode 100644 index 00000000..a116769a Binary files /dev/null and b/website/upload/migrations/__pycache__/0004_auto_20210217_0041.cpython-36.pyc differ diff --git a/website/upload/migrations/__pycache__/0005_videos.cpython-36.pyc b/website/upload/migrations/__pycache__/0005_videos.cpython-36.pyc new file mode 100644 index 00000000..c8b39ea9 Binary files /dev/null and b/website/upload/migrations/__pycache__/0005_videos.cpython-36.pyc differ diff --git a/website/upload/migrations/__pycache__/__init__.cpython-36.pyc b/website/upload/migrations/__pycache__/__init__.cpython-36.pyc index 192f30b7..e84bbe68 100644 Binary files a/website/upload/migrations/__pycache__/__init__.cpython-36.pyc and b/website/upload/migrations/__pycache__/__init__.cpython-36.pyc differ diff --git a/website/upload/models.py b/website/upload/models.py index a187bdad..dfaddbdc 100644 --- a/website/upload/models.py +++ b/website/upload/models.py @@ -1,4 +1,27 @@ from django.db import models +from .validators import videoValidate, imageValidate + +# def user_directory._path(instance, filename): + # print(request.user.id) + # return 'user_{0}/{1}'.format(instance.user.id, filename) +# Ok i got hella angry, so pleaSE fix this bullshit +# I want to be able to store each and every user's files in a separate folder, based on their id +# I CANT GET A FUCKING LOGGED IN USER ID FROM THE MODELS THINGY IM FUCKING PISSED class Image(models.Model): - image = models.FileField(upload_to='static/') + title = models.CharField(max_length=200) + image = models.ImageField(upload_to=f"images/{upload_to}",validators=[imageValidate]) + + def __str__(self): + return self.title + +class Videos(models.Model): + title = models.CharField(max_length=100) + video = models.FileField(upload_to=f'videos/', validators=[videoValidate]) + + class Meta: + verbose_name = 'video' + verbose_name_plural = 'videos' + + def __str__(self): + return self.title diff --git a/website/upload/validators.py b/website/upload/validators.py new file mode 100644 index 00000000..761b908e --- /dev/null +++ b/website/upload/validators.py @@ -0,0 +1,15 @@ +def imageValidate(value): + import os + from django.core.exceptions import ValidationError + ext = os.path.splitext(value.name)[1] + valid_extensions = ['.jpg', '.png', '.gif'] + if not ext.lower() in valid_extensions: + raise ValidationError('Unsupported file extension.') + +def videoValidate(value): + import os + from django.core.exceptions import ValidationError + ext = os.path.splitext(value.name)[1] + valid_extensions = ['.mp4', '.mkv', '.avi'] + if not ext.lower() in valid_extensions: + raise ValidationError('Unsupported file extension.') diff --git a/website/upload/views.py b/website/upload/views.py index 9d6bd330..20fac144 100644 --- a/website/upload/views.py +++ b/website/upload/views.py @@ -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}) + diff --git a/website/users/__pycache__/admin.cpython-36.pyc b/website/users/__pycache__/admin.cpython-36.pyc index 8573692b..e8b35c30 100644 Binary files a/website/users/__pycache__/admin.cpython-36.pyc and b/website/users/__pycache__/admin.cpython-36.pyc differ diff --git a/website/users/__pycache__/models.cpython-36.pyc b/website/users/__pycache__/models.cpython-36.pyc index 813ec63e..0d1a6c4c 100644 Binary files a/website/users/__pycache__/models.cpython-36.pyc and b/website/users/__pycache__/models.cpython-36.pyc differ diff --git a/website/users/__pycache__/urls.cpython-36.pyc b/website/users/__pycache__/urls.cpython-36.pyc index 4bf10ac2..f319fee5 100644 Binary files a/website/users/__pycache__/urls.cpython-36.pyc and b/website/users/__pycache__/urls.cpython-36.pyc differ diff --git a/website/users/__pycache__/views.cpython-36.pyc b/website/users/__pycache__/views.cpython-36.pyc index f6c59961..267606ac 100644 Binary files a/website/users/__pycache__/views.cpython-36.pyc and b/website/users/__pycache__/views.cpython-36.pyc differ diff --git a/website/website/__pycache__/settings.cpython-36.pyc b/website/website/__pycache__/settings.cpython-36.pyc index 3010f332..cbe3a40e 100644 Binary files a/website/website/__pycache__/settings.cpython-36.pyc and b/website/website/__pycache__/settings.cpython-36.pyc differ diff --git a/website/website/__pycache__/urls.cpython-36.pyc b/website/website/__pycache__/urls.cpython-36.pyc index 1f927953..73cb738e 100644 Binary files a/website/website/__pycache__/urls.cpython-36.pyc and b/website/website/__pycache__/urls.cpython-36.pyc differ diff --git a/website/website/__pycache__/wsgi.cpython-36.pyc b/website/website/__pycache__/wsgi.cpython-36.pyc index b1ac2cfa..a4bb207d 100644 Binary files a/website/website/__pycache__/wsgi.cpython-36.pyc and b/website/website/__pycache__/wsgi.cpython-36.pyc differ diff --git a/website/website/settings.py b/website/website/settings.py index 6e862f68..491e9033 100644 --- a/website/website/settings.py +++ b/website/website/settings.py @@ -40,7 +40,8 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'home', 'users', - 'upload' + 'upload', + ] MIDDLEWARE = [ @@ -51,6 +52,7 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + ] ROOT_URLCONF = 'website.urls' @@ -129,3 +131,6 @@ LOGOUT_REDIRECT_URL = "/" EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend" EMAIL_FILE_PATH = str(BASE_DIR.joinpath('sent_emails')) + +MEDIA_URL = '/media/' +MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') diff --git a/website/website/urls.py b/website/website/urls.py index c296003c..abf9f1dd 100644 --- a/website/website/urls.py +++ b/website/website/urls.py @@ -20,7 +20,7 @@ from django.conf import settings from django.conf.urls.static import static from django.contrib.auth import views from django.views.generic.base import TemplateView -from upload.views import uploadContent, imageUpload +from upload.views import uploadContent, imageUpload, videoUpload urlpatterns = [ path("", homePage, name='home'), @@ -28,8 +28,9 @@ urlpatterns = [ path("users/", include('django.contrib.auth.urls')), path('users/', include('users.urls')), path("upload/", uploadContent, name="Upload"), - path("upload_image/", imageUpload, name="Image") + path("upload_image/", imageUpload, name="Image"), + path("upload_video/", videoUpload, name="Video"), ] if settings.DEBUG: - urlpatterns += static(settings.STATIC_URL, - document_root=settings.STATIC_ROOT) + urlpatterns += static(settings.MEDIA_URL, + document_root=settings.MEDIA_ROOT)