예제 #1
0
파일: views.py 프로젝트: dmu2014/testapp
def postchild_new(request, pk):
    post = get_object_or_404(Item, pk=pk)
    post.haschildren = True
    post.save()
    if request.method == "POST":
        form = AddItemForm(request.POST)

        if form.is_valid():



            childpost = form.save(commit=False)
            #post = form.save()
            #post.pk = str(int(post.pk) + 1)
            childpost.hasparent = True

            childpost.parentId = pk
            childpost.created_date = timezone.now()
            childpost.save()


            return redirect('post_detail', pk=childpost.pk)
    else:
        form = AddItemForm()

        #post = form.save(commit=False)
        #post = form.save()
        #post.pk = str(int(post.pk) + 1)
    return render(request, 'todo/post_edit.html', {'form': form})
예제 #2
0
파일: views.py 프로젝트: rikonorris/gdms
def add_task(request, list_id):
    list_object = get_object_or_404(List, id=list_id)

    thedate = datetime.datetime.now()
    created_date = "%s/%s/%s" % (thedate.month, thedate.day, thedate.year)

    if request.POST:
        form = AddItemForm(list_object, request.POST, initial={
            'assigned_to': request.user.id,
            'priority': 999,
        })

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

            # Send email alert only if Notify checkbox is checked AND assignee is not same as the submitter
            if "notify" in request.POST and new_task.assigned_to != request.user:
                send_notify_mail(request, new_task)

            messages.success(request, "Задачу \"{t}\" було успішно створено!".format(t=new_task.title))
            return HttpResponseRedirect(request.path)
    else:
        form = AddItemForm(list_object, initial={
            'assigned_to': request.user.id,
            'priority': 999,
            'due_date': created_date,
        })
    return render(request, 'todo/add_task.html', locals())
예제 #3
0
파일: views.py 프로젝트: dmu2014/testapp
def post_edit(request,pk):
    post = get_object_or_404(Item, pk=pk)
    #projectID = get_object_or_404(Project, pk=pk)
    if request.method == "POST":
        form = AddItemForm(request.POST, instance=post)
        if form.is_valid():
            post = form.save(commit=False)
            #item.author = request.user
            post.created_date = timezone.now()
            post.save()
            return redirect('post_detail', pk=post.pk)
    else:
        form = AddItemForm(instance=post)
    return render(request, 'todo/post_edit.html', {'form': form})
예제 #4
0
파일: views.py 프로젝트: dmu2014/testapp
def post_new(request):
    if request.method == "POST":
        form = AddItemForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            #post = form.save()
            #post.pk = str(int(post.pk) + 1)
            post.created_date = timezone.now()
            post.save()
            return redirect('post_detail', pk=post.pk)
    else:
        form = AddItemForm()
        #post = form.save(commit=False)
        #post = form.save()
        #post.pk = str(int(post.pk) + 1)
    return render(request, 'todo/post_edit.html', {'form': form})
예제 #5
0
파일: views.py 프로젝트: rishinkaku/gdms
def add_task(request, list_id):
    list_object = get_object_or_404(List, id=list_id)

    thedate = datetime.datetime.now()
    created_date = "%s/%s/%s" % (thedate.month, thedate.day, thedate.year)

    if request.POST:
        form = AddItemForm(list_object,
                           request.POST,
                           initial={
                               'assigned_to': request.user.id,
                               'priority': 999,
                           })

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

            # Send email alert only if Notify checkbox is checked AND assignee is not same as the submitter
            if "notify" in request.POST and new_task.assigned_to != request.user:
                send_notify_mail(request, new_task)

            messages.success(
                request, "Задачу \"{t}\" було успішно створено!".format(
                    t=new_task.title))
            return HttpResponseRedirect(request.path)
    else:
        form = AddItemForm(list_object,
                           initial={
                               'assigned_to': request.user.id,
                               'priority': 999,
                               'due_date': created_date,
                           })
    return render(request, 'todo/add_task.html', locals())
