Skip to content

Commit

Permalink
Upgraded to Django1.9 + DRF 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinastone committed Dec 27, 2015
1 parent 00888c9 commit 091da77
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 35 deletions.
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM ubuntu:trusty

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y python-software-properties software-properties-common
RUN add-apt-repository -y ppa:chris-lea/node.js

RUN apt-get update && apt-get install -y \
build-essential git htop tmux pv \
postgresql libpq-dev \
python-pip python-dev libjpeg-dev zlib1g-dev \
nodejs

RUN npm install -g grunt-cli bower

ADD requirements.txt /src/
WORKDIR /src

RUN pip install -r requirements.txt

ADD package.json bower.json .bowerrc /src/
RUN npm install

RUN bower install --allow-root

ADD setup.py manage.py Makefile /src/
ADD example /src/example
ADD scripts /src/scripts
RUN python setup.py develop

ADD Gruntfile.coffee /src/
RUN grunt

RUN make create_database
RUN make make_fixtures

EXPOSE 8000 8000

CMD ["./manage.py", "runserver", "0.0.0.0:8000"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ clean:
rm -f example.sqlite

create_database:
./manage.py syncdb --noinput
./manage.py makemigrations --noinput
./manage.py migrate --noinput
./manage.py createsuperuser --username=root --email=root@example.com --noinput

Expand All @@ -11,4 +11,4 @@ make_fixtures:
./manage.py create_posts
./manage.py create_photos

all: clean create_database make_fixtures
all: clean create_database make_fixtures
6 changes: 3 additions & 3 deletions example/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class UserSerializer(serializers.ModelSerializer):
posts = serializers.HyperlinkedIdentityField('posts', view_name='userpost-list', lookup_field='username')
posts = serializers.HyperlinkedIdentityField(view_name='userpost-list', lookup_field='username')

class Meta:
model = User
Expand All @@ -13,7 +13,7 @@ class Meta:

class PostSerializer(serializers.ModelSerializer):
author = UserSerializer(required=False)
photos = serializers.HyperlinkedIdentityField('photos', view_name='postphoto-list')
photos = serializers.HyperlinkedIdentityField(view_name='postphoto-list')
# author = serializers.HyperlinkedRelatedField(view_name='user-detail', lookup_field='username')

def get_validation_exclusions(self, *args, **kwargs):
Expand All @@ -26,7 +26,7 @@ class Meta:


class PhotoSerializer(serializers.ModelSerializer):
image = serializers.Field('image.url')
image = serializers.ReadOnlyField(source='image.url')

class Meta:
model = Photo
18 changes: 9 additions & 9 deletions example/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
from django.conf.urls import patterns, url, include
from django.conf.urls import url, include

from .api import UserList, UserDetail
from .api import PostList, PostDetail, UserPostList
from .api import PhotoList, PhotoDetail, PostPhotoList

user_urls = patterns('',
user_urls = [
url(r'^/(?P<username>[0-9a-zA-Z_-]+)/posts$', UserPostList.as_view(), name='userpost-list'),
url(r'^/(?P<username>[0-9a-zA-Z_-]+)$', UserDetail.as_view(), name='user-detail'),
url(r'^$', UserList.as_view(), name='user-list')
)
]

post_urls = patterns('',
post_urls = [
url(r'^/(?P<pk>\d+)/photos$', PostPhotoList.as_view(), name='postphoto-list'),
url(r'^/(?P<pk>\d+)$', PostDetail.as_view(), name='post-detail'),
url(r'^$', PostList.as_view(), name='post-list')
)
]

photo_urls = patterns('',
photo_urls = [
url(r'^/(?P<pk>\d+)$', PhotoDetail.as_view(), name='photo-detail'),
url(r'^$', PhotoList.as_view(), name='photo-list')
)
]

urlpatterns = patterns('',
urlpatterns = [
url(r'^users', include(user_urls)),
url(r'^posts', include(post_urls)),
url(r'^photos', include(photo_urls)),
)
]
37 changes: 24 additions & 13 deletions example/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Django settings for example project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_email@example.com'),
Expand Down Expand Up @@ -88,12 +87,27 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'm7^i&pc&^*nx*3y9ui%c68c(lcor-^3_-ma+qjk!5lz7c!wrts'

# 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': [
# insert your TEMPLATE_DIRS here
],
'APP_DIRS': True,
'OPTIONS': {
'debug': DEBUG,
'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.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
}]

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
Expand All @@ -110,12 +124,6 @@
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'example.wsgi.application'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -165,5 +173,8 @@

AUTH_USER_MODEL = 'api.User'

# Don't complain about leading slashes in URL patterns
SILENCED_SYSTEM_CHECKS = ['urls.W002']

# !!!!!This is for demonstration only!!!!!
AUTHENTICATION_BACKENDS = ['example.api.auth.AlwaysRootBackend']
12 changes: 6 additions & 6 deletions example/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url
from django.conf import settings

from django.views.generic import TemplateView
Expand All @@ -21,17 +21,17 @@ def get(self, request, *args, **kwargs):
return super(SimpleStaticView, self).get(request, *args, **kwargs)


urlpatterns = patterns('',
urlpatterns = [
url(r'^api/', include('example.api.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^(?P<template_name>\w+)$', SimpleStaticView.as_view(), name='example'),
url(r'^$', TemplateView.as_view(template_name='index.html')),
)
]

if settings.DEBUG:
from django.views.static import serve
urlpatterns += patterns('',
urlpatterns += [
url(r'^(?P<path>favicon\..*)$', serve, {'document_root': settings.STATIC_ROOT}),
url(r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:], serve, {'document_root': settings.MEDIA_ROOT}),
url(r'^%s(?P<path>.*)$' % settings.STATIC_URL[1:], 'django.contrib.staticfiles.views.serve', dict(insecure=True)),
)
url(r'^%s(?P<path>.*)$' % settings.STATIC_URL[1:], serve, dict(insecure=True)),
]
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Django>=1.7
djangorestframework<3.0
Django>=1.9
djangorestframework>=3.3
pillow

# Optional
Expand Down

0 comments on commit 091da77

Please sign in to comment.