Squashed commit of the following:
commit4c5a5fee8d
Author: reverend <reverend@reverend2048.de> Date: Sun Dec 18 09:24:15 2022 +0100 commit17647bf4b7
Author: reverend <reverend@reverend2048.de> Date: Sun Dec 18 09:23:36 2022 +0100 commit4deeb3d773
Author: reverend <reverend@reverend2048.de> Date: Sun Dec 18 09:23:06 2022 +0100 commit5342e62bcb
Author: reverend <reverend@reverend2048.de> Date: Sun Dec 18 09:22:44 2022 +0100 commit02512c1677
Author: reverend <reverend@reverend2048.de> Date: Sun Dec 18 09:21:57 2022 +0100
This commit is contained in:
parent
ba6a40fbe5
commit
c5dfb4f926
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
django_web_galleries/media/*
|
2
Pipfile
2
Pipfile
@ -5,6 +5,8 @@ name = "pypi"
|
|||||||
|
|
||||||
[packages]
|
[packages]
|
||||||
django = "*"
|
django = "*"
|
||||||
|
django-responsive-images = "*"
|
||||||
|
pillow = "*"
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
|
|
||||||
|
@ -37,6 +37,8 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
'responsive_images',
|
||||||
|
'web_galleries',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
@ -115,9 +117,13 @@ USE_TZ = True
|
|||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/4.1/howto/static-files/
|
# https://docs.djangoproject.com/en/4.1/howto/static-files/
|
||||||
|
|
||||||
|
STATIC_ROOT = BASE_DIR / 'static'
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = 'static/'
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
|
MEDIA_ROOT = BASE_DIR / 'media'
|
||||||
|
MEDIA_URL = 'media/'
|
@ -14,8 +14,9 @@ Including another URLconf
|
|||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('', include('web_galleries.urls'))
|
||||||
]
|
]
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
# Register your models here.
|
from .models import (
|
||||||
|
Image,
|
||||||
|
Visitor,
|
||||||
|
Gallery
|
||||||
|
)
|
||||||
|
|
||||||
|
admin.site.register(Image)
|
||||||
|
admin.site.register(Visitor)
|
||||||
|
admin.site.register(Gallery)
|
||||||
|
9
django_web_galleries/web_galleries/forms.py
Normal file
9
django_web_galleries/web_galleries/forms.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from django import forms
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
from .models import Image
|
||||||
|
|
||||||
|
class ImageUploadForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Image
|
||||||
|
fields = ['description', 'image_file', 'private']
|
46
django_web_galleries/web_galleries/templates/global.html
Normal file
46
django_web_galleries/web_galleries/templates/global.html
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Web Gallery</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="RV-Page">
|
||||||
|
<head class="RV-Head">
|
||||||
|
<nav class="RV-Navigation">
|
||||||
|
<ul class="RV-Navigation__list">
|
||||||
|
<li class="RV-Navigation__item">
|
||||||
|
<a href="{% url 'home' %}" class="RV-Navigation__link">
|
||||||
|
Home
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="RV-Navigation__item">
|
||||||
|
<a href="{% url 'upload_image' %}" class="RV-Navigation__link">
|
||||||
|
Upload image
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="RV-Navigation__item">
|
||||||
|
<a href="#" class="RV-Navigation__link">
|
||||||
|
My galleries
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="RV-Navigation__item">
|
||||||
|
<a href="#" class="RV-Navigation__link">
|
||||||
|
Create gallery
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</head>
|
||||||
|
<main class="RV-Content">
|
||||||
|
{% block content %}
|
||||||
|
{% endblock content %}
|
||||||
|
</main>
|
||||||
|
<footer class="RV-Footer">
|
||||||
|
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,13 @@
|
|||||||
|
{% extends '../global.html' %}
|
||||||
|
|
||||||
|
{% load responsive_images %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<sectoin class="RV-Images">
|
||||||
|
<li class="RV-Images__list">
|
||||||
|
{% for image in images %}
|
||||||
|
<img src="{% src image.image_file 200x200 %}">
|
||||||
|
{% endfor %}
|
||||||
|
</li>
|
||||||
|
</sectoin>
|
||||||
|
{% endblock content %}
|
@ -0,0 +1,9 @@
|
|||||||
|
{% extends '../global.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form method="POST" enctype="multipart/form-data">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form }}
|
||||||
|
<button type="submit">Upload</button>
|
||||||
|
</form>
|
||||||
|
{% endblock content %}
|
19
django_web_galleries/web_galleries/urls.py
Normal file
19
django_web_galleries/web_galleries/urls.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
from django.urls import path
|
||||||
|
from django.conf import settings
|
||||||
|
from django.conf.urls.static import static
|
||||||
|
|
||||||
|
from .views import (
|
||||||
|
ImageUploadView,
|
||||||
|
PublicImageListView
|
||||||
|
)
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('', PublicImageListView.as_view(), name='home'),
|
||||||
|
path('upload/', ImageUploadView.as_view(), name='upload_image')
|
||||||
|
]
|
||||||
|
|
||||||
|
if settings.DEBUG:
|
||||||
|
urlpatterns += static(
|
||||||
|
settings.MEDIA_URL,
|
||||||
|
document_root=settings.MEDIA_ROOT
|
||||||
|
)
|
@ -1,3 +1,55 @@
|
|||||||
from django.shortcuts import render
|
import secrets
|
||||||
|
|
||||||
# Create your views here.
|
from django.views import View
|
||||||
|
from django.views.generic.list import ListView
|
||||||
|
from django.shortcuts import render, redirect
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from .forms import ImageUploadForm
|
||||||
|
from .models import Image
|
||||||
|
|
||||||
|
class ImageUploadView(View):
|
||||||
|
def get(self, request):
|
||||||
|
form = ImageUploadForm()
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
'upload_image/upload.html',
|
||||||
|
{
|
||||||
|
'form': form
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
form = ImageUploadForm(
|
||||||
|
request.POST,
|
||||||
|
request.FILES
|
||||||
|
)
|
||||||
|
|
||||||
|
if form.is_valid():
|
||||||
|
image = form.save(commit=False)
|
||||||
|
|
||||||
|
if image.private:
|
||||||
|
image.access_code = secrets.token_hex(32)
|
||||||
|
|
||||||
|
image.save()
|
||||||
|
return redirect(
|
||||||
|
reverse('home')
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
form = ImageUploadForm()
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
'upload_image/upload.html',
|
||||||
|
{
|
||||||
|
'form': form
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
class PublicImageListView(ListView):
|
||||||
|
model = Image
|
||||||
|
paginate_by = 20
|
||||||
|
context_object_name = 'images'
|
||||||
|
template_name = 'list_images/image_list.html'
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return Image.objects.all().filter(private=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user