From e071da26ddaac0c2753d02aaed9deb37f319e102 Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Sat, 9 Jul 2022 15:07:20 +0100 Subject: [PATCH 1/5] Add m2m saving --- flangr/circles/views.py | 1 + flangr/posts/views.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/flangr/circles/views.py b/flangr/circles/views.py index 590f5ed..3a77d30 100644 --- a/flangr/circles/views.py +++ b/flangr/circles/views.py @@ -34,6 +34,7 @@ class CircleCreateView(LoginRequiredMixin, CreateView): circle = form.save(commit=False) circle.owner = self.request.user circle.save() + form.save_m2m() return HttpResponseRedirect(self.get_success_url()) diff --git a/flangr/posts/views.py b/flangr/posts/views.py index f3685e3..ffbd1ba 100644 --- a/flangr/posts/views.py +++ b/flangr/posts/views.py @@ -4,6 +4,7 @@ from django.http import HttpResponseRedirect from django.urls import reverse from django.views.generic import CreateView from django.views.generic import DetailView +from django.views.generic import ListView from django.views.generic.edit import ModelFormMixin from .models import Comment @@ -48,5 +49,11 @@ class PostCreateView(LoginRequiredMixin, CreateView): self.object = form.save(commit=False) self.object.user = self.request.user self.object.save() + form.save_m2m() return HttpResponseRedirect(self.get_success_url()) + + +class PostListView(LoginRequiredMixin, ListView): + def get_queryset(self): + return Post.objects.filter(circles__members=self.request.user) From 6393dd5a5e26362cf93c219271646bc31230f1cf Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Sat, 9 Jul 2022 15:07:38 +0100 Subject: [PATCH 2/5] Add PostList view --- flangr/posts/urls.py | 1 + flangr/templates/posts/post_list.html | 9 +++++++++ flangr/urls.py | 3 +++ 3 files changed, 13 insertions(+) create mode 100644 flangr/templates/posts/post_list.html diff --git a/flangr/posts/urls.py b/flangr/posts/urls.py index 7dc96a0..74a376a 100644 --- a/flangr/posts/urls.py +++ b/flangr/posts/urls.py @@ -6,4 +6,5 @@ app_name = "posts" urlpatterns = [ path("post/", views.PostDetailView.as_view(), name="post_detail"), path("post/new", views.PostCreateView.as_view(), name="post_create"), + path("posts", views.PostListView.as_view(), name="post_list"), ] diff --git a/flangr/templates/posts/post_list.html b/flangr/templates/posts/post_list.html new file mode 100644 index 0000000..a4e002b --- /dev/null +++ b/flangr/templates/posts/post_list.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} +{% block content %} +

Posts Shared with you

