42 lines
1.8 KiB
Python
42 lines
1.8 KiB
Python
from django import forms
|
|
class AnswersForm(forms.Form):
|
|
def __init__(self, *args, **kwargs):
|
|
questions = kwargs.pop('questions', [])
|
|
super().__init__(*args, **kwargs)
|
|
for q in questions:
|
|
if q.question_type == 'TEXT_AUTO':
|
|
self.fields[f'answer_{q.id}'] = forms.CharField(
|
|
label='Ответ:',
|
|
required=False,
|
|
widget=forms.Textarea(attrs={
|
|
'class': 'w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500',
|
|
'rows': 3,
|
|
'placeholder': 'Введите ваш ответ здесь...'
|
|
})
|
|
)
|
|
else:
|
|
self.fields[f'file_{q.id}'] = forms.FileField(
|
|
label='Прикрепить файл:',
|
|
required=False,
|
|
widget=forms.ClearableFileInput(attrs={
|
|
'class': 'block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100'
|
|
})
|
|
)
|
|
|
|
from django.contrib.auth import get_user_model
|
|
from django.contrib.auth.forms import UserCreationForm
|
|
|
|
User = get_user_model()
|
|
|
|
class StudentRegistrationForm(UserCreationForm):
|
|
class Meta(UserCreationForm.Meta):
|
|
model = User
|
|
fields = ('username', 'first_name')
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
for field in self.fields.values():
|
|
field.widget.attrs.update({
|
|
'class': 'w-full px-4 py-3 rounded-xl border border-gray-300 focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none transition shadow-sm text-gray-800'
|
|
})
|