def ajax_clipboard(request): """ Displays the most recent object in clipboard. """ # Get the most current item in the clipboard. pid = request.POST.get("id", 0) user = request.user project = Project.objects.filter(id=pid).first() board = auth.recent_clipboard(request=request) key, vals = board count = len(vals) if project and auth.is_readable(user=user, obj=project) and count: # Load items into clipboard tmpl = loader.get_template('widgets/clipboard.html') movable = key in [COPIED_RECIPES, COPIED_DATA] context = dict(count=count, board=key, is_recipe=key == COPIED_RECIPES, movable=movable) template = tmpl.render(context=context) else: template = '' return ajax_success(html=template, msg="Refreshed clipboard")
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)
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)
def clipboard(context, project_uid): request = context['request'] user = request.user project = Project.objects.filter(uid=project_uid).first() board = auth.recent_clipboard(request=request) key, vals = board board_count = len(vals) movable = key in [const.COPIED_RECIPES, const.COPIED_DATA] if project and auth.is_readable(user=user, obj=project) and board_count: # Load items into clipboard context = dict(count=board_count, board=key, is_recipe=key == const.COPIED_RECIPES, movable=movable) else: context = dict() return context
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)