예제 #6
0
def view_list(request,list_id=0,list_slug=None,view_completed=0):
    
    """
    Display and manage items in a task list
    """
    
    # Make sure the accessing user has permission to view this list.
    # Always authorize the "mine" view. Admins can view/edit all lists.

    if list_slug == "mine"  or list_slug == "recent-add" or list_slug == "recent-complete" :
        auth_ok =1
    else: 
        list = get_object_or_404(List, slug=list_slug)
        listid = list.id    
        
        # Check whether current user is a member of the group this list belongs to.
        if list.group in request.user.groups.all() or request.user.is_staff or list_slug == "mine" :
            auth_ok = 1   # User is authorized for this view
        else: # User does not belong to the group this list is attached to
            request.user.message_set.create(message="You do not have permission to view/edit this list.")

        
    # First check for items in the mark_done POST array. If present, change
    # their status to complete.
    if request.POST.getlist('mark_done'):
        done_items = request.POST.getlist('mark_done')
        # Iterate through array of done items and update its representation in the model
        for thisitem in done_items:
        	p = Item.objects.get(id=thisitem)
        	p.completed = 1
        	p.completed_date = datetime.datetime.now()
        	p.save()
	        request.user.message_set.create(message="Item \"%s\" marked complete." % p.title )


	# Undo: Set completed items back to incomplete
    if request.POST.getlist('undo_completed_task'):
        undone_items = request.POST.getlist('undo_completed_task')
        for thisitem in undone_items:
        	p = Item.objects.get(id=thisitem)
        	p.completed = 0
        	p.save()
	        request.user.message_set.create(message="Previously completed task \"%s\" marked incomplete." % p.title)	        


    # And delete any requested items
    if request.POST.getlist('del_task'):
        deleted_items = request.POST.getlist('del_task')
        for thisitem in deleted_items:
        	p = Item.objects.get(id=thisitem)
        	p.delete()
	        request.user.message_set.create(message="Item \"%s\" deleted." % p.title )

    # And delete any *already completed* items
    if request.POST.getlist('del_completed_task'):
        deleted_items = request.POST.getlist('del_completed_task')
        for thisitem in deleted_items:
        	p = Item.objects.get(id=thisitem)
        	p.delete()
	        request.user.message_set.create(message="Deleted previously completed item \"%s\"."  % p.title)


    thedate = datetime.datetime.now()
    created_date = "%s-%s-%s" % (thedate.year, thedate.month, thedate.day)


    # Get list of items with this list ID, or filter on items assigned to me, or recently added/completed
    if list_slug == "mine":
        task_list = Item.objects.filter(assigned_to=request.user, completed=0)
        completed_list = Item.objects.filter(assigned_to=request.user, completed=1)
        
    elif list_slug == "recent-add":
        # We'll assume this only includes uncompleted items to avoid confusion.
        # Only show items in lists that are in groups that the current user is also in.
        task_list = Item.objects.filter(list__group__in=(request.user.groups.all()),completed=0).order_by('-created_date')[:50]
        # completed_list = Item.objects.filter(assigned_to=request.user, completed=1)   
        
    elif list_slug == "recent-complete":
        # Only show items in lists that are in groups that the current user is also in.
        task_list = Item.objects.filter(list__group__in=request.user.groups.all(),completed=1).order_by('-completed_date')[:50]
        # completed_list = Item.objects.filter(assigned_to=request.user, completed=1)             


    else:
        task_list = Item.objects.filter(list=list.id, completed=0)
        completed_list = Item.objects.filter(list=list.id, completed=1)


    if request.POST.getlist('add_task') :
        form = AddItemForm(list, request.POST,initial={
        'assigned_to':request.user.id,
        'priority':999,
        })
        
        if form.is_valid():
            # Save task first so we have a db object to play with
            new_task = form.save()

            # Send email alert only if the Notify checkbox is checked AND the assignee is not the same as the submittor
            # Email subect and body format are handled by templates
            if "notify" in request.POST :
                if new_task.assigned_to != request.user :
                                        
                    # Send email
                    email_subject = render_to_string("todo/email/assigned_subject.txt", { 'task': new_task })                    
                    email_body = render_to_string("todo/email/assigned_body.txt", { 'task': new_task, 'site': current_site, })
                    try:
                        send_mail(email_subject, email_body, new_task.created_by.email, [new_task.assigned_to.email], fail_silently=False)
                    except:
                        request.user.message_set.create(message="Task saved but mail not sent. Contact your administrator." )

            request.user.message_set.create(message="New task \"%s\" has been added." % new_task.title )
            return HttpResponseRedirect(request.path)

    else:
        if list_slug != "mine" and list_slug != "recent-add" and list_slug != "recent-complete" : # We don't allow adding a task on the "mine" view
            form = AddItemForm(list, initial={
                'assigned_to':request.user.id,
                'priority':999,
                } )

    if request.user.is_staff:
        can_del = 1

    return render_to_response('todo/view_list.html', locals(), context_instance=RequestContext(request))
