Create and modify drinks function.

This commit is contained in:
luxick
2018-03-14 14:08:19 +01:00
parent ec71d4415f
commit ac01a4441b
4 changed files with 22 additions and 10 deletions

View File

@@ -72,6 +72,11 @@ class GtkUi:
self.data_client.send_request('update_player', player)
self.full_reload()
def update_drink(self, drink: 'models.Drink'):
with util.network_operation(self):
self.data_client.send_request('update_drink', drink)
self.full_reload()
def update_season(self, season: 'models.Season'):
with util.network_operation(self):
self.data_client.send_request('update_season', season)

View File

@@ -28,20 +28,18 @@ class BaseDataHandlers:
def do_add_drink(self, entry):
if entry.get_text():
sql.Drink.create(name=entry.get_text(), vol=0)
drink = models.Drink({'name': entry.get_text(), 'vol': 0.00})
self.app.update_drink(drink)
entry.set_text('')
self.app.full_reload()
def on_drink_name_edited(self, _, index, value):
row = self.app.ui.get_object('drink_store')[index]
# sql.Drink.update(name=value)\
# .where(sql.Drink.id == row[0])\
# .execute()
self.app.full_reload()
drink = [d for d in self.app.drinks.data if d.id == row[0]][0]
drink.name = value
self.app.update_drink(drink)
def on_drink_vol_edited(self, _, index, value):
row = self.app.ui.get_object('drink_store')[index]
# sql.Drink.update(vol=value) \
# .where(sql.Drink.id == row[0]) \
# .execute()
self.app.full_reload()
drink = [d for d in self.app.drinks.data if d.id == row[0]][0]
drink.vol = value
self.app.update_drink(drink)

View File

@@ -2246,6 +2246,7 @@
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Name</property>
<property name="expand">True</property>
<child>
<object class="GtkCellRendererText">
<property name="editable">True</property>

View File

@@ -24,6 +24,14 @@ class WriteFunctions:
sql.Player.hex_id: player.hex_id})
.execute())
@staticmethod
def update_drink(drink: 'models.Drink', *_):
(sql.Drink
.insert(id=drink.id, name=drink.name, vol=drink.vol)
.on_conflict(update={sql.Drink.name: drink.name,
sql.Drink.vol: drink.vol})
.execute())
@staticmethod
def update_season(season: 'models.Season', *_):
(sql.Season