Major refractor to move PYTHON_PATH to top-level repo dir

- PYTHON_PATH now should point to `root_dir` instead of `apps_dir`
- `manage.py` now lives at the root dir
- `config` is moved out to root dir
This commit is contained in:
Saurabh Kumar 2015-04-24 17:42:34 +05:30
parent 0cc9958635
commit 9f3116ba4c
23 changed files with 59 additions and 107 deletions

View File

@ -121,20 +121,16 @@ First make sure to create and activate a virtualenv_, then open a terminal at th
Then, create a PostgreSQL database and add the database configuration using the ``dj-database-url`` app pattern: ``postgres://db_owner:password@dbserver_ip:port/db_name`` either: Then, create a PostgreSQL database and add the database configuration using the ``dj-database-url`` app pattern: ``postgres://db_owner:password@dbserver_ip:port/db_name`` either:
* in the ``config.common.py`` setting file, * in the ``config.settings.common.py`` setting file,
* or in the env variable ``DATABASE_URL`` * or in the environment variable ``DATABASE_URL``
You can now run the usual Django ``migrate`` and ``runserver`` command::
You can now run the usual Django ``migrate`` and ``runserver`` command (replace ``yourapp`` with the name of the directory containing the Django project):: $ python manage.py migrate
$ python yourapp/manage.py migrate $ python manage.py runserver
$ python yourapp/manage.py runserver
The base app will run but you'll need to carry out a few steps to make the sign-up and login forms work. These are currently detailed in `issue #39`_.
.. _issue #39: https://github.com/pydanny/cookiecutter-django/issues/39
**Live reloading and Sass CSS compilation** **Live reloading and Sass CSS compilation**

View File

@ -21,7 +21,7 @@ module.exports = function (grunt) {
fonts: this.app + '/static/fonts', fonts: this.app + '/static/fonts',
images: this.app + '/static/images', images: this.app + '/static/images',
js: this.app + '/static/js', js: this.app + '/static/js',
manageScript: this.app + '/manage.py' manageScript: 'manage.py'
} }
}; };

View File

@ -1 +1 @@
web: gunicorn --pythonpath="$PWD/{{cookiecutter.repo_name}}" wsgi:application web: gunicorn config.wsgi:application

View File

@ -52,7 +52,7 @@ First make sure to create and activate a virtualenv_, then open a terminal at th
You can now run the ``runserver_plus`` command:: You can now run the ``runserver_plus`` command::
$ python {{cookiecutter.repo_name}}/manage.py runserver_plus $ python manage.py runserver_plus
The base app will run but you'll need to carry out a few steps to make the sign-up and login forms work. These are currently detailed in `issue #39`_. The base app will run but you'll need to carry out a few steps to make the sign-up and login forms work. These are currently detailed in `issue #39`_.
@ -103,15 +103,15 @@ Run these commands to deploy the project to Heroku:
heroku addons:add memcachier:dev heroku addons:add memcachier:dev
heroku config:set DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE heroku config:set DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE
heroku config:set DJANGO_SETTINGS_MODULE='config.production' heroku config:set DJANGO_SETTINGS_MODULE='config.settings.production'
heroku config:set DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE heroku config:set DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE
heroku config:set DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE heroku config:set DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE
heroku config:set DJANGO_AWS_STORAGE_BUCKET_NAME=YOUR_AWS_S3_BUCKET_NAME_HERE heroku config:set DJANGO_AWS_STORAGE_BUCKET_NAME=YOUR_AWS_S3_BUCKET_NAME_HERE
git push heroku master git push heroku master
heroku run python {{cookiecutter.repo_name}}/manage.py migrate heroku run python manage.py migrate
heroku run python {{cookiecutter.repo_name}}/manage.py createsuperuser heroku run python manage.py createsuperuser
heroku open heroku open
Dokku Dokku
@ -145,13 +145,13 @@ You can then deploy by running the following commands.
ssh -t dokku@yourservername.com dokku postgres:create {{cookiecutter.repo_name}}-postgres ssh -t dokku@yourservername.com dokku postgres:create {{cookiecutter.repo_name}}-postgres
ssh -t dokku@yourservername.com dokku postgres:link {{cookiecutter.repo_name}}-postgres {{cookiecutter.repo_name}} ssh -t dokku@yourservername.com dokku postgres:link {{cookiecutter.repo_name}}-postgres {{cookiecutter.repo_name}}
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_SETTINGS_MODULE='config.production' ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_SETTINGS_MODULE='config.settings.production'
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_STORAGE_BUCKET_NAME=YOUR_AWS_S3_BUCKET_NAME_HERE ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} DJANGO_AWS_STORAGE_BUCKET_NAME=YOUR_AWS_S3_BUCKET_NAME_HERE
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} SENDGRID_USERNAME=YOUR_SENDGRID_USERNAME ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} SENDGRID_USERNAME=YOUR_SENDGRID_USERNAME
ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} SENDGRID_PASSWORD=YOUR_SENDGRID_PASSWORD ssh -t dokku@yourservername.com dokku config:set {{cookiecutter.repo_name}} SENDGRID_PASSWORD=YOUR_SENDGRID_PASSWORD
ssh -t dokku@yourservername.com dokku run {{cookiecutter.repo_name}} python {{cookiecutter.repo_name}}/manage.py migrate ssh -t dokku@yourservername.com dokku run {{cookiecutter.repo_name}} python manage.py migrate
ssh -t dokku@yourservername.com dokku run {{cookiecutter.repo_name}} python {{cookiecutter.repo_name}}/manage.py createsuperuser ssh -t dokku@yourservername.com dokku run {{cookiecutter.repo_name}} python manage.py createsuperuser
When deploying via Dokku make sure you backup your database in some fashion as it is NOT done automatically. When deploying via Dokku make sure you backup your database in some fashion as it is NOT done automatically.

