diff --git a/.gitignore b/.gitignore index c733221..0a83231 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.pyc .DS_Store *.egg-info +*.sqlite3 diff --git a/example_project/README b/example_project/README new file mode 100644 index 0000000..e69de29 diff --git a/example_project/apps/mainsite/__init__.py b/example_project/apps/mainsite/__init__.py new file mode 100644 index 0000000..ce29064 --- /dev/null +++ b/example_project/apps/mainsite/__init__.py @@ -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) diff --git a/example_project/apps/mainsite/admin.py b/example_project/apps/mainsite/admin.py new file mode 100644 index 0000000..e69de29 diff --git a/example_project/apps/mainsite/settings.py b/example_project/apps/mainsite/settings.py new file mode 100644 index 0000000..84dc94a --- /dev/null +++ b/example_project/apps/mainsite/settings.py @@ -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 diff --git a/example_project/apps/mainsite/settings_local.py b/example_project/apps/mainsite/settings_local.py new file mode 100644 index 0000000..d211bc5 --- /dev/null +++ b/example_project/apps/mainsite/settings_local.py @@ -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} diff --git a/example_project/apps/mainsite/urls.py b/example_project/apps/mainsite/urls.py new file mode 100644 index 0000000..fcc4409 --- /dev/null +++ b/example_project/apps/mainsite/urls.py @@ -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.*)$' % (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.*)' % (static_url,), 'django.contrib.staticfiles.views.serve', kwargs={ + 'insecure': True, + }) + ) + urlpatterns diff --git a/example_project/apps/mainsite/views.py b/example_project/apps/mainsite/views.py new file mode 100644 index 0000000..49552d2 --- /dev/null +++ b/example_project/apps/mainsite/views.py @@ -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() + diff --git a/example_project/apps/photos/__init__.py b/example_project/apps/photos/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/example_project/apps/photos/admin.py b/example_project/apps/photos/admin.py new file mode 100644 index 0000000..d6650ff --- /dev/null +++ b/example_project/apps/photos/admin.py @@ -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) \ No newline at end of file diff --git a/example_project/apps/photos/models.py b/example_project/apps/photos/models.py new file mode 100644 index 0000000..83dedb6 --- /dev/null +++ b/example_project/apps/photos/models.py @@ -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)), + } + ) \ No newline at end of file diff --git a/example_project/apps/photos/urls.py b/example_project/apps/photos/urls.py new file mode 100644 index 0000000..5bb4b8b --- /dev/null +++ b/example_project/apps/photos/urls.py @@ -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\d+)$', + view = PhotoDetail.as_view(), + name = 'photo_detail' + ), + +) \ No newline at end of file diff --git a/example_project/apps/photos/views.py b/example_project/apps/photos/views.py new file mode 100644 index 0000000..c6ab1f4 --- /dev/null +++ b/example_project/apps/photos/views.py @@ -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' \ No newline at end of file diff --git a/example_project/breakdown/static/.gitignore b/example_project/breakdown/static/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/example_project/breakdown/templates/.gitignore b/example_project/breakdown/templates/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/example_project/breakdown/templates/404.html b/example_project/breakdown/templates/404.html new file mode 100644 index 0000000..bfc3781 --- /dev/null +++ b/example_project/breakdown/templates/404.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} + +{% block content %} +

The page you requested could not be found.

+{% endblock %} diff --git a/example_project/breakdown/templates/500.html b/example_project/breakdown/templates/500.html new file mode 100644 index 0000000..b8a824f --- /dev/null +++ b/example_project/breakdown/templates/500.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} + +{% block content %} +

We're sorry, an error has occurred.

