Add css for dropzone upload

This commit is contained in:
HugoNeveux 2020-04-24 16:14:30 +02:00
parent 27c520554f
commit d4db72ecc0
5 changed files with 74 additions and 71 deletions

View File

@ -0,0 +1,3 @@
.dropzone {
border-style: dashed;
}

View File

@ -8,7 +8,7 @@
</a> </a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink"> <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Profile</a> <a class="dropdown-item" href="#">Profile</a>
<a class="dropdown-item" href="#">Upload module</a> <a class="dropdown-item" href="{% url 'upload' %}">Upload module</a>
<a class="dropdown-item" href="{% url 'logout' %}">Logout</a> <a class="dropdown-item" href="{% url 'logout' %}">Logout</a>
</div> </div>
</li> </li>

View File

@ -3,14 +3,28 @@
{% block extra_static %} {% block extra_static %}
<script type="text/javascript" src="{% static 'dropzone-5.7.0/dist/dropzone.js' %}"></script> <script type="text/javascript" src="{% static 'dropzone-5.7.0/dist/dropzone.js' %}"></script>
<link rel="stylesheet" href="{% static 'dropzone-5.7.0/dist/dropzone.css' %}"> <link rel="stylesheet" href="{% static 'dropzone-5.7.0/dist/dropzone.css' %}">
<link rel="stylesheet" href="{% static 'store/dropzone-style.css' %}">
{% endblock extra_static %} {% endblock extra_static %}
{% block navbar %}
{% include "store/store-navbar.html" %}
{% endblock navbar %}
{% block body %} {% block body %}
<form class="dropzone clsbox" enctype="multipart/form-data" method="post" id="multiFileUpload"> <main>
<div class="container pt-5">
<form class="dropzone" enctype="multipart/form-data" method="post" id="multiFileUpload">
<div class="fallback"> <div class="fallback">
<input type="file" name="file" id="file" multiple /> <input type="file" name="file" id="file" multiple />
<input type="submit" value="Upload" /> <input type="submit" value="Upload" />
</div> </div>
</form> </form>
<div class="d-flex justify-content-between my-3">
<div></div> <!-- Left -->
<div class=""> <!-- Right -->
<button id="submit-all" class="btn btn-primary">Sumbit all files</button>
<button id="clear-all" class="btn btn-danger">Clear queue</button>
</div>
</div>
</div>
<script type="text/javascript"> <script type="text/javascript">
function getCookie(name) { function getCookie(name) {
@ -34,29 +48,18 @@
crossDomain: false, crossDomain: false,
paramName: "file", paramName: "file",
parallelUploads: 5, parallelUploads: 5,
autoProcessQueue: true, autoProcessQueue: false,
filesizeBase: 1024, filesizeBase: 1024,
maxFilesize: 10000, maxFilesize: 10000,
dictRemoveFileConfirmation: null, dictRemoveFileConfirmation: null,
init: function() { init: function() {
myDropzone = this;
this.on('uploadprogress', function(file, progress, bytesSent) { this.on('uploadprogress', function(file, progress, bytesSent) {
progress = bytesSent / file.size * 100; progress = bytesSent / file.size * 100;
console.log(filesizecalculation(bytesSent));
}); });
this.on("maxfilesexceeded", function(data) { this.on("maxfilesexceeded", function(data) {
let res = eval('(' + data.xhr.responseText + ')'); let res = eval('(' + data.xhr.responseText + ')');
}); });
this.on("addedfile", function(file) {
let removeButton = Dropzone.createElement("<button data-dz-remove " +
"class='del_thumbnail btn btn-default'><span class='fas fa-trash'></span> Sil</button>");
let _this = this;
removeButton.addEventListener("click", function(e) {
e.preventDefault();
e.stopPropagation();
_this.removeFile(file);
});
file.previewElement.appendChild(removeButton);
});
this.on("error", function(file, message) { this.on("error", function(file, message) {
console.log(message); console.log(message);
this.removeFile(file); this.removeFile(file);
@ -64,20 +67,17 @@
this.on('sending', function(file, xhr, formData) { this.on('sending', function(file, xhr, formData) {
xhr.setRequestHeader("X-CSRFToken", csrftoken) xhr.setRequestHeader("X-CSRFToken", csrftoken)
}); });
let submitButton = $('#submit-all');
submitButton.on("click", function() {
myDropzone.processQueue();
});
let clearButton = $('#clear-all');
clearButton.on('click', function() {
myDropzone.removeAllFiles();
})
} }
}); });
Dropzone.prototype.filesize = function(size) {
filesizecalculation(size);
};
function filesizecalculation(size) {
if (size < 1024 * 1024) {
return "<strong>" + (Math.round(Math.round(size / 1024) * 10) / 10) + " KB</strong>";
} else if (size < 1024 * 1024 * 1024) {
return "<strong>" + (Math.round((size / 1024 / 1024) * 10) / 10) + " MB</strong>";
} else if (size < 1024 * 1024 * 1024 * 1024) {
return "<strong>" + (Math.round((size / 1024 / 1024 / 1024) * 10) / 10) + " GB</strong>";
}
}
</script> </script>
</main>
{% endblock body %} {% endblock body %}

View File

@ -23,5 +23,5 @@ urlpatterns = [
path('login/', views.CustomLoginView.as_view(), name='login'), path('login/', views.CustomLoginView.as_view(), name='login'),
path('signup/', views.SignUpView.as_view(), name='signup'), path('signup/', views.SignUpView.as_view(), name='signup'),
path('logout/', LogoutView.as_view(), name='logout'), path('logout/', LogoutView.as_view(), name='logout'),
path('upload/', views.FileFieldView.as_view(), name='upload'), path('upload/', views.UploadView.as_view(), name='upload'),
] ]

View File

@ -20,7 +20,7 @@ class CustomLoginView(BSModalLoginView):
success_message = 'Success: You were successfully logged in.' success_message = 'Success: You were successfully logged in.'
extra_content = dict(success_url=reverse_lazy('index')) extra_content = dict(success_url=reverse_lazy('index'))
class FileFieldView(FormView): class UploadView(FormView):
form_class = FileFieldForm form_class = FileFieldForm
template_name = 'store/upload.html' template_name = 'store/upload.html'