View File

@ -12,8 +12,8 @@ from __future__ import absolute_import, unicode_literals
import environ import environ
APPS_DIR = environ.Path(__file__) - 2 # one folder back (/a/b/ - 1 = /a/) ROOT_DIR = environ.Path(__file__) - 3 # (/a/b/myfile.py - 3 = /)
ROOT_DIR = APPS_DIR - 1 APPS_DIR = ROOT_DIR.path('{{ cookiecutter.repo_name }}')
env = environ.Env() env = environ.Env()
@ -44,7 +44,7 @@ THIRD_PARTY_APPS = (
# Apps specific for this project go here. # Apps specific for this project go here.
LOCAL_APPS = ( LOCAL_APPS = (
'users', # custom users app '{{ cookiecutter.repo_name }}.users', # custom users app
# Your stuff: custom apps go here # Your stuff: custom apps go here
) )
@ -66,7 +66,7 @@ MIDDLEWARE_CLASSES = (
# MIGRATIONS CONFIGURATION # MIGRATIONS CONFIGURATION
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
MIGRATION_MODULES = { MIGRATION_MODULES = {
'sites': 'contrib.sites.migrations' 'sites': '{{ cookiecutter.repo_name }}.contrib.sites.migrations'
} }
# DEBUG # DEBUG
@ -87,7 +87,6 @@ FIXTURE_DIRS = (
# EMAIL CONFIGURATION # EMAIL CONFIGURATION
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend') EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
# END EMAIL CONFIGURATION
# MANAGER CONFIGURATION # MANAGER CONFIGURATION
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -131,7 +130,6 @@ USE_L10N = True
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
USE_TZ = True USE_TZ = True
# END GENERAL CONFIGURATION
# TEMPLATE CONFIGURATION # TEMPLATE CONFIGURATION
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -192,10 +190,10 @@ MEDIA_URL = '/media/'
# URL Configuration # URL Configuration
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
ROOT_URLCONF = 'urls' ROOT_URLCONF = 'config.urls'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
WSGI_APPLICATION = 'wsgi.application' WSGI_APPLICATION = 'config.wsgi.application'
# AUTHENTICATION CONFIGURATION # AUTHENTICATION CONFIGURATION
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -208,7 +206,6 @@ AUTHENTICATION_BACKENDS = (
ACCOUNT_AUTHENTICATION_METHOD = 'username' ACCOUNT_AUTHENTICATION_METHOD = 'username'
ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory' ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
# END AUTHENTICATION CONFIGURATION
# Custom user app defaults # Custom user app defaults
# Select the correct user model # Select the correct user model

View File

@ -62,9 +62,9 @@ INSTALLED_APPS += (
STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID = env("DJANGO_AWS_ACCESS_KEY_ID") AWS_ACCESS_KEY_ID = env('DJANGO_AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = env("DJANGO_AWS_SECRET_ACCESS_KEY") AWS_SECRET_ACCESS_KEY = env('DJANGO_AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = env("DJANGO_AWS_STORAGE_BUCKET_NAME") AWS_STORAGE_BUCKET_NAME = env('DJANGO_AWS_STORAGE_BUCKET_NAME')
AWS_AUTO_CREATE_BUCKET = True AWS_AUTO_CREATE_BUCKET = True
AWS_QUERYSTRING_AUTH = False AWS_QUERYSTRING_AUTH = False
AWS_S3_CALLING_FORMAT = OrdinaryCallingFormat() AWS_S3_CALLING_FORMAT = OrdinaryCallingFormat()

View File

@ -6,28 +6,25 @@ from django.conf.urls import patterns, include, url
from django.conf.urls.static import static from django.conf.urls.static import static
from django.views.generic import TemplateView from django.views.generic import TemplateView
# Uncomment the next two lines to enable the admin: # Comment the next two lines to disable the admin:
from django.contrib import admin from django.contrib import admin
admin.autodiscover() admin.autodiscover()
urlpatterns = patterns('', urlpatterns = patterns('', # noqa
url(r'^$', # noqa url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name="home"),
TemplateView.as_view(template_name='pages/home.html'), url(r'^about/$', TemplateView.as_view(template_name='pages/about.html'), name="about"),
name="home"),
url(r'^about/$',
TemplateView.as_view(template_name='pages/about.html'),
name="about"),
# Uncomment the next line to enable the admin: # Django Admin (Comment the next line to disable the admin)
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
# User management # User management
url(r'^users/', include("users.urls", namespace="users")), url(r'^users/', include("{{ cookiecutter.repo_name }}.users.urls", namespace="users")),
url(r'^accounts/', include('allauth.urls')), url(r'^accounts/', include('allauth.urls')),
# Uncomment the next line to enable avatars # Uncomment the next line to enable avatars
url(r'^avatar/', include('avatar.urls')), url(r'^avatar/', include('avatar.urls')),
# Your stuff: custom urls go here # Your stuff: custom urls includes go here
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -18,8 +18,8 @@ import os
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use # if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use # mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "{{ repo_name }}.settings" # os.environ["DJANGO_SETTINGS_MODULE"] = "config.settings.production"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.production") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
# This application object is used by any WSGI server configured to use this # This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION # file. This includes Django's development server, if the WSGI_APPLICATION

View File

@ -35,6 +35,3 @@ else
pip install -r requirements/test.txt pip install -r requirements/test.txt
pip install -r requirements.txt pip install -r requirements.txt
fi fi

View File

@ -3,7 +3,7 @@ import os
import sys import sys
if __name__ == "__main__": if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.local") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line

View File

@ -1,24 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
setup(
name="{{ cookiecutter.project_name }}",
version="{{ cookiecutter.version }}",
author="{{ cookiecutter.author_name }}",
author_email="{{ cookiecutter.email }}",
packages=[
"{{ cookiecutter.repo_name }}",
],
include_package_data=True,
install_requires=[
"Django==1.7.6",
],
zip_safe=False,
scripts=["{{ cookiecutter.repo_name }}/manage.py"],
)

View File

@ -0,0 +1 @@
# -*- coding: utf-8 -*-

View File

@ -2,7 +2,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf import settings from django.conf import settings
from django.db import models, migrations from django.db import migrations
def update_site_forward(apps, schema_editor): def update_site_forward(apps, schema_editor):

View File

@ -0,0 +1 @@
# -*- coding: utf-8 -*-

View File

@ -1,8 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from django import forms from django import forms
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from .models import User from .models import User

View File

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from django import forms from django import forms
from .models import User from .models import User

View File

@ -1,31 +1,20 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from django.conf.urls import patterns, url from django.conf.urls import patterns, url
from users import views from . import views
urlpatterns = patterns('', urlpatterns = patterns('',
# URL pattern for the UserListView # noqa # URL pattern for the UserListView # noqa
url( url(regex=r'^$', view=views.UserListView.as_view(), name='list'),
regex=r'^$',
view=views.UserListView.as_view(),
name='list'
),
# URL pattern for the UserRedirectView # URL pattern for the UserRedirectView
url( url(regex=r'^~redirect/$', view=views.UserRedirectView.as_view(), name='redirect'),
regex=r'^~redirect/$',
view=views.UserRedirectView.as_view(),
name='redirect'
),
# URL pattern for the UserDetailView # URL pattern for the UserDetailView
url( url(regex=r'^(?P<username>[\w.@+-]+)/$', view=views.UserDetailView.as_view(), name='detail'),
regex=r'^(?P<username>[\w.@+-]+)/$',
view=views.UserDetailView.as_view(),
name='detail'
),
# URL pattern for the UserUpdateView # URL pattern for the UserUpdateView
url( url(regex=r'^~update/$', view=views.UserUpdateView.as_view(), name='update'),
regex=r'^~update/$',
view=views.UserUpdateView.as_view(),
name='update'
),
) )

View File

@ -1,20 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Import the reverse lookup function from __future__ import absolute_import, unicode_literals
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.views.generic import DetailView, ListView, RedirectView, UpdateView
# view imports
from django.views.generic import DetailView
from django.views.generic import RedirectView
from django.views.generic import UpdateView
from django.views.generic import ListView
# Only authenticated users can access views using this.
from braces.views import LoginRequiredMixin from braces.views import LoginRequiredMixin
# Import the form from users/forms.py
from .forms import UserForm from .forms import UserForm
# Import the customized User model
from .models import User from .models import User