summaryrefslogtreecommitdiff
path: root/website/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'website/forms.py')
-rw-r--r--website/forms.py39
1 files changed, 8 insertions, 31 deletions
diff --git a/website/forms.py b/website/forms.py
index e2e6783..14f4d2d 100644
--- a/website/forms.py
+++ b/website/forms.py
@@ -1,42 +1,19 @@
from django import forms
from website.models import *
-from spoken_auth.models import TutorialDetails, TutorialResources, FossCategory
+#from spoken_auth.models import TutorialDetails
from django.db.models import Q
-tutorials = (
- ("", "Select a Tutorial"),
-)
-minutes = (
- ("", "min"),
-)
-seconds= (
- ("", "sec"),
-)
+class NewQuestionForm(forms.ModelForm):
+ category = forms.ModelChoiceField(widget = forms.Select(attrs = {}), queryset = FossCategory.objects.order_by('name'), empty_label = "Select a category", error_messages = {'required':'Categoty field required.'})
+ tutorial = forms.ModelChoiceField(widget = forms.Select(attrs = {}), queryset = Issue.objects.order_by('name'), empty_label = "Select a Issue", error_messages = {'required':'Issue field required.'})
+ class Meta:
+ model = Question
+ fields = ['category', 'tutorial', 'title', 'body']
-class NewQuestionForm(forms.Form):
- category = forms.ChoiceField(choices = [('', 'Select a Category'),] + list(TutorialResources.objects.filter(Q(status = 1) | Q(status = 2), language__name = 'English').values('tutorial_detail__foss__foss').order_by('tutorial_detail__foss__foss').values_list('tutorial_detail__foss__foss', 'tutorial_detail__foss__foss').distinct()), widget=forms.Select(attrs = {}), required = True, error_messages = {'required':'State field is required.'})
def __init__(self, *args, **kwargs):
category = kwargs.pop('category', None)
super(NewQuestionForm, self).__init__(*args, **kwargs)
- tutorial_choices = (
- ("", "Select a Tutorial"),
- )
- if not category and args and 'category' in args[0] and args[0]['category']:
- category = args[0]['category']
- if FossCategory.objects.filter(foss=category).exists():
- self.fields['category'].initial = category
- tutorials = TutorialDetails.objects.using('spoken').filter(foss__foss=category)
- for tutorial in tutorials:
- tutorial_choices += ((tutorial.tutorial, tutorial.tutorial),)
- self.fields['tutorial'] = forms.CharField(widget=forms.Select(choices=tutorial_choices))
- else:
- self.fields['tutorial'] = forms.CharField(widget=forms.Select(choices=tutorial_choices))
-
- minute_range = forms.CharField(widget=forms.Select(choices=minutes))
- second_range = forms.CharField(widget=forms.Select(choices=seconds))
- title = forms.CharField(max_length=200)
- body = forms.CharField(widget=forms.Textarea())
-
+
class AnswerQuesitionForm(forms.Form):
question = forms.IntegerField(widget=forms.HiddenInput())
body = forms.CharField(widget=forms.Textarea())