taskapp/forms/task.py
author nishanth
Tue, 02 Mar 2010 14:46:05 +0530
changeset 174 d034cd77cfa6
parent 165 8ea5bcf3bd01
child 178 106909df0c17
permissions -rw-r--r--
added footer to base.html.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 12
diff changeset
     1
from django import forms
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
     2
from pytask.taskapp.models import Task, Claim
18
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 12
diff changeset
     3
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 12
diff changeset
     4
class TaskCreateForm(forms.ModelForm):
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 12
diff changeset
     5
    class Meta:
a39549bd5b08 implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents: 12
diff changeset
     6
        model = Task
50
d40e86f958f7 made changes in addtaskform to suit tagging.
nishanth
parents: 25
diff changeset
     7
        fields = ['title', 'desc', 'tags_field', 'credits']
165
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
     8
    #publish = forms.BooleanField(required=False)
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
     9
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
    10
def EditTaskForm(task, instance=None):
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
    11
    class myForm(forms.ModelForm):
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
    12
        class Meta:
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
    13
            model = Task
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
    14
            fields = ['title', 'desc', 'tags_field', 'credits']
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
    15
    data = {
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
    16
        'title': task.title,
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
    17
        'desc': task.desc,
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
    18
        'tags_field': task.tags_field,
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
    19
        'credits': task.credits,
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
    20
    }
8ea5bcf3bd01 implemented edit_task functionality.
nishanth
parents: 151
diff changeset
    21
    return myForm(instance) if instance else myForm(data)
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    22
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    23
def AddMentorForm(choices,instance=None):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    24
    """ return a form object with appropriate choices """
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    25
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    26
    class myform(forms.Form):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    27
        mentor = forms.ChoiceField(choices=choices, required=True)
151
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 136
diff changeset
    28
    form = myform(instance) if instance else myform()
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    29
    return form
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    30
22
36d3173ab7f9 addded link to view claims in 'view task' page .
nishanth
parents: 21
diff changeset
    31
class ClaimTaskForm(forms.ModelForm):
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    32
    class Meta:
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    33
        model = Claim
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 18
diff changeset
    34
        fields = ['message']
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
    35
151
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 136
diff changeset
    36
def ChoiceForm(choices, instance=None):
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
    37
    """ return a form object with appropriate choices """
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
    38
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
    39
    class myform(forms.Form):
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 91
diff changeset
    40
        choice = forms.ChoiceField(choices=choices, required=True)
151
d0cb85ba462a no bogus post request can be made now in addmentor page.
nishanth
parents: 136
diff changeset
    41
    form = myform(instance) if instance else myform()
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 22
diff changeset
    42
    return form
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 50
diff changeset
    43
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 50
diff changeset
    44
def AddTaskForm(task_choices, is_plain=False):
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 50
diff changeset
    45
    """ if is_plain is true, it means the task has no subs/deps.
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 50
diff changeset
    46
    so we also give a radio button to choose between subs and dependencies.
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 50
diff changeset
    47
    else we only give choices.
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 50
diff changeset
    48
    """
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 50
diff changeset
    49
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 50
diff changeset
    50
    class myForm(forms.Form):
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 50
diff changeset
    51
        if is_plain:
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 50
diff changeset
    52
            type_choices = [('S','Subtasks'),('D','Dependencies')]
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 50
diff changeset
    53
            type = forms.ChoiceField(type_choices, widget=forms.RadioSelect)
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 50
diff changeset
    54
90
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    55
        task = forms.ChoiceField(choices=task_choices)
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 50
diff changeset
    56
    return myForm()
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
    57
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
    58
def AssignCreditForm(choices, instance=None):
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
    59
    
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
    60
    class myForm(forms.Form):
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
    61
        user = forms.ChoiceField(choices=choices, required=True)
136
8632a44b743d deducing previous credits for a task using the request model. with a few changes, we can ditchax the credits model.
nishanth
parents: 94
diff changeset
    62
        pynts = forms.IntegerField(min_value=0, required=True, help_text="Choose wisely since it cannot be undone.")
93
1a1e712e60fd finished assign_credits view. hav to integrate it with requests now.
nishanth
parents: 92
diff changeset
    63
    return myForm(instance) if instance else myForm()
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
    64
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
    65
def RemoveUserForm(choices, instance=None):
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
    66
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
    67
    class myForm(forms.Form):
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
    68
        user = forms.ChoiceField(choices=choices, required=True)
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
    69
        reason = forms.CharField(min_length=1, required=True)
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
    70
    return myForm(instance) if instance else myForm()
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 93
diff changeset
    71