Exemplo n.º 1
0
def ajax_move(request):

    pid = request.POST.get("id", 0)
    user = request.user
    project = Project.objects.filter(id=pid).first()

    # Get the board.
    board = auth.recent_clipboard(request=request)
    key, vals = board
    next_url = auth.resolve_paste_url(key=key, project=project)

    count = len(vals)

    if not project:
        return ajax_error(msg="Project does not exist.")

    if not auth.is_writable(user=user, project=project):
        return ajax_error(msg="You do not have access to move here.")

    # Move objects in clipboard to given project.
    auth.move(uids=vals, project=project, otype=key, user=user)

    # Clear the clipboard after moving.
    auth.clear(request=request)

    return ajax_success(msg=f"Moved {count} items into project.",
                        redirect=next_url)
Exemplo n.º 2
0
def ajax_paste(request):
    """
    Paste the most recent
    """
    pid = request.POST.get("id", 0)
    user = request.user
    project = Project.objects.filter(id=pid).first()

    # Get the board.
    board = auth.recent_clipboard(request=request)
    key, vals = board
    count = len(vals)

    if not project:
        return ajax_error(msg="Project does not exist.")

    if not auth.is_writable(user=user, project=project):
        return ajax_error(msg="You do not have access to paste here.")

    if not count:
        return ajax_error(msg="Clipboard is empty")

    # The target of this action is to clone.
    clone = request.POST.get('target') == CLONED_RECIPES

    # Paste the clipboard item into the project
    auth.paste(board=board, user=user, project=project, clone=clone)

    # Resolve the redirect url.
    next_url = auth.resolve_paste_url(key=key, project=project)

    # Clear the clipboard after pasting.
    auth.clear(request=request)

    return ajax_success(msg=f"Pasted {count} items into project.", redirect=next_url)
Exemplo n.º 3
0
def ajax_paste(request):
    """
    Paste the most recent
    """
    pid = request.POST.get("id", 0)
    user = request.user
    project = Project.objects.filter(id=pid).first()

    # Get the board.
    board = auth.recent_clipboard(request=request)
    key, vals = board
    count = len(vals)

    if not project:
        return ajax_error(msg="Project does not exist.")

    if not auth.is_writable(user=user, project=project):
        return ajax_error(msg="You do not have access to paste here.")

    if not count:
        return ajax_error(msg="Clipboard is empty")

    # The target of this action is to clone.
    clone = request.POST.get('target')

    # Paste the clipboard item into the project
    auth.paste(board=board, user=user, project=project, clone=clone)

    data_url = reverse("data_list", kwargs=dict(uid=project.uid))
    recipes_url = reverse("recipe_list", kwargs=dict(uid=project.uid))

    # Resolve the redirect url.
    redir = recipes_url if key == COPIED_RECIPES else data_url

    # Clear the clipboard after pasting.
    auth.clear(request=request)

    return ajax_success(msg=f"Pasted {count} items into project.",
                        redirect=redir)
Exemplo n.º 4
0
def ajax_clear_clipboard(request):

    # Clear the clipboard
    auth.clear(request=request)

    return ajax_success(msg="Cleared clipboard. ", html="")