+ +{% endblock content %} diff --git a/flangr/urls.py b/flangr/urls.py index 19577ed..e836cd4 100644 --- a/flangr/urls.py +++ b/flangr/urls.py @@ -19,11 +19,14 @@ from django.contrib import admin from django.urls import include from django.urls import path +from .posts.views import PostListView + urlpatterns = [ path("admin/", admin.site.urls), path("accounts/", include("django.contrib.auth.urls")), path("posts/", include("flangr.posts.urls")), path("circles/", include("flangr.circles.urls")), + path("", PostListView.as_view(), name="home"), ] if settings.DEBUG: From 45e89601d2a451894492d01b0916eb04be13f4ad Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Sun, 10 Jul 2022 11:14:38 +0100 Subject: [PATCH 3/5] Install bootstrap5 --- config/settings/base.py | 3 +++ requirements/base.txt | 1 + requirements/development.txt | 1 + 3 files changed, 5 insertions(+) diff --git a/config/settings/base.py b/config/settings/base.py index c713143..764ac2e 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -35,6 +35,7 @@ INSTALLED_APPS = [ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + "django_bootstrap5", "flangr.posts", "flangr.circles", ] @@ -114,3 +115,5 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" MEDIA_URL = "media/" AUTH_USER_MODEL = "auth.User" + +STATICFILES_DIRS = ["flangr/static"] diff --git a/requirements/base.txt b/requirements/base.txt index c49991b..9cf60c8 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,3 +1,4 @@ pillow django coverage +django-bootstrap5 diff --git a/requirements/development.txt b/requirements/development.txt index 3290807..373944e 100644 --- a/requirements/development.txt +++ b/requirements/development.txt @@ -1,2 +1,3 @@ +-r base.txt pre-commit flake8 From aca86e2e04325d8412c0b610ebacb8eab2722bec Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Sun, 10 Jul 2022 11:15:19 +0100 Subject: [PATCH 4/5] Configure base template to use bootstrap --- flangr/static/css/base.css | 3 +++ flangr/templates/base.html | 45 +++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 flangr/static/css/base.css diff --git a/flangr/static/css/base.css b/flangr/static/css/base.css new file mode 100644 index 0000000..c37ca54 --- /dev/null +++ b/flangr/static/css/base.css @@ -0,0 +1,3 @@ +.img-full { + object-fit: contain; +} diff --git a/flangr/templates/base.html b/flangr/templates/base.html index 0f1d64b..302257b 100644 --- a/flangr/templates/base.html +++ b/flangr/templates/base.html @@ -1,6 +1,49 @@ +{% load django_bootstrap5 %} +{% load static %} + Flangr + + {% bootstrap_css %} + {% block extracss %}{% endblock extracss %} - {% block content %}{% endblock content %} + + {% block nav %} + + {% endblock nav %} + {% bootstrap_messages %} + {% block content %}{% endblock content %} + From 75cae77a5951ce7d4c09a26deab606910fb605ca Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Sun, 10 Jul 2022 11:15:48 +0100 Subject: [PATCH 5/5] Make it look good --- flangr/circles/urls.py | 2 +- flangr/posts/urls.py | 5 +++ flangr/templates/circles/circle_form.html | 20 +++++++--- flangr/templates/circles/circle_list.html | 25 +++++++++--- flangr/templates/posts/post_detail.html | 44 +++++++++++++-------- flangr/templates/posts/post_form.html | 21 +++++++--- flangr/templates/posts/post_fullscreen.html | 16 ++++++++ flangr/templates/posts/post_list.html | 18 ++++++--- flangr/templates/registration/login.html | 21 +++++++--- flangr/urls.py | 2 + 10 files changed, 126 insertions(+), 48 deletions(-) create mode 100644 flangr/templates/posts/post_fullscreen.html diff --git a/flangr/circles/urls.py b/flangr/circles/urls.py index 54d0d59..d911ce4 100644 --- a/flangr/circles/urls.py +++ b/flangr/circles/urls.py @@ -6,5 +6,5 @@ app_name = "circles" urlpatterns = [ path("", views.CircleListView.as_view(), name="circle_list"), path("circle/", views.CircleUpdateView.as_view(), name="circle_update"), - path("add", views.CircleCreateView.as_view(), name="circle_create"), + path("circle/new", views.CircleCreateView.as_view(), name="circle_create"), ] diff --git a/flangr/posts/urls.py b/flangr/posts/urls.py index 74a376a..fe472ee 100644 --- a/flangr/posts/urls.py +++ b/flangr/posts/urls.py @@ -5,6 +5,11 @@ from . import views app_name = "posts" urlpatterns = [ path("post/", views.PostDetailView.as_view(), name="post_detail"), + path( + "post//fullscreen", + views.PostDetailView.as_view(template_name_suffix="_fullscreen"), + name="post_fullscreen", + ), path("post/new", views.PostCreateView.as_view(), name="post_create"), path("posts", views.PostListView.as_view(), name="post_list"), ] diff --git a/flangr/templates/circles/circle_form.html b/flangr/templates/circles/circle_form.html index 1ccb008..622f6ac 100644 --- a/flangr/templates/circles/circle_form.html +++ b/flangr/templates/circles/circle_form.html @@ -1,9 +1,17 @@ {% extends "base.html" %} +{% load django_bootstrap5 %} + {% block content %} -

Circle {{ object.name }}

-
- {% csrf_token %} - {{ form }} - -
+
+
+
+

Create a new circle

+
+ {% csrf_token %} + {% bootstrap_form form %} + {% bootstrap_button button_type="submit" content="OK" %} +
+
+
+
{% endblock content %} diff --git a/flangr/templates/circles/circle_list.html b/flangr/templates/circles/circle_list.html index e608e86..899e1ca 100644 --- a/flangr/templates/circles/circle_list.html +++ b/flangr/templates/circles/circle_list.html @@ -1,9 +1,22 @@ {% extends "base.html" %} {% block content %} -

