def process_card_arrangement(request, board, axes): """Code common to the 2 card_arrangement views.""" # Check this user has permission. if not board.allows_rearrange(request.user): raise PermissionDenied('You cannot rearrange this board') event = { 'type': 'rearrange', 'board': board.id, } if request.method == 'POST': # Update dropped cards dropped_id = request.POST.get('dropped') if dropped_id: dropped = get_object_or_404(Card, id=dropped_id) axis_spec = board.parse_axis_spec(axes) tags_str = request.POST['tags'] tag_strs = tags_str.split(',') if tags_str else [] tags = [board.parse_tag(s) for s in tag_strs] dropped.replace_tags(axis_spec, tags) dropped.save() event.update({ 'xaxis': [b.id for b in axis_spec.x_axis or []], 'yaxis': [b.id for b in axis_spec.y_axis or []], 'dropped': dropped.id, 'tags': [t.id for t in tags], }) ids = [(None if x == '-' else int(x)) for s in request.POST.getlist('order') for x in s.split()] rearrange_objects(board.card_set, ids) event['order'] = ids er = EventRepeater() er.get_stream(board.id).append(event) success = { 'ids': ids, } if dropped_id: success['dropped'] = { 'id': dropped_id, 'label': dropped.label, 'tags': [{'id': t.id, 'name': t.name, 'axis': t.bag.name} for t in dropped.tag_set.all()], } #success['col_axis'] = {'id': axis_bag.id, 'name': axis_bag.name} success['tags'] = [request.POST.getlist('tags')] return success
def process_tag_arrangement(request, bag): """Code common to the 2 card_arrangement views.""" # Check this user has permission. if not bag.allows_rearrange(request.user): raise PermissionDenied('You cannot arrange tags on this board') event = { 'type': 'tags-arranged', 'board': bag.board.id, 'bag': bag.id, } if request.method == 'POST': ids = [(None if x == '-' else int(x)) for s in request.POST.getlist('order') for x in s.split()] rearrange_objects(bag.tag_set, ids) event['order'] = ids er = EventRepeater() er.get_stream(bag.board.id).append(event) success = { 'ids': ids, } return success