Skip to content
Snippets Groups Projects
forms.py 1.21 KiB
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
            fields: list = []
    
    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]
    
            action_field = self.fields['action']
            action_field.choices = choices
            action_field.label = f'Current status: {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)
    
    
    
    class UpdateSubmissionLeadForm(forms.ModelForm):
        class Meta:
            model = ApplicationSubmission
            fields = ('lead',)
    
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
    
            lead_field = self.fields['lead']
            lead_field.label = f'Update lead from { self.instance.lead } to'
            lead_field.queryset = lead_field.queryset.exclude(id=self.instance.lead.id)