mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-07 12:54:05 +02:00
brmbar-qt4: Add ALERT_SCRIPT support to call external hook on low balance
This commit is contained in:
parent
1c0e51a246
commit
6cc95ab680
1 changed files with 15 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
from PySide import QtCore, QtGui, QtDeclarative
|
||||
|
||||
|
@ -10,6 +11,12 @@ import brmbar
|
|||
|
||||
# User credit balance limit; sale will fail when balance is below this limit.
|
||||
LIMIT_BALANCE = -200
|
||||
# When below this credit balance, an alert hook script (see below) is run.
|
||||
ALERT_BALANCE = 0
|
||||
# This script is executed when a user is buying things and their balance is
|
||||
# below LIMIT_BALANCE (with argument "limit") or below ALERT_BALANCE
|
||||
# (with argument "alert").
|
||||
ALERT_SCRIPT = "./alert.sh"
|
||||
|
||||
|
||||
class ShopAdapter(QtCore.QObject):
|
||||
|
@ -76,7 +83,14 @@ class ShopAdapter(QtCore.QObject):
|
|||
@QtCore.Slot('QVariant', 'QVariant', result='QVariant')
|
||||
def canSellItem(self, itemid, userid):
|
||||
user = brmbar.Account.load(db, id = userid)
|
||||
return -user.balance() > LIMIT_BALANCE
|
||||
if -user.balance() > ALERT_BALANCE:
|
||||
return True
|
||||
elif -user.balance() > LIMIT_BALANCE:
|
||||
subprocess.call(["sh", ALERT_SCRIPT, "alert"])
|
||||
return True
|
||||
else:
|
||||
subprocess.call(["sh", ALERT_SCRIPT, "limit"])
|
||||
return False
|
||||
|
||||
@QtCore.Slot('QVariant', 'QVariant', result='QVariant')
|
||||
def sellItem(self, itemid, userid):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue