Skip to content
Snippets Groups Projects
forms.py 775 B
Newer Older
  • Learn to ignore specific revisions
  • Todd Dembrey's avatar
    Todd Dembrey committed
    from django import forms
    
    Todd Dembrey's avatar
    Todd Dembrey committed
    from .models import ApplicationSubmission
    
    Todd Dembrey's avatar
    Todd Dembrey committed
    class ProgressSubmissionForm(forms.ModelForm):
    
        action = forms.ChoiceField()
    
    
    Todd Dembrey's avatar
    Todd Dembrey committed
        class Meta:
            model = ApplicationSubmission
    
    Todd Dembrey's avatar
    Todd Dembrey committed
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
    
            choices = [(action, action) for action in self.instance.phase.action_names]
            self.fields['action'].choices = choices
            self.fields['action'].label = self.instance.phase.name
    
            self.should_show = bool(choices)
    
    
        def save(self, *args, **kwargs):
            new_phase = self.instance.workflow.process(self.instance.phase, self.cleaned_data['action'])
            self.instance.status = str(new_phase)
            return super().save(*args, **kwargs)