MCPcopy Index your code
hub / github.com/FloatingOctothorpe/python-kanban / order_cards

Function order_cards

cards.py:47–73  ·  view source on GitHub ↗

Reposition a specified card

(data)

Source from the content-addressed store, hash-verified

45 db.session.commit()
46
47def order_cards(data):
48 """Reposition a specified card"""
49
50 # TODO: handle missing 'card' property
51 card_id = data['card']
52 before_id = data.get('before', 'all')
53
54 cards = Card.query.order_by(Card.sort_order.asc()).all()
55
56 card = next(card for card in cards if card.id == card_id)
57
58 if before_id is None:
59 # move to end
60 cards.append(cards.pop(cards.index(card)))
61 elif before_id == 'all':
62 # move to start
63 cards.insert(0, cards.pop(cards.index(card)))
64 else:
65 before_card = next(card for card in cards if card.id == before_id)
66 moving_card = cards.pop(cards.index(card))
67 new_index = cards.index(before_card)
68 cards.insert(new_index, moving_card)
69
70 for i, card in enumerate(cards):
71 card.sort_order = i #len(cards) - i
72
73 db.session.commit()
74
75def update_card(card_id, json, columns):
76 """Update an existing card"""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected