Reposition a specified card
(data)
| 45 | db.session.commit() |
| 46 | |
| 47 | def 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 | |
| 75 | def update_card(card_id, json, columns): |
| 76 | """Update an existing card""" |
nothing calls this directly
no outgoing calls
no test coverage detected