''' @author: olivier.massot, 2018 ''' from django import forms from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.models import User from martor.fields import MartorFormField from main.models import Story, Epic, Comment, Sprint class RegisterForm(UserCreationForm): class Meta: model = User fields = ('username', 'first_name', 'last_name', 'email') def save(self, commit=True): user = super(RegisterForm, self).save(commit=False) user.first_name = self.cleaned_data["first_name"] user.last_name = self.cleaned_data["last_name"] user.email = self.cleaned_data["email"] if commit: user.save() class ProfileForm(forms.ModelForm): class Meta: model = User fields = ('username', 'first_name', 'last_name', 'email') class EpicForm(forms.ModelForm): description = MartorFormField(label="Description") class Meta: model = Epic fields = ('project', 'name', 'size', 'value', 'description') def __init__(self, *args, **kwargs): super(EpicForm, self).__init__(*args, **kwargs) self.fields['description'].required = False class StoryForm(forms.ModelForm): description = MartorFormField(label="Description") class Meta: model = Story widgets = {'author': forms.HiddenInput()} fields = ('epic', 'author', 'name', 'weight', 'description', 'assignees', 'sprints') def __init__(self, *args, **kwargs): super(StoryForm, self).__init__(*args, **kwargs) self.fields['description'].required = False self.fields['assignees'].required = False self.fields['sprints'].required = False self.fields['weight'].required = False def save(self, *args, **kwargs): if self.cleaned_data['weight'] == '': self.cleaned_data['weight'] = None return super(StoryForm, self).save(*args, **kwargs) class CommentForm(forms.ModelForm): class Meta: model = Comment widgets = {'content_type': forms.HiddenInput(), 'object_id': forms.HiddenInput()} fields = ('content','content_type', 'object_id') content = MartorFormField(label="Commentaire") def __init__(self, *args, **kwargs): super(CommentForm, self).__init__(*args, **kwargs) if not self.prefix: self.prefix = str(self.instance.id) if self.instance and self.instance.id else "new" class SprintForm(forms.ModelForm): class Meta: model = Sprint fields = ('retro',) retro = MartorFormField(label="Rétrospective")