summaryrefslogtreecommitdiff
path: root/yaksh/forms.py
diff options
context:
space:
mode:
authoradityacp2020-09-07 12:53:08 +0530
committeradityacp2020-09-07 12:53:08 +0530
commit7e5608d0853d69358c14f9fb8fbd6465e21b8962 (patch)
tree949aeb4303f7cdd8cdd106977b0a06dcd6d5b8af /yaksh/forms.py
parentd22930f72652b0b306dd491767e8368280bb8266 (diff)
downloadonline_test-7e5608d0853d69358c14f9fb8fbd6465e21b8962.tar.gz
online_test-7e5608d0853d69358c14f9fb8fbd6465e21b8962.tar.bz2
online_test-7e5608d0853d69358c14f9fb8fbd6465e21b8962.zip
Add edit and delete table of contents options
Diffstat (limited to 'yaksh/forms.py')
-rw-r--r--yaksh/forms.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py
index eedd809..ba8b7d5 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -652,6 +652,7 @@ class TopicForm(forms.ModelForm):
timer = forms.CharField()
def __init__(self, *args, **kwargs):
+ time = kwargs.pop("time") if "time" in kwargs else None
super(TopicForm, self).__init__(*args, **kwargs)
self.fields['name'].widget.attrs.update(
{'class': form_input_class, 'placeholder': 'Topic Name'}
@@ -659,11 +660,23 @@ class TopicForm(forms.ModelForm):
self.fields['timer'].widget.attrs.update(
{'class': form_input_class, 'placeholder': 'Topic Time'}
)
+ self.fields['timer'].initial = time
class Meta:
model = Topic
fields = "__all__"
+ def clean_timer(self):
+ timer = self.cleaned_data.get("timer")
+ if timer:
+ try:
+ hh, mm, ss = timer.split(":")
+ except ValueError:
+ raise forms.ValidationError(
+ "Marker time should be in the format hh:mm:ss"
+ )
+ return timer
+
class VideoQuizForm(forms.ModelForm):
@@ -676,6 +689,7 @@ class VideoQuizForm(forms.ModelForm):
question_type = kwargs.pop('question_type')
else:
question_type = "mcq"
+ time = kwargs.pop("time") if "time" in kwargs else None
super(VideoQuizForm, self).__init__(*args, **kwargs)
self.fields['summary'].widget.attrs.update(
{'class': form_input_class, 'placeholder': 'Summary'}
@@ -690,7 +704,7 @@ class VideoQuizForm(forms.ModelForm):
{'class': form_input_class, 'placeholder': 'Points'}
)
self.fields['type'].widget.attrs.update(
- {'class': form_input_class, 'readonly': True}
+ {'class': form_input_class}
)
self.fields['type'].initial = question_type
self.fields['description'].widget.attrs.update(
@@ -699,8 +713,20 @@ class VideoQuizForm(forms.ModelForm):
self.fields['timer'].widget.attrs.update(
{'class': form_input_class, 'placeholder': 'Quiz Time'}
)
+ self.fields['timer'].initial = time
class Meta:
model = Question
fields = ['summary', 'description', 'points',
'language', 'type', 'topic']
+
+ def clean_timer(self):
+ timer = self.cleaned_data.get("timer")
+ if timer:
+ try:
+ hh, mm, ss = timer.split(":")
+ except ValueError:
+ raise forms.ValidationError(
+ "Marker time should be in the format hh:mm:ss"
+ )
+ return timer \ No newline at end of file