Пример #1
0
def task_edit(request, task_id):
    group = get_current_group(request)
    if group == None:	
        return HttpResponseRedirect(reverse('index'))

    task = Task.objects.get(pk=int(task_id))
    
    if task.group != group:
        return HttpResponseRedirect(reverse('index'))
    
    page_heading = task
    
    if request.method == "POST":
        if request.POST['button']:
            if request.POST['button']=='delete_task':
                task.delete()
                return HttpResponseRedirect(reverse('task-list'))
            else:
                form = EditTaskForm(group, request.POST, instance=task,
                                    label_suffix='')
#                import pdb; pdb.set_trace()
                if form.is_valid():
                    form.save(group)    
                    return HttpResponseRedirect(reverse('task-list'))
    else:
        form = EditTaskForm(group, instance=task, label_suffix='')

    menu = {'parent': 'tasks'}        		
    return render(request, 'task_edit.html', {
	              'menu': menu,
                  'form': form,
                  'page_heading': page_heading,
                  'task_id': task_id,
                  })
Пример #2
0
def edit_task(request, task_id):
    """Opens a task for viewing or editing."""

    id, task = w.get_task(id=task_id)

    if request.method == "POST":
        form = EditTaskForm(request.POST, label_suffix='')
        if form.is_valid():
            # Write non-tag attributes to the task
            non_tag_fields = [
                'description',
                'view',
                'priority',
                'order',
                'time',
                'project',
                'due',
                'recur',
                'until',
                'wait'
            ]
            for attribute in non_tag_fields:
                value = form.cleaned_data[attribute]
                if value == '':
                    value = None
                # If their value isn't None, the time and order variables
                # must be integers to be saved into the task dictionary
                if attribute in ['time', 'order']:
                    if value:
                        value = int(value)
                task[attribute] = value
            # Create the tag attribute in the format which taskw expects and
            # write it to the task
            tag_fields = ['context_1',
                          'context_2',
                          'context_3']
            tags = []
            for attribute in tag_fields:
                value = form.cleaned_data[attribute]
                tags.append(value)
            task['tags'] = tags
            # Update the task while being aware that Taskwarrior may
            # ask a question as a result of the task update
            try:
                id, task = w.task_update(task)
            except Exception, e:
                question_received = e[11:83]
                expected_question = 'This is a recurring task.  Do you ' + \
                                    'want to modify all pending recurrences'
                if question_received == expected_question:
                    w.answer_question(answer='yes')

            return render(request, 'single_task.html', {'task': task})
Пример #3
0
def view_task(request, task_id):
    """
    Displays a chosen task
    """

    task = ProjectTask.objects.get(id=task_id)
    showTask = task.public

    args = {}
    initialDict = {
        "summary": task.summary,
        "description": task.description,
        "public":bool(task.public)
    }

    form = EditTaskForm()
    form.initial = initialDict
    args['form'] = form
    args['openOn'] = [task.project]
    args['task'] = task
    args['members'] = task.assigned.all()

    if( not request.user.is_authenticated() ):
      args['canEdit'] = False
      args['isMember'] = False
      args['tags'] = task.tags.filter(Q(public=True))
      args['yourTags'] = []

    elif( request.user.is_authenticated() ):

      args['user'] = request.user
      args['canEdit'] = (task.creator == request.user)
      args['isMember'] = (request.user in task.assigned.all())
      args['tags'] = task.tags.filter(Q(owner=request.user) | Q(
          users=request.user) | Q(viewers=request.user) | Q(public=True))
      args['yourTags'] = args['tags'].filter(
          Q(owner=request.user) | Q(users=request.user) | Q(viewers=request.user))

      showTask = args['canEdit'] or task.public or args['isMember']

    args.update(csrf(request))

    args['add_member_form'] = AddMemberForm()

    if ( showTask ):
      return render_to_response('task_view.html', RequestContext(request, args))
    else:
      messages.warning(request, "The task you tried to view does not exist, or you don't have permission to see it.")
      return HttpResponseRedirect('/projects/')
Пример #4
0
def task_details(request: WSGIRequest, task_pk: int, *args, **kwargs):
    task: Task = get_object_or_404(Task, pk=task_pk)

    if task.user != request.user:
        messages.add_message(
            request, messages.ERROR,
            'Vous n\'êtes pas autorisé à consulter cette tâche')

        return redirect(reverse('tasks:list'))

    form = EditTaskForm(instance=task)

    if request.method == 'POST':
        form = EditTaskForm(instance=task, data=request.POST)

        if form.is_valid():
            form.save()

            return redirect(reverse('tasks:list'))

    return render(request, 'tasks/task_details.html', {
        'active_menu': 'tasks',
        'task': task,
        'form': form,
    })
