mirror of
https://github.com/pinry/pinry.git
synced 2025-11-13 16:45:41 +01:00
Add in some new settings.
This commit is contained in:
13
README.md
13
README.md
@@ -48,6 +48,19 @@ hundreds of different ways to deploy a Django project and everyone has their own
|
||||
preference.
|
||||
|
||||
|
||||
### Quick Settings
|
||||
|
||||
There are a few settings provided specific to Pinry that allow you to get some
|
||||
of the most requested functionality easily.
|
||||
|
||||
+ **SITE_NAME**: For quickly changing the name Pinry to something you prefer.
|
||||
+ **ALLOW_NEW_REGISTRATIONS**: Set to False to prevent people from registering.
|
||||
+ **PUBLIC**: Set to False to require people to register before viewing pins.
|
||||
(Note: Setting PUBLIC to False does still allow registrations. Make sure
|
||||
both PUBLIC and the previous setting are set to False to prevent
|
||||
all public access.)
|
||||
|
||||
|
||||
## Roadmap
|
||||
|
||||
+ Non-image URL pinning
|
||||
|
||||
@@ -5,3 +5,4 @@ def template_settings(request):
|
||||
return {
|
||||
'site_name': settings.SITE_NAME,
|
||||
}
|
||||
|
||||
|
||||
15
pinry/core/middleware.py
Normal file
15
pinry/core/middleware.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
|
||||
class Public(object):
|
||||
def process_request(self, request):
|
||||
if settings.PUBLIC == False and not request.user.is_authenticated():
|
||||
acceptable_paths = [
|
||||
'/login/',
|
||||
'/private/',
|
||||
'/register/',
|
||||
]
|
||||
if request.path not in acceptable_paths:
|
||||
return HttpResponseRedirect(reverse('core:private'))
|
||||
18
pinry/core/templates/core/private.html
Normal file
18
pinry/core/templates/core/private.html
Normal file
@@ -0,0 +1,18 @@
|
||||
{% extends 'core/base.html' %}
|
||||
|
||||
{% load bootstrap_field %}
|
||||
|
||||
|
||||
{% block title %}Private{% endblock %}
|
||||
|
||||
{% block yield %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div id="form" class="span6 offset3">
|
||||
<h1>Private</h1>
|
||||
<p>This website is set to private. You need to login before you
|
||||
can view any content.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -3,6 +3,7 @@ from django.conf.urls import patterns, url
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^$', 'pinry.core.views.home', name='home'),
|
||||
url(r'^private/$', 'pinry.core.views.private', name='private'),
|
||||
url(r'^login/$', 'django.contrib.auth.views.login',
|
||||
{'template_name': 'core/login.html'}, name='login'),
|
||||
url(r'^register/$', 'pinry.core.views.register', name='register'),
|
||||
|
||||
@@ -12,10 +12,14 @@ def home(request):
|
||||
return HttpResponseRedirect(reverse('pins:recent-pins'))
|
||||
|
||||
|
||||
def private(request):
|
||||
return TemplateResponse(request, 'core/private.html', None)
|
||||
|
||||
|
||||
def register(request):
|
||||
if not settings.ALLOW_NEW_REGISTRATIONS:
|
||||
messages.error(request, "The admin of this service is currently not "
|
||||
"allowing new users to register.")
|
||||
messages.error(request, "The admin of this service is not "
|
||||
"allowing new registrations.")
|
||||
return HttpResponseRedirect(reverse('pins:recent-pins'))
|
||||
if request.method == 'POST':
|
||||
form = UserCreationForm(request.POST)
|
||||
|
||||
@@ -2,11 +2,17 @@ import os
|
||||
from django.contrib.messages import constants as messages
|
||||
|
||||
|
||||
SITE_ROOT = os.path.join(os.path.realpath(os.path.dirname(__file__)), '../../')
|
||||
|
||||
|
||||
# Changes the naming on the front-end of the website.
|
||||
SITE_NAME = 'Pinry'
|
||||
|
||||
# Set to False to disable people from creating new accounts.
|
||||
ALLOW_NEW_REGISTRATIONS = True
|
||||
|
||||
|
||||
SITE_ROOT = os.path.join(os.path.realpath(os.path.dirname(__file__)), '../../')
|
||||
# Set to False to force users to login before seeing any pins.
|
||||
PUBLIC = True
|
||||
|
||||
|
||||
TIME_ZONE = 'America/New_York'
|
||||
@@ -34,6 +40,7 @@ MIDDLEWARE_CLASSES = (
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'pinry.core.middleware.Public',
|
||||
)
|
||||
TEMPLATE_CONTEXT_PROCESSORS = (
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
|
||||
@@ -13,4 +13,4 @@ DATABASES = {
|
||||
}
|
||||
}
|
||||
|
||||
SECRET_KEY = ''
|
||||
SECRET_KEY = 'fake-key'
|
||||
|
||||
Reference in New Issue
Block a user