Skip to content

Commit d6f88bf

Browse files
committed
Add example app
1 parent 1df2365 commit d6f88bf

10 files changed

+229
-2
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ target/
5858

5959
# Pycharm:
6060
.idea
61+
62+
# Database
63+
*.sqlite3

Dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM python:3
2+
3+
# Install system dependencies
4+
RUN apt-get update && apt-get install -y \
5+
gettext && \
6+
pip install Django
7+
8+
# Install bananas source
9+
WORKDIR /usr/src
10+
COPY . django-bananas
11+
RUN pip install -e django-bananas && \
12+
rm -rf /usr/src/django-bananas/example && \
13+
mkdir /app
14+
15+
# Install example app
16+
WORKDIR /app
17+
COPY example ./
18+
19+
ENTRYPOINT ["python3", "manage.py"]

Makefile

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,17 @@ install:
2222
develop:
2323
python setup.py develop
2424

25+
.PHONY: example
26+
example:
27+
docker-compose up -d
28+
docker-compose run --rm django migrate --no-input
29+
docker-compose run --rm django createsuperuser \
30+
--username admin \
31+
32+
2533
.PHONY: clean
2634
clean:
27-
rm -rf dist/ *.egg *.egg-info .coverage .coverage.*
35+
rm -rf dist/ *.egg *.egg-info .coverage .coverage.* example/db.sqlite3
2836

2937
.PHONY: all # runs clean, test, lint
3038
all: clean test lint

docker-compose.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "3.3"
2+
3+
services:
4+
django:
5+
build: .
6+
command: ["runserver", "0.0.0.0:8000"]
7+
stdin_open: true
8+
tty: true
9+
ports:
10+
- "8000:8000"
11+
volumes:
12+
- ./bananas:/usr/src/django-bananas/bananas
13+
- ./example:/app

example/example/__init__.py

Whitespace-only changes.

example/example/settings.py

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
"""
2+
Django settings for example project.
3+
4+
Generated by 'django-admin startproject' using Django 1.11.5.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.11/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/1.11/ref/settings/
11+
"""
12+
13+
import os
14+
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = ')-9=nktek1%^x7tvw5bttxhz&_ke+q=b%c@m@u13d#_y=5z+kx'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = ['*']
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'django.contrib.auth',
35+
'django.contrib.contenttypes',
36+
# 'django.contrib.sessions',
37+
'django.contrib.messages',
38+
'django.contrib.staticfiles',
39+
40+
'bananas',
41+
42+
'django.contrib.admin',
43+
]
44+
45+
MIDDLEWARE = [
46+
'django.middleware.security.SecurityMiddleware',
47+
'django.contrib.sessions.middleware.SessionMiddleware',
48+
'django.middleware.common.CommonMiddleware',
49+
'django.middleware.csrf.CsrfViewMiddleware',
50+
'django.contrib.auth.middleware.AuthenticationMiddleware',
51+
'django.contrib.messages.middleware.MessageMiddleware',
52+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
53+
]
54+
55+
SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies'
56+
57+
ROOT_URLCONF = 'example.urls'
58+
59+
TEMPLATES = [
60+
{
61+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
62+
'DIRS': [],
63+
'APP_DIRS': True,
64+
'OPTIONS': {
65+
'context_processors': [
66+
'django.template.context_processors.debug',
67+
'django.template.context_processors.request',
68+
'django.contrib.auth.context_processors.auth',
69+
'django.contrib.messages.context_processors.messages',
70+
],
71+
},
72+
},
73+
]
74+
75+
WSGI_APPLICATION = 'example.wsgi.application'
76+
77+
78+
# Database
79+
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
80+
81+
DATABASES = {
82+
'default': {
83+
'ENGINE': 'django.db.backends.sqlite3',
84+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
85+
}
86+
}
87+
88+
89+
# Password validation
90+
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
91+
92+
AUTH_PASSWORD_VALIDATORS = [
93+
{
94+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
95+
},
96+
{
97+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
98+
},
99+
{
100+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
101+
},
102+
{
103+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
104+
},
105+
]
106+
107+
108+
# Internationalization
109+
# https://docs.djangoproject.com/en/1.11/topics/i18n/
110+
111+
LANGUAGE_CODE = 'en-us'
112+
113+
TIME_ZONE = 'UTC'
114+
115+
USE_I18N = True
116+
117+
USE_L10N = True
118+
119+
USE_TZ = True
120+
121+
122+
# Static files (CSS, JavaScript, Images)
123+
# https://docs.djangoproject.com/en/1.11/howto/static-files/
124+
125+
STATIC_URL = '/static/'

example/example/urls.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""example URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/1.11/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.conf.urls import url, include
14+
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
15+
"""
16+
from django.conf.urls import url
17+
from bananas import admin
18+
19+
urlpatterns = [
20+
url(r'^', admin.site.urls),
21+
]

example/example/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for example project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
15+
16+
application = get_wsgi_application()

example/manage.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
7+
try:
8+
from django.core.management import execute_from_command_line
9+
except ImportError:
10+
# The above import may fail for some other reason. Ensure that the
11+
# issue is really that Django is missing to avoid masking other
12+
# exceptions on Python 2.
13+
try:
14+
import django
15+
except ImportError:
16+
raise ImportError(
17+
"Couldn't import Django. Are you sure it's installed and "
18+
"available on your PYTHONPATH environment variable? Did you "
19+
"forget to activate a virtual environment?"
20+
)
21+
raise
22+
execute_from_command_line(sys.argv)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
long_description=long_description,
2121
url='https://github.com/5monkeys/django-bananas',
2222
version=__import__('bananas').__version__,
23-
packages=find_packages(exclude=['tests', '_*']),
23+
packages=find_packages(exclude=['tests', '_*', 'example']),
2424
include_package_data=True,
2525
zip_safe=False,
2626
install_requires=[],

0 commit comments

Comments
 (0)