+{% endblock %} diff --git a/example_project/breakdown/templates/allphotos.html b/example_project/breakdown/templates/allphotos.html new file mode 100644 index 0000000..67420dd --- /dev/null +++ b/example_project/breakdown/templates/allphotos.html @@ -0,0 +1,47 @@ +{% extends "base.html" %} + +{% block content %} + + + + + + + + + + + {% for photo in object_list %} + + {% if photo %} + + + {% if photo.image.medium %} + + {% endif %} + {% if photo.image.small %} + + {% endif %} + {% if photo.image.icon %} + + {% endif %} + + {% endif %} + + {% endfor %} + +
Full ImageMedium ImageSmall ImageIcon Image
+ + Full image + + + Medium image + + + Small image + + + Icon image +
+ +{% endblock %} diff --git a/example_project/breakdown/templates/base.html b/example_project/breakdown/templates/base.html new file mode 100644 index 0000000..2c5aa8d --- /dev/null +++ b/example_project/breakdown/templates/base.html @@ -0,0 +1,17 @@ + + + + {% block head %} + + + {% block page_title %}{% endblock %} + {% endblock %} + + + {% block body %} + + {% block content %}{% endblock %} + + {% endblock %} + + diff --git a/example_project/breakdown/templates/photodetail.html b/example_project/breakdown/templates/photodetail.html new file mode 100644 index 0000000..d324e24 --- /dev/null +++ b/example_project/breakdown/templates/photodetail.html @@ -0,0 +1,47 @@ +{% extends "base.html" %} + +{% block content %} + + {% if photo.image %} +

{{ photo.title }}