예제 #7
0
def view_list(request,
              list_id=0,
              list_slug=None,
              view_completed=0,
              view_category=0,
              category_id=0,
              category_slug=None):
    """
    Display and manage items in a task list
    """

    # Make sure the accessing user has permission to view this list.
    # Always authorize the "mine" view. Admins can view/edit all lists.

    if list_slug == "mine" or list_slug == "recent-add" or list_slug == "recent-complete":
        auth_ok = 1
    else:
        list = get_object_or_404(List, slug=list_slug)
        listid = list.id

        # Check whether current user is a member of the group this list belongs to.
        if list.group in request.user.groups.all(
        ) or request.user.is_staff or list_slug == "mine":
            auth_ok = 1  # User is authorized for this view
        else:  # User does not belong to the group this list is attached to
            messages.error(
                request, "You do not have permission to view/edit this list.")

    # First check for items in the mark_done POST array. If present, change
    # their status to complete.
    if request.POST.getlist('mark_done'):
        done_items = request.POST.getlist('mark_done')
        # Iterate through array of done items and update its representation in the model
        for thisitem in done_items:
            p = Item.objects.get(id=thisitem)
            p.completed = 1
            p.completed_date = datetime.datetime.now()
            p.completed_by = request.user
            p.save()
            messages.success(request, "Item \"%s\" marked complete." % p.title)

    # Undo: Set completed items back to incomplete
    if request.POST.getlist('undo_completed_task'):
        undone_items = request.POST.getlist('undo_completed_task')
        for thisitem in undone_items:
            p = Item.objects.get(id=thisitem)
            p.completed = 0
            p.save()
            messages.success(
                request,
                "Previously completed task \"%s\" marked incomplete." %
                p.title)

    # And delete any requested items
    if request.POST.getlist('del_task'):
        deleted_items = request.POST.getlist('del_task')
        for thisitem in deleted_items:
            p = Item.objects.get(id=thisitem)
            p.delete()
            messages.success(request, "Item \"%s\" deleted." % p.title)

    # And delete any *already completed* items
    if request.POST.getlist('del_completed_task'):
        deleted_items = request.POST.getlist('del_completed_task')
        for thisitem in deleted_items:
            p = Item.objects.get(id=thisitem)
            p.delete()
            messages.success(
                request, "Deleted previously completed item \"%s\"." % p.title)

    thedate = datetime.datetime.now()
    created_date = "%s-%s-%s" % (thedate.year, thedate.month, thedate.day)

    # Get list of items with this list ID, or filter on items assigned to me, or recently added/completed
    if list_slug == "mine":
        task_list = Item.objects.filter(assigned_to=request.user, completed=0)
        completed_list = Item.objects.filter(
            assigned_to=request.user, completed=1).order_by('-completed_date')

    elif list_slug == "recent-add":
        # We'll assume this only includes uncompleted items to avoid confusion.
        # Only show items in lists that are in groups that the current user is also in.
        task_list = Item.objects.filter(
            list__group__in=(request.user.groups.all()),
            completed=0).order_by('-created_date')[:50]
        # completed_list = Item.objects.filter(assigned_to=request.user, completed=1)

    elif list_slug == "recent-complete":
        # Only show items in lists that are in groups that the current user is also in.
        task_list = Item.objects.filter(
            list__group__in=request.user.groups.all(),
            completed=1).order_by('-completed_date')[:50]
        # completed_list = Item.objects.filter(assigned_to=request.user, completed=1)

    else:
        task_list = Item.objects.filter(list=list.id, completed=0)
        completed_list = Item.objects.filter(
            list=list.id, completed=1).order_by('-completed_date')
        category_list = Item.objects.filter(list=list.id,
                                            completed=0,
                                            category=category_id)

    if request.POST.getlist('add_task'):
        form = AddItemForm(list,
                           request.POST,
                           initial={
                               'assigned_to': request.user.id,
                               'priority': 999,
                           })

        if form.is_valid():
            # Save task first so we have a db object to play with
            new_task = form.save()

            # Send email alert only if the Notify checkbox is checked AND the assignee is not the same as the submittor
            # Email subect and body format are handled by templates
            if "notify" in request.POST:
                if new_task.assigned_to != request.user:

                    # Send email
                    email_subject = render_to_string(
                        "todo/email/assigned_subject.txt", {'task': new_task})
                    email_body = render_to_string(
                        "todo/email/assigned_body.txt", {
                            'task': new_task,
                            'site': current_site,
                        })
                    try:
                        send_mail(email_subject,
                                  email_body,
                                  new_task.created_by.email,
                                  [new_task.assigned_to.email],
                                  fail_silently=False)
                    except:
                        messages.error(
                            request,
                            "Task saved but mail not sent. Contact your administrator."
                        )

            messages.success(
                request, "New task \"%s\" has been added." % new_task.title)

            return HttpResponseRedirect(request.path)

    else:
        if list_slug != "mine" and list_slug != "recent-add" and list_slug != "recent-complete":  # We don't allow adding a task on the "mine" view
            form = AddItemForm(list,
                               initial={
                                   'assigned_to': request.user.id,
                                   'priority': 999,
                               })

    if request.user.is_staff:
        can_del = 1

    return render_to_response('todo/view_list.html',
                              locals(),
                              context_instance=RequestContext(request))
예제 #8
0
def view_list(request, list_id=0, list_slug=None, view_completed=False):
    """
    Display and manage items in a list.
    """

    # Make sure the accessing user has permission to view this list.
    # Always authorize the "mine" view. Admins can view/edit all lists.
    if list_slug == "mine" or list_slug == "recent-add" or list_slug == "recent-complete":
        auth_ok = True
    else:
        list = get_object_or_404(List, slug=list_slug)
        listid = list.id

        if list.group in request.user.groups.all() or request.user.is_staff or list_slug == "mine":
            auth_ok = True  # User is authorized for this view
        else:  # User does not belong to the group this list is attached to
            messages.error(request, "You do not have permission to view/edit this list.")

    # Check for items in the mark_done POST array. If present, change status to complete.
    if request.POST.getlist('mark_done'):
        done_items = request.POST.getlist('mark_done')
        for item in done_items:
            i = Item.objects.get(id=item)
            i.completed = True
            i.completed_date = datetime.datetime.now()
            i.save()
            messages.success(request, "Item \"{i}\" marked complete.".format(i=i.title))

    # Undo: Set completed items back to incomplete
    if request.POST.getlist('undo_completed_task'):
        undone_items = request.POST.getlist('undo_completed_task')
        for item in undone_items:
            i = Item.objects.get(id=item)
            i.completed = False
            i.save()
            messages.success(request, "Previously completed task \"{i}\" marked incomplete.".format(i=i.title))

    # And delete any requested items
    if request.POST.getlist('del_task'):
        deleted_items = request.POST.getlist('del_task')
        for item in deleted_items:
            Item.objects.get(id=item).delete()
            messages.success(request, "Item \"{i}\" deleted.".format(i=i.title))

    # Delete any already-completed items
    if request.POST.getlist('del_completed_task'):
        deleted_items = request.POST.getlist('del_completed_task')
        for item in deleted_items:
            Item.objects.get(id=item).delete()
            messages.success(request, "Deleted previously completed item \"{i}\".".format(i=i.title))

    thedate = datetime.datetime.now()
    created_date = "%s-%s-%s" % (thedate.year, thedate.month, thedate.day)

    # Get list of items with this list ID, or filter on items assigned to me, or recently added/completed
    if list_slug == "mine":
        task_list = Item.objects.filter(assigned_to=request.user, completed=False)
        completed_list = Item.objects.filter(assigned_to=request.user, completed=True)

    elif list_slug == "recent-add":
        # Only show items in lists that are in groups that the current user is also in.
        # Assume this only includes uncompleted items to avoid confusion.
        task_list = Item.objects.filter(
            list__group__in=(request.user.groups.all()),
            completed=False).order_by('-created_date')[:50]

    elif list_slug == "recent-complete":
        # Only show items in lists that are in groups that the current user is also in.
        task_list = Item.objects.filter(
            list__group__in=request.user.groups.all(),
            completed=True).order_by('-completed_date')[:50]

    else:
        task_list = Item.objects.filter(list=list.id, completed=0)
        completed_list = Item.objects.filter(list=list.id, completed=1)

    if request.POST.getlist('add_task'):
        form = AddItemForm(list, request.POST, initial={
            'assigned_to': request.user.id,
            'priority': 999,
        })

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

            # Send email alert only if Notify checkbox is checked AND assignee is not same as the submitter
            if "notify" in request.POST:
                if new_task.assigned_to != request.user:

                    # Send email
                    email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': new_task})
                    email_body = render_to_string(
                        "todo/email/assigned_body.txt",
                        {'task': new_task, 'site': current_site, })
                    try:
                        send_mail(
                            email_subject, email_body, new_task.created_by.email,
                            [new_task.assigned_to.email], fail_silently=False)
                    except:
                        messages.error(request, "Task saved but mail not sent. Contact your administrator.")

            messages.success(request, "New task \"{t}\" has been added.".format(t=new_task.title))

            return HttpResponseRedirect(request.path)
    else:
        # Don't allow adding new tasks on some views
        if list_slug != "mine" and list_slug != "recent-add" and list_slug != "recent-complete":
            form = AddItemForm(list, initial={
                'assigned_to': request.user.id,
                'priority': 999,
            })

    return render(request, 'todo/view_list.html', locals())