Пример #5
0
def view_task(request, task_id):
    """
    View task details. Allow task details to be edited.
    """
    task = get_object_or_404(Task, pk=task_id)

    # Ensure user has permission to view item.
    # Get the users this task belongs to.
    # Admins can edit all tasks.

    if task.assigned_to == request.user or request.user.is_staff:
        auth_ok = True

        if request.POST:
            form = EditTaskForm(request.POST, instance=task)

            if form.is_valid():
                form.save()

                messages.success(request, "The task has been edited.")

                return HttpResponseRedirect(reverse('tasks:task-lists'))
        else:
            form = EditTaskForm(instance=task)
            if task.due_date:
                thedate = task.due_date
            else:
                thedate = datetime.datetime.now()
    else:
        messages.info(request,
                      "You do not have permission to view/edit this task.")

    return render(request, 'tasks/view_task.html', locals())
Пример #6
0
def task(request, id, template_name="tasks/task.html"):
    task = get_object_or_404(Task, id=id)
    group = task.group
    
    # @@@ if group.deleted:
    # @@@     raise Http404
    
    if group:
        notify_list = group.member_users.all() # @@@
    else:
        notify_list = User.objects.all()
    
    is_member = True # @@@ groups.has_member(request.user)
    
    if is_member and request.method == "POST":
        form = EditTaskForm(request.user, request.POST, instance=task)
        if form.is_valid():
            task = form.save()
            if "status" in form.changed_data:
                request.user.message_set.create(message="updated your status on the task")
                if notification:
                    notification.send(notify_list, "tasks_status", {"user": request.user, "task": task, "group": group})
            if "state" in form.changed_data:
                request.user.message_set.create(message="task marked %s" % task.get_state_display())
                if notification:
                    notification.send(notify_list, "tasks_change", {"user": request.user, "task": task, "group": group, "new_state": task.get_state_display()})
            if "assignee" in form.changed_data:
                request.user.message_set.create(message="assigned task to '%s'" % task.assignee)
                if notification:
                    notification.send(notify_list, "tasks_assignment", {"user": request.user, "task": task, "assignee": task.assignee, "group": group})
            if "tags" in form.changed_data:
                request.user.message_set.create(message="updated tags on the task")
                if notification:
                    notification.send(notify_list, "tasks_tags", {"user": request.user, "task": task, "group": group})
            form = EditTaskForm(request.user, instance=task)
    else:
        form = EditTaskForm(request.user, instance=task)
    
    return render_to_response(template_name, {
        "task": task,
        "is_member": is_member,
        "form": form,
    }, context_instance=RequestContext(request))
Пример #7
0
def task_edit(request, task_id):
    group = get_current_group(request)
    if group == None:
        return HttpResponseRedirect(reverse('index'))

    task = Task.objects.get(pk=int(task_id))

    if task.group != group:
        return HttpResponseRedirect(reverse('index'))

    page_heading = task

    if request.method == "POST":
        if request.POST['button']:
            if request.POST['button'] == 'delete_task':
                task.delete()
                return HttpResponseRedirect(reverse('task-list'))
            else:
                form = EditTaskForm(group,
                                    request.POST,
                                    instance=task,
                                    label_suffix='')
                #                import pdb; pdb.set_trace()
                if form.is_valid():
                    form.save(group)
                    return HttpResponseRedirect(reverse('task-list'))
    else:
        form = EditTaskForm(group, instance=task, label_suffix='')

    menu = {'parent': 'tasks', 'child': 'manage_tasks', 'tips': 'edit_task'}
    return render(
        request, 'task_edit.html', {
            'menu': menu,
            'form': form,
            'page_heading': page_heading,
            'task_id': task_id,
        })