Your Circles

- +
+
+
+

Your Circles

+ + + + + + {% for circle in object_list %} + + + + + {% endfor %} +
NameMembers
{{ circle.name }}{{ circle.members.all }}
+
+
+
{% endblock content %} diff --git a/flangr/templates/posts/post_detail.html b/flangr/templates/posts/post_detail.html index 57d573c..726e5c2 100644 --- a/flangr/templates/posts/post_detail.html +++ b/flangr/templates/posts/post_detail.html @@ -1,20 +1,30 @@ {% extends "base.html" %} +{% load django_bootstrap5 %} + {% block content %} - {% if object.title %} -

{{ object.title }}

- {% else %} -

{{ object.user.username }}

- {% endif %} - -

Comments

-
    - {% for comment in object.comments.all %} -
  • {{ comment.user }} - {{ comment.comment }}
  • - {% endfor %} -
-
- {% csrf_token %} - {{ form }} - -
+
+
+
+ {% if object.title %} +

{{ object.title }}

+ {% else %} +

{{ object.user.username }}

+ {% endif %} + +
+
+

Comments

+
    + {% for comment in object.comments.all %} +
  • {{ comment.user }} - {{ comment.comment }}
  • + {% endfor %} +
+
+ {% csrf_token %} + {% bootstrap_form form %} + {% bootstrap_button button_type="submit" content="OK" %} +
+
+
+
{% endblock content %} diff --git a/flangr/templates/posts/post_form.html b/flangr/templates/posts/post_form.html index 66bfaba..09ae82c 100644 --- a/flangr/templates/posts/post_form.html +++ b/flangr/templates/posts/post_form.html @@ -1,10 +1,19 @@ {% extends "base.html" %} +{% load django_bootstrap5 %} {% block content %} -

Upload a new picture

-
- {% csrf_token %} - {{ form }} - -
+
+
+
+

Upload a new picture

+
+ {% csrf_token %} + {% bootstrap_form form %} + {% bootstrap_button button_type="submit" content="OK" %} + +
+
+
+
+ {% endblock content %} diff --git a/flangr/templates/posts/post_fullscreen.html b/flangr/templates/posts/post_fullscreen.html new file mode 100644 index 0000000..9200f39 --- /dev/null +++ b/flangr/templates/posts/post_fullscreen.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} +{% load django_bootstrap5 %} + +{% block nav %}{% endblock nav %} + +{% block content %} +
+
+

{{ object.title }}

+ X +
+
+ +
+
+{% endblock content %} diff --git a/flangr/templates/posts/post_list.html b/flangr/templates/posts/post_list.html index a4e002b..5bc3c66 100644 --- a/flangr/templates/posts/post_list.html +++ b/flangr/templates/posts/post_list.html @@ -1,9 +1,15 @@ {% extends "base.html" %} {% block content %} -

Posts Shared with you

- +
+
+
+

Posts Shared with you

+ +
+
+
{% endblock content %} diff --git a/flangr/templates/registration/login.html b/flangr/templates/registration/login.html index 21dad4a..fda684b 100644 --- a/flangr/templates/registration/login.html +++ b/flangr/templates/registration/login.html @@ -1,10 +1,19 @@ {% extends "base.html" %} +{% load django_bootstrap5 %} {% block content %} -

Login

-
- {% csrf_token %} - {{ form }} - -
+
+
+
+

Login

+
+ {% csrf_token %} + {% bootstrap_form form %} + {% bootstrap_button button_type="submit" content="OK" %} +
+
+
+
+ + {% endblock content %} diff --git a/flangr/urls.py b/flangr/urls.py index e836cd4..3485708 100644 --- a/flangr/urls.py +++ b/flangr/urls.py @@ -16,6 +16,7 @@ Including another URLconf from django.conf import settings from django.conf.urls.static import static from django.contrib import admin +from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.urls import include from django.urls import path @@ -31,3 +32,4 @@ urlpatterns = [ if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + urlpatterns += staticfiles_urlpatterns()