예제 #9
0
파일: views.py 프로젝트: rishinkaku/gdms
def view_list(request, list_id=0, list_slug=None, view_completed=False):
    """
    Display and manage items in a list.
    """

    # Make sure the accessing user has permission to view this list.
    # Always authorize the "mine" view. Admins can view/edit all lists.
    if list_slug == "mine" or list_slug == "recent-add" or list_slug == "recent-complete":
        auth_ok = True
    else:
        list = get_object_or_404(List, id=list_id)
        if list.group in request.user.groups.all(
        ) or request.user.is_staff or list_slug == "mine":
            auth_ok = True
        else:  # User does not belong to the group this list is attached to
            messages.error(
                request, "У вас немає прав на перегляд даної категорії задач")

    # Process all possible list interactions on each submit
    mark_done(request, request.POST.getlist('mark_done'))
    del_tasks(request, request.POST.getlist('del_tasks'))
    undo_completed_task(request, request.POST.getlist('undo_completed_task'))

    thedate = datetime.datetime.now()
    created_date = "%s-%s-%s" % (thedate.year, thedate.month, thedate.day)

    # Get set of items with this list ID, or filter on items assigned to me, or recently added/completed
    if list_slug == "mine":
        task_list = Item.objects.filter(assigned_to=request.user,
                                        completed=False)
        completed_list = Item.objects.filter(assigned_to=request.user,
                                             completed=True)

    elif list_slug == "recent-add":
        # Only show items in lists that are in groups that the current user is also in.
        # Assume this only includes uncompleted items.
        task_list = Item.objects.filter(
            list__group__in=(request.user.groups.all()),
            completed=False).order_by('-created_date')[:50]

    elif list_slug == "recent-complete":
        # Only show items in lists that are in groups that the current user is also in.
        task_list = Item.objects.filter(
            list__group__in=request.user.groups.all(),
            completed=True).order_by('-completed_date')[:50]

    else:
        task_list = Item.objects.filter(list=list.id, completed=0)
        completed_list = Item.objects.filter(list=list.id, completed=1)

    if request.POST.getlist('add_task'):
        form = AddItemForm(list,
                           request.POST,
                           initial={
                               'assigned_to': request.user.id,
                               'priority': 999,
                           })

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

            # Send email alert only if Notify checkbox is checked AND assignee is not same as the submitter
            if "notify" in request.POST and new_task.assigned_to != request.user:
                send_notify_mail(request, new_task)

            messages.success(
                request, "Задачу \"{t}\" було успішно створено!".format(
                    t=new_task.title))
            return HttpResponseRedirect(request.path)
    else:
        # Don't allow adding new tasks on some views
        if list_slug != "mine" and list_slug != "recent-add" and list_slug != "recent-complete":
            form = AddItemForm(list,
                               initial={
                                   'assigned_to': request.user.id,
                                   'priority': 999,
                               })

    return render(request, 'todo/view_list.html', locals())
예제 #10
0
def scratchpad(request, scratch_id):
    """ Shows list items in a scratchpad """
    pad = get_object_or_404(models.Scratchpad,id=scratch_id)
    list = None
    if pad.tasks_list:
        list = get_object_or_404(todomodels.List, slug=pad.tasks_list.slug)

    # Get all scratchpads connected via muaccounts with this user

    # get account scratchpads only if we have a muaccount!
    if getattr(request,"muaccount",False):

        pads = models.Scratchpad.objects.filter(account=request.muaccount)
    else:
        pads = None
    form = AddScratchpadForm()
    
    thedate = datetime.datetime.now()
    created_date = "%s-%s-%s" % (thedate.year, thedate.month, thedate.day)
    
