diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..50ae82ee --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__django diff --git a/currencyproj/currencyproj/__pycache__/__init__.cpython-36.pyc b/currencyproj/currencyproj/__pycache__/__init__.cpython-36.pyc index 1675128a..41072de4 100644 Binary files a/currencyproj/currencyproj/__pycache__/__init__.cpython-36.pyc and b/currencyproj/currencyproj/__pycache__/__init__.cpython-36.pyc differ diff --git a/currencyproj/currencyproj/__pycache__/settings.cpython-36.pyc b/currencyproj/currencyproj/__pycache__/settings.cpython-36.pyc index 9418a96c..e46fef6f 100644 Binary files a/currencyproj/currencyproj/__pycache__/settings.cpython-36.pyc and b/currencyproj/currencyproj/__pycache__/settings.cpython-36.pyc differ diff --git a/currencyproj/currencyproj/__pycache__/urls.cpython-36.pyc b/currencyproj/currencyproj/__pycache__/urls.cpython-36.pyc new file mode 100644 index 00000000..42a37e01 Binary files /dev/null and b/currencyproj/currencyproj/__pycache__/urls.cpython-36.pyc differ diff --git a/currencyproj/currencyproj/__pycache__/wsgi.cpython-36.pyc b/currencyproj/currencyproj/__pycache__/wsgi.cpython-36.pyc new file mode 100644 index 00000000..67addeed Binary files /dev/null and b/currencyproj/currencyproj/__pycache__/wsgi.cpython-36.pyc differ diff --git a/currencyproj/currencyproj/settings.py b/currencyproj/currencyproj/settings.py index 9b6ca056..e7edbfab 100644 --- a/currencyproj/currencyproj/settings.py +++ b/currencyproj/currencyproj/settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.1/ref/settings/ """ from pathlib import Path +import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -119,3 +120,6 @@ USE_TZ = True # https://docs.djangoproject.com/en/3.1/howto/static-files/ STATIC_URL = '/static/' +STATICFILES_DIRS = [ + os.path.join(BASE_DIR, "static"), + ] diff --git a/currencyproj/currencyproj/urls.py b/currencyproj/currencyproj/urls.py index 30e1417f..9cbd8bf1 100644 --- a/currencyproj/currencyproj/urls.py +++ b/currencyproj/currencyproj/urls.py @@ -1,27 +1,16 @@ -"""currencyproj URL Configuration -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/3.1/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" from django.contrib import admin from django.urls import path from home.models import upload_video,upload_image -from home.views import upload_content, imageUpload, videoUpload +# from home.views import upload_content, imageUpload, videoUpload +from home.views import finallyUploadImage +from home.forms import UploadImage urlpatterns = [ path('admin/', admin.site.urls), - path('upload/',upload_content, name="upload"), - path('upload_video/',videoUpload,name='upload_video'), - path('upload_image/',imageUpload,name='upload_image'), + # path('upload/',upload_content, name="upload"), + # path('upload_video/',videoUpload,name='upload_video'), + # path('upload_image/',imageUpload,name='upload_image'), + path('upload/',finallyUploadImage,name="Plsman") ] diff --git a/currencyproj/db.sqlite3 b/currencyproj/db.sqlite3 index 07ab0ea0..26e51092 100644 Binary files a/currencyproj/db.sqlite3 and b/currencyproj/db.sqlite3 differ diff --git a/currencyproj/home/__pycache__/__init__.cpython-36.pyc b/currencyproj/home/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 00000000..ebe51b8e Binary files /dev/null and b/currencyproj/home/__pycache__/__init__.cpython-36.pyc differ diff --git a/currencyproj/home/__pycache__/admin.cpython-36.pyc b/currencyproj/home/__pycache__/admin.cpython-36.pyc new file mode 100644 index 00000000..57f54fce Binary files /dev/null and b/currencyproj/home/__pycache__/admin.cpython-36.pyc differ diff --git a/currencyproj/home/__pycache__/forms.cpython-36.pyc b/currencyproj/home/__pycache__/forms.cpython-36.pyc new file mode 100644 index 00000000..4739c48a Binary files /dev/null and b/currencyproj/home/__pycache__/forms.cpython-36.pyc differ diff --git a/currencyproj/home/__pycache__/models.cpython-36.pyc b/currencyproj/home/__pycache__/models.cpython-36.pyc new file mode 100644 index 00000000..efac7289 Binary files /dev/null and b/currencyproj/home/__pycache__/models.cpython-36.pyc differ diff --git a/currencyproj/home/__pycache__/views.cpython-36.pyc b/currencyproj/home/__pycache__/views.cpython-36.pyc new file mode 100644 index 00000000..8e393b6a Binary files /dev/null and b/currencyproj/home/__pycache__/views.cpython-36.pyc differ diff --git a/currencyproj/home/forms.py b/currencyproj/home/forms.py new file mode 100644 index 00000000..fccd5a55 --- /dev/null +++ b/currencyproj/home/forms.py @@ -0,0 +1,9 @@ +from django import forms +from .models import upload_image + +class UploadImage(forms.ModelForm): + class Meta: + model = upload_image + fields = [ + 'image' + ] diff --git a/currencyproj/home/migrations/0003_auto_20210205_1213.py b/currencyproj/home/migrations/0003_auto_20210205_1213.py new file mode 100644 index 00000000..ff4ffb63 --- /dev/null +++ b/currencyproj/home/migrations/0003_auto_20210205_1213.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.6 on 2021-02-05 12:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0002_auto_20210205_0037'), + ] + + operations = [ + migrations.AlterField( + model_name='upload_image', + name='image', + field=models.FileField(upload_to='static/images/'), + ), + migrations.AlterField( + model_name='upload_video', + name='video', + field=models.FileField(upload_to='static/videos/'), + ), + ] diff --git a/currencyproj/home/migrations/0004_auto_20210205_1216.py b/currencyproj/home/migrations/0004_auto_20210205_1216.py new file mode 100644 index 00000000..2a2e7bb2 --- /dev/null +++ b/currencyproj/home/migrations/0004_auto_20210205_1216.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.6 on 2021-02-05 12:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0003_auto_20210205_1213'), + ] + + operations = [ + migrations.AlterField( + model_name='upload_image', + name='image', + field=models.FileField(upload_to='images/'), + ), + migrations.AlterField( + model_name='upload_video', + name='video', + field=models.FileField(upload_to='videos/'), + ), + ] diff --git a/currencyproj/home/migrations/__pycache__/0001_initial.cpython-36.pyc b/currencyproj/home/migrations/__pycache__/0001_initial.cpython-36.pyc new file mode 100644 index 00000000..a0c75d0a Binary files /dev/null and b/currencyproj/home/migrations/__pycache__/0001_initial.cpython-36.pyc differ diff --git a/currencyproj/home/migrations/__pycache__/0002_auto_20210205_0037.cpython-36.pyc b/currencyproj/home/migrations/__pycache__/0002_auto_20210205_0037.cpython-36.pyc new file mode 100644 index 00000000..cbf81199 Binary files /dev/null and b/currencyproj/home/migrations/__pycache__/0002_auto_20210205_0037.cpython-36.pyc differ diff --git a/currencyproj/home/migrations/__pycache__/0003_auto_20210205_1213.cpython-36.pyc b/currencyproj/home/migrations/__pycache__/0003_auto_20210205_1213.cpython-36.pyc new file mode 100644 index 00000000..766e1a3d Binary files /dev/null and b/currencyproj/home/migrations/__pycache__/0003_auto_20210205_1213.cpython-36.pyc differ diff --git a/currencyproj/home/migrations/__pycache__/0004_auto_20210205_1216.cpython-36.pyc b/currencyproj/home/migrations/__pycache__/0004_auto_20210205_1216.cpython-36.pyc new file mode 100644 index 00000000..ced8b274 Binary files /dev/null and b/currencyproj/home/migrations/__pycache__/0004_auto_20210205_1216.cpython-36.pyc differ diff --git a/currencyproj/home/migrations/__pycache__/__init__.cpython-36.pyc b/currencyproj/home/migrations/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 00000000..bb31f620 Binary files /dev/null and b/currencyproj/home/migrations/__pycache__/__init__.cpython-36.pyc differ diff --git a/currencyproj/home/templates/details.html b/currencyproj/home/templates/details.html new file mode 100644 index 00000000..3b65e9d8 --- /dev/null +++ b/currencyproj/home/templates/details.html @@ -0,0 +1,13 @@ +{% extends 'uploadImage.html' %} +{% block replace %} +<div class="jumbotron"> + <h1 class="display-4">Welcome to DataFlair<br>Hello {{ user_pr.fname }}</h1> + <p class="lead">its an awesome profile picture</p> + <hr class="my-4"> + {% load static %} + <img src="{% static user_pr.image.url %}" class="image_responsive" height="100px" width="100px"> + <p> + {{ user_pr.display_picture.url }}<BR> + You have learned some awesome technologies like {{ user_pr.technologies }}</p> +</div> +{% endblock %} diff --git a/currencyproj/home/templates/error.html b/currencyproj/home/templates/error.html new file mode 100644 index 00000000..1bc13d58 --- /dev/null +++ b/currencyproj/home/templates/error.html @@ -0,0 +1,10 @@ +<!DOCTYPE html> +<html lang="en" dir="ltr"> + <head> + <meta charset="utf-8"> + <title></title> + </head> + <body> + <h1>404</h1> + </body> +</html> diff --git a/currencyproj/home/templates/uploadImage.html b/currencyproj/home/templates/uploadImage.html index 3015a042..e6c104ea 100644 --- a/currencyproj/home/templates/uploadImage.html +++ b/currencyproj/home/templates/uploadImage.html @@ -1,10 +1,25 @@ <!DOCTYPE html> -<html lang="en" dir="ltr"> - <head> - <meta charset="utf-8"> - <title>test</title> - </head> - <body> -<h1>test 1</h1> - </body> +<html> + <head> + <title>Make Profile</title> + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> + </head> + <body> + + <center> + <div class="jumbotron"> + <h1 class="display-4">DataFlair Django File Uploading</h1> + {% block replace %} + <p class="lead">To make a user profile and upload the files fill this form</p> + <hr class="my-4"> + <form method="POST" enctype="multipart/form-data"> + {% csrf_token %} + <table> + {{ form.as_table }} + </table> + <input type="submit" class="btn btn-primary btn-lg" name="register"> + </div> + </center> + {% endblock %} + </body> </html> diff --git a/currencyproj/home/views.py b/currencyproj/home/views.py index 0b119d96..a150f364 100644 --- a/currencyproj/home/views.py +++ b/currencyproj/home/views.py @@ -1,40 +1,67 @@ -from django.shortcuts import render, redirect - -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 - return upload_image(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 +# 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 +from django.shortcuts import render +from .forms import UploadImage +from .models import upload_image -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 +IMAGE_FILE_TYPES = ['png', 'jpg', 'jpeg'] + +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) diff --git a/currencyproj/images/WIN_20171203_11_38_21_Pro.jpg b/currencyproj/images/WIN_20171203_11_38_21_Pro.jpg new file mode 100644 index 00000000..312e9737 Binary files /dev/null and b/currencyproj/images/WIN_20171203_11_38_21_Pro.jpg differ diff --git a/currencyproj/images/proxy.duckduckgo.com.jpg b/currencyproj/images/proxy.duckduckgo.com.jpg new file mode 100644 index 00000000..22f74a41 Binary files /dev/null and b/currencyproj/images/proxy.duckduckgo.com.jpg differ diff --git a/currencyproj/images/proxy.duckduckgo.com.png b/currencyproj/images/proxy.duckduckgo.com.png new file mode 100644 index 00000000..05cf7bb6 Binary files /dev/null and b/currencyproj/images/proxy.duckduckgo.com.png differ diff --git a/currencyproj/images/proxy.duckduckgo.com_CM5TyHm.png b/currencyproj/images/proxy.duckduckgo.com_CM5TyHm.png new file mode 100644 index 00000000..05cf7bb6 Binary files /dev/null and b/currencyproj/images/proxy.duckduckgo.com_CM5TyHm.png differ diff --git a/currencyproj/images/proxy.duckduckgo.com_EMLFjoc.png b/currencyproj/images/proxy.duckduckgo.com_EMLFjoc.png new file mode 100644 index 00000000..05cf7bb6 Binary files /dev/null and b/currencyproj/images/proxy.duckduckgo.com_EMLFjoc.png differ diff --git a/currencyproj/images/proxy.duckduckgo.com_UsCE4m2.jpg b/currencyproj/images/proxy.duckduckgo.com_UsCE4m2.jpg new file mode 100644 index 00000000..22f74a41 Binary files /dev/null and b/currencyproj/images/proxy.duckduckgo.com_UsCE4m2.jpg differ diff --git a/currencyproj/images/proxy.duckduckgo.com_WqV3PIs.jpg b/currencyproj/images/proxy.duckduckgo.com_WqV3PIs.jpg new file mode 100644 index 00000000..22f74a41 Binary files /dev/null and b/currencyproj/images/proxy.duckduckgo.com_WqV3PIs.jpg differ diff --git a/currencyproj/images/proxy.duckduckgo.com_dR7TUYf.png b/currencyproj/images/proxy.duckduckgo.com_dR7TUYf.png new file mode 100644 index 00000000..05cf7bb6 Binary files /dev/null and b/currencyproj/images/proxy.duckduckgo.com_dR7TUYf.png differ diff --git a/currencyproj/images/proxy.duckduckgo.com_dmVqC3C.png b/currencyproj/images/proxy.duckduckgo.com_dmVqC3C.png new file mode 100644 index 00000000..05cf7bb6 Binary files /dev/null and b/currencyproj/images/proxy.duckduckgo.com_dmVqC3C.png differ diff --git a/currencyproj/images/proxy.duckduckgo.com_hEqsj47.jpg b/currencyproj/images/proxy.duckduckgo.com_hEqsj47.jpg new file mode 100644 index 00000000..22f74a41 Binary files /dev/null and b/currencyproj/images/proxy.duckduckgo.com_hEqsj47.jpg differ diff --git a/currencyproj/images/proxy.duckduckgo.com_jlaO7oa.jpg b/currencyproj/images/proxy.duckduckgo.com_jlaO7oa.jpg new file mode 100644 index 00000000..22f74a41 Binary files /dev/null and b/currencyproj/images/proxy.duckduckgo.com_jlaO7oa.jpg differ diff --git a/currencyproj/images/proxy.duckduckgo.com_wEukfAL.jpg b/currencyproj/images/proxy.duckduckgo.com_wEukfAL.jpg new file mode 100644 index 00000000..22f74a41 Binary files /dev/null and b/currencyproj/images/proxy.duckduckgo.com_wEukfAL.jpg differ diff --git a/currencyproj/static/images/WIN_20171203_11_38_21_Pro.jpg b/currencyproj/static/images/WIN_20171203_11_38_21_Pro.jpg new file mode 100644 index 00000000..312e9737 Binary files /dev/null and b/currencyproj/static/images/WIN_20171203_11_38_21_Pro.jpg differ diff --git a/currencyproj/static/images/WIN_20171203_11_38_21_Pro_GnuWtID.jpg b/currencyproj/static/images/WIN_20171203_11_38_21_Pro_GnuWtID.jpg new file mode 100644 index 00000000..312e9737 Binary files /dev/null and b/currencyproj/static/images/WIN_20171203_11_38_21_Pro_GnuWtID.jpg differ diff --git a/currencyproj/static/images/WIN_20171203_11_38_21_Pro_Mypenc5.jpg b/currencyproj/static/images/WIN_20171203_11_38_21_Pro_Mypenc5.jpg new file mode 100644 index 00000000..312e9737 Binary files /dev/null and b/currencyproj/static/images/WIN_20171203_11_38_21_Pro_Mypenc5.jpg differ diff --git a/currencyproj/static/images/WIN_20171203_11_38_21_Pro_ZoyKCCJ.jpg b/currencyproj/static/images/WIN_20171203_11_38_21_Pro_ZoyKCCJ.jpg new file mode 100644 index 00000000..312e9737 Binary files /dev/null and b/currencyproj/static/images/WIN_20171203_11_38_21_Pro_ZoyKCCJ.jpg differ