Commit b9a1a073 authored by Nico Schottelius's avatar Nico Schottelius

Make it pretty!

parent da9ddab8
Pipeline #1316 failed with stages
in 31 seconds
......@@ -154,3 +154,5 @@ AUTHENTICATION_BACKENDS = [
AUTH_USER_MODEL = 'ubookmark.User'
CRISPY_TEMPLATE_PACK = 'bootstrap4'
LOGOUT_URL="/logout"
......@@ -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>
......
{% 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 %}
......@@ -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),
]
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("/")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment