diff --git a/.gitignore b/.gitignore index b0d4e48..8fef53c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,8 +7,9 @@ db /share /env /venv -/django-jquery-file-upload +/django-jquery-file-upload/media *.log *.pot *.pyc local_settings.py +.idea diff --git a/README.md b/README.md index 8f185a9..3498b31 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,17 @@ fileupload/models.py as commented in the file. Installation ============ -* pip install -r requirements.txt (will install django and pillow) -* python manage.py syncdb -* python manage.py runserver -* go to localhost:8000/upload/new/ and upload some files +I recommend to install this within a virtualenv. + +```sh +virtualenv -p python3 venv +source venv/bin/activate +pip install -r requirements.txt +./manage.py migrate +./manage.py runserver +``` + +And then go to localhost:8000 and try to upload some files. License ======= diff --git a/__init__.py b/django-jquery-file-upload/__init__.py similarity index 100% rename from __init__.py rename to django-jquery-file-upload/__init__.py diff --git a/django-jquery-file-upload/settings.py b/django-jquery-file-upload/settings.py new file mode 100644 index 0000000..d27d9db --- /dev/null +++ b/django-jquery-file-upload/settings.py @@ -0,0 +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 + +ALLOWED_HOSTS = [] + +# Application definition + +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', +) + +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', + 'NAME': os.path.join(BASE_DIR, 'db'), + } +} + + +# Internationalization +# https://docs.djangoproject.com/en/1.8/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'Europe/Oslo' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +STATIC_URL = '/static/' + +STATICFILES_DIRS = [ + 'django-jquery-file-upload/static', +] + +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 new file mode 100644 index 0000000..8f26ec4 --- /dev/null +++ b/django-jquery-file-upload/urls.py @@ -0,0 +1,17 @@ +from django.urls import include, path +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 = [ + path('', lambda x: HttpResponseRedirect('/upload/new/')), + path('upload/', include('fileupload.urls')), + path('admin/', admin.site.urls), +] + +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/response.py b/fileupload/response.py index 829685a..334eb29 100644 --- a/fileupload/response.py +++ b/fileupload/response.py @@ -1,6 +1,6 @@ # encoding: utf-8 from django.http import HttpResponse -from django.utils import simplejson +import json MIMEANY = '*/*' MIMEJSON = 'application/json' @@ -34,5 +34,5 @@ def a_iew(request): """ def __init__(self, obj='', json_opts=None, mimetype=MIMEJSON, *args, **kwargs): json_opts = json_opts if isinstance(json_opts, dict) else {} - content = simplejson.dumps(obj, **json_opts) + content = json.dumps(obj, **json_opts) super(JSONResponse, self).__init__(content, mimetype, *args, **kwargs) diff --git a/fileupload/serialize.py b/fileupload/serialize.py index 4494e79..96749af 100644 --- a/fileupload/serialize.py +++ b/fileupload/serialize.py @@ -1,7 +1,7 @@ # encoding: utf-8 import mimetypes import re -from django.core.urlresolvers import reverse +from django.urls import reverse def order_name(name): 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 @@ - + - + - + - + - + - + - +