From 243bcec04a632cd2519e92cf2841ce1a4ddbcc75 Mon Sep 17 00:00:00 2001
From: Saurabh
Date: Wed, 26 Dec 2012 14:25:39 +0530
Subject: [PATCH 1/3] Code now working with an extra field description
---
.gitignore | 2 ++
fileupload/models.py | 2 ++
fileupload/static/js/main.js | 11 +++++++++++
fileupload/templatetags/upload_tags.py | 3 ++-
fileupload/views.py | 12 +++++++++++-
settings.py | 2 +-
6 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/.gitignore b/.gitignore
index 06f5f1d..327912b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,5 @@
/lib
/local
/share
+
+*.pyc
diff --git a/fileupload/models.py b/fileupload/models.py
index 64cf98b..ee1bc41 100644
--- a/fileupload/models.py
+++ b/fileupload/models.py
@@ -1,5 +1,6 @@
from django.db import models
+
class Picture(models.Model):
# This is a small demo using just two fields. The slug field is really not
@@ -9,6 +10,7 @@ class Picture(models.Model):
#file = models.FileField(upload_to="pictures")
file = models.ImageField(upload_to="pictures")
+ description = models.CharField(max_length=200, blank=True)
slug = models.SlugField(max_length=50, blank=True)
def __unicode__(self):
diff --git a/fileupload/static/js/main.js b/fileupload/static/js/main.js
index 01c86fe..0cca7ac 100644
--- a/fileupload/static/js/main.js
+++ b/fileupload/static/js/main.js
@@ -28,6 +28,17 @@ $(function () {
)
);
+ $('#fileupload').bind('fileuploadsubmit', function (e, data) {
+ var inputs = data.context.find(':input');
+ console.log(inputs);
+ if (inputs.filter('[required][value=""]').first().focus().length) {
+ return false;
+ }
+ data.formData = inputs.serializeArray();
+ data.formData.push({"name": 'csrfmiddlewaretoken', 'value': $('input[name=csrfmiddlewaretoken]').val() });
+ console.log(data.formData);
+ });
+
if (window.location.hostname === 'blueimp.github.com') {
// Demo settings:
$('#fileupload').fileupload('option', {
diff --git a/fileupload/templatetags/upload_tags.py b/fileupload/templatetags/upload_tags.py
index aefce2e..f2af81f 100644
--- a/fileupload/templatetags/upload_tags.py
+++ b/fileupload/templatetags/upload_tags.py
@@ -11,6 +11,7 @@ def upload_js():
|
{%=file.name%} |
+ |
{%=o.formatFileSize(file.size)%} |
{% if (file.error) { %}
{%=locale.fileupload.error%} {%=locale.fileupload.errors[file.error] || file.error%} |
@@ -53,7 +54,7 @@ def upload_js():
{%=file.name%}
{%=o.formatFileSize(file.size)%} |
- |
+ Description{%=file.description%} |
{% } %}
|
{%=o.formatFileSize(file.size)%} |
- Description{%=file.description%} |
+ {%=file.description%} |
{% } %}
|