Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New example project for the library #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.pyc
.DS_Store
*.egg-info
*.sqlite3
Empty file added example_project/README
Empty file.
12 changes: 12 additions & 0 deletions example_project/apps/mainsite/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sys
import os

__all__ = ['APPS_DIR','TOP_DIR']

# assume we are ./apps/mainsite/__init__.py
APPS_DIR = os.path.dirname(os.path.abspath(os.path.dirname(__file__)))
if APPS_DIR not in sys.path:
sys.path.insert(0, APPS_DIR)

# Path to the whole project (one level up from apps)
TOP_DIR = os.path.dirname(APPS_DIR)
Empty file.
172 changes: 172 additions & 0 deletions example_project/apps/mainsite/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import sys
import os

from mainsite import TOP_DIR


##
#
# Important Stuff
#
##

INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',

'mainsite',

# Include sky-Thumbnails in your project apps list
'sky_thumbnails',

'south',

'photos',
]

MIDDLEWARE_CLASSES = [
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'mainsite.urls'

SECRET_KEY = '{{secret_key}}'


##
#
# Templates
#
##

TEMPLATE_LOADERS = [
'jingo.Loader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]

TEMPLATE_DIRS = [
os.path.join(TOP_DIR, 'breakdown', 'templates'),
]

TEMPLATE_CONTEXT_PROCESSORS = [
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.request',
'django.contrib.messages.context_processors.messages',
]

JINGO_EXCLUDE_APPS = ('admin', 'registration', 'debug_toolbar')


##
#
# Static Files
#
##

STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

STATIC_ROOT = os.path.join(TOP_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(TOP_DIR, 'breakdown', 'static'),
]


##
#
# Media Files
#
##

MEDIA_ROOT = os.path.join(TOP_DIR, 'mediafiles')
MEDIA_URL = '/media/'


##
#
# Thumbnails Settings
#
##

THUMBNAILS_DELAYED_GENERATION = True
THUMBNAILS_DIRNAME = 'thumbnails'

##
#
# Fixtures
#
##

FIXTURE_DIRS = [
os.path.join(TOP_DIR, 'etc', 'fixtures'),
]


##
#
# Logging
#
##

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': [],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}


##
#
# Misc.
#
##

SITE_ID = 1

USE_I18N = False
USE_L10N = False
USE_TZ = True

##
#
# Import settings_local.
#
##

try:
from settings_local import *
except ImportError as e:
import sys
sys.stderr.write("no settings_local found, setting DEBUG=True...\n")
DEBUG = True
pass
47 changes: 47 additions & 0 deletions example_project/apps/mainsite/settings_local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# settings_local.py is for all instance specific settings


from settings import *
from mainsite import TOP_DIR

DEBUG = True
TEMPLATE_DEBUG = DEBUG

DEBUG_ERRORS = True
DEBUG_STATIC = True
DEBUG_MEDIA = True

TIME_ZONE = 'America/Los_Angeles'
LANGUAGE_CODE = 'en-us'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'thumbnails', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '/tmp/mysql.sock', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
'OPTIONS': {
"init_command": "SET storage_engine=InnoDB",
},
}
}

CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': '',
'TIMEOUT': 300,
'KEY_PREFIX': '',
'VERSION': 1,
}
}

# debug_toolbar settings
#MIDDLEWARE_CLASSES.insert(0, 'debug_toolbar.middleware.DebugToolbarMiddleware')
#INSTALLED_APPS.append('debug_toolbar')
#INTERNAL_IPS = (
# '127.0.0.1',
#)
#DEBUG_TOOLBAR_CONFIG = {'INTERCEPT_REDIRECTS': False}
38 changes: 38 additions & 0 deletions example_project/apps/mainsite/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib import admin


admin.autodiscover()
#make sure that any view/model/form imports occur AFTER admin.autodiscover

# Links to the admin site for uploading new photos and to the photos urls for viewing them
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^photos/', include('photos.urls')),
)

# Test URLs to allow you to see these pages while DEBUG is True
if getattr(settings, 'DEBUG_ERRORS', False):
urlpatterns = patterns('mainsite.views',
url(r'^error/404/$', 'error404', name='404'),
url(r'^error/500/$', 'error500', name='500'),
) + urlpatterns

