Skip to content

Commit 508b0b0

Browse files
committed
Adding doc and examples to publish v0.0.1 to pypi
1 parent 225ce31 commit 508b0b0

33 files changed

Lines changed: 418 additions & 45 deletions

‎.gitignore‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*,cover
46+
47+
# Translations
48+
#*.mo
49+
#*.pot
50+
51+
# Django stuff:
52+
*.log
53+
54+
# Sphinx documentation
55+
docs/_build/
56+
57+
# PyBuilder
58+
target/
59+
60+
# PyCharm
61+
.idea/
62+
63+
*.db
64+
*.sqlite3

‎Dockerfile‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM python:2.7
2+
3+
ENV PYTHONUNBUFFERED 1
4+
5+
RUN pip install "Django>=1.11.0,<1.12.0".
6+
7+
ADD ./example_project /app
8+
ADD ./variable_settings /packages/variable_settings
9+
10+
ENV PYTHONPATH /packages/
11+
WORKDIR /app
12+
13+
ENTRYPOINT ./docker-entrypoint.sh

‎MANIFEST.in‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include LICENSE
2+
include MANIFEST.in
3+
include README.md
4+
recursive-include variable_settings/*
5+
recursive-exclude * __pycache__
6+
recursive-exclude * *.py[co]

‎README.md‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# django-variable-settings
2+
3+
A simple django application to manage dynamic settings saved in database using namespaced keys and json string values.
4+
5+
## Demo
6+
7+
To try it now, download this repo and use docker-compose to run it
8+
9+
git clone git@github.com:jperelli/django-variable-settings.git
10+
cd django-variable-settings
11+
docker-compose up
12+
13+
Then go to http://localhost:8080/admin and login with user `admin` and password `admin`, you should see the Settings. If you add a settings, it should be a json object. So a string should be saved with double quotes around it.
14+
15+
It can be tested from django shell also easily. Go to another console while `docker-compose up` is running and type
16+
17+
docker-compose exec django ./manage.py shell
18+
>>> import variable_settings
19+
>>> variable_settings.set('evergreenstreet', 123)
20+
>>> variable_settings.set('address.evergreenstreet', 123)
21+
>>> variable_settings.set('address.evergreenavenue', 'first')
22+
>>> variable_settings.get('evergreenstreet')
23+
123
24+
>>> variable_settings.get('address.evergreenavenue')
25+
u'first'
26+
>>> variable_settings.get('address.*')
27+
{u'address.evergreenavenue': u'first', u'address.evergreenstreet': 123}
28+
>>> variable_settings.all()
29+
{u'address.evergreenavenue': u'first', u'evergreenstreet': 123, u'address.evergreenstreet': 123}
30+
31+
## Installation
32+
33+
pip install django-variable-settings
34+
35+
In settings.py add
36+
37+
variable_settings
38+
39+
Then run migrations
40+
41+
manage.py migrate variable_settings
42+
43+
Then use it as in the Demo
44+
45+
## Settings and custom command
46+
47+
If you want to add some default settings to the database then you can add something like this to `settings.py`
48+
49+
# default django_variable_settings
50+
# use ./manage.py variable_settings_initialize
51+
# If overwrite=False(default) they are not applied if already exist in database
52+
VARIABLE_SETTINGS = [
53+
#[ key , value (, overwrite) ]
54+
['alerting.connection', '127.0.0.1', False],
55+
['alerting.warning', 123, False],
56+
['wrong_permissions.enabled', True, True],
57+
]
58+
59+
Use custom command `./manage.py variable_settings_initialize` to save those in database. The command only overwrites the variable value if the last parameter is set to true
60+
61+
## Caching
62+
63+
WIP
64+
65+
# Authors
66+
67+
- Julian Perelli
68+
- Maxi Padulo
69+
70+
# LICENSE
71+
72+
MIT

‎docker-compose.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
django:
2+
build: .
3+
ports:
4+
- "0.0.0.0:8080:8080"
5+
command: python manage.py runserver 0.0.0.0:8080
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
python manage.py migrate
2+
echo "from django.contrib.auth.models import User; User.objects.filter(email='admin@example.com').delete(); User.objects.create_superuser('admin', 'admin@example.com', 'admin')" | python manage.py shell
3+
python manage.py runserver 0.0.0.0:8080

management/__init__.py renamed to example_project/example_project/__init__.py

File renamed without changes.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
"""
2+
Django settings for example_project project.
3+
4+
Generated by 'django-admin startproject' using Django 1.11.12.
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 = 'w94-@sp+l334vx&qpamf+&n#+&(5ylm!7*a#6%*cuc+vdx_7b-'
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.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
'variable_settings',
41+
]
42+
43+
MIDDLEWARE = [
44+
'django.middleware.security.SecurityMiddleware',
45+
'django.contrib.sessions.middleware.SessionMiddleware',
46+
'django.middleware.common.CommonMiddleware',
47+
'django.middleware.csrf.CsrfViewMiddleware',
48+
'django.contrib.auth.middleware.AuthenticationMiddleware',
49+
'django.contrib.messages.middleware.MessageMiddleware',
50+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
51+
]
52+
53+
ROOT_URLCONF = 'example_project.urls'
54+
55+
TEMPLATES = [
56+
{
57+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
58+
'DIRS': [],
59+
'APP_DIRS': True,
60+
'OPTIONS': {
61+
'context_processors': [
62+
'django.template.context_processors.debug',
63+
'django.template.context_processors.request',
64+
'django.contrib.auth.context_processors.auth',
65+
'django.contrib.messages.context_processors.messages',
66+
],
67+
},
68+
},
69+
]
70+
71+
WSGI_APPLICATION = 'example_project.wsgi.application'
72+
73+
74+
# Database
75+
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
76+
77+
DATABASES = {
78+
'default': {
79+
'ENGINE': 'django.db.backends.sqlite3',
80+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
81+
}
82+
}
83+
84+
85+
# Password validation
86+
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
87+
88+
AUTH_PASSWORD_VALIDATORS = [
89+
{
90+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
91+
},
92+
{
93+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
94+
},
95+
{
96+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
97+
},
98+
{
99+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
100+
},
101+
]
102+
103+
104+
# Internationalization
105+
# https://docs.djangoproject.com/en/1.11/topics/i18n/
106+
107+
LANGUAGE_CODE = 'en-us'
108+
109+
TIME_ZONE = 'UTC'
110+
111+
USE_I18N = True
112+
113+
USE_L10N = True
114+
115+
USE_TZ = True
116+
117+
118+
# Static files (CSS, JavaScript, Images)
119+
# https://docs.djangoproject.com/en/1.11/howto/static-files/
120+
121+
STATIC_URL = '/static/'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""example_project 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 include, url
17+
from django.contrib import admin
18+
19+
urlpatterns = [
20+
url(r'^polls/', include('polls.urls')),
21+
url(r'^admin/', admin.site.urls),
22+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for example_project 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_project.settings")
15+
16+
application = get_wsgi_application()

0 commit comments

Comments
 (0)