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:
|
dev-setup:
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
pip install -r dev-requirements.txt
|
pip install -r dev-requirements.txt
|
||||||
./manage.py migrate
|
./manage.py migrate
|
||||||
./manage.py createsuperuser --username admin --email admin@localhost
|
./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)
|
deadline =models.DateField(null=True, blank=True)
|
||||||
bucket = models.CharField(max_length=100)
|
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):
|
def presigned_post(self, object_name, fields={}, conditions=[], expires=3600):
|
||||||
key = os.path.join(slugify(self.name), object_name)
|
key = os.path.join(slugify(self.name), object_name)
|
||||||
return s3client.generate_presigned_post(self.bucket, key, Fields=fields, Conditions=conditions, ExpiresIn=expires)
|
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
|
return self.title
|
||||||
|
|
||||||
class Submission(models.Model):
|
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)
|
date = models.DateField(auto_now_add=True)
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
instrument = models.CharField(max_length=100)
|
instrument = models.CharField(max_length=100)
|
||||||
|
|||||||
@ -3,6 +3,10 @@
|
|||||||
background-color: #69C;
|
background-color: #69C;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.form-actions {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
#project H1 {
|
#project H1 {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
@ -39,14 +39,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>No content!</h1>
|
<h1>No content!</h1>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
<!-- Optional JavaScript -->
|
<!-- Optional JavaScript -->
|
||||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
<!-- 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://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>
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
{% extends "interface/project.html" %}
|
{% extends "interface/project.html" %}
|
||||||
|
|
||||||
{% block page %}
|
{% block page %}
|
||||||
<p>
|
<div class="card">
|
||||||
Some instructions about how to submit the file
|
<div class="card-header">Make a submission</div>
|
||||||
{{ url }}
|
<div class="card-body">
|
||||||
</p>
|
<p>
|
||||||
|
Some instructions about how to submit the file
|
||||||
|
{{ url }}
|
||||||
|
</p>
|
||||||
|
|
||||||
<div class="col-md-6 offset-md-3">
|
<div class="">
|
||||||
{% include "interface/bootstrap-form.html" %}
|
{% include "interface/bootstrap-form.html" %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@ -1,19 +1,47 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="col-md-4 offset-md-4">
|
<div class="col-md-4 offset-md-4">
|
||||||
<form method="POST" action="{{ upload.url }}" enctype="multipart/form-data">
|
<div class="card" id="legacy-upload">
|
||||||
{% for field, value in upload.fields.items %}
|
<div class="card-header">Ready to upload file</div>
|
||||||
<input type="hidden" name="{{ field }}" value="{{ value }}" />
|
<div class="card-body">
|
||||||
{% endfor %}
|
<form method="POST" action="{{ upload.url }}" enctype="multipart/form-data" id="video-upload">
|
||||||
File:
|
{% for field, value in upload.fields.items %}
|
||||||
<input name="file" type="file" accept="video/*"/>
|
<input type="hidden" name="{{ field }}" value="{{ value }}" />
|
||||||
<div class="text-right">
|
{% endfor %}
|
||||||
<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>
|
<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>
|
</div>
|
||||||
</form>
|
|
||||||
|
</div>
|
||||||
</div>
|
</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 %}
|
{% endblock %}
|
||||||
@ -72,7 +72,7 @@ def submission(request, project_id):
|
|||||||
form = forms.SubmissionForm()
|
form = forms.SubmissionForm()
|
||||||
|
|
||||||
context = {'project': project, 'form': form}
|
context = {'project': project, 'form': form}
|
||||||
return render(request, 'interface/submission.html', context)
|
return render(request, 'interface/submission.html', context)
|
||||||
|
|
||||||
@check_allowed
|
@check_allowed
|
||||||
def cancel_submission(request, project_id, submission_id):
|
def cancel_submission(request, project_id, submission_id):
|
||||||
@ -84,7 +84,7 @@ def cancel_submission(request, project_id, submission_id):
|
|||||||
@check_allowed
|
@check_allowed
|
||||||
def complete_submission(request, project_id, submission_id):
|
def complete_submission(request, project_id, submission_id):
|
||||||
project = get_object_or_404(models.Project, pk=project_id, ensemble=request.ensemble_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.complete = True
|
||||||
s.key = request.GET['key']
|
s.key = request.GET['key']
|
||||||
s.save()
|
s.save()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user