#    task_list = todomodels.Item.objects.filter(list=list.id, list__account=request.muaccount, completed=0)

    if request.POST.getlist('add_task') :
        form1 = AddItemForm(list, request.muaccount, request.POST,initial={
        'assigned_to':request.user.id,
        'priority':999,
        })

        if form1.is_valid():
            # Save task first so we have a db object to play with
            new_task = form1.save()

            # Send email alert only if the Notify checkbox is checked AND the assignee is not the same as the submittor
            # Email subect and body format are handled by templates
            if "notify" in request.POST :
                if new_task.assigned_to != request.user :

                    # Send email
                    email_subject = render_to_string("todo/email/assigned_subject.txt", { 'task': new_task })
                    email_body = render_to_string("todo/email/assigned_body.txt", { 'task': new_task, 'site': current_site, })
                    try:
                        send_mail(email_subject, email_body, new_task.created_by.email, [new_task.assigned_to.email], fail_silently=False)
                    except:
                        request.user.message_set.create(message="Task saved but mail not sent. Contact your administrator." )

            request.user.message_set.create(message="New task \"%s\" has been added." % new_task.title )
            return HttpResponseRedirect(request.path)
        else:
            print form1.errors
            #for error in form1.errors:
             #   request.user.message_set.create(message=error[1])           
    else:      
        form1 = AddItemForm(list, request.muaccount, initial={
            'assigned_to':request.user.id,
            'priority':999,
            } )

    if request.POST:
        if request.POST['scratchpad_type']:
            item = models.Item()
            item.notes = request.POST['content']
            item.title = request.POST['title']

            if request.POST['scratchpad_type'] == 'new':
                spad = models.Scratchpad()
                spad.title = request.POST['new_scratchpad']
                spad.author = request.user
                spad.account = request.muaccount

                newtodo = todomodels.List()
                newtodo.name = spad.title
                newtodo.slug = "Tasks for scratchpad %s" % spad.title
                newtodo.account = request.muaccount
                newtodo.save()

                spad.tasks_list = newtodo
                spad.save()
                item.scratchpad = spad
                request.user.message_set.create(message="New Note added to '%s'" % spad.title)
            else:
                item.scratchpad = models.Scratchpad.objects.get(id=request.POST['scratchpad'])
                request.user.message_set.create(message="New Note added to '%s'" % item.scratchpad.title)

            item.save()


            strcomment = request.POST['comment']
            if strcomment != "":
                comment = tmodels.ThreadedComment()
                comment.content_object = item
                comment.user = request.user
                comment.comment = strcomment
                comment.save()
    
    form2 = AddToScratchpad(None, request.muaccount)
    comment = forms.CharField(widget=forms.Textarea).widget.render("comment","")

    return render_to_response("scratchpad/view_scratchpad.html", locals(), context_instance=RequestContext(request))
예제 #11
0
def task_add(request):
    if request.POST:
        add_item_form = AddItemForm(request.POST.copy())
        if add_item_form.is_valid():
            form = add_item_form.save(request.user)
            return HttpResponseRedirect('/#list-%s' % form.list.id)
예제 #12
0
def view_list(request,
              group_pk=None,
              list_id=0,
              list_slug=None,
              view_completed=False):
    """
    Display and manage items in a list.
    """
    #this list is repeated a lot. lets re-factor somehow
    group = get_object_or_404(models.Group, pk=group_pk)
    familygroup = get_object_or_404(FamilyGroup, group_id=group_pk)
    #list = get_object_or_404(List, group_id=group_pk)
    event = familygroup.event
    members = models.User.objects.filter(groups=group)
    profile = request.user.userprofile
    # Make sure the accessing user has permission to view this list.
    # Always authorize the "mine" view. Admins can view/edit all lists.
    if list_slug == "mine" or list_slug == "recent-add" or list_slug == "recent-complete":
        auth_ok = True
    else:
        list = get_object_or_404(List, id=list_id)
        if list.group in request.user.groups.all(
        ) or request.user.is_staff or list_slug == "mine":
            auth_ok = True
        else:  # User does not belong to the group this list is attached to
            messages.error(
                request, "You do not have permission to view/edit this list.")

    # Process all possible list interactions on each submit
    mark_done(request, request.POST.getlist('mark_done'))
    del_tasks(request, request.POST.getlist('del_tasks'))
    undo_completed_task(request, request.POST.getlist('undo_completed_task'))

    thedate = datetime.datetime.now()
    created_date = "%s-%s-%s" % (thedate.year, thedate.month, thedate.day)

    # Get set of items with this list ID, or filter on items assigned to me, or recently added/completed
    if list_slug == "mine":
        task_list = Item.objects.filter(assigned_to=request.user,
                                        completed=False)
        completed_list = Item.objects.filter(assigned_to=request.user,
                                             completed=True)

    elif list_slug == "recent-add":
        # Only show items in lists that are in groups that the current user is also in.
        # Assume this only includes uncompleted items.
        task_list = Item.objects.filter(
            list__group__in=(request.user.groups.all()),
            completed=False).order_by('-created_date')[:50]

    elif list_slug == "recent-complete":
        # Only show items in lists that are in groups that the current user is also in.
        task_list = Item.objects.filter(
            list__group__in=request.user.groups.all(),
            completed=True).order_by('-completed_date')[:50]

    else:
        task_list = Item.objects.filter(list=list.id, completed=0)
        completed_list = Item.objects.filter(list=list.id, completed=1)

    if request.POST.getlist('add_task'):
        print('got request')

        form = AddItemForm(list,
                           request.POST,
                           initial={
                               'assigned_to': request.user.id,
                               'priority': 999,
                           })
        print('set form variable')
        print(form.errors)
        print(form.is_valid)

        if form.is_valid():
            form.save()
            print('saved')
            new_task = form.save()

            # Send email alert only if Notify checkbox is checked AND assignee is not same as the submitter
            if "notify" in request.POST and new_task.assigned_to != request.user:
                send_notify_mail(request, new_task)

            messages.success(
                request,
                "New task \"{t}\" has been added.".format(t=new_task.title))
            return HttpResponseRedirect(request.path)
    else:
        # Don't allow adding new tasks on some views
        if list_slug != "mine" and list_slug != "recent-add" and list_slug != "recent-complete":
            form = AddItemForm(list,
                               initial={
                                   'assigned_to': request.user.id,
                                   'priority': 999,
                               })

    return render(request, 'todo/view_list.html', locals())
