Update main ojusomap settings.py and urls.py

This commit is contained in:
Livvy Mackintosh 2017-05-23 01:13:14 +02:00
parent f25bb691d2
commit 2ebc58d026
2 changed files with 75 additions and 13 deletions

View File

@ -43,8 +43,13 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'bootstrap3',
'cas_server',
'crispy_forms',
'django_extensions',
'leaflet',
'rest_framework',
'rest_framework_gis',
]
MIDDLEWARE = [
@ -78,10 +83,20 @@ TEMPLATES = [
WSGI_APPLICATION = 'ojusomap.wsgi.application'
# Admins
# https://docs.djangoproject.com/en/1.11/ref/settings/#admins
# E-Mail
# https://docs.djangoproject.com/en/1.11/topics/email/
ADMINS = [('Livvy','livvy@base.nu')]
EMAIL_HOST = os.getenv('EMAIL_HOST', 'localhost')
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD')
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER')
EMAIL_PORT = os.getenv('EMAIL_PORT', 25)
EMAIL_USE_TLS = bool(int(os.getenv('EMAIL_USE_TLS', False)))
EMAIL_SUBJECT_PREFIX = "Ojuso Platform"
SERVER_EMAIL = os.getenv('SERVER_EMAIL', 'root@localhost')
ADMINS = [('Livvy Mackintosh', 'livvy@base.nu')]
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
@ -102,20 +117,16 @@ DATABASES = {
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.\
UserAttributeSimilarityValidator',
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.\
MinimumLengthValidator',
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.\
CommonPasswordValidator',
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.\
NumericPasswordValidator',
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
@ -123,7 +134,7 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'en-gb'
TIME_ZONE = 'UTC'
@ -164,3 +175,19 @@ else:
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
# Django-Rest-Framework
# http://django-rest-framework.org/#installation
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
],
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
),
'DEFAULT_PARSER_CLASSES': (
'rest_framework.parsers.JSONParser',
)
}

View File

@ -13,9 +13,44 @@ Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth.models import User
from apps.map.models import CaseStudy
from django.views.generic.base import RedirectView
from rest_framework import routers, serializers, viewsets
from rest_framework_gis import serializers as gis_serializers
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ('url', 'username', 'email', 'is_staff')
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
class CaseStudySerializer(gis_serializers.GeoFeatureModelSerializer):
class Meta:
model = CaseStudy
geo_field = "location"
fields = '__all__'
class CaseStudyViewSet(viewsets.ModelViewSet):
queryset = CaseStudy.objects.all()
serializer_class = CaseStudySerializer
apirouter = routers.DefaultRouter()
apirouter.register(r'users', UserViewSet)
apirouter.register(r'case-studies', CaseStudyViewSet)
urlpatterns = [
url(r'^$', RedirectView.as_view(url="/beta/")),
url(r'api/', include(apirouter.urls)),
url(r'^beta/', include('apps.map.urls'), name="beta"),
url(r'^admin/', admin.site.urls),
url(r'^cas/', include('cas_server.urls', namespace='cas_server')),
]