From 07f7a8a384a43f6f2ba03a660b160dab465eb860 Mon Sep 17 00:00:00 2001
From: A-Malone
Date: Sat, 19 Dec 2015 14:37:58 -0500
Subject: [PATCH 1/3] Revamped old project
---
.gitignore | 2 +-
django-jquery-file-upload/settings.py | 160 +++++++-------
django-jquery-file-upload/urls.py | 20 +-
fileupload/admin.py | 4 +-
fileupload/migrations/0001_initial.py | 24 ++
fileupload/migrations/__init__.py | 0
fileupload/models.py | 9 +-
fileupload/serialize.py | 6 +-
.../fileupload/file_angular_form.html | 174 +++++++++++++++
.../fileupload/picture_angular_form.html | 207 ------------------
fileupload/templates/upload_base.html | 13 +-
fileupload/urls.py | 21 +-
fileupload/views.py | 30 +--
13 files changed, 322 insertions(+), 348 deletions(-)
create mode 100644 fileupload/migrations/0001_initial.py
create mode 100644 fileupload/migrations/__init__.py
create mode 100644 fileupload/templates/fileupload/file_angular_form.html
delete mode 100644 fileupload/templates/fileupload/picture_angular_form.html
diff --git a/.gitignore b/.gitignore
index 8fef53c..9c6faaf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-db
+db.sqlite3
/media
/bin
/include
diff --git a/django-jquery-file-upload/settings.py b/django-jquery-file-upload/settings.py
index d7e49bd..eb0c0d2 100644
--- a/django-jquery-file-upload/settings.py
+++ b/django-jquery-file-upload/settings.py
@@ -1,49 +1,23 @@
-import os
-
-DEBUG = True
-TEMPLATE_DEBUG = DEBUG
-
-SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
-
-ADMINS = (
- # ('Your Name', 'your_email@example.com'),
-)
-
-MANAGERS = ADMINS
+"""
+Django settings for this project.
-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.
- }
-}
+Generated by 'django-admin startproject' using Django 1.9.
-# 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'
+For more information on this file, see
+https://docs.djangoproject.com/en/1.9/topics/settings/
-# Language code for this installation. All choices can be found here:
-# http://www.i18nguy.com/unicode/language-identifiers.html
-LANGUAGE_CODE = 'en-us'
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/1.9/ref/settings/
+"""
+import os
-SITE_ID = 1
+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
+BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-# If you set this to False, Django will make some optimizations so as not
-# to load the internationalization machinery.
-USE_I18N = True
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = '9%$in^gpdaig@v3or_to&_z(=n)3)$f1mr3hf9e#kespy2ajlo'
-# If you set this to False, Django will not format dates, numbers and
-# calendars according to the current locale
-USE_L10N = True
+DEBUG = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
@@ -69,11 +43,21 @@
# 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.
+ADMINS = (
+ # ('Your Name', 'your_email@example.com'),
+)
+
+MANAGERS = ADMINS
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ 'django.contrib.admin',
+ 'fileupload',
)
# List of finder classes that know how to find static files in
@@ -81,17 +65,6 @@
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 = (
@@ -105,25 +78,50 @@
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.
-)
+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',
+ ],
+ },
+ },
+]
-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',
-)
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), # 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.
+ }
+}
+
+# Password validation
+# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+ {
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+ },
+]
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
@@ -147,3 +145,17 @@
},
}
}
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# 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
diff --git a/django-jquery-file-upload/urls.py b/django-jquery-file-upload/urls.py
index 7072912..a3f0b97 100644
--- a/django-jquery-file-upload/urls.py
+++ b/django-jquery-file-upload/urls.py
@@ -1,25 +1,19 @@
from django.conf.urls import patterns, include, url
from django.http import HttpResponseRedirect
+from django.views.static import serve
+
# 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')}),
-)
+urlpatterns += [
+ url(r'^media/(.*)$', serve, {'document_root': join(abspath(dirname(__file__)), 'media')}),
+]
diff --git a/fileupload/admin.py b/fileupload/admin.py
index faa5cdc..8b5ec66 100644
--- a/fileupload/admin.py
+++ b/fileupload/admin.py
@@ -1,4 +1,4 @@
-from fileupload.models import Picture
+from fileupload.models import File
from django.contrib import admin
-admin.site.register(Picture)
\ No newline at end of file
+admin.site.register(File)
diff --git a/fileupload/migrations/0001_initial.py b/fileupload/migrations/0001_initial.py
new file mode 100644
index 0000000..460e4ac
--- /dev/null
+++ b/fileupload/migrations/0001_initial.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9 on 2015-12-19 13:27
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='File',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('file', models.FileField(upload_to='')),
+ ('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..5e135a9 100644
--- a/fileupload/models.py
+++ b/fileupload/models.py
@@ -1,15 +1,14 @@
# encoding: utf-8
from django.db import models
-
-class Picture(models.Model):
+class File(models.Model):
"""This is a small demo using just two fields. The slug field is really not
necessary, but makes the code simpler. ImageField depends on PIL or
pillow (where Pillow is easily installable in a virtualenv. If you have
problems installing pillow, use a more generic FileField instead.
"""
- file = models.ImageField(upload_to="pictures")
+ file = models.FileField()
slug = models.SlugField(max_length=50, blank=True)
def __unicode__(self):
@@ -21,9 +20,9 @@ def get_absolute_url(self):
def save(self, *args, **kwargs):
self.slug = self.file.name
- super(Picture, self).save(*args, **kwargs)
+ super(File, self).save(*args, **kwargs)
def delete(self, *args, **kwargs):
"""delete -- Remove to leave file."""
self.file.delete(False)
- super(Picture, self).delete(*args, **kwargs)
+ super(File, self).delete(*args, **kwargs)
diff --git a/fileupload/serialize.py b/fileupload/serialize.py
index 4494e79..e320f33 100644
--- a/fileupload/serialize.py
+++ b/fileupload/serialize.py
@@ -18,9 +18,9 @@ def order_name(name):
def serialize(instance, file_attr='file'):
- """serialize -- Serialize a Picture instance into a dict.
+ """serialize -- Serialize a File instance into a dict.
- instance -- Picture instance
+ instance -- File instance
file_attr -- attribute name that contains the FileField or ImageField
"""
@@ -34,5 +34,3 @@ def serialize(instance, file_attr='file'):
'deleteUrl': reverse('upload-delete', args=[instance.pk]),
'deleteType': 'DELETE',
}
-
-
diff --git a/fileupload/templates/fileupload/file_angular_form.html b/fileupload/templates/fileupload/file_angular_form.html
new file mode 100644
index 0000000..39edb1f
--- /dev/null
+++ b/fileupload/templates/fileupload/file_angular_form.html
@@ -0,0 +1,174 @@
+{% load staticfiles %}
+
+
+
+
+
+
+
+jQuery File Upload Demo - AngularJS version
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Demo Notes
+
+
+
+
You can drag & drop files from your desktop on this webpage (see Browser support).
File Upload widget with multiple file selection, drag&drop support, progress bars, validation and preview images, audio and video for AngularJS.
- Supports cross-domain, chunked and resumable file uploads and client-side image resizing.
-
-
-
-
-
-
-
-
Demo Notes
-
-
-
-
You can drag & drop files from your desktop on this webpage (see Browser support).