예제 #13
0
def view_list(request, list_id=0, list_slug=None, view_completed=False):
    """
    Display and manage items in a list.
    """

    # Make sure the accessing user has permission to view this list.
    # Always authorize the "mine" view. Admins can view/edit all lists.
    if list_slug == "mine" or list_slug == "recent-add" or list_slug == "recent-complete":
        auth_ok = True
    else:
        list = get_object_or_404(List, id=list_id)
        if list.group in request.user.groups.all() or request.user.is_staff or list_slug == "mine":
            auth_ok = True
        else:  # User does not belong to the group this list is attached to
            messages.error(request, "You do not have permission to view/edit this list.")

    # Process all possible list interactions on each submit
    mark_done(request, request.POST.getlist('mark_done'))
    del_tasks(request, request.POST.getlist('del_tasks'))
    undo_completed_task(request, request.POST.getlist('undo_completed_task'))

    thedate = datetime.datetime.now()
    created_date = "%s-%s-%s" % (thedate.year, thedate.month, thedate.day)

    # Get set of items with this list ID, or filter on items assigned to me, or recently added/completed
    if list_slug == "mine":
        task_list = Item.objects.filter(assigned_to=request.user, completed=False)
        completed_list = Item.objects.filter(assigned_to=request.user, completed=True)

    elif list_slug == "recent-add":
        # Only show items in lists that are in groups that the current user is also in.
        # Assume this only includes uncompleted items.
        task_list = Item.objects.filter(
            list__group__in=(request.user.groups.all()),
            completed=False).order_by('-created_date')[:50]

    elif list_slug == "recent-complete":
        # Only show items in lists that are in groups that the current user is also in.
        task_list = Item.objects.filter(
            list__group__in=request.user.groups.all(),
            completed=True).order_by('-completed_date')[:50]

    else:
        task_list = Item.objects.filter(list=list.id, completed=0)
        completed_list = Item.objects.filter(list=list.id, completed=1)

    if request.POST.getlist('add_task'):
        form = AddItemForm(list, request.POST, initial={
            'assigned_to': request.user.id,
            'priority': 999,
        })

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

            # Send email alert only if Notify checkbox is checked AND assignee is not same as the submitter
            if "notify" in request.POST and new_task.assigned_to != request.user:
                send_notify_mail(request, new_task)

            messages.success(request, "New task \"{t}\" has been added.".format(t=new_task.title))
            return HttpResponseRedirect(request.path)
    else:
        # Don't allow adding new tasks on some views
        if list_slug != "mine" and list_slug != "recent-add" and list_slug != "recent-complete":
            form = AddItemForm(list, initial={
                'assigned_to': request.user.id,
                'priority': 999,
            })

    return render(request, 'todo/view_list.html', locals())
예제 #14
0
def view_list(request, list_slug):
    """
    Display and manage items in a task list
    """

    # Make sure the accessing user has permission to view this list.
    # Always authorize the "mine" view. Admins can view/edit all lists.

    if list_slug == "mine":
        auth_ok = 1
    else:
        list = get_object_or_404(List, slug=list_slug)
        listid = list.id

        # Check whether current user is a member of the group this list belongs to.
        if list.group in request.user.groups.all(
        ) or request.user.is_staff or list_slug == "mine":
            auth_ok = 1  # User is authorized for this view
        else:  # User does not belong to the group this list is attached to
            request.user.message_set.create(
                message="You do not have permission to view/edit this list.")

    # First check for items in the mark_done POST array. If present, change
    # their status to complete.
    if request.POST.getlist('mark_done'):
        done_items = request.POST.getlist('mark_done')
        # Iterate through array of done items and update its representation in the model
        for thisitem in done_items:
            p = Item.objects.get(id=thisitem)
            p.completed = 1
            p.completed_date = datetime.datetime.now()
            p.save()
            request.user.message_set.create(message="Item marked complete.")

# Undo: Set completed items back to incomplete
    if request.POST.getlist('undo_completed_task'):
        undone_items = request.POST.getlist('undo_completed_task')
        for thisitem in undone_items:
            p = Item.objects.get(id=thisitem)
            p.completed = 0
            p.save()
            request.user.message_set.create(
                message="Previously completed task marked incomplete.")

    # And delete any requested items
    if request.POST.getlist('del_task'):
        deleted_items = request.POST.getlist('del_task')
        for thisitem in deleted_items:
            p = Item.objects.get(id=thisitem)
            p.delete()
            request.user.message_set.create(message="Item deleted.")

    # And delete any *already completed* items
    if request.POST.getlist('del_completed_task'):
        deleted_items = request.POST.getlist('del_completed_task')
        for thisitem in deleted_items:
            p = Item.objects.get(id=thisitem)
            p.delete()
            request.user.message_set.create(
                message="Deleted previously completed item.")

    thedate = datetime.datetime.now()
    created_date = "%s-%s-%s" % (thedate.year, thedate.month, thedate.day)

    # Get list of items with this list ID, or filter on items assigned to me
    if list_slug == "mine":
        task_list = Item.objects.filter(assigned_to=request.user, completed=0)
        completed_list = Item.objects.filter(assigned_to=request.user,
                                             completed=1)
        # item = Item.objects.get(pk=1)
        # item.overdue_status()

    else:
        # list = get_object_or_404(List, slug=list_slug)
        # listid = list.id
        task_list = Item.objects.filter(list=list.id, completed=0)
        completed_list = Item.objects.filter(list=list.id, completed=1)

    if request.POST.getlist('add_task'):
        form = AddItemForm(request.user,
                           request.POST,
                           initial={
                               'assigned_to': request.user.id,
                           })

        if form.is_valid():
            form.save()
            # confirmation = "A new task has been added."
            request.user.message_set.create(
                message="A new task has been added.")
            return HttpResponseRedirect(request.path)

    else:
        form = AddItemForm(request.user,
                           initial={
                               'assigned_to': request.user.id,
                           })

    if request.user.is_staff:
        can_del = 1

    return render_to_response('todo/view_list.html',
                              locals(),
                              context_instance=RequestContext(request))
예제 #15
0
파일: views.py 프로젝트: inturiasgary/gme
def view_list(request,repo_id=0, list_id=0,list_slug='',view_completed=0):
    """
    Muestra y administra los items de una lista
    """
    repositorio = get_object_or_404(Repositorio, id=repo_id)
    # Para verificar la seguridad de ingreso a una lista.
    if list_slug == "mine" :
        auth_ok =1
        if repositorio in Repositorio.objects.filter(miembros=request.user, miembro__creador=True, miembro__activo=True):
            can_del = 1
    else: 
        list = get_object_or_404(List, slug=list_slug)
        listid = list.id    
        # verifica si el usuario actual es miembro del repositorio
        if list.grupo in request.user.repositorio_set.all() or request.user.is_staff:
            auth_ok = 1   # El usuario es autorizado para el ingreso a  la lista
            if list.grupo in Repositorio.objects.filter(miembros=request.user, miembro__creador=True, miembro__activo=True):
                can_del = 1
        else: # no se autoriza su ingreso
            request.user.message_set.create(message=_("You do not have permission to view/edit this list."))
    if request.POST.getlist('mark_done'):
        done_items = request.POST.getlist('mark_done')
        # Iteracion a traves del arreglo de utems realizados y actualiza en el modelo
        for thisitem in done_items:
            p = Item.objects.get(id=thisitem)
            p.completed = 1
            p.completed_date = datetime.datetime.now()
            descripcion = (_("Tarea Completada -> %s")%p.title)
            Mensaje.objects.create(usuario=request.user, repositorio= repositorio, descripcion=descripcion, tipo='s')
            p.save()
            request.user.message_set.create(message=_("Item \"%s\" marked complete.") % p.title )
        # establece de nuevo como item no realizado
    if request.POST.getlist('undo_completed_task'):
        undone_items = request.POST.getlist('undo_completed_task')
        for thisitem in undone_items:
            p = Item.objects.get(id=thisitem)
            p.completed = 0
            p.save()
            request.user.message_set.create(message=_("Previously completed task \"%s\" marked incomplete.") % p.title)	        
    # elimina cualquier item
    if request.POST.getlist('del_task'):
        deleted_items = request.POST.getlist('del_task')
        list_to_delete = []
        for thisitem in deleted_items:
            p = Item.objects.get(id=thisitem)
            list_to_delete.append(p.title)
            p.delete()
            request.user.message_set.create(message=_("Item \"%s\" deleted.") % p.title )
        descripcion=_("Tareas Eliminadas->\n")
        for item in list_to_delete:
            descripcion+=('%s.\n'%item)
        Mensaje.objects.create(usuario=request.user, repositorio=repositorio, descripcion=descripcion, tipo="s")

    # elimina items completados
    if request.POST.getlist('del_completed_task'):
        deleted_items = request.POST.getlist('del_completed_task')
        for thisitem in deleted_items:
            p = Item.objects.get(id=thisitem)
            p.delete()
            request.user.message_set.create(message=_("Deleted previously completed item \"%s\".")  % p.title)
    thedate = datetime.datetime.now()
    created_date = "%s-%s-%s" % (thedate.year, thedate.month, thedate.day)
    # Obtiene la lista de items de la lista dado el ID, filtra los items asignados al usuario
    if list_slug == "mine":
        task_list = Item.objects.filter(assigned_to=request.user, completed=0, list__grupo__id = repo_id )
        completed_list = Item.objects.filter(assigned_to=request.user, completed=1, list__grupo__id = repo_id )
    else:
        usuario_actual = request.user.username
        task_list = Item.objects.filter(list=list.id, completed=0, list__grupo__id = repo_id )
        completed_list = Item.objects.filter(list=list.id, completed=1, list__grupo__id = repo_id)
    if request.POST.getlist('add_task') :
        form = AddItemForm(list, request.POST,initial={
            'assigned_to':request.user.id,
            'priority':999,
        })
        if form.is_valid():
            # primero se graba la tarea para luego editarla
            new_task = form.save()
            Mensaje.objects.create(usuario=new_task.assigned_to , repositorio=repositorio, descripcion='Nueva Tarea: %s - %s'%(new_task.title, new_task.note), tipo="s")
            # Envio de email alerta solo si el checkbos es seleccionado y el asignado no es el mismo que el que esta creando        
            if "notify" in request.POST :
                if new_task.assigned_to != request.user :
                    current_site = Site.objects.get_current() # Necesario para acoplamiento de la plantilla en el email
                    # enviar email
                    email_subject = render_to_string("todo/email/assigned_subject.txt", { 'task': new_task })                    
                    email_body = render_to_string("todo/email/assigned_body.txt", { 'task': new_task, 'site': current_site, })
                    try:
                        send_mail(email_subject, email_body, new_task.created_by.email, [new_task.assigned_to.email], fail_silently=False)
                    except:
                        request.user.message_set.create(message=_("Task saved but mail not sent. Contact your administrator.") )
            request.user.message_set.create(message=_("New task \"%s\" has been added.") % new_task.title )
            return HttpResponseRedirect(request.path)
    else:
        if list_slug != "mine" : # No permitimos el agregar de una tarea en la vista mia
            form = AddItemForm(list, initial={
                'assigned_to':request.user.id,
                'priority':999,
            } )
    #solo adicionado el try
    #try:
        #Controlamos que el usario sea el administrador del repositorio, caso contrario no podra borrar la tarea
        #miembro_creador   = Miembro.objects.get(repositorio__nombre="repositorioUsuario2", usuario__username=request.user.username,creador=True)
        #list_slug = "mine"
    #except:
        #list_slug = "notmine"
    return render_to_response('todo/view_list.html', locals(), context_instance=RequestContext(request))
