configurable bot token
This commit is contained in:
@@ -17,6 +17,27 @@
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
{% if request.user.is_superuser %}
|
||||
<hr class="separator" />
|
||||
|
||||
<div class="nav-subtitle">Admin</div>
|
||||
<nav class="nav-main" role="navigation">
|
||||
<ul class="nav nav-main">
|
||||
<li class="nav-parent {% if sidebar_section %}nav-active{% endif %}">
|
||||
<a href="#">
|
||||
<i class="fas fa-cog" aria-hidden="true"></i>
|
||||
<span>Configs</span>
|
||||
</a>
|
||||
<ul class="nav nav-children">
|
||||
{% for slug, title in admin_configs.items %}
|
||||
<li><a href="{% url 'cabinet:admin_config' slug=slug %}" class="nav-link">{{ title }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
23
cabinet/templates/cabinet/admin_config.html
Normal file
23
cabinet/templates/cabinet/admin_config.html
Normal file
@@ -0,0 +1,23 @@
|
||||
{% extends 'cabinet/_internal_base.html' %}
|
||||
{% load bootstrap4 %}
|
||||
|
||||
|
||||
{% block breadcrumbs %}
|
||||
<li><span>Configs</span></li>
|
||||
<li><span>{{ form.title }}</span></li>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form action="" method="post" class="card">
|
||||
{% csrf_token %}
|
||||
<header class="card-header">
|
||||
<h2 class="card-title">Config</h2>
|
||||
</header>
|
||||
<div class="card-body">
|
||||
{% bootstrap_form form layout='horizontal' %}
|
||||
</div>
|
||||
<footer class="card-footer text-right">
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</footer>
|
||||
</form>
|
||||
{% endblock %}
|
@@ -1,7 +1,7 @@
|
||||
from django.contrib.auth.views import LogoutView
|
||||
from django.urls import path, include
|
||||
|
||||
from cabinet.views import CabinetIndexView, LoginView
|
||||
from cabinet.views import CabinetIndexView, LoginView, AdminConfigView
|
||||
|
||||
app_name = 'cabinet'
|
||||
urlpatterns = [
|
||||
@@ -9,4 +9,5 @@ urlpatterns = [
|
||||
path('login/', LoginView.as_view(), name='login'),
|
||||
path('logout/', LogoutView.as_view(), name='logout'),
|
||||
path('feeds/', include('feeds.urls', namespace='feeds')),
|
||||
path('admin/config/<slug>/', AdminConfigView.as_view(), name='admin_config'),
|
||||
]
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import djconfig
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
|
||||
|
||||
@@ -13,3 +14,9 @@ class CabinetViewMixin(LoginRequiredMixin):
|
||||
ctx['title'] = self.get_title()
|
||||
ctx['sidebar_section'] = self.sidebar_section
|
||||
return ctx
|
||||
|
||||
|
||||
def cabinet_context_processor(ctx):
|
||||
return {
|
||||
'admin_configs': {form.slug: form.title for form in djconfig.config._registry},
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
import djconfig
|
||||
from django.contrib.auth.views import LoginView as BaseLoginView
|
||||
from django.views.generic import TemplateView
|
||||
from django.http import Http404
|
||||
from django.views.generic import TemplateView, FormView
|
||||
|
||||
from cabinet.utils import CabinetViewMixin
|
||||
|
||||
@@ -23,3 +25,16 @@ class LoginView(BaseLoginView):
|
||||
if not self.request.POST.get('remember'):
|
||||
self.request.session.set_expiry(0)
|
||||
return res
|
||||
|
||||
|
||||
class AdminConfigView(CabinetViewMixin, FormView):
|
||||
template_name = 'cabinet/admin_config.html'
|
||||
|
||||
def get_title(self):
|
||||
return '{} config'.format(self.get_form_class().title)
|
||||
|
||||
def get_form_class(self):
|
||||
for form in djconfig.config._registry:
|
||||
if form.slug == self.kwargs.get('slug'):
|
||||
return form
|
||||
raise Http404()
|
||||
|
Reference in New Issue
Block a user