From a9b307c9e2670c044a97f2961206404b0c1d517d Mon Sep 17 00:00:00 2001 From: Sigurd Gartmann Date: Tue, 7 Jun 2016 22:24:48 +0200 Subject: [PATCH 01/10] Upgrade to Django 1.9 --- django-jquery-file-upload/settings.py | 194 +++++++----------- django-jquery-file-upload/urls.py | 22 +- django-jquery-file-upload/wsgi.py | 11 + fileupload/apps.py | 6 + fileupload/migrations/0001_initial.py | 24 +++ fileupload/migrations/__init__.py | 0 fileupload/models.py | 2 +- .../fileupload/picture_angular_form.html | 36 ++-- .../fileupload/picture_basic_form.html | 12 +- .../fileupload/picture_basicplus_form.html | 26 +-- .../templates/fileupload/picture_form.html | 38 ++-- .../fileupload/picture_jquery_form.html | 40 ++-- fileupload/templates/upload_base.html | 8 +- fileupload/urls.py | 6 +- 14 files changed, 202 insertions(+), 223 deletions(-) create mode 100644 django-jquery-file-upload/wsgi.py create mode 100644 fileupload/apps.py create mode 100644 fileupload/migrations/0001_initial.py create mode 100644 fileupload/migrations/__init__.py diff --git a/django-jquery-file-upload/settings.py b/django-jquery-file-upload/settings.py index d7e49bd..d27d9db 100644 --- a/django-jquery-file-upload/settings.py +++ b/django-jquery-file-upload/settings.py @@ -1,149 +1,95 @@ +""" +Django settings. +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '9%$in^gpdaig@v3or_to&_z(=n)3)$f1mr3hf9e#kespy2ajlo' + +# SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -TEMPLATE_DEBUG = DEBUG -SITE_ROOT = os.path.dirname(os.path.realpath(__file__)) +ALLOWED_HOSTS = [] + +# Application definition -ADMINS = ( - # ('Your Name', 'your_email@example.com'), +INSTALLED_APPS = ( + 'fileupload.apps.FileuploadConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +) + +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', ) -MANAGERS = ADMINS +ROOT_URLCONF = 'django-jquery-file-upload.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + #'DIRS': ['django-jquery-file-upload/templates'], + '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 = 'django-jquery-file-upload.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.8/ref/settings/#databases DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': os.path.join(SITE_ROOT, 'db'), # Or path to database file if using sqlite3. - 'USER': '', # Not used with sqlite3. - 'PASSWORD': '', # Not used with sqlite3. - 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. - 'PORT': '', # Set to empty string for default. Not used with sqlite3. + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db'), } } -# Local time zone for this installation. Choices can be found here: -# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -# although not all choices may be available on all operating systems. -# On Unix systems, a value of None will cause Django to use the same -# timezone as the operating system. -# If running in a Windows environment this must be set to the same as your -# system time zone. -TIME_ZONE = 'America/Chicago' - -# Language code for this installation. All choices can be found here: -# http://www.i18nguy.com/unicode/language-identifiers.html + +# Internationalization +# https://docs.djangoproject.com/en/1.8/topics/i18n/ + LANGUAGE_CODE = 'en-us' -SITE_ID = 1 +TIME_ZONE = 'Europe/Oslo' -# If you set this to False, Django will make some optimizations so as not -# to load the internationalization machinery. USE_I18N = True -# If you set this to False, Django will not format dates, numbers and -# calendars according to the current locale USE_L10N = True -# Absolute filesystem path to the directory that will hold user-uploaded files. -# Example: "/home/media/media.lawrence.com/media/" -MEDIA_ROOT = os.path.abspath(os.path.dirname(__file__)) + '/media/' +USE_TZ = True -# URL that handles the media served from MEDIA_ROOT. Make sure to use a -# trailing slash. -# Examples: "http://media.lawrence.com/media/", "http://example.com/media/" -MEDIA_URL = '/media/' - -# Absolute path to the directory static files should be collected to. -# Don't put anything in this directory yourself; store your static files -# in apps' "static/" subdirectories and in STATICFILES_DIRS. -# Example: "/home/media/media.lawrence.com/static/" -STATIC_ROOT = os.path.abspath(os.path.dirname(__file__)) + '/static/' -# URL prefix for static files. -# Example: "http://media.lawrence.com/static/" +# Static files (CSS, JavaScript, Images) STATIC_URL = '/static/' -# URL prefix for admin static files -- CSS, JavaScript and images. -# Make sure to use a trailing slash. -# Examples: "http://foo.com/static/admin/", "/static/admin/". -ADMIN_MEDIA_PREFIX = '/static/admin/' - -# Additional locations of static files -STATICFILES_DIRS = ( - # Put strings here, like "/home/html/static" or "C:/www/django/static". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. -) +STATICFILES_DIRS = [ + 'django-jquery-file-upload/static', +] -# List of finder classes that know how to find static files in -# various locations. -STATICFILES_FINDERS = ( - 'django.contrib.staticfiles.finders.FileSystemFinder', - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', -# 'django.contrib.staticfiles.finders.DefaultStorageFinder', -) - -# Make this unique, and don't share it with anybody. -SECRET_KEY = '9%$in^gpdaig@v3or_to&_z(=n)3)$f1mr3hf9e#kespy2ajlo' - -# List of callables that know how to import templates from various sources. -TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', -# 'django.template.loaders.eggs.Loader', -) - -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.contrib.auth.middleware.SessionAuthenticationMiddleware', -) - -ROOT_URLCONF = 'django-jquery-file-upload.urls' - -TEMPLATE_DIRS = ( - # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. -) - -INSTALLED_APPS = ( - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.sites', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'fileupload', - # Uncomment the next line to enable the admin: - 'django.contrib.admin', - # Uncomment the next line to enable admin documentation: - # 'django.contrib.admindocs', -) - -# A sample logging configuration. The only tangible logging -# performed by this configuration is to send an email to -# the site admins on every HTTP 500 error. -# See http://docs.djangoproject.com/en/dev/topics/logging for -# more details on how to customize your logging configuration. -LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'handlers': { - 'mail_admins': { - 'level': 'ERROR', - 'class': 'django.utils.log.AdminEmailHandler' - } - }, - 'loggers': { - 'django.request': { - 'handlers': ['mail_admins'], - 'level': 'ERROR', - 'propagate': True, - }, - } -} +MEDIA_URL = '/media/' +MEDIA_ROOT = os.path.join(BASE_DIR, 'django-jquery-file-upload', 'media') diff --git a/django-jquery-file-upload/urls.py b/django-jquery-file-upload/urls.py index 7072912..53f314a 100644 --- a/django-jquery-file-upload/urls.py +++ b/django-jquery-file-upload/urls.py @@ -1,25 +1,17 @@ -from django.conf.urls import patterns, include, url +from django.conf.urls import include, url from django.http import HttpResponseRedirect +from django.conf import settings # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() -urlpatterns = patterns('', - # Examples: - # url(r'^$', 'upload.views.home', name='home'), - +urlpatterns = [ url(r'^$', lambda x: HttpResponseRedirect('/upload/new/')), url(r'^upload/', include('fileupload.urls')), - - # Uncomment the admin/doc line below to enable admin documentation: - # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), - - # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), -) +] -from os.path import join, abspath, dirname -urlpatterns += patterns('', - (r'^media/(.*)$', 'django.views.static.serve', {'document_root': join(abspath(dirname(__file__)), 'media')}), -) +if settings.DEBUG: + from django.conf.urls.static import static + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/django-jquery-file-upload/wsgi.py b/django-jquery-file-upload/wsgi.py new file mode 100644 index 0000000..8e47fba --- /dev/null +++ b/django-jquery-file-upload/wsgi.py @@ -0,0 +1,11 @@ +""" +WSGI config for django-jquery-file-upload project. +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django-jquery-file-upload.settings") + +application = get_wsgi_application() diff --git a/fileupload/apps.py b/fileupload/apps.py new file mode 100644 index 0000000..ff22d3e --- /dev/null +++ b/fileupload/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class FileuploadConfig(AppConfig): + name = 'fileupload' + diff --git a/fileupload/migrations/0001_initial.py b/fileupload/migrations/0001_initial.py new file mode 100644 index 0000000..0c157ef --- /dev/null +++ b/fileupload/migrations/0001_initial.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-06-07 19:15 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Picture', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('file', models.ImageField(upload_to='pictures')), + ('slug', models.SlugField(blank=True)), + ], + ), + ] diff --git a/fileupload/migrations/__init__.py b/fileupload/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/fileupload/models.py b/fileupload/models.py index f28d242..81a20a3 100644 --- a/fileupload/models.py +++ b/fileupload/models.py @@ -12,7 +12,7 @@ class Picture(models.Model): file = models.ImageField(upload_to="pictures") slug = models.SlugField(max_length=50, blank=True) - def __unicode__(self): + def __str__(self): return self.file.name @models.permalink diff --git a/fileupload/templates/fileupload/picture_angular_form.html b/fileupload/templates/fileupload/picture_angular_form.html index a5ac9c0..a6add16 100644 --- a/fileupload/templates/fileupload/picture_angular_form.html +++ b/fileupload/templates/fileupload/picture_angular_form.html @@ -24,13 +24,13 @@ - + - + - + - + - + - + - +