Skip to content

Commit

Permalink
Provide example project integration (#28)
Browse files Browse the repository at this point in the history
Demonstrate basic integration of django-improved-user with
Django and django-registration.
  • Loading branch information
jambonrose authored Aug 23, 2017
1 parent db3e06a commit 791fb68
Show file tree
Hide file tree
Showing 28 changed files with 612 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Project Specific
example_project/db.sqlite3

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
4 changes: 3 additions & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ balanced_wrapping=true
combine_as_imports=true
force_add=true
include_trailing_comma=true
known_third_party=django
known_third_party=
django
registration
known_first_party=improved_user
indent=' '
line_length=79
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class-rgx=[A-Z_][a-zA-Z0-9]+$
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$

# Regular expression matching correct constant names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__)|urlpatterns|application)$

# Minimum line length for functions/classes that require docstrings, shorter
# ones are exempt.
Expand Down
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ before_script:
- if [[ `python -V | grep -c -e 3.6` -eq 1 && "$DJANGO" == 'django>=1.11,<1.12' ]]; then check-manifest . ; fi
- if [[ `python -V | grep -c -e 3.6` -eq 1 && "$DJANGO" == 'django>=1.11,<1.12' ]]; then flake8 src tests setup.py runtests.py ; fi
- if [[ `python -V | grep -c -e 3.6` -eq 1 && "$DJANGO" == 'django>=1.11,<1.12' ]]; then isort --verbose --check-only --diff --recursive src tests setup.py runtests.py ; fi
- if [[ `python -V | grep -c -e 3.6` -eq 1 && "$DJANGO" == 'django>=1.11,<1.12' ]]; then pylint --rcfile=.pylintrc -d fixme src tests setup.py runtests.py ; fi
- if [[ `python -V | grep -c -e 3.6` -eq 1 && "$DJANGO" == 'django>=1.11,<1.12' ]]; then pylint --rcfile=.pylintrc -d duplicate-code -d fixme src tests setup.py runtests.py ; fi
script:
# do not use setup.py test with coverage; missing files omitted entirely
- coverage run runtests.py
- cd example_project
- ./manage.py test
- cd .. # for coverage reports
after_success:
# coverage is run in parallel, so it is necessary to combine the reports
# Note that this is only for our benefit: codecov handles this itself
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ include setup.cfg
include tox.ini
prune .github
prune docs
prune example_project
recursive-include tests *.json
recursive-include tests *.py
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,10 @@ To run all linters and test multiple Python and Django versions, use
You will need to install Python 3.4, 3.5, and 3.6 on your system for
this to work.

You may also limit tests to specific environments or test suites with tox. For instance:

.. code:: console
$ tox -e py36-django111-unit tests.test_basic
$ tox -e py36-django111-integration user_integration.tests.TestViews.test_home
Empty file.
151 changes: 151 additions & 0 deletions example_project/config/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
"""
Django settings for config project.
Generated by 'django-admin startproject' using Django 1.11.3.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os

from django import VERSION as DjangoVersion

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ')#-l63lltqso!-&dz3r)xb&p#mz*s=dti_l@=1&ynd_3$+sw85'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'improved_user.apps.ImprovedUserConfig',
'user_integration.apps.UserIntegrationConfig',
]

if DjangoVersion >= (1, 10):
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',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
else:
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'config.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'config.wsgi.application'

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_USER_MODEL = 'improved_user.User'

LOGIN_REDIRECT_URL = 'home'
LOGIN_URL = LOGOUT_REDIRECT_URL = 'auth_login'

AUTH_PREFIX = 'django.contrib.auth.password_validation.'
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': AUTH_PREFIX + 'UserAttributeSimilarityValidator',
'OPTIONS': {
'user_attributes': ('email', 'full_name', 'short_name'),
},
},
{
'NAME': AUTH_PREFIX + 'MinimumLengthValidator',
'OPTIONS': {
'min_length': 12,
},
},
{
'NAME': AUTH_PREFIX + 'CommonPasswordValidator',
},
{
'NAME': AUTH_PREFIX + 'NumericPasswordValidator',
},
]

ACCOUNT_ACTIVATION_DAYS = 3


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'
26 changes: 26 additions & 0 deletions example_project/config/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""config URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
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 include, url
from django.contrib import admin
from django.views.generic import TemplateView

from user_integration import urls as account_urls

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^accounts/', include(account_urls)),
url(r'^$', TemplateView.as_view(template_name='home.html'), name='home'),
]
16 changes: 16 additions & 0 deletions example_project/config/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for config project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

application = get_wsgi_application()
22 changes: 22 additions & 0 deletions example_project/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Script that allows developers to run Django commands"""
import os
import sys

if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django # noqa: F401 pylint: disable=unused-import
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
'available on your PYTHONPATH environment variable? Did you '
'forget to activate a virtual environment?')
raise
execute_from_command_line(sys.argv)
Empty file.
7 changes: 7 additions & 0 deletions example_project/user_integration/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Application Definition File"""
from django.apps import AppConfig


class UserIntegrationConfig(AppConfig):
"""AppConfig definition for user integration code"""
name = 'user_integration'
15 changes: 15 additions & 0 deletions example_project/user_integration/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Django Improved User Test Project</title>
<meta name="description" content="A test Django project to demo key-features in django-improved-user.">
<meta name="author" content="JamBon Software">
<!--[if lt IE 9]>
<script src="https://cdn.jsdelivr.net/html5shiv/3.7.3/html5shiv.min.js"></script>
<![endif]-->
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
17 changes: 17 additions & 0 deletions example_project/user_integration/templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends parent_template|default:'base.html' %}
{% load i18n %}

{% block content %}
{% if user.is_authenticated %}
<p>{% blocktrans with name=user.get_short_name %}
Hello {{name}}!
{% endblocktrans %}</p>
<p><a href="{% url 'auth_logout' %}?next={{ request.path }}">
{% trans 'Log Out' %}</a></p>
{% else %}
<p><a href="{% url 'registration_register' %}">
{% trans 'Register' %}</a></p>
<p><a href="{% url 'auth_login' %}?next={{ request.path }}">
{% trans 'Log In' %}</a></p>
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends parent_template|default:'base.html' %}
{% load i18n %}

{% block content %}
<p>{% trans 'Your account is now activated.' %}</p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% load i18n %}
{% trans "Activate account at" %} {{ site.name }}:

http://{{ site.domain }}{% url 'registration_activate' activation_key %}

{% blocktrans %}Link is valid for {{ expiration_days }} days.{% endblocktrans %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% load i18n %}{% trans 'Account activation on' %} {{ site.name }}
19 changes: 19 additions & 0 deletions example_project/user_integration/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends parent_template|default:'base.html' %}
{% load i18n %}

{% block content %}
<p>
{% trans 'Not a member?' %}
<a href="{% url 'registration_register' %}">{% trans 'Register!' %}</a>
</p>
<form method="post" action=".">
<input type="hidden" name="next" value="{{ next }}" />
{% csrf_token %}
{{ form.as_p }}
<p>
{% trans 'Forgot password?' %}
<a href="{% url 'auth_password_reset' %}">{% trans 'Reset it!' %}</a>
</p>
<button type="submit">{% trans 'Log In' %}</button>
</form>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends parent_template|default:'base.html' %}
{% load i18n %}
{# Used only in Django 1.8, as LOGOUT_REDIRECT_URL setting added in 1.10 #}
{# TODO: delete this when Django 1.8 support dropped #}

{% block content %}
<p>{% trans 'Logged out' %}</p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends parent_template|default:'base.html' %}
{% load i18n %}

{% block content %}
<p>{% trans 'Email with password reset instructions has been sent.' %}</p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load i18n %}
{% blocktrans %}Reset password at {{ site_name }}{% endblocktrans %}:
{% block reset_link %}
{{ protocol }}://{{ domain }}{% url 'auth_password_reset_confirm' uid token %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends parent_template|default:'base.html' %}
{% load i18n %}

{% block content %}
<p>{% trans 'Your account is now activated.' %}</p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends parent_template|default:'base.html' %}
{% load i18n %}

{% block content %}
<form method="post" action="{% url 'registration_register' %}">
{% csrf_token %}
{{ form.as_p }}

<button type="submit">{% trans 'Register' %}</button>
</form>
{% endblock %}
Loading

0 comments on commit 791fb68

Please sign in to comment.