Ejemplo n.º 1
0
def create_task(task_title, user):
    """
    Creates the task with the `task_title` and assigns the `user` to
    `assigned_users` if `assigned_users` is empty.
    """
    task = Task()
    task.save_from_re(task_title)

    # If user was not yet assigned use the email user.
    if len(task.assigned_users.all()) == 0:
        task.assigned_users.add(user)

    return task
Ejemplo n.º 2
0
def read_create(request, filter_type=None, filter_id=None):
    '''
    Gets all the tasks given the filter_type. If filter_type is none it returns all 
    uncompleted Tasks. It also creates a Task.
    '''
    # Create Task
    if request.method == 'POST':
        task = request.POST.get('task')
        notes = request.POST.get('notes')
        if task:
            new_task = Task()
            new_task.notes = notes
            new_task.save_from_re(task)
            return HttpResponse('success')

    # Get Tasks
    else:
        tasks = Task.objects.order_by('-created')

        # GET has a parameted, completed, which is used to fetch all completed tasks.
        if request.GET.get('completed'):
            tasks = tasks.filter(completed=True)
        else:
            tasks = tasks.filter(completed=False)

        if filter_type == 'user':
            user = User.objects.get(id=filter_id)
            tasks = tasks.filter(assigned_users=user)

        elif filter_type == 'tag':
            tag = Tag.objects.get(id=filter_id)
            tasks = tasks.filter(tag=tag)

        elif filter_type == 'list':
            task_list = TaskList.objects.get(id=filter_id)
            tasks = tasks.filter(task_list=task_list)


        return render_to_response('tasks/index.html', 
                                    {'tasks': tasks}, 
                                    context_instance=RequestContext(request))