53 lines
2.6 KiB
Python
53 lines
2.6 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-3 bg-obsidian-base border border-obsidian-border rounded-lg text-white placeholder-txt-faint focus:outline-none focus:ring-2 focus:ring-accent-blue/30 focus:border-accent-blue transition-colors font-mono text-sm',
|
|
'rows': 3,
|
|
'placeholder': 'Введите ваш ответ здесь...'
|
|
})
|
|
)
|
|
elif q.question_type == 'TABLE_AUTO':
|
|
rows = getattr(q, 'table_rows', 2) or 2
|
|
for i in range(1, rows + 1):
|
|
for j in range(1, 3):
|
|
self.fields[f'answer_{q.id}_r{i}_c{j}'] = forms.CharField(
|
|
required=False,
|
|
widget=forms.TextInput(attrs={
|
|
'class': 'w-full px-3 py-2 bg-transparent border-0 focus:ring-0 text-white font-mono text-sm',
|
|
'placeholder': '...'
|
|
})
|
|
)
|
|
else:
|
|
self.fields[f'file_{q.id}'] = forms.FileField(
|
|
label='Прикрепить файл:',
|
|
required=False,
|
|
widget=forms.ClearableFileInput(attrs={
|
|
'class': 'block w-full text-sm text-txt-secondary file:mr-4 file:py-2 file:px-4 file:rounded-md file:border-0 file:text-sm file:font-semibold file:bg-obsidian-border file:text-white hover:file:bg-obsidian-borderLight transition-colors cursor-pointer'
|
|
})
|
|
)
|
|
|
|
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'
|
|
})
|