Skip to content

Commit

Permalink
merge base and fixed error message display under button error and loa…
Browse files Browse the repository at this point in the history
…ded max file size from settings
  • Loading branch information
Amir Qayyum khan committed Apr 9, 2015
1 parent 2de749a commit ce68e3f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion edx_sga/sga.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from django.core.exceptions import PermissionDenied
from django.core.files import File
from django.core.files.storage import default_storage
from django.conf import settings
from django.template import Context, Template

from student.models import user_by_anonymous_id
Expand Down Expand Up @@ -55,6 +56,7 @@ class StaffGradedAssignmentXBlock(XBlock):
"""
has_score = True
icon_class = 'problem'
STUDENT_FILEUPLOAD_MAX_SIZE = 4 * 1000 * 1000 # 4 MB

display_name = String(
default='Staff Graded Assignment', scope=Scope.settings,
Expand Down Expand Up @@ -174,7 +176,11 @@ def student_view(self, context=None):
"""
context = {
"student_state": json.dumps(self.student_state()),
"id": self.location.name.replace('.', '_')
"id": self.location.name.replace('.', '_'),
"max_file_size": getattr(
settings, "STUDENT_FILEUPLOAD_MAX_SIZE",
self.STUDENT_FILEUPLOAD_MAX_SIZE
)
}
if self.show_staff_grading_interface():
context['is_course_staff'] = True
Expand Down
11 changes: 11 additions & 0 deletions edx_sga/static/js/src/edx_sga.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,22 @@ function StaffGradedAssignmentXBlock(runtime, element) {
url: uploadUrl,
add: function(e, data) {
var do_upload = $(content).find(".upload").html('');
$(content).find('p.error').html("");
$('<button/>')
.text('Upload ' + data.files[0].name)
.appendTo(do_upload)
.click(function() {
do_upload.text("Uploading...");
var block = $(element).find(".sga-block");
var data_max_size = block.attr("data-max-size");
var size = data.files[0].size;
if (!_.isUndefined(size)) {
if (size >= data_max_size) { //if file size is larger max file size define in env(django)
state.error = "The file you are trying to upload is too large.";
render(state);
return;
}
}
data.submit();
});
},
Expand Down
2 changes: 1 addition & 1 deletion edx_sga/templates/staff_graded_assignment/show.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load i18n %}

<div class="sga-block" data-state="{{ student_state }}"
<div class="sga-block" data-state="{{ student_state }}" data-max-size="{{ max_file_size }}"
data-staff="{{ is_course_staff }}">
<script type="text/template" id="sga-tmpl">
<% if (display_name) { %>
Expand Down

0 comments on commit ce68e3f

Please sign in to comment.