summaryrefslogtreecommitdiff
path: root/yaksh/forms.py
diff options
context:
space:
mode:
authorPalaparthy Adityachandra2020-04-30 17:24:17 +0530
committerGitHub2020-04-30 17:24:17 +0530
commit2fd29bf1fff3d57a49b8a5cdffa9efc305946214 (patch)
tree16d974b5a5e1effaf15be2235813dca4108c4f29 /yaksh/forms.py
parent6fc01303dba0b821aa2344b761e98dc36b33807b (diff)
parent53a0c4ad3e733f3960000527f83565f2fd8fc412 (diff)
downloadonline_test-2fd29bf1fff3d57a49b8a5cdffa9efc305946214.tar.gz
online_test-2fd29bf1fff3d57a49b8a5cdffa9efc305946214.tar.bz2
online_test-2fd29bf1fff3d57a49b8a5cdffa9efc305946214.zip
Merge branch 'master' into API
Diffstat (limited to 'yaksh/forms.py')
-rw-r--r--yaksh/forms.py120
1 files changed, 81 insertions, 39 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py
index c0f40ea..216f5c2 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -1,7 +1,7 @@
from django import forms
from yaksh.models import (
get_model_class, Profile, Quiz, Question, Course, QuestionPaper, Lesson,
- LearningModule, TestCase
+ LearningModule, TestCase, languages, question_types, Post, Comment
)
from grades.models import GradingSystem
from django.contrib.auth import authenticate
@@ -17,27 +17,9 @@ from string import punctuation, digits
import pytz
from .send_emails import generate_activation_key
-languages = (
- ("select", "Select Language"),
- ("python", "Python"),
- ("bash", "Bash"),
- ("c", "C Language"),
- ("cpp", "C++ Language"),
- ("java", "Java Language"),
- ("scilab", "Scilab"),
-)
+languages = (("", "Select Language"),) + languages
-question_types = (
- ("select", "Select Question Type"),
- ("mcq", "Multiple Choice"),
- ("mcc", "Multiple Correct Choices"),
- ("code", "Code"),
- ("upload", "Assignment Upload"),
- ("integer", "Answer in Integer"),
- ("string", "Answer in String"),
- ("float", "Answer in Float"),
- ("arrange", "Arrange in Correct Order"),
-)
+question_types = (("", "Select Question Type"),) + question_types
test_case_types = (
("standardtestcase", "Standard Testcase"),
@@ -50,7 +32,7 @@ test_case_types = (
)
status_types = (
- ('select','Select Status'),
+ ('select', 'Select Status'),
('active', 'Active'),
('closed', 'Inactive'),
)
@@ -362,39 +344,58 @@ class RandomQuestionForm(forms.Form):
class QuestionFilterForm(forms.Form):
+
+ language = forms.ChoiceField(
+ choices=languages,
+ widget=forms.Select(attrs={'class': 'custom-select'}),
+ required=False
+ )
+ question_type = forms.ChoiceField(
+ choices=question_types,
+ widget=forms.Select(attrs={'class': 'custom-select'}),
+ required=False
+ )
+
def __init__(self, *args, **kwargs):
user = kwargs.pop("user")
+ lang = kwargs.pop("language") if "language" in kwargs else None
+ que_type = kwargs.pop("type") if "type" in kwargs else None
+ marks = kwargs.pop("marks") if "marks" in kwargs else None
super(QuestionFilterForm, self).__init__(*args, **kwargs)
- questions = Question.objects.filter(user_id=user.id)
- points_list = questions.values_list('points', flat=True).distinct()
- points_options = [(None, 'Select Marks')]
- points_options.extend([(point, point) for point in points_list])
- self.fields['marks'] = forms.FloatField(
- widget=forms.Select(choices=points_options,
- attrs={'class': 'custom-select'})
+ points = Question.objects.filter(
+ user_id=user.id).values_list('points', flat=True).distinct()
+ points_options = [('', 'Select Marks')]
+ points_options.extend([(point, point) for point in points])
+ self.fields['marks'] = forms.ChoiceField(
+ choices=points_options,
+ widget=forms.Select(attrs={'class': 'custom-select'}),
+ required=False
)
self.fields['marks'].required = False
- language = forms.CharField(
- max_length=8, widget=forms.Select(choices=languages,
- attrs={'class': 'custom-select'}))
- question_type = forms.CharField(
- max_length=8, widget=forms.Select(choices=question_types,
- attrs={'class': 'custom-select'})
- )
+ self.fields['language'].initial = lang
+ self.fields['question_type'].initial = que_type
+ self.fields['marks'].initial = marks
class SearchFilterForm(forms.Form):
search_tags = forms.CharField(
label='Search Tags',
widget=forms.TextInput(attrs={'placeholder': 'Search',
- 'class': form_input_class,}),
+ 'class': form_input_class, }),
required=False
)
- search_status = forms.CharField(max_length=16, widget=forms.Select(
+ search_status = forms.ChoiceField(
choices=status_types,
- attrs={'class': 'custom-select'}),
+ widget=forms.Select(attrs={'class': 'custom-select'})
)
+ def __init__(self, *args, **kwargs):
+ status = kwargs.pop("status") if "status" in kwargs else None
+ tags = kwargs.pop("tags") if "tags" in kwargs else None
+ super(SearchFilterForm, self).__init__(*args, **kwargs)
+ self.fields["search_status"].initial = status
+ self.fields["search_tags"].initial = tags
+
class CourseForm(forms.ModelForm):
""" course form for moderators """
@@ -570,3 +571,44 @@ class TestcaseForm(forms.ModelForm):
class Meta:
model = TestCase
fields = ["type"]
+
+
+class PostForm(forms.ModelForm):
+ class Meta:
+ model = Post
+ fields = ["title", "description", "image"]
+ widgets = {
+ 'title': forms.TextInput(
+ attrs={
+ 'class': 'form-control'
+ }
+ ),
+ 'description': forms.Textarea(
+ attrs={
+ 'class': 'form-control'
+ }
+ ),
+ 'image': forms.FileInput(
+ attrs={
+ 'class': 'form-control-file'
+ }
+ )
+ }
+
+
+class CommentForm(forms.ModelForm):
+ class Meta:
+ model = Comment
+ fields = ["description", "image"]
+ widgets = {
+ 'description': forms.Textarea(
+ attrs={
+ 'class': 'form-control'
+ }
+ ),
+ 'image': forms.FileInput(
+ attrs={
+ 'class': 'form-control-file'
+ }
+ )
+ }