Created
October 16, 2013 16:16
-
-
Save murilobsd/7010576 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'base.html' %} | |
{% load breadcrumbs %} | |
{% block breadcrumbs %} | |
{% breadcrumb 'Upload' %} | |
{% endblock %} | |
{% block css_especifico %} | |
<link rel="stylesheet" href="{{ STATIC_URL }}assets/css/dropzone.css"> | |
{% endblock %} | |
{% block title %}Upload{% endblock %} | |
{% block content %} | |
<div class="page-header position-relative"> | |
<h1> | |
Cadastro Inteligente | |
<small> | |
<i class="icon-double-angle-right"></i> | |
Arraste o documento | |
</small> | |
</h1> | |
</div> | |
<div class="row-fluid"> | |
<div class="span12"> | |
<div id="dropzone"> | |
<form action="{% url 'upload' %}" class="dropzone" enctype="multipart/form-data" method="post"> | |
{% csrf_token %} | |
<div class="fallback"> | |
<input name="file" type="file" multiple="" /> | |
</div> | |
</form> | |
</div> | |
</div> | |
</div> | |
{% endblock %} | |
{% block java_especifico %} | |
<script src="{{ STATIC_URL }}assets/js/dropzone.min.js"></script> | |
{% endblock %} | |
{% block inline_especifico %} | |
<script type="text/javascript"> | |
jQuery(function($){ | |
Dropzone.autoDiscover = false; | |
try { | |
$(".dropzone").dropzone({ | |
paramName: "file", // The name that will be used to transfer the file | |
maxFilesize: 50.5, // MB | |
addRemoveLinks : true, | |
dictDefaultMessage : | |
'<span class="bigger-150 bolder"><i class="icon-caret-right red"></i> Upload Inteligente</span> arraste aqui \ | |
<span class="smaller-80 grey">(ou clique)</span> <br /> \ | |
<i class="upload-icon icon-cloud-upload blue icon-3x"></i>', | |
dictResponseError: 'Erro ao enviar o arquivo!', | |
//change the previewTemplate to use Bootstrap progress bars | |
previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n <div class=\"dz-details\">\n <div class=\"dz-filename\"><span data-dz-name></span></div>\n <div class=\"dz-size\" data-dz-size></div>\n <img data-dz-thumbnail />\n </div>\n <div class=\"progress progress-small progress-success progress-striped active\"><span class=\"bar\" data-dz-uploadprogress></span></div>\n <div class=\"dz-success-mark\"><span></span></div>\n <div class=\"dz-error-mark\"><span></span></div>\n <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>" | |
}); | |
} catch(e) { | |
alert('Dropzone.js não é suportado pelo seu navegador, por favor atualize para versão mais recente'); | |
} | |
}); | |
</script> | |
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render, HttpResponse | |
from django.utils import simplejson as json | |
class JsonResponse(HttpResponse): | |
def __init__(self, data, **kwargs): | |
HttpResponse.__init__(self, content=json.dumps(data), mimetype='application/json', **kwargs) | |
def index(request, template_name='upload/upload.html'): | |
return render(request, template_name) | |
def upload(request): | |
status = 400 | |
response = None | |
if request.POST and request.FILES: | |
for i in request.FILES.getlist('file'): | |
print i.name | |
status = 200 | |
response = {'success': 200} | |
else: | |
response = {'error': 400} | |
return JsonResponse(response, status=status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment