Ejemplo n.º 1
0
def view_task(request,task_id):
    """
    vista para detalles de tareas. Permite la edicion de las tareas.
    """
    task = get_object_or_404(Item, pk=task_id)
    comment_list = Comment.objects.filter(task=task_id)
    # antes de adicionar cualquier cosa, hace seguro el acceso a usuario con permiso para ver estos items.
    # determina el repositorio al que pertenece esta tarea, verfica si el usuario actual es miembro del repositorio.
    if task.list.grupo in request.user.repositorio_set.all() or request.user.is_staff:
        if task.list.grupo in Repositorio.objects.filter(miembros=request.user, miembro__creador=True, miembro__activo=True):
            can_del = 1
        auth_ok = 1
        if request.POST:
            form = EditItemForm(request.POST,instance=task)
            if form.is_valid():
                form.save()
                    # Also save submitted comment, if non-empty
                if request.POST['comment-body']:
                    c = Comment(
                        author=request.user, 
                        task=task,
                        body=request.POST['comment-body'],
                    )
                    c.save()
                request.user.message_set.create(message=_("The task has been edited."))
                return HttpResponseRedirect(reverse('todo-incomplete_tasks', args=[task.list.grupo.id, task.list.id, task.list.slug]))
        else:
            form = EditItemForm(instance=task)
            thedate = task.due_date
    else:
        request.user.message_set.create(message=_("You do not have permission to view/edit this task."))
    return render_to_response('todo/view_task.html', locals(), context_instance=RequestContext(request))
Ejemplo n.º 2
0
def view_task(request,task_id):

    """
    View task details. Allow task details to be edited.
    """

    task = get_object_or_404(Item, pk=task_id)
    comment_list = Comment.objects.filter(task=task_id)
        
    # Before doing anything, make sure the accessing user has permission to view this item.
    # Determine the group this task belongs to, and check whether current user is a member of that group.
    # Admins can edit all tasks.

    if task.list.group in request.user.groups.all() or request.user.is_staff:
        
        auth_ok = 1
        if request.POST:
             form = EditItemForm(request.POST,instance=task)

             if form.is_valid():
                 form.save()
                 
                 # Also save submitted comment, if non-empty
                 if request.POST['comment-body']:
                     c = Comment(
                         author=request.user, 
                         task=task,
                         body=request.POST['comment-body'],
                     )
                     c.save()
                    
                     # And email comment to all people who have participated in this thread.
                     email_subject = render_to_string("todo/email/assigned_subject.txt", { 'task': task })                    
                     email_body = render_to_string("todo/email/newcomment_body.txt", { 'task': task, 'body':request.POST['comment-body'], 'site': current_site, 'user':request.user })

                     # Get list of all thread participants - task creator plus everyone who has commented on it.
                     recip_list = []
                     recip_list.append(task.created_by.email)
                     commenters = Comment.objects.filter(task=task)
                     for c in commenters:
                         recip_list.append(c.author.email)
                     # Eliminate duplicate emails with the Python set() function
                     recip_list = set(recip_list)     
                     
                     # Send message
                     try:
                        send_mail(email_subject, email_body, task.created_by.email, recip_list, fail_silently=False)
                        request.user.message_set.create(message="Comment sent to thread participants.")
                     except:
                        request.user.message_set.create(message="Comment saved but mail not sent. Contact your administrator." )
                    
                 
                 request.user.message_set.create(message="The task has been edited.")
                 return HttpResponseRedirect(reverse('todo-incomplete_tasks', args=[task.list.id, task.list.slug]))
                 
        else:
            form = EditItemForm(instance=task)
            if task.due_date:
                thedate = task.due_date
            else:
                thedate = datetime.datetime.now()
            

    else:
        request.user.message_set.create(message="You do not have permission to view/edit this task.")

    return render_to_response('todo/view_task.html', locals(), context_instance=RequestContext(request))
Ejemplo n.º 3
0
def view_task(request, task_id):
    """
    View task details. Allow task details to be edited.
    """

    task = get_object_or_404(Item, pk=task_id)
    comment_list = Comment.objects.filter(task=task_id)

    # Before doing anything, make sure the accessing user has permission to view this item.
    # Determine the group this task belongs to, and check whether current user is a member of that group.
    # Admins can edit all tasks.

    if task.list.group in request.user.groups.all() or request.user.is_staff:

        auth_ok = 1
        if request.POST:
            form = EditItemForm(request.POST, instance=task)

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

                # Also save submitted comment, if non-empty
                if request.POST['comment-body']:
                    c = Comment(
                        author=request.user,
                        task=task,
                        body=request.POST['comment-body'],
                    )
                    c.save()

                    # And email comment to all people who have participated in this thread.
                    email_subject = render_to_string(
                        "todo/email/assigned_subject.txt", {'task': task})
                    email_body = render_to_string(
                        "todo/email/newcomment_body.txt", {
                            'task': task,
                            'body': request.POST['comment-body'],
                            'site': current_site,
                            'user': request.user
                        })

                    # Get list of all thread participants - task creator plus everyone who has commented on it.
                    recip_list = []
                    recip_list.append(task.created_by.email)
                    commenters = Comment.objects.filter(task=task)
                    for c in commenters:
                        recip_list.append(c.author.email)
                    # Eliminate duplicate emails with the Python set() function
                    recip_list = set(recip_list)

                    # Send message
                    try:
                        send_mail(email_subject,
                                  email_body,
                                  task.created_by.email,
                                  recip_list,
                                  fail_silently=False)
                        messages.success(
                            request, "Comment sent to thread participants.")

                    except:
                        messages.error(
                            request,
                            "Comment saved but mail not sent. Contact your administrator."
                        )

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

                return HttpResponseRedirect(
                    reverse('todo-incomplete_tasks',
                            args=[task.list.id, task.list.slug]))

        else:
            form = EditItemForm(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_to_response('todo/view_task.html',
                              locals(),
                              context_instance=RequestContext(request))
Ejemplo n.º 4
0
def view_task(request, task_id):
    """
    View task details. Allow task details to be edited.
    """
    task = get_object_or_404(Item, pk=task_id)
    comment_list = Comment.objects.filter(task=task_id)

    # Ensure user has permission to view item.
    # Get the group this task belongs to, and check whether current user is a member of that group.
    # Admins can edit all tasks.

    if task.list.group in request.user.groups.all() or request.user.is_staff:
        auth_ok = True

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

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

                # Also save submitted comment, if non-empty
                if request.POST['comment-body']:
                    c = Comment(
                        author=request.user,
                        task=task,
                        body=request.POST['comment-body'],
                    )
                    c.save()

                    # And email comment to all people who have participated in this thread.
                    email_subject = render_to_string(
                        "todo/email/assigned_subject.txt", {'task': task})
                    email_body = render_to_string(
                        "todo/email/newcomment_body.txt", {
                            'task': task,
                            'body': request.POST['comment-body'],
                            'site': current_site,
                            'user': request.user
                        })

                    # Get list of all thread participants - task creator plus everyone who has commented on it.
                    recip_list = []
                    recip_list.append(task.created_by.email)
                    commenters = Comment.objects.filter(task=task)
                    for c in commenters:
                        recip_list.append(c.author.email)
                    recip_list = set(recip_list)  # Eliminate duplicates

                    try:
                        send_mail(email_subject,
                                  email_body,
                                  task.created_by.email,
                                  recip_list,
                                  fail_silently=False)
                        messages.success(
                            request,
                            "Ваш коментар було надіслано усім учасникам задачі"
                        )
                    except:
                        messages.error(
                            request,
                            "Коментар не було надіслано! Зв'яжіться з адміністратором"
                        )

                messages.success(request, "")

                return HttpResponseRedirect(
                    reverse('todo-incomplete_tasks',
                            args=[task.list.id, task.list.slug]))
        else:
            form = EditItemForm(instance=task)
            if task.due_date:
                thedate = task.due_date
            else:
                thedate = datetime.datetime.now()
            created_date = "%s-%s-%s" % (thedate.year, thedate.month,
                                         thedate.day)
    else:
        messages.info(request, "У вас немає прав на перегляд чи зміну задачі")

    return render(request, 'todo/view_task.html', locals())
Ejemplo n.º 5
0
def view_task(request, task_id):
    """
    View task details. Allow task details to be edited.
    """
    task = get_object_or_404(Item, pk=task_id)
    comment_list = Comment.objects.filter(task=task_id)

    # Ensure user has permission to view item.
    # Get the group this task belongs to, and check whether current user is a member of that group.
    # Admins can edit all tasks.

    if task.list.group in request.user.groups.all() or request.user.is_staff:
        auth_ok = True

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

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

                # Also save submitted comment, if non-empty
                if request.POST['comment-body']:
                    c = Comment(
                        author=request.user,
                        task=task,
                        body=request.POST['comment-body'],
                    )
                    c.save()

                    # And email comment to all people who have participated in this thread.
                    email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': task})
                    email_body = render_to_string(
                        "todo/email/newcomment_body.txt",
                        {'task': task, 'body': request.POST['comment-body'], 'site': current_site, 'user': request.user}
                    )

                    # Get list of all thread participants - task creator plus everyone who has commented on it.
                    recip_list = []
                    recip_list.append(task.created_by.email)
                    commenters = Comment.objects.filter(task=task)
                    for c in commenters:
                        recip_list.append(c.author.email)
                    recip_list = set(recip_list)  # Eliminate duplicates

                    try:
                        send_mail(email_subject, email_body, task.created_by.email, recip_list, fail_silently=False)
                        messages.success(request, "Ваш коментар було надіслано усім учасникам задачі")
                    except:
                        messages.error(request, "Коментар не було надіслано! Зв'яжіться з адміністратором")

                messages.success(request, "")

                return HttpResponseRedirect(reverse('todo-incomplete_tasks', args=[task.list.id, task.list.slug]))
        else:
            form = EditItemForm(instance=task)
            if task.due_date:
                thedate = task.due_date
            else:
                thedate = datetime.datetime.now()
            created_date = "%s-%s-%s" % (thedate.year, thedate.month, thedate.day)
    else:
        messages.info(request, "У вас немає прав на перегляд чи зміну задачі")

    return render(request, 'todo/view_task.html', locals())