# If DEBUG_MEDIA is set, have django serve anything in MEDIA_ROOT at MEDIA_URL
if getattr(settings, 'DEBUG_MEDIA', True):
media_url = getattr(settings, 'MEDIA_URL', '/media/').lstrip('/')
urlpatterns = patterns('',
url(r'^%s(?P<path>.*)$' % (media_url,), 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT
}),
) + urlpatterns

# If DEBUG_STATIC is set, have django serve up static files even if DEBUG=False
if getattr(settings, 'DEBUG_STATIC', True):
static_url = getattr(settings, 'STATIC_URL', '/static/').lstrip('/')
urlpatterns = patterns('',
url(r'^%s(?P<path>.*)' % (static_url,), 'django.contrib.staticfiles.views.serve', kwargs={
'insecure': True,
})
) + urlpatterns
41 changes: 41 additions & 0 deletions example_project/apps/mainsite/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from django import http
from django import template
from django.conf import settings
from django.template.response import SimpleTemplateResponse
from django.views.generic.base import TemplateView


##
#
# Error Handler Views
#
##

class Error404(TemplateView):
template_name = '404.html'

def render_to_response(self, context, **response_kwargs):
response_kwargs.update({'status': 404})
return super(Error404, self).render_to_response(context, **response_kwargs)
error404 = Error404.as_view()


class Error500(TemplateView):
template_name = '500.html'
response_class = SimpleTemplateResponse # Doesn't call context_processors (which could be where the 500 came from in the first place)

def get_context_data(self, **kwargs):
# We must add STATIC_URL manually because context_processors aren't being called
return {
'STATIC_URL': getattr(settings, 'STATIC_URL', '/static/'),
}

def render_to_response(self, context, **response_kwargs):
response_kwargs.update({'status': 500})
return self.response_class(
template=self.get_template_names(),
context=context,
**response_kwargs
)
error500 = Error500.as_view()

Empty file.
8 changes: 8 additions & 0 deletions example_project/apps/photos/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin
from photos.models import *

# For displaying the uploaded photos in the admin site
class PhotoAdmin(admin.ModelAdmin):
list_display = ('title', 'description', 'image')

admin.site.register(Photo, PhotoAdmin)
33 changes: 33 additions & 0 deletions example_project/apps/photos/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.db import models
from sky_thumbnails.fields import EnhancedImageField

# A simple photo model with title, description, and image fields
class Photo(models.Model):
title = models.CharField(
max_length = 200,
help_text = 'Title of the image',
)
description = models.CharField(
max_length = 500,
help_text = 'Description of the image',
)
# The EnhancedImageField will upload the photo into the uploads
# directory at the indicated resolution when you save the file.
# Smaller sizes (thumbnails) will be generated on-demand in the
# uploads/thumbnails directory.
image = EnhancedImageField(
verbose_name='Image of various sizes',
upload_to = 'uploads',

# (width, height) of original image. The image will be cropped
# if it does not match the indicated dimensions
process_source = dict(size=(300,300)),

thumbnails = {
# identifier for the size (can be anything you choose), again
# with the (width, height).
'medium': dict(size=(115,115)),
'small': dict(size=(80,80)),
'icon': dict(size=(30,30)),
}
)
18 changes: 18 additions & 0 deletions example_project/apps/photos/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.conf.urls.defaults import *
from photos.views import *

urlpatterns = patterns('',

# /photos/all shows all the photos
url(r'^all$',
view = AllPhotos.as_view(),
name = 'all_photos'
),

# /photos/id# shows an individual photo
url(r'^(?P<pk>\d+)$',
view = PhotoDetail.as_view(),
name = 'photo_detail'
),

)
12 changes: 12 additions & 0 deletions example_project/apps/photos/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.views.generic import *
from photos.models import Photo

# /photos/all shows all the photos
class AllPhotos(ListView):
model = Photo
template_name = 'allphotos.html'

# /photos/id# shows an individual photo
class PhotoDetail(DetailView):
model = Photo
template_name = 'photodetail.html'
Empty file.
Empty file.
Loading