Merge branch 'services-menu'
This commit is contained in:
commit
8035656823
|
@ -5,4 +5,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## master
|
## master
|
||||||
|
- Login & logout methods using backend as auth method
|
||||||
|
- Base template
|
||||||
|
- Services sidebar menu
|
||||||
|
|
|
@ -1,15 +1,23 @@
|
||||||
from django.contrib.auth.mixins import UserPassesTestMixin
|
from django.contrib.auth.mixins import UserPassesTestMixin
|
||||||
from django.views.generic.base import ContextMixin
|
from django.views.generic.base import ContextMixin
|
||||||
|
|
||||||
from . import get_version
|
from . import api, get_version
|
||||||
from .auth import SESSION_KEY_TOKEN
|
from .auth import SESSION_KEY_TOKEN
|
||||||
|
|
||||||
|
|
||||||
class CustomContextMixin(ContextMixin):
|
class CustomContextMixin(ContextMixin):
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
# TODO generate menu items
|
# generate services menu items
|
||||||
|
services_menu = [
|
||||||
|
{'pattern_name': 'musician:dashboard', 'title': 'Domains & websites'},
|
||||||
|
{'pattern_name': 'musician:mails', 'title': 'Mails'},
|
||||||
|
{'pattern_name': 'musician:mailing-lists', 'title': 'Mailing lists'},
|
||||||
|
{'pattern_name': 'musician:databases', 'title': 'Databases'},
|
||||||
|
{'pattern_name': 'musician:saas', 'title': 'SaaS'},
|
||||||
|
]
|
||||||
context.update({
|
context.update({
|
||||||
|
'services_menu': services_menu,
|
||||||
'version': get_version(),
|
'version': get_version(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -38,11 +38,13 @@
|
||||||
<h4>{{ version }}</h4>
|
<h4>{{ version }}</h4>
|
||||||
<div class="dropdown-divider"></div>
|
<div class="dropdown-divider"></div>
|
||||||
{# <!-- services menu --> #}
|
{# <!-- services menu --> #}
|
||||||
|
{% for item in services_menu %}
|
||||||
<ul class="nav flex-column">
|
<ul class="nav flex-column">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" href="#">Domains & websites</a>
|
<a class="nav-link active" href="{% url item.pattern_name %}">{{ item.title }}</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
{% endfor %}
|
||||||
{# <!-- user profile menu --> #}
|
{# <!-- user profile menu --> #}
|
||||||
<div class="dropdown-divider mt-5"></div>
|
<div class="dropdown-divider mt-5"></div>
|
||||||
<ul class="nav flex-column">
|
<ul class="nav flex-column">
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
{% extends "musician/base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h1>Section title</h1>
|
||||||
|
<p>Little description of what to be expected...</p>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{% extends "musician/base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h1>Section title</h1>
|
||||||
|
<p>Little description of what to be expected...</p>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{% extends "musician/base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h1>Section title</h1>
|
||||||
|
<p>Little description of what to be expected...</p>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{% extends "musician/base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h1>Section title</h1>
|
||||||
|
<p>Little description of what to be expected...</p>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -15,4 +15,8 @@ urlpatterns = [
|
||||||
path('auth/login/', views.LoginView.as_view(), name='login'),
|
path('auth/login/', views.LoginView.as_view(), name='login'),
|
||||||
path('auth/logout/', views.LogoutView.as_view(), name='logout'),
|
path('auth/logout/', views.LogoutView.as_view(), name='logout'),
|
||||||
path('dashboard/', views.DashboardView.as_view(), name='dashboard'),
|
path('dashboard/', views.DashboardView.as_view(), name='dashboard'),
|
||||||
|
path('mails/', views.MailView.as_view(), name='mails'),
|
||||||
|
path('maling-lists/', views.MailingListsView.as_view(), name='mailing-lists'),
|
||||||
|
path('databases/', views.DatabasesView.as_view(), name='databases'),
|
||||||
|
path('software-as-a-service/', views.SaasView.as_view(), name='saas'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
from django.utils.http import is_safe_url
|
||||||
from django.views.generic.base import RedirectView, TemplateView
|
from django.views.generic.base import RedirectView, TemplateView
|
||||||
from django.views.generic.edit import FormView
|
from django.views.generic.edit import FormView
|
||||||
|
|
||||||
|
@ -48,6 +49,7 @@ class LoginView(FormView):
|
||||||
template_name = 'auth/login.html'
|
template_name = 'auth/login.html'
|
||||||
form_class = LoginForm
|
form_class = LoginForm
|
||||||
success_url = reverse_lazy('musician:dashboard')
|
success_url = reverse_lazy('musician:dashboard')
|
||||||
|
redirect_field_name = 'next'
|
||||||
extra_context = {'version': get_version()}
|
extra_context = {'version': get_version()}
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
|
@ -60,6 +62,31 @@ class LoginView(FormView):
|
||||||
auth_login(self.request, form.username, form.token)
|
auth_login(self.request, form.username, form.token)
|
||||||
return HttpResponseRedirect(self.get_success_url())
|
return HttpResponseRedirect(self.get_success_url())
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
url = self.get_redirect_url()
|
||||||
|
return url or self.success_url
|
||||||
|
|
||||||
|
def get_redirect_url(self):
|
||||||
|
"""Return the user-originating redirect URL if it's safe."""
|
||||||
|
redirect_to = self.request.POST.get(
|
||||||
|
self.redirect_field_name,
|
||||||
|
self.request.GET.get(self.redirect_field_name, '')
|
||||||
|
)
|
||||||
|
url_is_safe = is_safe_url(
|
||||||
|
url=redirect_to,
|
||||||
|
allowed_hosts={self.request.get_host()},
|
||||||
|
require_https=self.request.is_secure(),
|
||||||
|
)
|
||||||
|
return redirect_to if url_is_safe else ''
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context.update({
|
||||||
|
self.redirect_field_name: self.get_redirect_url(),
|
||||||
|
**(self.extra_context or {})
|
||||||
|
})
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
class LogoutView(RedirectView):
|
class LogoutView(RedirectView):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue