diff --git a/imageuploader/imageuploader/urls.py b/imageuploader/imageuploader/urls.py index f7302ca3de92ab10634b918efb653d6661789107..fc23a5273a077da83611761a398565df8881f93d 100644 --- a/imageuploader/imageuploader/urls.py +++ b/imageuploader/imageuploader/urls.py @@ -27,7 +27,7 @@ urlpatterns = [ path('admin/', admin.site.urls), path('', views.homepage), path('about/', views.about), - path('posts/', include('posts.urls')), + path('pictures/', include('pictures.urls')), path('users/', include('users.urls')) ] diff --git a/imageuploader/posts/__init__.py b/imageuploader/pictures/__init__.py similarity index 100% rename from imageuploader/posts/__init__.py rename to imageuploader/pictures/__init__.py diff --git a/imageuploader/posts/__pycache__/__init__.cpython-313.pyc b/imageuploader/pictures/__pycache__/__init__.cpython-313.pyc similarity index 100% rename from imageuploader/posts/__pycache__/__init__.cpython-313.pyc rename to imageuploader/pictures/__pycache__/__init__.cpython-313.pyc diff --git a/imageuploader/posts/__pycache__/admin.cpython-313.pyc b/imageuploader/pictures/__pycache__/admin.cpython-313.pyc similarity index 100% rename from imageuploader/posts/__pycache__/admin.cpython-313.pyc rename to imageuploader/pictures/__pycache__/admin.cpython-313.pyc diff --git a/imageuploader/posts/__pycache__/apps.cpython-313.pyc b/imageuploader/pictures/__pycache__/apps.cpython-313.pyc similarity index 100% rename from imageuploader/posts/__pycache__/apps.cpython-313.pyc rename to imageuploader/pictures/__pycache__/apps.cpython-313.pyc diff --git a/imageuploader/posts/__pycache__/forms.cpython-313.pyc b/imageuploader/pictures/__pycache__/forms.cpython-313.pyc similarity index 100% rename from imageuploader/posts/__pycache__/forms.cpython-313.pyc rename to imageuploader/pictures/__pycache__/forms.cpython-313.pyc diff --git a/imageuploader/posts/__pycache__/models.cpython-313.pyc b/imageuploader/pictures/__pycache__/models.cpython-313.pyc similarity index 100% rename from imageuploader/posts/__pycache__/models.cpython-313.pyc rename to imageuploader/pictures/__pycache__/models.cpython-313.pyc diff --git a/imageuploader/posts/__pycache__/urls.cpython-313.pyc b/imageuploader/pictures/__pycache__/urls.cpython-313.pyc similarity index 100% rename from imageuploader/posts/__pycache__/urls.cpython-313.pyc rename to imageuploader/pictures/__pycache__/urls.cpython-313.pyc diff --git a/imageuploader/posts/__pycache__/views.cpython-313.pyc b/imageuploader/pictures/__pycache__/views.cpython-313.pyc similarity index 100% rename from imageuploader/posts/__pycache__/views.cpython-313.pyc rename to imageuploader/pictures/__pycache__/views.cpython-313.pyc diff --git a/imageuploader/posts/admin.py b/imageuploader/pictures/admin.py similarity index 100% rename from imageuploader/posts/admin.py rename to imageuploader/pictures/admin.py diff --git a/imageuploader/posts/apps.py b/imageuploader/pictures/apps.py similarity index 84% rename from imageuploader/posts/apps.py rename to imageuploader/pictures/apps.py index b18ed0dcb3371478f1ca309cde1ef0749cd42a53..b38c60c813aa6e2c1f0c3e49db1b96f87c90f09b 100644 --- a/imageuploader/posts/apps.py +++ b/imageuploader/pictures/apps.py @@ -3,4 +3,4 @@ from django.apps import AppConfig class PostsConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' - name = 'posts' + name = 'pictures' diff --git a/imageuploader/posts/forms.py b/imageuploader/pictures/forms.py similarity index 100% rename from imageuploader/posts/forms.py rename to imageuploader/pictures/forms.py diff --git a/imageuploader/posts/migrations/0001_initial.py b/imageuploader/pictures/migrations/0001_initial.py similarity index 100% rename from imageuploader/posts/migrations/0001_initial.py rename to imageuploader/pictures/migrations/0001_initial.py diff --git a/imageuploader/posts/migrations/0002_post_banner.py b/imageuploader/pictures/migrations/0002_post_banner.py similarity index 100% rename from imageuploader/posts/migrations/0002_post_banner.py rename to imageuploader/pictures/migrations/0002_post_banner.py diff --git a/imageuploader/posts/migrations/0003_post_author.py b/imageuploader/pictures/migrations/0003_post_author.py similarity index 100% rename from imageuploader/posts/migrations/0003_post_author.py rename to imageuploader/pictures/migrations/0003_post_author.py diff --git a/imageuploader/posts/migrations/0004_alter_post_author.py b/imageuploader/pictures/migrations/0004_alter_post_author.py similarity index 100% rename from imageuploader/posts/migrations/0004_alter_post_author.py rename to imageuploader/pictures/migrations/0004_alter_post_author.py diff --git a/imageuploader/posts/migrations/__init__.py b/imageuploader/pictures/migrations/__init__.py similarity index 100% rename from imageuploader/posts/migrations/__init__.py rename to imageuploader/pictures/migrations/__init__.py diff --git a/imageuploader/posts/migrations/__pycache__/0001_initial.cpython-313.pyc b/imageuploader/pictures/migrations/__pycache__/0001_initial.cpython-313.pyc similarity index 100% rename from imageuploader/posts/migrations/__pycache__/0001_initial.cpython-313.pyc rename to imageuploader/pictures/migrations/__pycache__/0001_initial.cpython-313.pyc diff --git a/imageuploader/posts/migrations/__pycache__/0002_post_banner.cpython-313.pyc b/imageuploader/pictures/migrations/__pycache__/0002_post_banner.cpython-313.pyc similarity index 100% rename from imageuploader/posts/migrations/__pycache__/0002_post_banner.cpython-313.pyc rename to imageuploader/pictures/migrations/__pycache__/0002_post_banner.cpython-313.pyc diff --git a/imageuploader/posts/migrations/__pycache__/0003_post_author.cpython-313.pyc b/imageuploader/pictures/migrations/__pycache__/0003_post_author.cpython-313.pyc similarity index 100% rename from imageuploader/posts/migrations/__pycache__/0003_post_author.cpython-313.pyc rename to imageuploader/pictures/migrations/__pycache__/0003_post_author.cpython-313.pyc diff --git a/imageuploader/posts/migrations/__pycache__/0004_alter_post_author.cpython-313.pyc b/imageuploader/pictures/migrations/__pycache__/0004_alter_post_author.cpython-313.pyc similarity index 100% rename from imageuploader/posts/migrations/__pycache__/0004_alter_post_author.cpython-313.pyc rename to imageuploader/pictures/migrations/__pycache__/0004_alter_post_author.cpython-313.pyc diff --git a/imageuploader/posts/migrations/__pycache__/__init__.cpython-313.pyc b/imageuploader/pictures/migrations/__pycache__/__init__.cpython-313.pyc similarity index 100% rename from imageuploader/posts/migrations/__pycache__/__init__.cpython-313.pyc rename to imageuploader/pictures/migrations/__pycache__/__init__.cpython-313.pyc diff --git a/imageuploader/posts/models.py b/imageuploader/pictures/models.py similarity index 93% rename from imageuploader/posts/models.py rename to imageuploader/pictures/models.py index 6aafd6b13750feb56d2fb9efa06d42f117b5778d..e255e6f858177ec3fc9efdef274bb82c85d22a9c 100644 --- a/imageuploader/posts/models.py +++ b/imageuploader/pictures/models.py @@ -1,7 +1,7 @@ from django.db import models from django.contrib.auth.models import User -class Post(models.Model): +class Picture(models.Model): title = models.CharField(max_length=75) body = models.TextField() slug = models.SlugField() diff --git a/imageuploader/posts/templates/posts/post_new.html b/imageuploader/pictures/templates/posts/picture_new.html similarity index 60% rename from imageuploader/posts/templates/posts/post_new.html rename to imageuploader/pictures/templates/posts/picture_new.html index 637fd6262a66c8924b5893be18125c2df2e32251..11741b0d2db1fb602ce6fd4cf321ea96888b2efd 100644 --- a/imageuploader/posts/templates/posts/post_new.html +++ b/imageuploader/pictures/templates/posts/picture_new.html @@ -1,16 +1,16 @@ {% extends 'layout.html' %} {% block title %} - New Post + New Picture {% endblock %} {% block content %} <section> - <h1>New Post</h1> - <form class="form-with-validation" action="{% url 'posts:new-post' %}" method="post" enctype="multipart/form-data"> + <h1>New Picture</h1> + <form class="form-with-validation" action="{% url 'posts:new-picture' %}" method="post" enctype="multipart/form-data"> {% csrf_token %} {{ form }} - <button class="form-submit">Add Post</button> + <button class="form-submit">Add Picture</button> </form> </section> {% endblock %} \ No newline at end of file diff --git a/imageuploader/posts/templates/posts/post_page.html b/imageuploader/pictures/templates/posts/picture_page.html similarity index 51% rename from imageuploader/posts/templates/posts/post_page.html rename to imageuploader/pictures/templates/posts/picture_page.html index b2e965d02f1a0ab8c0a14e31acf8ab505dbe9f00..d828673b8fa8a2a9e5789470771bbf21e93f5c15 100644 --- a/imageuploader/posts/templates/posts/post_page.html +++ b/imageuploader/pictures/templates/posts/picture_page.html @@ -1,21 +1,21 @@ {% extends 'layout.html' %} {% block title %} - {{ post.title }} + {{ picture.title }} {% endblock %} {% block content %} <section> <img class="banner" - src="{{ post.banner.url }}" - alt="{{ post.title }}" + src="{{ picture.banner.url }}" + alt="{{ picture.title }}" /> <h1> - {{ post.title }} + {{ picture.title }} </h1> - <p>{{ post.date }}</p> - <p>{{ post.body }}</p> + <p>{{ picture.date }}</p> + <p>{{ picture.body }}</p> </section> {% endblock %} \ No newline at end of file diff --git a/imageuploader/pictures/templates/posts/pictures_list.html b/imageuploader/pictures/templates/posts/pictures_list.html new file mode 100644 index 0000000000000000000000000000000000000000..b17308ecfbbea10327bcb6a3a427e83ffeab20b5 --- /dev/null +++ b/imageuploader/pictures/templates/posts/pictures_list.html @@ -0,0 +1,23 @@ +{% extends 'layout.html' %} + +{% block title %} + Pictures +{% endblock %} + +{% block content %} + <section> + <h1>Pictures</h1> + + {% for picture in pictures %} + <article class="post"> + <h2> + <a href="{% url 'pictures:page' slug=picture.slug %}"> + {{ picture.title }} + </a> + </h2> + <p>{{ picture.date }} by {{ picture.author }}</p> + <p>{{ picture.body }}</p> + </article> + {% endfor %} +</section> +{% endblock %} \ No newline at end of file diff --git a/imageuploader/posts/tests.py b/imageuploader/pictures/tests.py similarity index 100% rename from imageuploader/posts/tests.py rename to imageuploader/pictures/tests.py diff --git a/imageuploader/pictures/urls.py b/imageuploader/pictures/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..2ea0e738b620b5a5f3af7ddb3268e2b8e9292aba --- /dev/null +++ b/imageuploader/pictures/urls.py @@ -0,0 +1,11 @@ +from django.contrib import admin +from django.urls import path +from . import views + +app_name = "pictures" + +urlpatterns = [ + path("", views.pictures_list, name="list"), + path('new-picture/', views.picture_new, name="new-picture"), + path("<slug:slug>", views.picture_page, name="page") +] \ No newline at end of file diff --git a/imageuploader/pictures/views.py b/imageuploader/pictures/views.py new file mode 100644 index 0000000000000000000000000000000000000000..e5818e1fabf516795b7640dbee9e7d7eb598ce83 --- /dev/null +++ b/imageuploader/pictures/views.py @@ -0,0 +1,28 @@ +from django.shortcuts import render, redirect +from .models import Post +from django.contrib.auth.decorators import login_required +from . import forms + + + +def pictures_list(request): + pictures = Post.objects.all().order_by('-date') + return render(request, 'posts/posts_list.html', {'pictures': pictures}) + + +def picture_page(request, slug): + picture = Post.objects.get(slug=slug) + return render(request, 'pictures/picture_page.html', {'picture': picture}) + +@login_required(login_url="/users/login/") +def picture_new(request): + if request.method == 'POST': + form = forms.CreatePost(request.POST, request.FILES) + if form.is_valid(): + newpicture = form.save(commit=False) + newpicture.author = request.user + newpicture.save() + return redirect('pictures:list') + else: + form = forms.CreatePost() + return render(request, 'pictures/picture_new.html', { 'form': form }) \ No newline at end of file diff --git a/imageuploader/posts/templates/posts/posts_list.html b/imageuploader/posts/templates/posts/posts_list.html deleted file mode 100644 index 1fd39c216d7eddaca9f923b9e64c46f8f50ff0df..0000000000000000000000000000000000000000 --- a/imageuploader/posts/templates/posts/posts_list.html +++ /dev/null @@ -1,23 +0,0 @@ -{% extends 'layout.html' %} - -{% block title %} - Posts -{% endblock %} - -{% block content %} - <section> - <h1>Posts</h1> - - {% for post in posts %} - <article class="post"> - <h2> - <a href="{% url 'posts:page' slug=post.slug %}"> - {{ post.title }} - </a> - </h2> - <p>{{ post.date }} by {{ post.author }}</p> - <p>{{ post.body }}</p> - </article> - {% endfor %} -</section> -{% endblock %} \ No newline at end of file diff --git a/imageuploader/posts/urls.py b/imageuploader/posts/urls.py deleted file mode 100644 index 930f131868456f01902f0814f49a91898cebcd63..0000000000000000000000000000000000000000 --- a/imageuploader/posts/urls.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.contrib import admin -from django.urls import path -from . import views - -app_name = "posts" - -urlpatterns = [ - path("", views.posts_list, name="list"), - path('new-post/', views.post_new, name="new-post"), - path("<slug:slug>", views.post_page, name="page") -] \ No newline at end of file diff --git a/imageuploader/posts/views.py b/imageuploader/posts/views.py deleted file mode 100644 index 86762871907e50ae7e4bbd4e95b63308da439823..0000000000000000000000000000000000000000 --- a/imageuploader/posts/views.py +++ /dev/null @@ -1,28 +0,0 @@ -from django.shortcuts import render, redirect -from .models import Post -from django.contrib.auth.decorators import login_required -from . import forms - - - -def posts_list(request): - posts = Post.objects.all().order_by('-date') - return render(request, 'posts/posts_list.html', {'posts': posts}) - - -def post_page(request, slug): - post = Post.objects.get(slug=slug) - return render(request, 'posts/post_page.html', {'post': post}) - -@login_required(login_url="/users/login/") -def post_new(request): - if request.method == 'POST': - form = forms.CreatePost(request.POST, request.FILES) - if form.is_valid(): - newpost = form.save(commit=False) - newpost.author = request.user - newpost.save() - return redirect('posts:list') - else: - form = forms.CreatePost() - return render(request, 'posts/post_new.html', { 'form': form }) \ No newline at end of file diff --git a/imageuploader/templates/layout.html b/imageuploader/templates/layout.html index a3f76b8473bff51be973a1b13f17403f85710019..d248ac0a5c91d34a5207246d0bfec2764eeb9d94 100644 --- a/imageuploader/templates/layout.html +++ b/imageuploader/templates/layout.html @@ -21,11 +21,11 @@ <span role="img" aria-label="About" title="About">😀</span> </a> | {% if user.is_authenticated %} - <a href="{% url 'posts:list' %}"> - <span role="img" aria-label="Posts" title="Posts">📰</span> + <a href="{% url 'pictures:list' %}"> + <span role="img" aria-label="pictures" title="pictures">📰</span> </a> | - <a href="{% url 'posts:new-post' %}"> - <span role="img" aria-label="New Post" title="New Post">🆕</span> + <a href="{% url 'pictures:new-picture' %}"> + <span role="img" aria-label="New picture" title="New picture">🆕</span> </a> | <form class="logout" action="{% url 'users:logout' %}" method="post"> {% csrf_token %}