예제 #1
0
def create_column(request, project_id):
    project = get_object_or_404(Project.objects.select_related("owner"),
                                pk=project_id)
    has_perm_or_403(request.user, "columns.create_column", project)
    if request.method == "POST":
        form = ColumnForm(request.POST)
        if form.is_valid():
            column = form.save(commit=False)
            column.project = project
            column.save()
            messages.success(request, _("Column has been added"))
            return redirect(project)
    else:
        form = ColumnForm()

    breadcrumbs = [
        (_("Projects"), reverse("projects:projects_overview")),
        (_("New Column"), None),
    ]

    return TemplateResponse(
        request,
        "columns/column_form.html",
        {
            "form": form,
            "project": project,
            "breadcrumbs": breadcrumbs
        },
    )
예제 #2
0
def edit_column(request, column_id):
    column = get_object_or_404(Column.objects.select_related(
        "project", "project__owner"),
                               pk=column_id)
    has_perm_or_403(request.user, "columns.change_column", column)
    if request.method == "POST":
        form = ColumnForm(request.POST, instance=column)
        if form.is_valid():
            form.save()
            messages.success(request, _("Column has been updated"))
            return redirect(column)
    else:
        form = ColumnForm(instance=column)

    breadcrumbs = [
        (_("Projects"), reverse("projects:projects_overview")),
        (column.name, column.get_absolute_url()),
        (_("Edit Column"), None),
    ]

    return TemplateResponse(
        request,
        "columns/column_form.html",
        {
            "form": form,
            "project": column.project,
            "column": column,
            "breadcrumbs": breadcrumbs,
        },
    )
예제 #3
0
파일: views.py 프로젝트: danjac/kando
def card_detail(request, card_id):
    card = get_object_or_404(
        Card.objects.select_related("project", "column", "project__owner",
                                    "assignee", "owner"),
        pk=card_id,
    )
    has_perm_or_403(request.user, "cards.view_card", card)

    tasks = card.task_set.select_related("card", "owner", "card__owner",
                                         "card__assignee").order_by("position")

    attachments = card.attachment_set.select_related(
        "card", "owner", "card__owner", "card__assignee").order_by("created")

    breadcrumbs = [
        (_("Projects"), reverse("projects:projects_overview")),
        (card.project.name, card.project.get_absolute_url()),
        (card.name, None),
    ]

    return TemplateResponse(
        request,
        "cards/detail.html",
        {
            "card": card,
            "tasks": tasks,
            "attachments": attachments,
            "breadcrumbs": breadcrumbs,
        },
    )
예제 #4
0
파일: views.py 프로젝트: danjac/kando
def edit_card(request, card_id):
    card = get_object_or_404(
        Card.objects.select_related("project", "column", "project__owner",
                                    "owner"),
        pk=card_id,
    )
    has_perm_or_403(request.user, "cards.change_card", card)
    if request.method == "POST":
        form = CardForm(request.POST, instance=card)
        if form.is_valid():
            form.save()
            messages.success(request, _("Card has been updated"))
            return redirect(card)
    else:
        form = CardForm(instance=card)

    breadcrumbs = [
        (_("Projects"), reverse("projects:projects_overview")),
        (card.project.name, card.project.get_absolute_url()),
        (card.name, card.get_absolute_url()),
        (_("Edit Card"), None),
    ]

    return TemplateResponse(
        request,
        "cards/card_form.html",
        {
            "card": card,
            "form": form,
            "project": card.project,
            "breadcrumbs": breadcrumbs,
        },
    )
예제 #5
0
def send_invites(request, project_id):
    project = get_object_or_404(Project.objects.select_related("owner"),
                                pk=project_id)
    has_perm_or_403(request.user, "projects.add_members", project)

    if request.method == "POST":
        form = InviteForm(request.POST, project=project)
        if form.is_valid():
            invites = form.save(request.user)
            for invite in invites:
                send_invite_email(
                    invite,
                    accept_url=request.build_absolute_uri(
                        reverse("invites:accept_invite", args=[invite.guid])),
                )
            messages.success(
                request,
                _("You have sent %(num_invites)s invite(s)") %
                {"num_invites": len(invites)},
            )
            return redirect("projects:project_members", project.id)
    else:
        form = InviteForm(project=project)
    return TemplateResponse(request, "invites/invite_form.html", {
        "form": form,
        "project": project
    })
예제 #6
0
파일: views.py 프로젝트: danjac/kando
def delete_card(request, card_id):
    card = get_object_or_404(
        Card.objects.select_related("project", "project__owner"),
        pk=card_id,
    )
    has_perm_or_403(request.user, "cards.delete_card", card)
    card.delete()
    messages.info(request, _("Card has been deleted"))
    return redirect(card.project)
예제 #7
0
def delete_task(request, task_id):
    task = get_object_or_404(
        Task.objects.select_related("owner", "card", "card__project",
                                    "card__owner", "card__assignee"),
        pk=task_id,
    )
    has_perm_or_403(request.user, "tasks.delete_task", task)
    task.delete()
    return redirect(task.card)
예제 #8
0
파일: views.py 프로젝트: danjac/kando
def delete_attachment(request, attachment_id):
    attachment = get_object_or_404(
        Attachment.objects.select_related(
            "owner", "card", "card__project", "card__owner", "card__assignee"
        ),
        pk=attachment_id,
    )
    has_perm_or_403(request.user, "attachments.delete_attachment", attachment)
    attachment.delete()
    messages.info(request, _("Attachment has been deleted"))
    return redirect(attachment.card)
