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 + + + + + + + + + + + + + + + + + +
{% csrf_token %} + + + +
+
+ + + + Add files... + + + + + +
+
+ +
+ +
+ +
 
+
+
+ {% verbatim %} + + + + + + + + +
+
+ +
+
+
+

+ + {{file.name}} + {{file.name}} + + {{file.name}} +

+
Error {{file.error}}
+
+

{{file.size | formatFileSize}}

+
+
+ + + +
+ {% endverbatim %} +
+
+
+
+

Demo Notes

+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fileupload/templates/fileupload/picture_angular_form.html b/fileupload/templates/fileupload/picture_angular_form.html deleted file mode 100644 index a5ac9c0..0000000 --- a/fileupload/templates/fileupload/picture_angular_form.html +++ /dev/null @@ -1,207 +0,0 @@ - - - - - - - -jQuery File Upload Demo - AngularJS version - - - - - - - - - - - - - - - - -
-

Django jQuery File Upload Demo

-

AngularJS version

- -
-
-

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.

-
-
- -
{% csrf_token %} - - - -
-
- - - - Add files... - - - - - -
-
- -
- -
- -
 
-
-
- {% verbatim %} - - - - - - - - -
-
- -
-
-
-

- - {{file.name}} - {{file.name}} - - {{file.name}} -

-
Error {{file.error}}
-
-

{{file.size | formatFileSize}}

-
-
- - - -
- {% endverbatim %} -
-
-
-
-

Demo Notes

-
-
- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/fileupload/templates/upload_base.html b/fileupload/templates/upload_base.html index e75c3fc..ff40681 100644 --- a/fileupload/templates/upload_base.html +++ b/fileupload/templates/upload_base.html @@ -1,3 +1,4 @@ +{% load staticfiles %} @@ -12,14 +13,14 @@ - + - + - + - - + + @@ -48,5 +49,5 @@

No content set

