forked from mirrors/bookwyrm
Add instance settings.
Addresses: #58 Currently implemented: * Instance name * Instance description * Code of conduct * Allow registration I decided to store this in the database so that settings can be easily changed at runtime through the web interface. (This web interface does not exist.)
This commit is contained in:
parent
4d6ecafcf4
commit
92a669ffaf
6 changed files with 72 additions and 1 deletions
|
@ -6,3 +6,4 @@ from .status import Favorite, Boost, Tag, Notification, ReadThrough
|
|||
from .user import User, UserFollows, UserFollowRequest, UserBlocks
|
||||
from .user import FederatedServer
|
||||
from .import_job import ImportJob, ImportItem
|
||||
from .site import SiteSettings
|
||||
|
|
19
fedireads/models/site.py
Normal file
19
fedireads/models/site.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from django.db import models
|
||||
from fedireads.settings import DOMAIN
|
||||
|
||||
class SiteSettings(models.Model):
|
||||
name = models.CharField(default=DOMAIN, max_length=100)
|
||||
instance_description = models.TextField(
|
||||
default="This instance has no description.")
|
||||
code_of_conduct = models.TextField(
|
||||
default="Add a code of conduct here.")
|
||||
allow_registration = models.BooleanField(default=True)
|
||||
|
||||
@classmethod
|
||||
def get(cls):
|
||||
try:
|
||||
return cls.objects.get(id=1)
|
||||
except cls.DoesNotExist:
|
||||
default_settings = SiteSettings(id=1)
|
||||
default_settings.save()
|
||||
return default_settings
|
21
fedireads/templates/about.html
Normal file
21
fedireads/templates/about.html
Normal file
|
@ -0,0 +1,21 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% block content %}
|
||||
<div class="content-container">
|
||||
<h2>About {{ site_settings.name }}</h2>
|
||||
<p>
|
||||
{{ site_settings.instance_description }}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small>
|
||||
<a href="/login/">Login or Create an Account</a>
|
||||
</small>
|
||||
</p>
|
||||
|
||||
<h2>Code of Conduct</h2>
|
||||
<p>
|
||||
{{ site_settings.code_of_conduct }}
|
||||
</p>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,7 +1,20 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
|
||||
<div class="content-container">
|
||||
<h2>About {{ site_settings.name }}</h2>
|
||||
<p>
|
||||
{{ site_settings.instance_description }}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<small>
|
||||
<a href="/about/">More about this site</a>
|
||||
</small>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="content-container login">
|
||||
<h2>Create an Account</h2>
|
||||
<p><small>
|
||||
|
@ -9,6 +22,7 @@
|
|||
friends here and on any other federated server, like Mastodon and PixelFed.
|
||||
</small></p>
|
||||
|
||||
{% if site_settings.allow_registration %}
|
||||
<div>
|
||||
<form name="register" method="post" action="/register">
|
||||
{% csrf_token %}
|
||||
|
@ -16,6 +30,12 @@
|
|||
<button type="submit">Create account</button>
|
||||
</form>
|
||||
</div>
|
||||
{% else %}
|
||||
|
||||
<small>
|
||||
This instance is not open for registration.
|
||||
</small>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="content-container login">
|
||||
|
|
|
@ -34,6 +34,7 @@ urlpatterns = [
|
|||
|
||||
# ui views
|
||||
re_path(r'^login/?$', views.login_page),
|
||||
re_path(r'^about/?$', views.about_page),
|
||||
|
||||
path('', views.home),
|
||||
re_path(r'^(?P<tab>home|local|federated)/?$', views.home_tab),
|
||||
|
|
|
@ -208,12 +208,21 @@ def login_page(request):
|
|||
''' authentication '''
|
||||
# send user to the login page
|
||||
data = {
|
||||
'site_settings': models.SiteSettings.get(),
|
||||
'login_form': forms.LoginForm(),
|
||||
'register_form': forms.RegisterForm(),
|
||||
}
|
||||
return TemplateResponse(request, 'login.html', data)
|
||||
|
||||
|
||||
def about_page(request):
|
||||
''' more information about the instance '''
|
||||
data = {
|
||||
'site_settings': models.SiteSettings.get(),
|
||||
}
|
||||
return TemplateResponse(request, 'about.html', data)
|
||||
|
||||
|
||||
@login_required
|
||||
def notifications_page(request):
|
||||
''' list notitications '''
|
||||
|
|
Loading…
Reference in a new issue