Make it pretty!
This commit is contained in:
parent
da9ddab82d
commit
b9a1a0739d
5 changed files with 51 additions and 4 deletions
|
@ -154,3 +154,5 @@ AUTHENTICATION_BACKENDS = [
|
||||||
AUTH_USER_MODEL = 'ubookmark.User'
|
AUTH_USER_MODEL = 'ubookmark.User'
|
||||||
|
|
||||||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
||||||
|
|
||||||
|
LOGOUT_URL="/logout"
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
<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">
|
<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>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
|
@ -59,6 +59,15 @@
|
||||||
<a class="nav-link" href="/submit">submit</a>
|
<a class="nav-link" href="/submit">submit</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</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>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|
14
ubookmark/templates/ubookmark/login.html
Normal file
14
ubookmark/templates/ubookmark/login.html
Normal 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 %}
|
|
@ -21,5 +21,7 @@ from ubookmark import views
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.IndexView.as_view(), name='index'),
|
path('', views.IndexView.as_view(), name='index'),
|
||||||
path('submit/', views.SubmitView.as_view(), name='submit'),
|
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),
|
path('admin/', admin.site.urls),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
from django.views.generic.list import ListView
|
from django.views.generic.list import ListView
|
||||||
from django.views.generic.edit import CreateView
|
from django.views.generic.edit import CreateView
|
||||||
from django.contrib.auth import views as auth_views
|
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
|
from django.conf import settings
|
||||||
|
|
||||||
|
@ -8,19 +12,22 @@ from ubookmark.models import *
|
||||||
|
|
||||||
class IndexView(ListView):
|
class IndexView(ListView):
|
||||||
model = BookmarkModel
|
model = BookmarkModel
|
||||||
paginate_by = 3
|
paginate_by = 5
|
||||||
queryset = BookmarkModel.objects.order_by('-posted_at')
|
queryset = BookmarkModel.objects.order_by('-posted_at')
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(IndexView, self).get_context_data(**kwargs)
|
context = super(IndexView, self).get_context_data(**kwargs)
|
||||||
context['site_name'] = settings.SITE_NAME
|
context['site_name'] = settings.SITE_NAME
|
||||||
context['site_description'] = settings.SITE_DESCRIPTION
|
context['site_description'] = settings.SITE_DESCRIPTION
|
||||||
|
context['site_description'] = settings.SITE_DESCRIPTION
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
class SubmitView(CreateView):
|
class SubmitView(LoginRequiredMixin, CreateView):
|
||||||
model = BookmarkModel
|
model = BookmarkModel
|
||||||
fields = [ 'comment', 'url' ]
|
fields = [ 'comment', 'url' ]
|
||||||
|
login_url = '/login/'
|
||||||
|
success_url = '/'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(CreateView, self).get_context_data(**kwargs)
|
context = super(CreateView, self).get_context_data(**kwargs)
|
||||||
|
@ -29,5 +36,18 @@ class SubmitView(CreateView):
|
||||||
|
|
||||||
return context
|
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):
|
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("/")
|
||||||
|
|
Loading…
Reference in a new issue