Пример #8
0
def task(request, id, group_slug=None, template_name="tasks/task.html", bridge=None):
    
    if bridge:
        try:
            group = bridge.get_group(group_slug)
        except ObjectDoesNotExist:
            raise Http404
    else:
        group = None
    
    if group:
        tasks = group.content_objects(Task)
        group_base = bridge.group_base_template()
    else:
        tasks = Task.objects.filter(object_id=None)
        group_base = None
    
    task = get_object_or_404(tasks, id=id)
    
    if group:
        notify_list = group.member_queryset()
    else:
        notify_list = User.objects.all()
    notify_list = notify_list.exclude(id__exact=request.user.id)
    
    if not request.user.is_authenticated():
        is_member = False
    else:
        if group:
            is_member = group.user_is_member(request.user)
        else:
            is_member = True
    
    if is_member and request.method == "POST":
        form = EditTaskForm(request.user, group, request.POST, instance=task)
        if form.is_valid():
            task = form.save()
            task.save_history(change_owner=request.user)
            if task.assignee == request.user:
                task.denudge()
            if "status" in form.changed_data:
                messages.add_message(request, messages.SUCCESS,
                    ugettext("updated your status on the task")
                )
                if notification:
                    notification.send(notify_list, "tasks_status", {"user": request.user, "task": task, "group": group})
            if "state" in form.changed_data:
                messages.add_message(request, messages.SUCCESS,
                    ugettext("task marked %(state)s") % {
                        "state": task.get_state_display()
                    }
                )
                if notification:
                    notification.send(notify_list, "tasks_change", {"user": request.user, "task": task, "group": group, "new_state": task.get_state_display()})
            if "assignee" in form.changed_data:
                messages.add_message(request, messages.SUCCESS,
                    ugettext("assigned task to '%(assignee)s'") % {
                        # @@@ user_display
                        "assignee": task.assignee
                    }
                )
                if notification:
                    notification.send(notify_list, "tasks_assignment", {"user": request.user, "task": task, "assignee": task.assignee, "group": group})
            if "tags" in form.changed_data:
                messages.add_message(request, messages.SUCCESS,
                    ugettext("updated tags on the task")
                )
                if notification:
                    notification.send(notify_list, "tasks_tags", {"user": request.user, "task": task, "group": group})
            form = EditTaskForm(request.user, group, instance=task)
    else:
        form = EditTaskForm(request.user, group, instance=task)
    
    # The NUDGE dictionary
    nudge = {}
    nudge["nudgeable"] = False
    
    # get the count of nudges so assignee can see general level of interest.
    nudge["count"] = Nudge.objects.filter(task__exact=task).count()
    
    # get the nudge if you are not the assignee otherwise just a None
    if is_member and request.user != task.assignee and task.assignee:
        nudge["nudgeable"] = True
        try:
            nudge["nudge"] = Nudge.objects.filter(nudger__exact=request.user, task__exact=task)[0]
        except IndexError:
            nudge["nudge"] = None
    
    # get the nudge history
    nudge["history"] = Nudge.objects.filter(task__exact=task)
    
    return render_to_response(template_name, {
        "group": group,
        "nudge": nudge,
        "task": task,
        "is_member": is_member,
        "form": form,
        "group_base": group_base,
    }, context_instance=RequestContext(request))
Пример #9
0
def task(request, id, template_name="tasks/task.html"):
    
    group, bridge = group_and_bridge(request)
    if group:
        is_member = group.request.user_is_member()
    else:
        is_member = True
    
    if group:
        tasks = group.content_objects(Task)
    else:
        tasks = Task.objects.filter(object_id=None)
    
    task = get_object_or_404(tasks, id=id)
    
    if not request.user.is_authenticated():
        is_member = False
    else:
        if group:
            is_member = group.user_is_member(request.user)
        else:
            is_member = True
    
    if is_member and request.method == "POST":
        form = EditTaskForm(request.user, group, request.POST, instance=task)
        if form.is_valid():
            task = form.save()
            task.save_history(change_owner=request.user)
            if task.assignee == request.user:
                task.denudge()
            if "status" in form.changed_data:
                messages.add_message(request, messages.SUCCESS,
                    ugettext("updated your status on the task")
                )
                signals.task_status_changed.send(
                    sender = Task,
                    user = request.user,
                    task = task,
                    group = group,
                )
            if "state" in form.changed_data:
                messages.add_message(request, messages.SUCCESS,
                    ugettext("task marked %(state)s") % {
                        "state": task.get_state_display()
                    }
                )
                signals.task_changed.send(
                    sender = Task,
                    user = request.user,
                    task = task,
                    group = group,
                )
            if "assignee" in form.changed_data:
                messages.add_message(request, messages.SUCCESS,
                    ugettext("assigned task to '%(assignee)s'") % {
                        # @@@ user_display
                        "assignee": task.assignee
                    }
                )
                signals.task_assignment_changed.send(
                    sender = Task,
                    user = request.user,
                    task = task,
                    group = group,
                )
            if "tags" in form.changed_data:
                messages.add_message(request, messages.SUCCESS,
                    ugettext("updated tags on the task")
                )
                signals.task_tags_changed.send(
                    sender = Task,
                    user = request.user,
                    task = task,
                    group = group,
                )
            form = EditTaskForm(request.user, group, instance=task)
    else:
        form = EditTaskForm(request.user, group, instance=task)
    
    # The NUDGE dictionary
    nudge = {}
    nudge["nudgeable"] = False
    
    # get the count of nudges so assignee can see general level of interest.
    nudge["count"] = Nudge.objects.filter(task__exact=task).count()
    
    # get the nudge if you are not the assignee otherwise just a None
    if is_member and request.user != task.assignee and task.assignee:
        nudge["nudgeable"] = True
        try:
            nudge["nudge"] = Nudge.objects.filter(nudger__exact=request.user, task__exact=task)[0]
        except IndexError:
            nudge["nudge"] = None
    
    # get the nudge history
    nudge["history"] = Nudge.objects.filter(task__exact=task)
    
    ctx = group_context(group, bridge)
    ctx.update({
        "nudge": nudge,
        "task": task,
        "is_member": is_member,
        "form": form,
    })
    
    return render_to_response(template_name, RequestContext(request, ctx))
