Port to new django version - not yet fully working
- location field makes problems
This commit is contained in:
Binary file not shown.
@@ -2,7 +2,8 @@ from django.http import HttpResponseRedirect
|
||||
from django.conf import settings
|
||||
import re
|
||||
|
||||
class EnforceLoginMiddleware(object):
|
||||
|
||||
class EnforceLoginMiddleware:
|
||||
"""
|
||||
Middlware class which requires the user to be authenticated for all urls except
|
||||
those defined in PUBLIC_URLS in settings.py. PUBLIC_URLS should be a tuple of regular
|
||||
@@ -14,70 +15,77 @@ class EnforceLoginMiddleware(object):
|
||||
validation on these set SERVE_STATIC_TO_PUBLIC to False.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.login_url = getattr(settings, 'LOGIN_URL', '/accounts/login/' )
|
||||
|
||||
if hasattr(settings,'PUBLIC_URLS'):
|
||||
def __init__(self, get_response):
|
||||
self.login_url = getattr(settings, 'LOGIN_URL', '/accounts/login/')
|
||||
self.get_response = get_response
|
||||
|
||||
if hasattr(settings, 'PUBLIC_URLS'):
|
||||
public_urls = [re.compile(url) for url in settings.PUBLIC_URLS]
|
||||
else:
|
||||
public_urls = [(re.compile("^%s/?$" % ( self.login_url[1:] )))]
|
||||
if getattr(settings, 'SERVE_STATIC_TO_PUBLIC', True ):
|
||||
public_urls = [(re.compile("^%s/?$" % (self.login_url[1:])))]
|
||||
if getattr(settings, 'SERVE_STATIC_TO_PUBLIC', True):
|
||||
root_urlconf = __import__(settings.ROOT_URLCONF)
|
||||
public_urls.extend([ re.compile(url.regex)
|
||||
for url in root_urlconf.urls.urlpatterns
|
||||
if url.__dict__.get('_callback_str') == 'django.views.static.serve'
|
||||
])
|
||||
public_urls.extend([re.compile(url.regex)
|
||||
for url in root_urlconf.urls.urlpatterns
|
||||
if url.__dict__.get('_callback_str') == 'django.views.static.serve'
|
||||
])
|
||||
self.public_urls = tuple(public_urls)
|
||||
|
||||
def process_request(self, request):
|
||||
def __call__(self, request):
|
||||
"""
|
||||
Redirect anonymous users to login_url from non public urls
|
||||
"""
|
||||
try:
|
||||
if request.user.is_anonymous():
|
||||
if request.user.is_anonymous:
|
||||
for url in self.public_urls:
|
||||
if url.match(request.path[1:]):
|
||||
return None
|
||||
return HttpResponseRedirect("%s?next=%s" % (self.login_url, request.path))
|
||||
except AttributeError:
|
||||
return HttpResponseRedirect("%s?next=%s" % (self.login_url, request.path))
|
||||
|
||||
|
||||
|
||||
class DetectDevice(object):
|
||||
|
||||
def process_request(self, request):
|
||||
return self.get_response(request)
|
||||
|
||||
|
||||
class DetectDevice:
|
||||
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
device = self.mobile(request)
|
||||
|
||||
request.device = device
|
||||
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
|
||||
def mobile(self, request):
|
||||
device = {}
|
||||
|
||||
|
||||
ua = request.META.get('HTTP_USER_AGENT', '').lower()
|
||||
|
||||
|
||||
if ua.find("iphone") > 0:
|
||||
device['iphone'] = "iphone" + re.search("iphone os (\d)", ua).groups(0)[0]
|
||||
|
||||
|
||||
if ua.find("ipad") > 0:
|
||||
device['ipad'] = "ipad"
|
||||
|
||||
|
||||
if ua.find("android") > 0:
|
||||
device['android'] = "android" + re.search("android (\d\.\d)", ua).groups(0)[0].translate(None, '.')
|
||||
|
||||
|
||||
if ua.find("blackberry") > 0:
|
||||
device['blackberry'] = "blackberry"
|
||||
|
||||
|
||||
if ua.find("windows phone os 7") > 0:
|
||||
device['winphone7'] = "winphone7"
|
||||
|
||||
|
||||
if ua.find("iemobile") > 0:
|
||||
device['winmo'] = "winmo"
|
||||
|
||||
if not device: # either desktop, or something we don't care about.
|
||||
|
||||
if not device: # either desktop, or something we don't care about.
|
||||
device['baseline'] = "baseline"
|
||||
|
||||
|
||||
# spits out device names for CSS targeting, to be applied to <html> or <body>.
|
||||
device['classes'] = " ".join(v for (k,v) in device.items())
|
||||
|
||||
device['classes'] = " ".join(v for (k, v) in device.items())
|
||||
|
||||
return device
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# Setting the path
|
||||
|
||||
import os
|
||||
|
||||
gettext = lambda s: s
|
||||
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
|
||||
# Django settings for blechreiz project.
|
||||
|
||||
DEBUG = True
|
||||
@@ -16,7 +16,6 @@ ADMINS = (
|
||||
|
||||
MANAGERS = ADMINS
|
||||
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
@@ -26,11 +25,10 @@ DATABASES = {
|
||||
|
||||
# Email
|
||||
|
||||
EMAIL_HOST='smtp.blechreiz.com'
|
||||
EMAIL_HOST_USER='m02b721a'
|
||||
EMAIL_HOST_PASSWORD='9Hp4WG5bZ2WVPX5z'
|
||||
EMAIL_USE_TLS=False
|
||||
|
||||
EMAIL_HOST = 'smtp.blechreiz.com'
|
||||
EMAIL_HOST_USER = 'm02b721a'
|
||||
EMAIL_HOST_PASSWORD = '9Hp4WG5bZ2WVPX5z'
|
||||
EMAIL_USE_TLS = False
|
||||
|
||||
# Hosts/domain names that are valid for this site; required if DEBUG is False
|
||||
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
|
||||
@@ -78,8 +76,8 @@ STATIC_ROOT = PROJECT_PATH + '/static_collection'
|
||||
# Example: "http://example.com/static/", "http://static.example.com/"
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
LOGIN_URL="/musicians/login"
|
||||
PUBLIC_URLS=( "^musicians/login/?$", "^musicians/login/usernames/?$", "^eventplanner_gcal/gcalApiCallback*")
|
||||
LOGIN_URL = "/musicians/login"
|
||||
PUBLIC_URLS = ("^musicians/login/?$", "^musicians/login/usernames/?$", "^eventplanner_gcal/gcalApiCallback*")
|
||||
|
||||
# Additional locations of static files
|
||||
STATICFILES_DIRS = (
|
||||
@@ -94,26 +92,42 @@ STATICFILES_DIRS = (
|
||||
STATICFILES_FINDERS = (
|
||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
||||
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
|
||||
)
|
||||
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
|
||||
)
|
||||
|
||||
# Make this unique, and don't share it with anybody.
|
||||
SECRET_KEY = 'x$8&9s6t%eeg=wyhar87934wh_s$dbpm(73g4ho&n)9_wogj6p'
|
||||
|
||||
# List of callables that know how to import templates from various sources.
|
||||
TEMPLATE_LOADERS = (
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
# 'django.template.loaders.eggs.Loader',
|
||||
)
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [
|
||||
PROJECT_PATH + '/templates',
|
||||
],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
|
||||
# list if you haven't customized them:
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.template.context_processors.i18n',
|
||||
'django.template.context_processors.request',
|
||||
'django.template.context_processors.media',
|
||||
'django.template.context_processors.static',
|
||||
'sekizai.context_processors.sekizai',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
MIDDLEWARE = (
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'blechreiz.middleware.EnforceLoginMiddleware',
|
||||
#'blechreiz.middleware.EnforceLoginMiddleware',
|
||||
'blechreiz.middleware.DetectDevice',
|
||||
# Uncomment the next line for simple clickjacking protection:
|
||||
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
@@ -125,20 +139,6 @@ ROOT_URLCONF = 'blechreiz.urls'
|
||||
WSGI_APPLICATION = 'blechreiz.wsgi.application'
|
||||
|
||||
|
||||
TEMPLATE_DIRS = (
|
||||
PROJECT_PATH + '/templates',
|
||||
)
|
||||
|
||||
|
||||
TEMPLATE_CONTEXT_PROCESSORS = (
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.core.context_processors.i18n',
|
||||
'django.core.context_processors.request',
|
||||
'django.core.context_processors.media',
|
||||
'django.core.context_processors.static',
|
||||
'sekizai.context_processors.sekizai',
|
||||
)
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
@@ -148,45 +148,40 @@ INSTALLED_APPS = (
|
||||
'django.contrib.staticfiles',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.admindocs',
|
||||
'crispy_forms', # better looking forms ( bootstrap )
|
||||
'sekizai', # for the addtoblock directive in templates
|
||||
'rest_framework', # for event management api
|
||||
'south',
|
||||
|
||||
'crispy_forms', # better looking forms ( bootstrap )
|
||||
'sekizai', # for the addtoblock directive in templates
|
||||
'rest_framework', # for event management api
|
||||
|
||||
# Own Things
|
||||
'bootstrapTheme', # Theme
|
||||
'website', # Blechreiz Website in general
|
||||
'musicians', # User Management
|
||||
'eventplanner', # Event Management
|
||||
'eventplanner_gcal', # Event Management Sync with Google Calendar
|
||||
'simpleforum', # Messages ( Forum )
|
||||
'location_field', # custom location field used in Event Management
|
||||
'scoremanager', # manager of scores, repertoire etc.
|
||||
#'imagestore',
|
||||
#'sorl.thumbnail',
|
||||
#'tagging'
|
||||
'bootstrapTheme', # Theme
|
||||
'website', # Blechreiz Website in general
|
||||
'musicians', # User Management
|
||||
'eventplanner', # Event Management
|
||||
'eventplanner_gcal', # Event Management Sync with Google Calendar
|
||||
'simpleforum', # Messages ( Forum )
|
||||
'location_field', # custom location field used in Event Management
|
||||
'scoremanager', # manager of scores, repertoire etc.
|
||||
# 'imagestore',
|
||||
# 'sorl.thumbnail',
|
||||
# 'tagging'
|
||||
)
|
||||
|
||||
IMAGESTORE_TEMPLATE = "website/base.html"
|
||||
|
||||
|
||||
IMAGESTORE_TEMPLATE = "website/base.html"
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
|
||||
'PAGINATE_BY': 10
|
||||
}
|
||||
|
||||
|
||||
GCAL_COUPLING = {
|
||||
'eventPrefix' : 'Blechreiz: ',
|
||||
'developerKey' : 'blechreiz-homepage',
|
||||
'clientId' : '34462582242-4kpdvvbi27ajt4u22uitqurpve9o8ipj.apps.googleusercontent.com',
|
||||
'client_secret' : 'y4t9XBrJdCODPTO5UvtONWWn',
|
||||
'credentials_file' : PROJECT_PATH + '/calendarCredentials.dat',
|
||||
'push_url' : "https://blechreiz.bauer.technology/eventplanner_gcal/gcalApiCallback",
|
||||
'eventPrefix': 'Blechreiz: ',
|
||||
'developerKey': 'blechreiz-homepage',
|
||||
'clientId': '34462582242-4kpdvvbi27ajt4u22uitqurpve9o8ipj.apps.googleusercontent.com',
|
||||
'client_secret': 'y4t9XBrJdCODPTO5UvtONWWn',
|
||||
'credentials_file': PROJECT_PATH + '/calendarCredentials.dat',
|
||||
'push_url': "https://blechreiz.bauer.technology/eventplanner_gcal/gcalApiCallback",
|
||||
}
|
||||
|
||||
|
||||
CRISPY_TEMPLATE_PACK = 'bootstrap'
|
||||
|
||||
# A sample logging configuration. The only tangible logging
|
||||
@@ -198,6 +193,16 @@ CRISPY_TEMPLATE_PACK = 'bootstrap'
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'formatters': {
|
||||
'verbose': {
|
||||
'format': '{levelname} {asctime} {module} {message}',
|
||||
'style': '{',
|
||||
},
|
||||
'simple': {
|
||||
'format': '{levelname} {asctime} {message}',
|
||||
'style': '{',
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'file': {
|
||||
'level': 'DEBUG',
|
||||
@@ -211,12 +216,13 @@ LOGGING = {
|
||||
'level': 'DEBUG',
|
||||
'propagate': True,
|
||||
},
|
||||
'eventplanner': {
|
||||
'eventplanner': {
|
||||
'handler': ['file'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': True,
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
}
|
||||
|
||||
GOOGLE_MAPS_API_KEY = 'AIzaSyCf9Lm5ckjmVd08scTOd7fB1dC_UCoumKg'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.conf.urls import include, url
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
@@ -6,26 +6,23 @@ import simpleforum.views
|
||||
|
||||
import eventplanner.urls
|
||||
import musicians.urls
|
||||
#import imagestore.urls
|
||||
import website.urls
|
||||
import scoremanager.urls
|
||||
import eventplanner_gcal.urls
|
||||
|
||||
|
||||
|
||||
import settings
|
||||
from . import settings
|
||||
from django.conf.urls.static import static
|
||||
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^', include( website.urls ) ),
|
||||
url(r'^events/', include( eventplanner.urls.urlpatterns) ),
|
||||
url(r'^musicians/', include( musicians.urls.urlpatterns) ),
|
||||
url(r'^scores/', include( scoremanager.urls.urlpatterns) ),
|
||||
url(r'^messages/$', simpleforum.views.message_view ),
|
||||
url(r'^admin/', include( admin.site.urls ) ),
|
||||
url(r'^location_field/', include( 'location_field.urls' ) ),
|
||||
url(r'^eventplanner_gcal/', include( eventplanner_gcal.urls) ),
|
||||
#url(r'^gallery/', include(imagestore.urls, namespace='imagestore') ),
|
||||
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
urlpatterns = [
|
||||
url(r'^', include(website.urls)),
|
||||
url(r'^events/', include(eventplanner.urls.urlpatterns)),
|
||||
url(r'^musicians/', include(musicians.urls.urlpatterns)),
|
||||
url(r'^scores/', include(scoremanager.urls.urlpatterns)),
|
||||
url(r'^messages/$', simpleforum.views.message_view),
|
||||
url(r'^admin/', admin.site.urls),
|
||||
url(r'^location_field/', include('location_field.urls')),
|
||||
url(r'^eventplanner_gcal/', include(eventplanner_gcal.urls)),
|
||||
# url(r'^gallery/', include(imagestore.urls, namespace='imagestore') ),
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
||||
Reference in New Issue
Block a user