This commit is contained in:
Ross
2022-05-18 17:55:48 +01:00
parent 40e7ff29bf
commit 72cf7b0c3e
6 changed files with 42 additions and 3 deletions
+14 -1
View File
@@ -23,6 +23,7 @@ from rapids.models import (
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.forms.widgets import RadioSelect, TextInput, Textarea
from django.contrib.auth.models import User
class RapidAnswerForm(ModelForm):
@@ -189,7 +190,7 @@ class RapidForm(ModelForm):
ImageFormSet = inlineformset_factory(
Rapid,
RapidImage,
fields=["image", "feedback_image", "description"],
fields=["image", "feedback_image", "filename", "description"],
exclude=[],
can_delete=True,
extra=1,
@@ -244,3 +245,15 @@ class ExamForm(ExamFormMixin, ModelForm):
"cid_user_groups",
#"author",
]
class ExamAuthorForm(ModelForm):
class Meta:
model = Exam
fields = ["author"]
def __init__(self, *args, **kwargs):
ModelForm.__init__(self, *args, **kwargs)
self.fields["author"] = ModelMultipleChoiceField(
queryset=User.objects.all(),
widget=FilteredSelectMultiple(verbose_name="Authors", is_stacked=False),
)
@@ -0,0 +1,18 @@
# Generated by Django 3.2.13 on 2022-05-18 16:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rapids', '0051_exam_authors_only'),
]
operations = [
migrations.AddField(
model_name='rapidimage',
name='filename',
field=models.CharField(blank=True, help_text='Name of the original file when uploaded', max_length=255, null=True),
),
]
+2
View File
@@ -501,6 +501,8 @@ class RapidImage(models.Model):
feedback_image = models.BooleanField(default=False)
filename = models.CharField(max_length=255, null=True, blank=True, help_text="Name of the original file when uploaded")
description = models.CharField(max_length=255, null=True, blank=True)
image_md5_hash = models.CharField(max_length=32, null=True, blank=True)
+2 -2
View File
@@ -212,7 +212,6 @@
};
dropContainer.ondrop = function (evt) {
console.log("SHIT", evt);
$(evt.target).removeClass("drop-target-active");
file_drop_number = evt.dataTransfer.files.length;
@@ -621,7 +620,8 @@
// If a (new) file is being uploaded we save it's name prior to it being hashed
if (file_element.files.length > 0) {
file_name = file_element.files[0].name
$(ul).find("input[type=text]").val(file_name);
//$(ul).find("input[type=text]").val(file_name);
$(ul).find("input[name~='filename']").val(file_name);
}
if (file_element.files.length > 0 || $(ul).find(":contains('Currently:')")) {
+1
View File
@@ -70,6 +70,7 @@ urlpatterns = [
name="exam_question_detail",
),
path("exam/<int:pk>/", views.GenericExamViews.exam_overview, name="exam_overview"),
path("exam/<int:pk>/authors", views.ExamAuthorUpdate.as_view(), name="exam_authors"),
path(
"exam/<int:pk>/json_edit",
views.GenericExamViews.exam_json_edit,
+5
View File
@@ -20,6 +20,7 @@ from django.http import Http404, JsonResponse
from django.http import HttpResponseRedirect, HttpResponse
from .forms import (
ExamAuthorForm,
RapidForm,
MarkRapidQuestionForm,
ImageFormSet,
@@ -858,6 +859,10 @@ class ExamUpdate(
return super().form_valid(form)
#TODO: AUTHOR REQURIED (NOT AUTHORORCHECKER)
class ExamAuthorUpdate(RevisionMixin, LoginRequiredMixin, AuthorOrCheckerRequiredMixin, UpdateView):
model = Exam
form_class = ExamAuthorForm
class ExamDelete(RevisionMixin, AuthorOrCheckerRequiredMixin, DeleteView):
model = Exam