Пример #10
0
def task(request, id, template_name="tasks/task.html"):
    task = get_object_or_404(Task, id=id)
    group = task.group

    # @@@ if group.deleted:
    # @@@     raise Http404

    if group:
        notify_list = group.member_users.all().exclude(id__exact=request.user.id) # @@@
    else:
        notify_list = User.objects.all().exclude(id__exact=request.user.id)

    is_member = request.user.is_authenticated() # @@@ groups.has_member(request.user)

    if is_member and request.method == "POST":
        form = EditTaskForm(request.user, request.POST, instance=task)
        if form.is_valid():
            task = form.save()
            task.save_history(change_owner=request.user)
            if task.assignee == request.user:
                task.denudge()
            if "status" in form.changed_data:
                request.user.message_set.create(message="updated your status on the task")
                if notification:
                    notification.send(notify_list, "tasks_status", {"user": request.user, "task": task, "group": group})
            if "state" in form.changed_data:
                request.user.message_set.create(message="task marked %s" % task.get_state_display())
                if notification:
                    notification.send(notify_list, "tasks_change", {"user": request.user, "task": task, "group": group, "new_state": task.get_state_display()})
            if "assignee" in form.changed_data:
                request.user.message_set.create(message="assigned task to '%s'" % task.assignee)
                if notification:
                    notification.send(notify_list, "tasks_assignment", {"user": request.user, "task": task, "assignee": task.assignee, "group": group})
            if "tags" in form.changed_data:
                request.user.message_set.create(message="updated tags on the task")
                if notification:
                    notification.send(notify_list, "tasks_tags", {"user": request.user, "task": task, "group": group})
            form = EditTaskForm(request.user, instance=task)
    else:
        form = EditTaskForm(request.user, instance=task)

    # The NUDGE dictionary
    nudge = {}
    nudge['nudgeable'] = False

    # get the count of nudges so assignee can see general level of interest.
    nudge['count'] = Nudge.objects.filter(task__exact=task).count()

    # get the nudge if you are not the assignee otherwise just a None
    if is_member and request.user != task.assignee and task.assignee:
        nudge['nudgeable'] = True
        try:
            nudge['nudge'] = Nudge.objects.filter(nudger__exact=request.user, task__exact=task)[0]
        except IndexError:
            nudge['nudge'] = None

    # get the nudge history
    nudge['history'] = Nudge.objects.filter(task__exact=task)

    return render_to_response(template_name, {
        "nudge": nudge,
        "task": task,
        "is_member": is_member,
        "form": form,
    }, context_instance=RequestContext(request))
