Use context processor to include site settings in templates

This commit is contained in:
Mouse Reeve 2020-12-11 12:07:37 -08:00
parent 3aba3c8052
commit b33ea40da2
9 changed files with 21 additions and 18 deletions

View file

@ -75,6 +75,7 @@ TEMPLATES = [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'bookwyrm.context_processors.site_settings',
],
},
},

View file

@ -3,13 +3,13 @@
<div class="columns">
<div class="column block">
{% include 'snippets/about.html' with site_settings=site_settings %}
{% include 'snippets/about.html' %}
</div>
<div class="column block">
<h2 class="title">Code of Conduct</h2>
<div class="content">
{{ site_settings.code_of_conduct | safe }}
{{ site.code_of_conduct | safe }}
</div>
</div>
</div>

View file

@ -15,7 +15,7 @@
</div>
<div class="column">
<div class="block">
{% include 'snippets/about.html' with site_settings=site_settings %}
{% include 'snippets/about.html' %}
</div>
</div>
</div>

View file

@ -2,7 +2,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% if title %}{{ title }} | {% endif %}BookWyrm</title>
<title>{% if title %}{{ title }} | {% endif %}{{ site.name }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link type="text/css" rel="stylesheet" href="/static/css/bulma.min.css">
<link type="text/css" rel="stylesheet" href="/static/css/format.css">
@ -11,12 +11,10 @@
<link rel="shortcut icon" type="image/x-icon" href="/static/images/favicon.ico">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="BookWyrm">
<meta name="og:title" content="BookWyrm">
<meta name="twitter:title" content="{{ site.name }}">
<meta name="og:title" content="{{ site.name }}">
<meta name="twitter:description" content="Federated Social Reading">
<meta name="og:description" content="Federated Social Reading">
<meta name="twitter:creator" content="@tripofmice">
<meta name="twitter:site" content="@tripofmice">
</head>
<body>
@ -123,6 +121,15 @@
{% endblock %}
</div>
<div class="footer">
<div class="columns">
<div class="column">
About this server
</div>
</div>
</div>
<script>
var csrf_token = '{{ csrf_token }}';
</script>

View file

@ -36,7 +36,7 @@
</form>
</div>
<div class="box has-background-primary-light">
{% if site_settings.allow_registration %}
{% if site.allow_registration %}
<h2 class="title">Create an Account</h2>
<form name="register" method="post" action="/user-register">
{% include 'snippets/register_form.html' %}
@ -50,7 +50,7 @@
<div class="column">
<div class="block">
{% include 'snippets/about.html' with site_settings=site_settings %}
{% include 'snippets/about.html' %}
<p class="block">
<a href="/about/">More about this site</a>

View file

@ -34,7 +34,7 @@
<div class="column">
<div class="block">
{% include 'snippets/about.html' with site_settings=site_settings %}
{% include 'snippets/about.html' %}
</div>
</div>

View file

@ -1,7 +1,7 @@
<h1 class="title">About {{ site_settings.name }}</h1>
<h1 class="title">About {{ site.name }}</h1>
<div class="block">
<img src="/static/images/logo.png" alt="BookWyrm">
</div>
<p class="block">
{{ site_settings.instance_description }}
{{ site.instance_description }}
</p>

View file

@ -42,7 +42,6 @@ def user_login(request):
login_form.non_field_errors = 'Username or password are incorrect'
register_form = forms.RegisterForm()
data = {
'site_settings': models.SiteSettings.get(),
'login_form': login_form,
'register_form': register_form
}
@ -78,7 +77,6 @@ def register(request):
if errors:
data = {
'site_settings': models.SiteSettings.get(),
'login_form': forms.LoginForm(),
'register_form': form
}

View file

@ -235,7 +235,6 @@ def login_page(request):
# send user to the login page
data = {
'title': 'Login',
'site_settings': models.SiteSettings.get(),
'login_form': forms.LoginForm(),
'register_form': forms.RegisterForm(),
}
@ -247,7 +246,6 @@ def about_page(request):
''' more information about the instance '''
data = {
'title': 'About',
'site_settings': models.SiteSettings.get(),
}
return TemplateResponse(request, 'about.html', data)
@ -295,7 +293,6 @@ def invite_page(request, code):
data = {
'title': 'Join',
'site_settings': models.SiteSettings.get(),
'register_form': forms.RegisterForm(),
'invite': invite,
}