예제 #9
0
def edit_task(request, task_id):
    task = get_object_or_404(
        Task.objects.select_related("owner", "card", "card__project",
                                    "card__owner", "card__assignee"),
        pk=task_id,
    )
    has_perm_or_403(request.user, "tasks.change_task", task)
    form = TaskForm(request.POST, instance=task)
    if form.is_valid():
        task.save()
    return redirect(task.card)
예제 #10
0
def move_tasks(request, card_id):
    card = get_object_or_404(Card.objects.select_related(
        "owner", "project", "assignee"),
                             pk=card_id)
    has_perm_or_403(request.user, "tasks.move_tasks", card)

    for position, task in sort_draggable_items(request, card.task_set.all(),
                                               ["position"]):
        task.position = position

    return HttpResponseNoContent()
예제 #11
0
def create_task(request, card_id):
    card = get_object_or_404(Card.objects.select_related(
        "owner", "project", "assignee"),
                             pk=card_id)
    has_perm_or_403(request.user, "tasks.create_task", card)

    form = TaskForm(request.POST)
    if form.is_valid():
        task = form.save(commit=False)
        task.card = card
        task.owner = request.user
        task.save()
    return redirect(card)
예제 #12
0
파일: views.py 프로젝트: danjac/kando
def move_cards(request, column_id):
    column = get_object_or_404(Column.objects.select_related(
        "project", "project__owner"),
                               pk=column_id)
    qs = column.project.card_set.select_related("project", "project__owner",
                                                "assignee", "owner")

    for position, card in sort_draggable_items(request, qs,
                                               ["position", "column"]):
        has_perm_or_403(request.user, "cards.move_card", card)
        card.position = position
        card.column = column

    return HttpResponseNoContent()
예제 #13
0
def delete_column(request, column_id):
    column = get_object_or_404(Column.objects.select_related(
        "project", "project__owner"),
                               pk=column_id)
    has_perm_or_403(request.user, "columns.delete_column", column)
    if column.card_set.count() > 0:
        messages.error(request,
                       _("You cannot delete a column containing cards"))
    elif column.project.column_set.count() == 1:
        messages.error(request,
                       _("You must have at least one column per project"))
    else:
        column.delete()
        messages.info(request, _("Column has been deleted"))
    return redirect(column.project)
예제 #14
0
파일: views.py 프로젝트: danjac/kando
def create_attachment(request, card_id):
    # for now we just add attachments to cards
    card = get_object_or_404(
        Card.objects.select_related("owner", "project", "assignee"), pk=card_id
    )
    has_perm_or_403(request.user, "attachments.create_attachment", card)

    form = AttachmentForm(request.POST, request.FILES)
    if form.is_valid():
        attachment = form.save(commit=False)
        attachment.card = card
        attachment.project = card.project
        attachment.owner = request.user
        attachment.save()
    return redirect(card)
예제 #15
0
def toggle_task_complete(request, task_id):
    task = get_object_or_404(
        Task.objects.select_related("owner", "card", "card__owner",
                                    "card__assignee"),
        pk=task_id,
    )
    has_perm_or_403(request.user, "tasks.change_task", task)
    task.completed = None if task.completed else timezone.now()
    task.save()
    if request.is_ajax_fragment:
        return TemplateResponse(
            request,
            "cards/_task_description.html",
            {
                "task": task,
                "can_change_task": True
            },
        )
    return redirect(task.card)
예제 #16
0
파일: views.py 프로젝트: danjac/kando
def create_card(request, project_id, column_id=None):
    project = get_object_or_404(Project.objects.select_related("owner"),
                                pk=project_id)
    has_perm_or_403(request.user, "cards.create_card", project)

    if column_id:
        column = get_object_or_404(project.column_set.all(), pk=column_id)
    else:
        column = None

    if request.method == "POST":
        form = CardForm(request.POST, project=project)
        if form.is_valid():
            card = form.save(commit=False)
            card.owner = request.user
            card.project = project
            card.save()
            messages.success(request, _("Your card has been added"))
            return redirect(card)
    else:
        form = CardForm(initial={"column": column}, project=project)

    breadcrumbs = [
        (_("Projects"), reverse("projects:projects_overview")),
        (project.name, project.get_absolute_url()),
    ]
    if column:
        breadcrumbs += [(column.name, column.get_absolute_url())]
    breadcrumbs += [(_("New Card"), None)]

    return TemplateResponse(
        request,
        "cards/card_form.html",
        {
            "form": form,
            "project": project,
            "column": column,
            "breadcrumbs": breadcrumbs,
        },
    )
예제 #17
0
def column_detail(request, column_id):
    column = get_object_or_404(Column.objects.select_related(
        "project", "project__owner"),
                               pk=column_id)
    has_perm_or_403(request.user, "columns.view_column", column)
    cards = column.card_set.order_by("position").select_related(
        "owner", "project", "project__owner")
    is_deletable = cards.count() == 0 and column.project.column_set.count() > 1

    breadcrumbs = [
        (_("Projects"), reverse("projects:projects_overview")),
        (column.project.name, None),
    ]

    return TemplateResponse(
        request,
        "columns/detail.html",
        {
            "column": column,
            "cards": cards,
            "is_deletable": is_deletable,
            "breadcrumbs": breadcrumbs,
        },
    )