Пример #11
0
def edit_task(request, proj_id=False, task_id=False):
    """
    Provides a blank form for creating a new
    task and the facilities for saving it and
    redirecting to assign it to a project.
    """

    if request.method == "POST" and "useexisting" not in request.POST:

        postData = deepcopy(request.POST)

        if ('public' not in request.POST):
            postData['public'] = 'off'

        if ( task_id == False):
          form = EditTaskForm(postData)
        else:
          instance = ProjectTask.objects.get(id=task_id)
          form = EditTaskForm(postData, instance=instance)

        if form.is_valid():

            if ( task_id == False ):
              projTask = ProjectTask()
            else:
              projTask = ProjectTask.objects.get(id=task_id)

            projTask.summary = form.cleaned_data['summary']
            projTask.description = form.cleaned_data['description']
            projTask.public = (postData['public'] != 'off')
            projTask.creator = request.user

            if ( task_id == False):
              projTask.save()

              projTask.assigned.add(request.user)
              projTask.save()

            elif( task_id != False and instance.creator == request.user ):
              projTask.save()


            if proj_id != False:
                project = Project.objects.get(id=proj_id)

                if request.user in project.members.all() or request.user == project.manager:
                    projTask.project = project
                    projTask.save()
                else:
                    messages.warning(
                        request, "You do not have the rights to add tasks to " + project.name)

            messages.info(request, "Task Saved.")

            if ( "saveandassign" in request.POST ):
              return HttpResponseRedirect('/projects/addtotask/' + str(projTask.id))
            else:
              return HttpResponseRedirect('/projects/task/view/' + str(projTask.id))

        else:
            messages.error(request, "Please fill out both fields.")

            pageData = {}
            pageData['form'] = EditTaskForm(request.POST)

            return render_to_response('task_create.html', RequestContext(request, pageData))

    else:

        args = {}
        try:
            request.session['returnUrl'] = request.META['HTTP_REFERER']
        except:
            request.session['returnUrl'] = '/projects/usertasks'

        if (proj_id != False):
            args['project'] = project = Project.objects.get(id=proj_id)

        args['form'] = EditTaskForm()

        return render_to_response('task_create.html', RequestContext(request, args))
Пример #12
0
def task(request,
         id,
         group_slug=None,
         template_name="tasks/task.html",
         bridge=None):

    if bridge:
        try:
            group = bridge.get_group(group_slug)
        except ObjectDoesNotExist:
            raise Http404
    else:
        group = None

    if group:
        tasks = group.content_objects(Task)
        group_base = bridge.group_base_template()
    else:
        tasks = Task.objects.filter(object_id=None)
        group_base = None

    task = get_object_or_404(tasks, id=id)

    if group:
        notify_list = group.member_queryset()
    else:
        notify_list = User.objects.all()
    notify_list = notify_list.exclude(id__exact=request.user.id)

    if not request.user.is_authenticated():
        is_member = False
    else:
        if group:
            is_member = group.user_is_member(request.user)
        else:
            is_member = True

    if is_member and request.method == "POST":
        form = EditTaskForm(request.user, group, request.POST, instance=task)
        if form.is_valid():
            task = form.save()
            task.save_history(change_owner=request.user)
            if task.assignee == request.user:
                task.denudge()
            if "status" in form.changed_data:
                request.user.message_set.create(
                    message="updated your status on the task")
                if notification:
                    notification.send(notify_list, "tasks_status", {
                        "user": request.user,
                        "task": task,
                        "group": group
                    })
            if "state" in form.changed_data:
                request.user.message_set.create(message="task marked %s" %
                                                task.get_state_display())
                if notification:
                    notification.send(
                        notify_list, "tasks_change", {
                            "user": request.user,
                            "task": task,
                            "group": group,
                            "new_state": task.get_state_display()
                        })
            if "assignee" in form.changed_data:
                request.user.message_set.create(
                    message="assigned task to '%s'" % task.assignee)
                if notification:
                    notification.send(
                        notify_list, "tasks_assignment", {
                            "user": request.user,
                            "task": task,
                            "assignee": task.assignee,
                            "group": group
                        })
            if "tags" in form.changed_data:
                request.user.message_set.create(
                    message="updated tags on the task")
                if notification:
                    notification.send(notify_list, "tasks_tags", {
                        "user": request.user,
                        "task": task,
                        "group": group
                    })
            form = EditTaskForm(request.user, group, instance=task)
    else:
        form = EditTaskForm(request.user, group, instance=task)

    # The NUDGE dictionary
    nudge = {}
    nudge['nudgeable'] = False

    # get the count of nudges so assignee can see general level of interest.
    nudge['count'] = Nudge.objects.filter(task__exact=task).count()

    # get the nudge if you are not the assignee otherwise just a None
    if is_member and request.user != task.assignee and task.assignee:
        nudge['nudgeable'] = True
        try:
            nudge['nudge'] = Nudge.objects.filter(nudger__exact=request.user,
                                                  task__exact=task)[0]
        except IndexError:
            nudge['nudge'] = None

    # get the nudge history
    nudge['history'] = Nudge.objects.filter(task__exact=task)

    return render_to_response(template_name, {
        "group": group,
        "nudge": nudge,
        "task": task,
        "is_member": is_member,
        "form": form,
        "group_base": group_base,
    },
                              context_instance=RequestContext(request))