pytask/taskapp/forms.py
author Nishanth Amuluru <nishanth@fossee.in>
Sun, 09 Jan 2011 11:13:36 +0530
changeset 114 1a88b04adb39
parent 109 d291c08c62de
child 121 fc26de9c943f
permissions -rw-r--r--
created form for making a claim
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
94
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     1
from django import forms
114
1a88b04adb39 created form for making a claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 109
diff changeset
     2
from pytask.taskapp.models import Task, WorkReport, TaskComment, TaskClaim
94
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     3
98
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
     4
class CreateTaskForm(forms.ModelForm):
94
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     5
    class Meta:
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     6
        model = Task
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     7
        fields = ['title', 'desc', 'tags_field', 'pynts']
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     8
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
     9
    def clean_title(self):
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    10
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    11
        data = self.cleaned_data['title'].strip()
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    12
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    13
        if not data:
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    14
            raise forms.ValidationError("This field is required")
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    15
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    16
        try:
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    17
            Task.objects.exclude(status="DL").get(title__iexact=data)
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    18
            raise forms.ValidationError("Another task with same title exists")
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    19
        except Task.DoesNotExist:
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    20
            return data
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    21
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    22
    def clean_desc(self):
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    23
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    24
        data = self.cleaned_data['desc'].strip()
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    25
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    26
        if not data:
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    27
            raise forms.ValidationError("This field is required")
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    28
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    29
        return data
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    30
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    31
class EditTaskForm(forms.ModelForm):
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    32
    class Meta:
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    33
        model = Task
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    34
        fields = ['title', 'desc', 'tags_field', 'pynts']
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    35
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    36
    def clean_desc(self):
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    37
        data = self.cleaned_data['desc'].strip()
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    38
        if not data:
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    39
            raise forms.ValidationError("Enter some description for the task")
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    40
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    41
        return data
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    42
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    43
    def clean_title(self):
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    44
        data = self.cleaned_data['title'].strip()
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    45
        try:
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    46
            prev_task = Task.objects.exclude(status="DL").get(title__iexact=data)
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    47
            if prev_task.id != self.instance.id:
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    48
                raise forms.ValidationError("Another task with same title exists")
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    49
            else:
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    50
                return data
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    51
        except Task.DoesNotExist:
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    52
            return data
385702a0bbde Added forms for creating and editing a task
Nishanth Amuluru <nishanth@fossee.in>
parents:
diff changeset
    53
109
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    54
class TaskCommentForm(forms.ModelForm):
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    55
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    56
    class Meta:
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    57
        model = TaskComment
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    58
        fields = ['data']
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    59
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    60
    def clean_data(self):
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    61
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    62
        data = self.cleaned_data['data'].strip()
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    63
        if not data:
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    64
            raise forms.ValidationError("Please add some content")
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    65
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    66
        return data
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    67
114
1a88b04adb39 created form for making a claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 109
diff changeset
    68
class ClaimTaskForm(forms.ModelForm):
1a88b04adb39 created form for making a claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 109
diff changeset
    69
1a88b04adb39 created form for making a claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 109
diff changeset
    70
    class Meta:
1a88b04adb39 created form for making a claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 109
diff changeset
    71
        model = TaskClaim
1a88b04adb39 created form for making a claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 109
diff changeset
    72
        fields = ["proposal"]
1a88b04adb39 created form for making a claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 109
diff changeset
    73
1a88b04adb39 created form for making a claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 109
diff changeset
    74
    def clean_proposal(self):
1a88b04adb39 created form for making a claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 109
diff changeset
    75
        data = self.cleaned_data['proposal'].strip()
1a88b04adb39 created form for making a claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 109
diff changeset
    76
        if not data:
1a88b04adb39 created form for making a claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 109
diff changeset
    77
            raise forms.ValidationError('Enter something as a proposal')
1a88b04adb39 created form for making a claim
Nishanth Amuluru <nishanth@fossee.in>
parents: 109
diff changeset
    78
        return data
109
d291c08c62de added a form for commenting on tasks
Nishanth Amuluru <nishanth@fossee.in>
parents: 98
diff changeset
    79
98
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    80
def AddReviewerForm(choices,instance=None):
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    81
    """ return a form object with appropriate choices """
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    82
    
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    83
    class myform(forms.Form):
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    84
        reviewer = forms.ChoiceField(choices=choices, required=True)
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    85
    form = myform(instance) if instance else myform()
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    86
    return form
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    87
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    88
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    89
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    90
def ChoiceForm(choices, instance=None):
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    91
    """ return a form object with appropriate choices """
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    92
    
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    93
    class myform(forms.Form):
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    94
        choice = forms.ChoiceField(choices=choices, required=True)
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    95
    form = myform(instance) if instance else myform()
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    96
    return form
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    97
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    98
def AddTaskForm(task_choices, is_plain=False):
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
    99
    """ if is_plain is true, it means the task has no subs/deps.
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   100
    so we also give a radio button to choose between subs and dependencies.
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   101
    else we only give choices.
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   102
    """
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   103
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   104
    class myForm(forms.Form):
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   105
        if is_plain:
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   106
            type_choices = [('S','Subtasks'),('D','Dependencies')]
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   107
            type = forms.ChoiceField(type_choices, widget=forms.RadioSelect)
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   108
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   109
        task = forms.ChoiceField(choices=task_choices)
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   110
    return myForm()
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   111
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   112
def AssignPyntForm(choices, instance=None):
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   113
    
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   114
    class myForm(forms.Form):
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   115
        user = forms.ChoiceField(choices=choices, required=True)
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   116
        pynts = forms.IntegerField(min_value=0, required=True, help_text="Choose wisely since it cannot be undone.")
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   117
    return myForm(instance) if instance else myForm()
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   118
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   119
def RemoveUserForm(choices, instance=None):
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   120
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   121
    class myForm(forms.Form):
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   122
        user = forms.ChoiceField(choices=choices, required=True)
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   123
        reason = forms.CharField(min_length=1, required=True)
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   124
    return myForm(instance) if instance else myForm()
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   125
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   126
class WorkReportForm(forms.ModelForm):
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   127
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   128
    class Meta:
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   129
        model = WorkReport
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   130
        fields = ['remarks', 'attachment']
01c1e6966d86 created template for create_task
Nishanth Amuluru <nishanth@fossee.in>
parents: 94
diff changeset
   131