S3 Upload working
This commit is contained in:
parent
83c011e32f
commit
a1d10ea30a
7
Makefile
7
Makefile
@ -1,5 +1,12 @@
|
||||
DROPZONE=https://github.com/enyo/dropzone/archive/v5.7.0.zip
|
||||
|
||||
|
||||
dev-setup:
|
||||
pip install -r requirements.txt
|
||||
pip install -r dev-requirements.txt
|
||||
./manage.py migrate
|
||||
./manage.py createsuperuser --username admin --email admin@localhost
|
||||
|
||||
interface/static/dropzone/dropzone.js:
|
||||
wget -O dropzone.zip ${DROPZONE}
|
||||
unzip -d interface/static dropzone.zip
|
||||
@ -27,6 +27,9 @@ class Project(models.Model):
|
||||
deadline =models.DateField(null=True, blank=True)
|
||||
bucket = models.CharField(max_length=100)
|
||||
|
||||
def submissions(self):
|
||||
return self.all_submissions.filter(complete=True)
|
||||
|
||||
def presigned_post(self, object_name, fields={}, conditions=[], expires=3600):
|
||||
key = os.path.join(slugify(self.name), object_name)
|
||||
return s3client.generate_presigned_post(self.bucket, key, Fields=fields, Conditions=conditions, ExpiresIn=expires)
|
||||
@ -48,7 +51,7 @@ class WikiPage(models.Model):
|
||||
return self.title
|
||||
|
||||
class Submission(models.Model):
|
||||
project = models.ForeignKey(Project, related_name='submissions', on_delete=models.CASCADE)
|
||||
project = models.ForeignKey(Project, related_name='all_submissions', on_delete=models.CASCADE)
|
||||
date = models.DateField(auto_now_add=True)
|
||||
name = models.CharField(max_length=255)
|
||||
instrument = models.CharField(max_length=100)
|
||||
|
||||
@ -3,6 +3,10 @@
|
||||
background-color: #69C;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
#project H1 {
|
||||
text-align: center;
|
||||
}
|
||||
@ -39,14 +39,15 @@
|
||||
</div>
|
||||
</nav>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
|
||||
{% block content %}
|
||||
<h1>No content!</h1>
|
||||
{% endblock %}
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
{% extends "interface/project.html" %}
|
||||
|
||||
{% block page %}
|
||||
<p>
|
||||
Some instructions about how to submit the file
|
||||
{{ url }}
|
||||
</p>
|
||||
<div class="card">
|
||||
<div class="card-header">Make a submission</div>
|
||||
<div class="card-body">
|
||||
<p>
|
||||
Some instructions about how to submit the file
|
||||
{{ url }}
|
||||
</p>
|
||||
|
||||
<div class="col-md-6 offset-md-3">
|
||||
{% include "interface/bootstrap-form.html" %}
|
||||
<div class="">
|
||||
{% include "interface/bootstrap-form.html" %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@ -1,19 +1,47 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
||||
<div class="container">
|
||||
<div class="col-md-4 offset-md-4">
|
||||
<form method="POST" action="{{ upload.url }}" enctype="multipart/form-data">
|
||||
{% for field, value in upload.fields.items %}
|
||||
<input type="hidden" name="{{ field }}" value="{{ value }}" />
|
||||
{% endfor %}
|
||||
File:
|
||||
<input name="file" type="file" accept="video/*"/>
|
||||
<div class="text-right">
|
||||
<a class="btn btn-secondary" href="{% url 'cancel_submission' project_id=project.pk submission_id=submission.pk %}">Cancel</a>
|
||||
<button class="btn btn-primary">Upload</button>
|
||||
<div class="card" id="legacy-upload">
|
||||
<div class="card-header">Ready to upload file</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="{{ upload.url }}" enctype="multipart/form-data" id="video-upload">
|
||||
{% for field, value in upload.fields.items %}
|
||||
<input type="hidden" name="{{ field }}" value="{{ value }}" />
|
||||
{% endfor %}
|
||||
|
||||
<input name="file" type="file" accept="video/*"/>
|
||||
|
||||
<div class="form-actions text-right">
|
||||
<a class="btn btn-secondary" href="{% url 'cancel_submission' project_id=project.pk submission_id=submission.pk %}">Cancel</a>
|
||||
<button class="btn btn-primary">Upload</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="{% static 'dropzone/dropzone.js' %}"></script>
|
||||
<script>
|
||||
(function() {
|
||||
|
||||
//document.getElementById('fallback-file').remove();
|
||||
|
||||
Dropzone.options.videoUpload = {
|
||||
paramName: "file", // The name that will be used to transfer the file
|
||||
maxFilesize: 500, // MB
|
||||
accept: function(file, done) {
|
||||
if (file.name == "justinbieber.jpg") {
|
||||
done("Naha, you don't.");
|
||||
} else { done(); }
|
||||
}
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
@ -72,7 +72,7 @@ def submission(request, project_id):
|
||||
form = forms.SubmissionForm()
|
||||
|
||||
context = {'project': project, 'form': form}
|
||||
return render(request, 'interface/submission.html', context)
|
||||
return render(request, 'interface/submission.html', context)
|
||||
|
||||
@check_allowed
|
||||
def cancel_submission(request, project_id, submission_id):
|
||||
@ -84,7 +84,7 @@ def cancel_submission(request, project_id, submission_id):
|
||||
@check_allowed
|
||||
def complete_submission(request, project_id, submission_id):
|
||||
project = get_object_or_404(models.Project, pk=project_id, ensemble=request.ensemble_id)
|
||||
s = project.submissions.get(pk=submission_id)
|
||||
s = project.all_submissions.get(pk=submission_id)
|
||||
s.complete = True
|
||||
s.key = request.GET['key']
|
||||
s.save()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user