Make it pretty!

This commit is contained in:
Nico Schottelius 2020-04-25 21:09:00 +02:00
parent da9ddab82d
commit b9a1a0739d
5 changed files with 51 additions and 4 deletions

View file

@ -154,3 +154,5 @@ AUTHENTICATION_BACKENDS = [
AUTH_USER_MODEL = 'ubookmark.User'
CRISPY_TEMPLATE_PACK = 'bootstrap4'
LOGOUT_URL="/logout"

View file

@ -14,7 +14,7 @@
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">{{ site_name }}</a>
<a class="navbar-brand" href="/">{{ site_name }}</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
@ -59,6 +59,15 @@
<a class="nav-link" href="/submit">submit</a>
</li>
</ul>
{% if user.is_authenticated %}
<span class="navbar-text">Logged in as {{ user }}.</span>
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="/logout">Logout</a>
</li>
</ul>
{% endif %}
</div>
</nav>

View file

@ -0,0 +1,14 @@
{% extends 'ubookmark/base.html' %}
{% load crispy_forms_tags %}
{% block content %}
<div class="container">
<form method="post">
{% csrf_token %}
{{ form|crispy }}
<input type="submit" value="Login">
</form>
</div>
{% endblock %}

View file

@ -21,5 +21,7 @@ from ubookmark import views
urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
path('submit/', views.SubmitView.as_view(), name='submit'),
path('login/', views.LoginView.as_view(), name='login'),
path('logout/', views.logout_view, name='logout'),
path('admin/', admin.site.urls),
]

View file

@ -1,6 +1,10 @@
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.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth import logout
from django.shortcuts import redirect
from django.conf import settings
@ -8,19 +12,22 @@ from ubookmark.models import *
class IndexView(ListView):
model = BookmarkModel
paginate_by = 3
paginate_by = 5
queryset = BookmarkModel.objects.order_by('-posted_at')
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
context['site_name'] = settings.SITE_NAME
context['site_description'] = settings.SITE_DESCRIPTION
context['site_description'] = settings.SITE_DESCRIPTION
return context
class SubmitView(CreateView):
class SubmitView(LoginRequiredMixin, CreateView):
model = BookmarkModel
fields = [ 'comment', 'url' ]
login_url = '/login/'
success_url = '/'
def get_context_data(self, **kwargs):
context = super(CreateView, self).get_context_data(**kwargs)
@ -29,5 +36,18 @@ class SubmitView(CreateView):
return context
def form_valid(self, form):
form.instance.owner = self.request.user
return super(SubmitView, self).form_valid(form)
class LoginView(auth_views.LoginView):
pass
template_name = 'ubookmark/login.html'
extra_context = {}
extra_context['site_name'] = settings.SITE_NAME
extra_context['site_description'] = settings.SITE_DESCRIPTION
def logout_view(request):
logout(request)
return redirect("/")