2018-10-17 09:39:31 +00:00
|
|
|
from django import forms
|
2018-10-17 11:18:34 +00:00
|
|
|
from django.forms import inlineformset_factory
|
2018-10-17 09:39:31 +00:00
|
|
|
from dal.autocomplete import ModelSelect2Multiple
|
|
|
|
|
2018-10-20 06:59:28 +00:00
|
|
|
from .models import Job, Question, Application, Answer
|
2018-10-17 09:39:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class JobForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Job
|
|
|
|
fields = ('title', 'description', 'tags')
|
|
|
|
widgets = {
|
|
|
|
'tags': ModelSelect2Multiple(url='jobs:tag-autocomplete')
|
|
|
|
}
|
|
|
|
|
2018-10-17 11:18:34 +00:00
|
|
|
|
|
|
|
class QuestionForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Question
|
|
|
|
fields = '__all__'
|
|
|
|
widgets = {
|
|
|
|
'name': forms.widgets.TextInput()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-20 06:59:28 +00:00
|
|
|
class ApplicationForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Application
|
|
|
|
exclude = ('job', 'applicant')
|
|
|
|
|
|
|
|
|
|
|
|
class AnswerForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Answer
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.fields['text'].required = True
|
|
|
|
self.fields['question'].disabled = True
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def inlineformset_factory(cls, extra=3):
|
|
|
|
return inlineformset_factory(
|
|
|
|
Application,
|
|
|
|
Answer,
|
|
|
|
form=cls,
|
|
|
|
min_num=extra,
|
|
|
|
max_num=extra,
|
|
|
|
validate_min=True,
|
|
|
|
can_delete=False,
|
|
|
|
can_order=False)
|
|
|
|
|
|
|
|
|
2018-10-17 11:18:34 +00:00
|
|
|
QuestionFormSet = inlineformset_factory(
|
2018-10-20 05:34:49 +00:00
|
|
|
Job, Question, form=QuestionForm, can_delete=False, can_order=False)
|
|
|
|
|
|
|
|
QuestionUpdateFormSet = inlineformset_factory(
|
2018-10-20 06:59:28 +00:00
|
|
|
Job, Question, form=QuestionForm, can_delete=True, can_order=False)
|