{% endblock %} - + diff --git a/fileupload/urls.py b/fileupload/urls.py index dbbcbca..68944d7 100644 --- a/fileupload/urls.py +++ b/fileupload/urls.py @@ -1,17 +1,10 @@ # encoding: utf-8 from django.conf.urls import patterns, url -from fileupload.views import ( - BasicVersionCreateView, BasicPlusVersionCreateView, - jQueryVersionCreateView, AngularVersionCreateView, - PictureCreateView, PictureDeleteView, PictureListView, - ) +from . import views -urlpatterns = patterns('', - url(r'^basic/$', BasicVersionCreateView.as_view(), name='upload-basic'), - url(r'^basic/plus/$', BasicPlusVersionCreateView.as_view(), name='upload-basic-plus'), - url(r'^new/$', PictureCreateView.as_view(), name='upload-new'), - url(r'^angular/$', AngularVersionCreateView.as_view(), name='upload-angular'), - url(r'^jquery-ui/$', jQueryVersionCreateView.as_view(), name='upload-jquery'), - url(r'^delete/(?P\d+)$', PictureDeleteView.as_view(), name='upload-delete'), - url(r'^view/$', PictureListView.as_view(), name='upload-view'), -) +urlpatterns = [ + url(r'^new/$', views.FileCreateView.as_view(), name='upload-new'), + url(r'^angular/$', views.AngularVersionCreateView.as_view(), name='upload-angular'), + url(r'^delete/(?P\d+)$', views.FileDeleteView.as_view(), name='upload-delete'), + url(r'^view/$', views.FileListView.as_view(), name='upload-view'), +] diff --git a/fileupload/views.py b/fileupload/views.py index e9f6b01..23a163f 100644 --- a/fileupload/views.py +++ b/fileupload/views.py @@ -3,13 +3,13 @@ from django.http import HttpResponse from django.views.generic import CreateView, DeleteView, ListView -from .models import Picture +from .models import File from .response import JSONResponse, response_mimetype from .serialize import serialize -class PictureCreateView(CreateView): - model = Picture +class FileCreateView(CreateView): + model = File fields = "__all__" def form_valid(self, form): @@ -24,24 +24,11 @@ def form_invalid(self, form): data = json.dumps(form.errors) return HttpResponse(content=data, status=400, content_type='application/json') -class BasicVersionCreateView(PictureCreateView): - template_name_suffix = '_basic_form' - - -class BasicPlusVersionCreateView(PictureCreateView): - template_name_suffix = '_basicplus_form' - - -class AngularVersionCreateView(PictureCreateView): +class AngularVersionCreateView(FileCreateView): template_name_suffix = '_angular_form' - -class jQueryVersionCreateView(PictureCreateView): - template_name_suffix = '_jquery_form' - - -class PictureDeleteView(DeleteView): - model = Picture +class FileDeleteView(DeleteView): + model = File def delete(self, request, *args, **kwargs): self.object = self.get_object() @@ -50,9 +37,8 @@ def delete(self, request, *args, **kwargs): response['Content-Disposition'] = 'inline; filename=files.json' return response - -class PictureListView(ListView): - model = Picture +class FileListView(ListView): + model = File def render_to_response(self, context, **response_kwargs): files = [ serialize(p) for p in self.get_queryset() ] From 674c79d939a8850feaf4ea8e8e026124bd7c267c Mon Sep 17 00:00:00 2001 From: A-Malone Date: Sat, 19 Dec 2015 17:29:17 -0500 Subject: [PATCH 2/3] Added token functionality --- fileupload/admin.py | 3 ++- fileupload/migrations/0001_initial.py | 19 ++++++++++++++++++- fileupload/models.py | 19 ++++++++++++++++--- fileupload/serialize.py | 2 +- fileupload/static/js/app.js | 15 +++++---------- .../fileupload/file_angular_form.html | 8 ++++++-- fileupload/urls.py | 6 +++--- fileupload/views.py | 16 +++++++++++++++- 8 files changed, 66 insertions(+), 22 deletions(-) diff --git a/fileupload/admin.py b/fileupload/admin.py index 8b5ec66..7aff4e9 100644 --- a/fileupload/admin.py +++ b/fileupload/admin.py @@ -1,4 +1,5 @@ -from fileupload.models import File +from fileupload.models import File, SingleUseToken from django.contrib import admin admin.site.register(File) +admin.site.register(SingleUseToken) diff --git a/fileupload/migrations/0001_initial.py b/fileupload/migrations/0001_initial.py index 460e4ac..2808f90 100644 --- a/fileupload/migrations/0001_initial.py +++ b/fileupload/migrations/0001_initial.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2015-12-19 13:27 +# Generated by Django 1.9 on 2015-12-19 14:19 from __future__ import unicode_literals from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone +import fileupload.models class Migration(migrations.Migration): @@ -21,4 +24,18 @@ class Migration(migrations.Migration): ('slug', models.SlugField(blank=True)), ], ), + migrations.CreateModel( + name='SingleUseToken', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('token', models.CharField(default=fileupload.models.get_new_token, max_length=200)), + ('create_date', models.DateTimeField(default=django.utils.timezone.now)), + ('expiry_date', models.DateTimeField(default=django.utils.timezone.now)), + ], + ), + migrations.AddField( + model_name='file', + name='token', + field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='fileupload.SingleUseToken'), + ), ] diff --git a/fileupload/models.py b/fileupload/models.py index 5e135a9..565ae06 100644 --- a/fileupload/models.py +++ b/fileupload/models.py @@ -1,5 +1,17 @@ -# encoding: utf-8 +import os +import uuid + from django.db import models +from django.utils import timezone + +def get_new_token(): + return uuid.uuid1() + +# Create your models here. +class SingleUseToken(models.Model): + token = models.CharField(default=get_new_token, max_length=200) + create_date = models.DateTimeField(default=timezone.now) + expiry_date = models.DateTimeField(default=timezone.now) class File(models.Model): """This is a small demo using just two fields. The slug field is really not @@ -8,8 +20,9 @@ class File(models.Model): problems installing pillow, use a more generic FileField instead. """ - file = models.FileField() - slug = models.SlugField(max_length=50, blank=True) + file = models.FileField() + slug = models.SlugField(max_length=50, blank=True) + token = models.ForeignKey(SingleUseToken, on_delete=models.CASCADE) def __unicode__(self): return self.file.name diff --git a/fileupload/serialize.py b/fileupload/serialize.py index e320f33..c69b043 100644 --- a/fileupload/serialize.py +++ b/fileupload/serialize.py @@ -31,6 +31,6 @@ def serialize(instance, file_attr='file'): 'type': mimetypes.guess_type(obj.path)[0] or 'image/png', 'thumbnailUrl': obj.url, 'size': obj.size, - 'deleteUrl': reverse('upload-delete', args=[instance.pk]), + 'deleteUrl': reverse('upload-delete', args=[instance.token.token,instance.pk]), 'deleteType': 'DELETE', } diff --git a/fileupload/static/js/app.js b/fileupload/static/js/app.js index 729eb1a..e3d9839 100644 --- a/fileupload/static/js/app.js +++ b/fileupload/static/js/app.js @@ -11,14 +11,10 @@ /*jslint nomen: true, regexp: true */ /*global window, angular */ - -(function () { +function createControllers(url, urlview) { 'use strict'; - - var isOnGitHub = window.location.hostname === 'blueimp.github.io', - url = '/upload/angular/', - urlview = '/upload/view/'; + var demo_settings = false angular.module('demo', [ 'blueimp.fileupload' @@ -32,7 +28,7 @@ '/cors/result.html?%s' ); - if (isOnGitHub) { + if (demo_settings) { // Demo settings: angular.extend(fileUploadProvider.defaults, { // Enable image resizing, except for Android and Opera, @@ -53,7 +49,7 @@ $scope.options = { url: url }; - if (!isOnGitHub) { + if (!demo_settings) { $scope.loadingFiles = true; $http.get(urlview) .then( @@ -102,5 +98,4 @@ } } ]); - -}()); +}; diff --git a/fileupload/templates/fileupload/file_angular_form.html b/fileupload/templates/fileupload/file_angular_form.html index 39edb1f..de2acad 100644 --- a/fileupload/templates/fileupload/file_angular_form.html +++ b/fileupload/templates/fileupload/file_angular_form.html @@ -43,8 +43,7 @@
{% csrf_token %} - - +
@@ -169,6 +168,11 @@

