From f00e106dfe1fefecc39a3907865e13d180fc810d Mon Sep 17 00:00:00 2001 From: Isaac Bythewood Date: Wed, 1 Aug 2012 21:30:18 +0000 Subject: [PATCH] Add in some new settings. --- README.md | 13 +++++++++++++ pinry/core/context_processors.py | 1 + pinry/core/middleware.py | 15 +++++++++++++++ pinry/core/templates/core/private.html | 18 ++++++++++++++++++ pinry/core/urls.py | 1 + pinry/core/views.py | 8 ++++++-- pinry/settings/__init__.py | 11 +++++++++-- pinry/settings/development.py | 2 +- 8 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 pinry/core/middleware.py create mode 100644 pinry/core/templates/core/private.html diff --git a/README.md b/README.md index 8b102ca..d22a6e8 100644 --- a/README.md +++ b/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 diff --git a/pinry/core/context_processors.py b/pinry/core/context_processors.py index 0417083..e48b060 100644 --- a/pinry/core/context_processors.py +++ b/pinry/core/context_processors.py @@ -5,3 +5,4 @@ def template_settings(request): return { 'site_name': settings.SITE_NAME, } + diff --git a/pinry/core/middleware.py b/pinry/core/middleware.py new file mode 100644 index 0000000..5a670ca --- /dev/null +++ b/pinry/core/middleware.py @@ -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')) diff --git a/pinry/core/templates/core/private.html b/pinry/core/templates/core/private.html new file mode 100644 index 0000000..07e2212 --- /dev/null +++ b/pinry/core/templates/core/private.html @@ -0,0 +1,18 @@ +{% extends 'core/base.html' %} + +{% load bootstrap_field %} + + +{% block title %}Private{% endblock %} + +{% block yield %} +
+
+
+

Private

+

This website is set to private. You need to login before you + can view any content.

+
+
+
+{% endblock %} diff --git a/pinry/core/urls.py b/pinry/core/urls.py index 5f74d3d..2c24676 100644 --- a/pinry/core/urls.py +++ b/pinry/core/urls.py @@ -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'), diff --git a/pinry/core/views.py b/pinry/core/views.py index 3d50ee7..ac65812 100644 --- a/pinry/core/views.py +++ b/pinry/core/views.py @@ -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) diff --git a/pinry/settings/__init__.py b/pinry/settings/__init__.py index d421285..f88714c 100644 --- a/pinry/settings/__init__.py +++ b/pinry/settings/__init__.py @@ -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' -ALLOW_NEW_REGISTRATIONS = True +# 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", diff --git a/pinry/settings/development.py b/pinry/settings/development.py index dc19818..6c43f73 100644 --- a/pinry/settings/development.py +++ b/pinry/settings/development.py @@ -13,4 +13,4 @@ DATABASES = { } } -SECRET_KEY = '' +SECRET_KEY = 'fake-key'