+ + + + + + + + + + + + + + + {% if photo.image.medium %} + + {% endif %} + {% if photo.image.small %} + + {% endif %} + {% if object.image.icon %} + + {% endif %} + + + + {% endif %} + +{% endblock %} diff --git a/example_project/local.sqlite3 b/example_project/local.sqlite3 new file mode 100644 index 0000000..e69de29 diff --git a/example_project/manage.py b/example_project/manage.py new file mode 100755 index 0000000..0e07a86 --- /dev/null +++ b/example_project/manage.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +import sys +import os + +# assume 'apps' is a directory with same parent directory as us +APPS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), 'apps')) +if APPS_DIR not in sys.path: + sys.path.insert(0, APPS_DIR) + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mainsite.settings") + from django.core.management import execute_from_command_line + execute_from_command_line(sys.argv) \ No newline at end of file diff --git a/example_project/mediafiles/uploads/2808498c-9b3c-4b92-82f8-6bd39d270813.jpg b/example_project/mediafiles/uploads/2808498c-9b3c-4b92-82f8-6bd39d270813.jpg new file mode 100644 index 0000000..bf37845 Binary files /dev/null and b/example_project/mediafiles/uploads/2808498c-9b3c-4b92-82f8-6bd39d270813.jpg differ diff --git a/example_project/mediafiles/uploads/Footprint_Apollo_11_Satellite_Photo.jpg b/example_project/mediafiles/uploads/Footprint_Apollo_11_Satellite_Photo.jpg new file mode 100644 index 0000000..56942c1 Binary files /dev/null and b/example_project/mediafiles/uploads/Footprint_Apollo_11_Satellite_Photo.jpg differ diff --git a/example_project/mediafiles/uploads/Tannensee-by-Philippe-Sainte-Laudy.jpg b/example_project/mediafiles/uploads/Tannensee-by-Philippe-Sainte-Laudy.jpg new file mode 100644 index 0000000..daba5cf Binary files /dev/null and b/example_project/mediafiles/uploads/Tannensee-by-Philippe-Sainte-Laudy.jpg differ diff --git a/example_project/mediafiles/uploads/thumbnails/2808498c-9b3c-4b92-82f8-6bd39d270813.icon.jpg b/example_project/mediafiles/uploads/thumbnails/2808498c-9b3c-4b92-82f8-6bd39d270813.icon.jpg new file mode 100644 index 0000000..6f376da Binary files /dev/null and b/example_project/mediafiles/uploads/thumbnails/2808498c-9b3c-4b92-82f8-6bd39d270813.icon.jpg differ diff --git a/example_project/mediafiles/uploads/thumbnails/2808498c-9b3c-4b92-82f8-6bd39d270813.medium.jpg b/example_project/mediafiles/uploads/thumbnails/2808498c-9b3c-4b92-82f8-6bd39d270813.medium.jpg new file mode 100644 index 0000000..bcb0724 Binary files /dev/null and b/example_project/mediafiles/uploads/thumbnails/2808498c-9b3c-4b92-82f8-6bd39d270813.medium.jpg differ diff --git a/example_project/mediafiles/uploads/thumbnails/2808498c-9b3c-4b92-82f8-6bd39d270813.small.jpg b/example_project/mediafiles/uploads/thumbnails/2808498c-9b3c-4b92-82f8-6bd39d270813.small.jpg new file mode 100644 index 0000000..e028df4 Binary files /dev/null and b/example_project/mediafiles/uploads/thumbnails/2808498c-9b3c-4b92-82f8-6bd39d270813.small.jpg differ diff --git a/example_project/mediafiles/uploads/thumbnails/Footprint_Apollo_11_Satellite_Photo.icon.jpg b/example_project/mediafiles/uploads/thumbnails/Footprint_Apollo_11_Satellite_Photo.icon.jpg new file mode 100644 index 0000000..b01fa1f Binary files /dev/null and b/example_project/mediafiles/uploads/thumbnails/Footprint_Apollo_11_Satellite_Photo.icon.jpg differ diff --git a/example_project/mediafiles/uploads/thumbnails/Footprint_Apollo_11_Satellite_Photo.medium.jpg b/example_project/mediafiles/uploads/thumbnails/Footprint_Apollo_11_Satellite_Photo.medium.jpg new file mode 100644 index 0000000..8fae36e Binary files /dev/null and b/example_project/mediafiles/uploads/thumbnails/Footprint_Apollo_11_Satellite_Photo.medium.jpg differ diff --git a/example_project/mediafiles/uploads/thumbnails/Footprint_Apollo_11_Satellite_Photo.small.jpg b/example_project/mediafiles/uploads/thumbnails/Footprint_Apollo_11_Satellite_Photo.small.jpg new file mode 100644 index 0000000..8222496 Binary files /dev/null and b/example_project/mediafiles/uploads/thumbnails/Footprint_Apollo_11_Satellite_Photo.small.jpg differ diff --git a/example_project/mediafiles/uploads/thumbnails/Tannensee-by-Philippe-Sainte-Laudy.icon.jpg b/example_project/mediafiles/uploads/thumbnails/Tannensee-by-Philippe-Sainte-Laudy.icon.jpg new file mode 100644 index 0000000..b9eeb54 Binary files /dev/null and b/example_project/mediafiles/uploads/thumbnails/Tannensee-by-Philippe-Sainte-Laudy.icon.jpg differ diff --git a/example_project/mediafiles/uploads/thumbnails/Tannensee-by-Philippe-Sainte-Laudy.medium.jpg b/example_project/mediafiles/uploads/thumbnails/Tannensee-by-Philippe-Sainte-Laudy.medium.jpg new file mode 100644 index 0000000..c6a789e Binary files /dev/null and b/example_project/mediafiles/uploads/thumbnails/Tannensee-by-Philippe-Sainte-Laudy.medium.jpg differ diff --git a/example_project/mediafiles/uploads/thumbnails/Tannensee-by-Philippe-Sainte-Laudy.small.jpg b/example_project/mediafiles/uploads/thumbnails/Tannensee-by-Philippe-Sainte-Laudy.small.jpg new file mode 100644 index 0000000..add7d02 Binary files /dev/null and b/example_project/mediafiles/uploads/thumbnails/Tannensee-by-Philippe-Sainte-Laudy.small.jpg differ diff --git a/example_project/requirements.txt b/example_project/requirements.txt new file mode 100644 index 0000000..d29b90b --- /dev/null +++ b/example_project/requirements.txt @@ -0,0 +1,16 @@ +Django==1.5.1 +MySQL-python==1.2.3 +pytz==2013b +Pillow==1.7.8 + +South==0.7.6 + +# sky-thumbnails +git+ssh://git@github.com/concentricsky/django-skythumbnails.git@v0.2.2 +cropresize==0.1.6 + +# Common Dependencies +Jinja2==2.6 +git+ssh://git@github.com/concentricsky/jingo.git +git+ssh://git@github.com/concentricsky/django-cachemodel.git +git+ssh://git@github.com/concentricsky/django-basic-models.git
Full ImageMedium ImageSmall ImageIcon Image
+ + Full image + + + Medium image + + + Small image + + + Icon image +