+ diff --git a/fileupload/urls.py b/fileupload/urls.py index 68944d7..84dabc9 100644 --- a/fileupload/urls.py +++ b/fileupload/urls.py @@ -4,7 +4,7 @@ urlpatterns = [ url(r'^new/$', views.FileCreateView.as_view(), name='upload-new'), - url(r'^angular/$', views.AngularVersionCreateView.as_view(), name='upload-angular'), - url(r'^delete/(?P\d+)$', views.FileDeleteView.as_view(), name='upload-delete'), - url(r'^view/$', views.FileListView.as_view(), name='upload-view'), + url(r'^(?P[a-z0-9\-]+)$', views.AngularVersionCreateView.as_view(), name='upload-angular'), + url(r'^(?P[a-z0-9\-]+)/delete/(?P\d+)$', views.FileDeleteView.as_view(), name='upload-delete'), + url(r'^(?P[a-z0-9\-]+)/view/$', views.FileListView.as_view(), name='upload-view'), ] diff --git a/fileupload/views.py b/fileupload/views.py index 23a163f..0dd1feb 100644 --- a/fileupload/views.py +++ b/fileupload/views.py @@ -3,7 +3,8 @@ from django.http import HttpResponse from django.views.generic import CreateView, DeleteView, ListView -from .models import File +from django.shortcuts import get_object_or_404 +from .models import File, SingleUseToken from .response import JSONResponse, response_mimetype from .serialize import serialize @@ -12,7 +13,20 @@ class FileCreateView(CreateView): model = File fields = "__all__" + def dispatch(self, *args, **kwargs): + print(kwargs['token_id']) + self.token = get_object_or_404(SingleUseToken, token=kwargs['token_id']) + return super(FileCreateView, self).dispatch(*args, **kwargs) + + # Adds the token to the context + def get_context_data(self, *args, **kwargs): + context_data = super(FileCreateView, self).get_context_data( + *args, **kwargs) + context_data.update({'token': self.token}) + return context_data + def form_valid(self, form): + print("Valid") self.object = form.save() files = [serialize(self.object)] data = {'files': files} From 353d1fa06de44bf4aac252be152e383e1dcdcb8d Mon Sep 17 00:00:00 2001 From: A-Malone Date: Sat, 19 Dec 2015 17:49:03 -0500 Subject: [PATCH 3/3] Cleaned up UI --- fileupload/static/css/style.css | 6 +----- fileupload/templates/fileupload/file_angular_form.html | 6 ++---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/fileupload/static/css/style.css b/fileupload/static/css/style.css index 6f1a7f2..c6697bd 100644 --- a/fileupload/static/css/style.css +++ b/fileupload/static/css/style.css @@ -10,10 +10,6 @@ * http://www.opensource.org/licenses/MIT */ -body { - padding-top: 60px; -} - .preview img { max-height:50px; -} \ No newline at end of file +} diff --git a/fileupload/templates/fileupload/file_angular_form.html b/fileupload/templates/fileupload/file_angular_form.html index de2acad..d39cf37 100644 --- a/fileupload/templates/fileupload/file_angular_form.html +++ b/fileupload/templates/fileupload/file_angular_form.html @@ -40,7 +40,7 @@ - +

Upload Files

{% csrf_token %} @@ -117,13 +117,11 @@
-

Demo Notes

+

Usage Notes