예제 #16
0
def view_list(request, list_id=0, list_slug=None, view_completed=False):
    """
    Display and manage items in a list.
    """

    # Make sure the accessing user has permission to view this list.
    # Always authorize the "mine" view. Admins can view/edit all lists.
    if list_slug == "mine" or list_slug == "recent-add" or list_slug == "recent-complete":
        auth_ok = 1
    else:
        list = get_object_or_404(List, slug=list_slug)
        listid = list.id

        if list.group in request.user.groups.all() or request.user.is_staff or list_slug == "mine":
            auth_ok = True  # User is authorized for this view
        else:  # User does not belong to the group this list is attached to
            messages.error(request, "You do not have permission to view/edit this list.")

    # Check for items in the mark_done POST array. If present, change status to complete.
    if request.POST.getlist('mark_done'):
        done_items = request.POST.getlist('mark_done')
        for item in done_items:
            i = Item.objects.get(id=item)
            i.completed = 1
            i.completed_date = datetime.datetime.now()
            i.save()
            messages.success(request, "Item \"{i}\" marked complete.".format(i=i.title))

    # Undo: Set completed items back to incomplete
    if request.POST.getlist('undo_completed_task'):
        undone_items = request.POST.getlist('undo_completed_task')
        for item in undone_items:
            i = Item.objects.get(id=item)
            i.completed = False
            i.save()
            messages.success(request, "Previously completed task \"{i}\" marked incomplete.".format(i=i.title))

    # And delete any requested items
    if request.POST.getlist('del_task'):
        deleted_items = request.POST.getlist('del_task')
        for item in deleted_items:
            i = Item.objects.get(id=item)
            i.delete()
            messages.success(request, "Item \"{i}\" deleted.".format(i=i.title))

    # Delete any already-completed items
    if request.POST.getlist('del_completed_task'):
        deleted_items = request.POST.getlist('del_completed_task')
        for item in deleted_items:
            i = Item.objects.get(id=item)
            i.delete()
            messages.success(request, "Deleted previously completed item \"{i}\".".format(i=i.title))

    thedate = datetime.datetime.now()
    created_date = "%s-%s-%s" % (thedate.year, thedate.month, thedate.day)

    # Get list of items with this list ID, or filter on items assigned to me, or recently added/completed
    if list_slug == "mine":
        task_list = Item.objects.filter(assigned_to=request.user, completed=False)
        completed_list = Item.objects.filter(assigned_to=request.user, completed=True)

    elif list_slug == "recent-add":
        # Only show items in lists that are in groups that the current user is also in.
        # Assume this only includes uncompleted items to avoid confusion.
        task_list = Item.objects.filter(
            list__group__in=(request.user.groups.all()),
            completed=False).order_by('-created_date')[:50]

    elif list_slug == "recent-complete":
        # Only show items in lists that are in groups that the current user is also in.
        task_list = Item.objects.filter(
            list__group__in=request.user.groups.all(),
            completed=True).order_by('-completed_date')[:50]

    else:
        task_list = Item.objects.filter(list=list.id, completed=0)
        completed_list = Item.objects.filter(list=list.id, completed=1)

    if request.POST.getlist('add_task'):
        form = AddItemForm(list, request.POST, initial={
            'assigned_to': request.user.id,
            'priority': 999,
        })

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

            # Send email alert only if Notify checkbox is checked AND assignee is not same as the submitter
            if "notify" in request.POST:
                if new_task.assigned_to != request.user:

                    # Send email
                    email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': new_task})
                    email_body = render_to_string(
                        "todo/email/assigned_body.txt",
                        {'task': new_task, 'site': current_site, })
                    try:
                        send_mail(
                            email_subject, email_body, new_task.created_by.email,
                            [new_task.assigned_to.email], fail_silently=False)
                    except:
                        messages.error(request, "Task saved but mail not sent. Contact your administrator.")

            messages.success(request, "New task \"{t}\" has been added.".format(t=new_task.title))

            return HttpResponseRedirect(request.path)
    else:
        # Don't allow adding new tasks on some views
        if list_slug != "mine" and list_slug != "recent-add" and list_slug != "recent-complete":
            form = AddItemForm(list, initial={
                'assigned_to': request.user.id,
                'priority': 999,
            })

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