From da9ddab82d3b5ff3f1535224cd83c51ebc4a0fb7 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 25 Apr 2020 20:36:33 +0200 Subject: [PATCH] Phase in crispy forms for rendering with bootstrap --- requirements.txt | 1 + ubookmark/forms.py | 1 + ubookmark/settings.py | 3 + ubookmark/templates/ubookmark/base.html | 79 +++++++++ .../ubookmark/bookmarkmodel_form.html | 14 ++ .../ubookmark/bookmarkmodel_list.html | 167 +++--------------- ubookmark/urls.py | 1 + ubookmark/views.py | 18 +- 8 files changed, 140 insertions(+), 144 deletions(-) create mode 100644 ubookmark/forms.py create mode 100644 ubookmark/templates/ubookmark/base.html create mode 100644 ubookmark/templates/ubookmark/bookmarkmodel_form.html diff --git a/requirements.txt b/requirements.txt index ae6f3a1..07fd6c1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ django django-auth-ldap psycopg2 +django-crispy-forms diff --git a/ubookmark/forms.py b/ubookmark/forms.py new file mode 100644 index 0000000..e79048b --- /dev/null +++ b/ubookmark/forms.py @@ -0,0 +1 @@ +from django import forms diff --git a/ubookmark/settings.py b/ubookmark/settings.py index 4512ecd..59a5521 100644 --- a/ubookmark/settings.py +++ b/ubookmark/settings.py @@ -37,6 +37,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'crispy_forms', 'ubookmark' ] @@ -151,3 +152,5 @@ AUTHENTICATION_BACKENDS = [ ] AUTH_USER_MODEL = 'ubookmark.User' + +CRISPY_TEMPLATE_PACK = 'bootstrap4' diff --git a/ubookmark/templates/ubookmark/base.html b/ubookmark/templates/ubookmark/base.html new file mode 100644 index 0000000..512d4c2 --- /dev/null +++ b/ubookmark/templates/ubookmark/base.html @@ -0,0 +1,79 @@ +{% load static %} + + + + + + + + + + + + {{ site_name }} powered by ubookmark + + + + + {% block content %} + {% endblock %} + + + + - - - + + {% endfor %} + + + +{% endblock %} diff --git a/ubookmark/urls.py b/ubookmark/urls.py index 5f44d30..b290419 100644 --- a/ubookmark/urls.py +++ b/ubookmark/urls.py @@ -20,5 +20,6 @@ from ubookmark import views urlpatterns = [ path('', views.IndexView.as_view(), name='index'), + path('submit/', views.SubmitView.as_view(), name='submit'), path('admin/', admin.site.urls), ] diff --git a/ubookmark/views.py b/ubookmark/views.py index 4f0f898..86f290c 100644 --- a/ubookmark/views.py +++ b/ubookmark/views.py @@ -1,10 +1,12 @@ from django.views.generic.list import ListView +from django.views.generic.edit import CreateView +from django.contrib.auth import views as auth_views + from django.conf import settings from ubookmark.models import * class IndexView(ListView): - model = BookmarkModel paginate_by = 3 queryset = BookmarkModel.objects.order_by('-posted_at') @@ -15,3 +17,17 @@ class IndexView(ListView): context['site_description'] = settings.SITE_DESCRIPTION return context + +class SubmitView(CreateView): + model = BookmarkModel + fields = [ 'comment', 'url' ] + + def get_context_data(self, **kwargs): + context = super(CreateView, self).get_context_data(**kwargs) + context['site_name'] = settings.SITE_NAME + context['site_description'] = settings.SITE_DESCRIPTION + + return context + +class LoginView(auth_views.LoginView): + pass