e
This commit is contained in:
parent
63168a485c
commit
d1280445f4
Binary file not shown.
BIN
website/home/__pycache__/admin.cpython-36.pyc
Normal file
BIN
website/home/__pycache__/admin.cpython-36.pyc
Normal file
Binary file not shown.
BIN
website/home/__pycache__/models.cpython-36.pyc
Normal file
BIN
website/home/__pycache__/models.cpython-36.pyc
Normal file
Binary file not shown.
BIN
website/home/__pycache__/views.cpython-36.pyc
Normal file
BIN
website/home/__pycache__/views.cpython-36.pyc
Normal file
Binary file not shown.
0
website/static/akmddGB.png
Normal file
0
website/static/akmddGB.png
Normal file
21
website/templates/uploadChoice.html
Normal file
21
website/templates/uploadChoice.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block title %} Home {% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
Hi {{ user.username }}!<br>
|
||||||
|
<form action="" method="POST">{% csrf_token %}
|
||||||
|
<label for="choice">What are we gonna upload today?</label>
|
||||||
|
<select name="choices" id="choices">
|
||||||
|
<option value="image">Picture</option>
|
||||||
|
<option value="video">Video</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<button type="submit"> Submit </button>
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
<p>You are not logged in</p>
|
||||||
|
<a href="{% url 'login' %}">Log In</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
17
website/templates/uploadImage.html
Normal file
17
website/templates/uploadImage.html
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block title %} Home {% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
Hi {{ user.username }}!<br>
|
||||||
|
<form action="" method="POST">{% csrf_token %}
|
||||||
|
<input type="file" name="image" id="image">
|
||||||
|
|
||||||
|
<button type="submit"> Submit </button>
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
<p>You are not logged in</p>
|
||||||
|
<a href="{% url 'login' %}">Log In</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
0
website/upload/__init__.py
Normal file
0
website/upload/__init__.py
Normal file
BIN
website/upload/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
website/upload/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
website/upload/__pycache__/admin.cpython-36.pyc
Normal file
BIN
website/upload/__pycache__/admin.cpython-36.pyc
Normal file
Binary file not shown.
BIN
website/upload/__pycache__/models.cpython-36.pyc
Normal file
BIN
website/upload/__pycache__/models.cpython-36.pyc
Normal file
Binary file not shown.
BIN
website/upload/__pycache__/views.cpython-36.pyc
Normal file
BIN
website/upload/__pycache__/views.cpython-36.pyc
Normal file
Binary file not shown.
3
website/upload/admin.py
Normal file
3
website/upload/admin.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
5
website/upload/apps.py
Normal file
5
website/upload/apps.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class UploadConfig(AppConfig):
|
||||||
|
name = 'upload'
|
9
website/upload/forms.py
Normal file
9
website/upload/forms.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from django import forms
|
||||||
|
from .models import Image
|
||||||
|
|
||||||
|
|
||||||
|
class ImageForm(forms.ModelForm):
|
||||||
|
"""Form for the image model"""
|
||||||
|
class Meta:
|
||||||
|
model = Image
|
||||||
|
fields = ('title', 'image')
|
0
website/upload/migrations/__init__.py
Normal file
0
website/upload/migrations/__init__.py
Normal file
BIN
website/upload/migrations/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
website/upload/migrations/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
4
website/upload/models.py
Normal file
4
website/upload/models.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
class Image(models.Model):
|
||||||
|
image = models.ImageField(upload_to='static/%Y/%m/%d/', blank=True)
|
3
website/upload/tests.py
Normal file
3
website/upload/tests.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
30
website/upload/views.py
Normal file
30
website/upload/views.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
from django.shortcuts import render, redirect
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
def uploadContent(request):
|
||||||
|
if request.method == "GET":
|
||||||
|
return render(request, "uploadChoice.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
|
||||||
|
|
||||||
|
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"static/{image}","wb")
|
||||||
|
for i in image:
|
||||||
|
savingImage.write(i)
|
||||||
|
savingImage.close()
|
||||||
|
return redirect(f"/static/{image}")
|
||||||
|
else:
|
||||||
|
return
|
BIN
website/users/__pycache__/admin.cpython-36.pyc
Normal file
BIN
website/users/__pycache__/admin.cpython-36.pyc
Normal file
Binary file not shown.
BIN
website/users/__pycache__/models.cpython-36.pyc
Normal file
BIN
website/users/__pycache__/models.cpython-36.pyc
Normal file
Binary file not shown.
BIN
website/users/__pycache__/urls.cpython-36.pyc
Normal file
BIN
website/users/__pycache__/urls.cpython-36.pyc
Normal file
Binary file not shown.
BIN
website/users/__pycache__/views.cpython-36.pyc
Normal file
BIN
website/users/__pycache__/views.cpython-36.pyc
Normal file
Binary file not shown.
BIN
website/website/__pycache__/settings.cpython-36.pyc
Normal file
BIN
website/website/__pycache__/settings.cpython-36.pyc
Normal file
Binary file not shown.
BIN
website/website/__pycache__/urls.cpython-36.pyc
Normal file
BIN
website/website/__pycache__/urls.cpython-36.pyc
Normal file
Binary file not shown.
BIN
website/website/__pycache__/wsgi.cpython-36.pyc
Normal file
BIN
website/website/__pycache__/wsgi.cpython-36.pyc
Normal file
Binary file not shown.
@ -40,6 +40,7 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'home',
|
'home',
|
||||||
'users',
|
'users',
|
||||||
|
'upload'
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
@ -121,8 +122,10 @@ USE_TZ = True
|
|||||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
STATIC_ROOT= "/media/kanina/AtmoSphere/Projects/CurrencySite/website/static/"
|
STATIC_ROOT= str(BASE_DIR.joinpath('static'))
|
||||||
|
|
||||||
|
MEDIA_URL = '/media/'
|
||||||
|
MEDIA_ROOT = str(BASE_DIR.joinpath('media'))
|
||||||
LOGIN_REDIRECT_URL = "/"
|
LOGIN_REDIRECT_URL = "/"
|
||||||
LOGOUT_REDIRECT_URL = "/"
|
LOGOUT_REDIRECT_URL = "/"
|
||||||
|
|
||||||
|
@ -20,11 +20,13 @@ from django.conf import settings
|
|||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from django.contrib.auth import views
|
from django.contrib.auth import views
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
|
from upload.views import uploadContent, imageUpload
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", homePage, name='home'),
|
path("", homePage, name='home'),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path("users/", include('django.contrib.auth.urls')),
|
path("users/", include('django.contrib.auth.urls')),
|
||||||
path('users/', include('users.urls')),
|
path('users/', include('users.urls')),
|
||||||
|
path("upload/", uploadContent, name="Upload"),
|
||||||
|
path("upload_image/", imageUpload, name="Image")
|
||||||
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user