Add css for dropzone upload
This commit is contained in:
parent
27c520554f
commit
d4db72ecc0
3
PDMI/static/store/dropzone-style.css
Normal file
3
PDMI/static/store/dropzone-style.css
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.dropzone {
|
||||||
|
border-style: dashed;
|
||||||
|
}
|
@ -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>
|
||||||
|
@ -3,81 +3,81 @@
|
|||||||
{% 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="fallback">
|
<div class="container pt-5">
|
||||||
<input type="file" name="file" id="file" multiple />
|
<form class="dropzone" enctype="multipart/form-data" method="post" id="multiFileUpload">
|
||||||
<input type="submit" value="Upload" />
|
<div class="fallback">
|
||||||
|
<input type="file" name="file" id="file" multiple />
|
||||||
|
<input type="submit" value="Upload" />
|
||||||
|
</div>
|
||||||
|
</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>
|
</div>
|
||||||
</form>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function getCookie(name) {
|
function getCookie(name) {
|
||||||
let cookieValue = null;
|
let cookieValue = null;
|
||||||
if (document.cookie && document.cookie != '') {
|
if (document.cookie && document.cookie != '') {
|
||||||
let cookies = document.cookie.split(';');
|
let cookies = document.cookie.split(';');
|
||||||
for (let i = 0; i < cookies.length; i++) {
|
for (let i = 0; i < cookies.length; i++) {
|
||||||
let cookie = $.trim(cookies[i]);
|
let cookie = $.trim(cookies[i]);
|
||||||
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
||||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return cookieValue;
|
||||||
}
|
}
|
||||||
return cookieValue;
|
let csrftoken = getCookie('csrftoken');
|
||||||
}
|
Dropzone.autoDiscover = false;
|
||||||
let csrftoken = getCookie('csrftoken');
|
$('#multiFileUpload').dropzone({
|
||||||
Dropzone.autoDiscover = false;
|
url: "{% url 'upload' %}",
|
||||||
$('#multiFileUpload').dropzone({
|
crossDomain: false,
|
||||||
url: "{% url 'upload' %}",
|
paramName: "file",
|
||||||
crossDomain: false,
|
parallelUploads: 5,
|
||||||
paramName: "file",
|
autoProcessQueue: false,
|
||||||
parallelUploads: 5,
|
filesizeBase: 1024,
|
||||||
autoProcessQueue: true,
|
maxFilesize: 10000,
|
||||||
filesizeBase: 1024,
|
dictRemoveFileConfirmation: null,
|
||||||
maxFilesize: 10000,
|
init: function() {
|
||||||
dictRemoveFileConfirmation: null,
|
myDropzone = this;
|
||||||
init: function() {
|
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) {
|
|
||||||
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("maxfilesexceeded", function(data) {
|
||||||
});
|
let res = eval('(' + data.xhr.responseText + ')');
|
||||||
this.on("error", function(file, message) {
|
});
|
||||||
console.log(message);
|
this.on("error", function(file, message) {
|
||||||
this.removeFile(file);
|
console.log(message);
|
||||||
});
|
this.removeFile(file);
|
||||||
this.on('sending', function(file, xhr, formData) {
|
});
|
||||||
xhr.setRequestHeader("X-CSRFToken", csrftoken)
|
this.on('sending', function(file, xhr, formData) {
|
||||||
});
|
xhr.setRequestHeader("X-CSRFToken", csrftoken)
|
||||||
}
|
});
|
||||||
});
|
let submitButton = $('#submit-all');
|
||||||
Dropzone.prototype.filesize = function(size) {
|
submitButton.on("click", function() {
|
||||||
filesizecalculation(size);
|
myDropzone.processQueue();
|
||||||
};
|
});
|
||||||
|
let clearButton = $('#clear-all');
|
||||||
|
clearButton.on('click', function() {
|
||||||
|
myDropzone.removeAllFiles();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function filesizecalculation(size) {
|
</script>
|
||||||
if (size < 1024 * 1024) {
|
</main>
|
||||||
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>
|
|
||||||
{% endblock body %}
|
{% endblock body %}
|
||||||
|
@ -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'),
|
||||||
]
|
]
|
||||||
|
@ -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'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user