Skip to content

Commit

Permalink
bump django version from 4.1.x to 5.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
IonMich committed Oct 8, 2024
1 parent 7ee865a commit 4d2a343
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
26 changes: 25 additions & 1 deletion assignments/static/assignments/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,37 @@ function uploadPDFs (event, form) {
// Enable the upload PDFs button
uploadPDFsButton.innerHTML = buttonText;
uploadPDFsButton.disabled = false;
// Display error message as an alert
// clear the bootstrap validation classes
form.classList.remove('was-validated');
// Display error message as a toast
const toast = createToastElement(data.message, data.message_type);
// append the toast to the toast-container
const toastContainer = document.querySelector('#toast-container');
toastContainer.appendChild(toast);
console.log("toast", toast);
var toastElement = new bootstrap.Toast(toast,
{delay: 10000, autohide: false});
toastElement.show();
}})
.catch(error => {
console.log("error", error);
// Enable the upload PDFs button
uploadPDFsButton.innerHTML = buttonText;
uploadPDFsButton.disabled = false;
// clear the bootstrap validation classes
form.classList.remove('was-validated');
// show toast
const toast = createToastElement(
"An error occurred while uploading the PDFs. Please try again.",
"danger"
);
// append the toast to the toast-container
const toastContainer = document.querySelector('#toast-container');
toastContainer.appendChild(toast);
console.log("toast", toast);
var toastElement = new bootstrap.Toast(toast,
{delay: 10000, autohide: false});
toastElement.show();
});

}
Expand Down
8 changes: 8 additions & 0 deletions assignments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ def assignment_detail_view(request, course_pk, assignment_pk):
"message": message,
"message_type": message_type,
})
else:
print(upload_form.errors)
message = "Error while uploading files"
message_type = 'danger'
return JsonResponse({
"message": message,
"message_type": message_type,
})
elif 'submit-classify' in request.POST:
print("request was POST:classify")
classify_form = StudentClassifyForm(no_assignment=False, data=request.POST)
Expand Down
8 changes: 7 additions & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dependencies:
- aiohttp
- llvm-openmp
- numpy<1.25
- django=4.1
- django=5.1
- matplotlib=3.5.3
- pandas=1.4.4
- pillow=9.2.0
Expand All @@ -21,8 +21,14 @@ dependencies:
- tesseract=5.3.0
- pip:
- canvasapi==2.2.0
- djangorestframework==3.15.1
- markdown
- django-cors-headers
- drf-nested-routers
- djangorestframework-simplejwt
- crispy-bootstrap5==0.6
- django-crispy-forms==1.14.0
- opencv-python-headless==4.7.0.72
- onnxruntime==1.14.1
- pymupdf==1.21.1
name: django-ta
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dependencies:
- aiohttp
- llvm-openmp
- numpy<1.25
- django=4.1
- django=5.1
- matplotlib=3.5.3
- pandas=1.4.4
- pillow=9.2.0
Expand Down
23 changes: 20 additions & 3 deletions submissions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ def __init__(self, *args, **kwargs):
self.new_comment = forms.Textarea()
self.comment_file = forms.FileField()

class MultipleFileInput(forms.ClearableFileInput):
allow_multiple_selected = True

class MultipleFileField(forms.FileField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("widget", MultipleFileInput())
super().__init__(*args, **kwargs)

def clean(self, data, initial=None):
single_file_clean = super().clean
if isinstance(data, (list, tuple)):
result = [single_file_clean(d, initial) for d in data]
else:
result = [single_file_clean(data, initial)]
return result

class SubmissionFilesUploadForm(forms.Form):
def __init__(self,*args,**kwargs):
from django.forms.widgets import HiddenInput
Expand All @@ -176,9 +192,10 @@ def __init__(self,*args,**kwargs):
sections__in=assignment_targeted.course.sections.all()
)

file_field = forms.FileField(
widget=forms.ClearableFileInput(attrs={'multiple': True})
)
file_field = MultipleFileField(
required=True,
label="Select file(s) to split and upload",
)

assignment = forms.ModelChoiceField(
queryset=Assignment.objects.all(),
Expand Down

0 comments on commit 4d2a343

Please sign in to comment.