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:
Adam Kelly 2020-06-01 19:54:08 +01:00
parent 4d6ecafcf4
commit 92a669ffaf
6 changed files with 72 additions and 1 deletions

View file

@ -6,3 +6,4 @@ from .status import Favorite, Boost, Tag, Notification, ReadThrough
from .user import User, UserFollows, UserFollowRequest, UserBlocks from .user import User, UserFollows, UserFollowRequest, UserBlocks
from .user import FederatedServer from .user import FederatedServer
from .import_job import ImportJob, ImportItem from .import_job import ImportJob, ImportItem
from .site import SiteSettings

19
fedireads/models/site.py Normal file
View 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

View 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 %}

View file

@ -1,7 +1,20 @@
{% extends 'layout.html' %} {% extends 'layout.html' %}
{% block content %} {% 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"> <div class="content-container login">
<h2>Create an Account</h2> <h2>Create an Account</h2>
<p><small> <p><small>
@ -9,6 +22,7 @@
friends here and on any other federated server, like Mastodon and PixelFed. friends here and on any other federated server, like Mastodon and PixelFed.
</small></p> </small></p>
{% if site_settings.allow_registration %}
<div> <div>
<form name="register" method="post" action="/register"> <form name="register" method="post" action="/register">
{% csrf_token %} {% csrf_token %}
@ -16,6 +30,12 @@
<button type="submit">Create account</button> <button type="submit">Create account</button>
</form> </form>
</div> </div>
{% else %}
<small>
This instance is not open for registration.
</small>
{% endif %}
</div> </div>
<div class="content-container login"> <div class="content-container login">

View file

@ -34,6 +34,7 @@ urlpatterns = [
# ui views # ui views
re_path(r'^login/?$', views.login_page), re_path(r'^login/?$', views.login_page),
re_path(r'^about/?$', views.about_page),
path('', views.home), path('', views.home),
re_path(r'^(?P<tab>home|local|federated)/?$', views.home_tab), re_path(r'^(?P<tab>home|local|federated)/?$', views.home_tab),

View file

@ -208,12 +208,21 @@ def login_page(request):
''' authentication ''' ''' authentication '''
# send user to the login page # send user to the login page
data = { data = {
'site_settings': models.SiteSettings.get(),
'login_form': forms.LoginForm(), 'login_form': forms.LoginForm(),
'register_form': forms.RegisterForm(), 'register_form': forms.RegisterForm(),
} }
return TemplateResponse(request, 'login.html', data) 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 @login_required
def notifications_page(request): def notifications_page(request):
''' list notitications ''' ''' list notitications '''