#! /usr/bin/env python # -*- coding: utf-8 -*- # # Copyright (C) 2011 Sebastian Pipping # Licensed under GPL v3 or later import freitagslib.network as net from freitagslib.network import ITEM_ONLY, DEPOSIT_ONLY class Command(object): def difference(self): return self._difference class DepositCommand(Command): def __init__(self, amount): self._difference = amount def run(self, user_name): net.deposit(self._difference, net.DEPOSIT_CASH, user_name) def label(self): return '%.2f Euro einzahlen' % self._difference class _ItemBasedCommand(Command): def __init__(self, item): self._item = item def item(self): return self._item class BuyCommand(_ItemBasedCommand): def __init__(self, item): super(BuyCommand, self).__init__(item) self._difference = -item.price self._to_go = False ## TODO session state, instead? def run(self, user_name): net.buy_item(self._item.id, what_about_it=ITEM_ONLY, user_name=user_name) def label(self): return self._item.name def is_to_go(self): return self._to_go def set_to_go(self, to_go): self._to_go = to_go def deposit(self): return self._item.deposit class ToGoCommand(_ItemBasedCommand): def __init__(self, item): super(ToGoCommand, self).__init__(item) self._difference = -item.deposit def run(self, user_name): net.buy_item(self._item.id, what_about_it=DEPOSIT_ONLY, user_name=user_name) def label(self): return '%s Pfand' % self._item.name