def award_dkp(self): try: value = int(self.value_entry.get()) except ValueError: messagebox.showerror("", "DKP must be a number") return if not self.type_choice.get(): messagebox.showerror("", "Must choose time, boss kill, or other") return try: timestamp = None if 'Time' == self.type_choice.get(): if not self.time_choice.get(): messagebox.showerror( "", "Must choose a time slot for Time award") return timestamp = timestamps.time_from_gui_display( self.time_choice.get()) result = api_client.award_dkp_from_dump(self.filename, self.type_choice.get(), value, self.attendance_var.get(), self.waitlist, self.notes_entry.get(), timestamp, self.api_token) print(result) except Exception: messagebox.showerror("", "Action Failed, no DKP awarded") raise if result.status_code == 201: messagebox.showinfo("", "DKP awarded") self.window.destroy() else: messagebox.showerror( "", "Server error, no DKP awarded\n\n{}".format(result.text))
def charge_dkp(self): selected = self.tree.selection() charges = [] for row_id in selected: row = self.tree.item(row_id) timestamp = row['text'] vals = row['values'] if vals[2] != 'Concluded': continue if vals[4] == '': continue item = vals[0] winners = [x.strip() for x in vals[3].split(',')] costs = [vals[4]] if type(vals[4]) is int else [int(x) for x in vals[4].split(',')] time = timestamps.time_from_gui_display(timestamp) for winner, cost in zip(winners, costs): if winner != 'ROT': charges.append({'character': winner, 'item_name': item, 'value': cost, 'time': timestamps.time_to_django_repr(time), 'notes': '', 'token': self.api_token}) charges_human_readable = ['{} to {} for {}'.format(x['item_name'], x['character'], x['value']) for x in charges] confirm = messagebox.askyesno('', '\n'.join(charges_human_readable) + "\n\nCharge DKP?") if confirm: for charge, msg in zip(charges, charges_human_readable): result = api_client.charge_dkp(**charge) if result.status_code == 201: messagebox.showinfo("", "Charged {}".format(msg)) else: err_msg = '{} could not be charged to {}\nSend Quaff a bug report\n\n{}'\ .format(charge['item_name'], charge['character'], result.text) messagebox.showerror('Failed to charge', err_msg) print('charge completed with status code {}'.format(result.status_code))
def test_timestamp_reversible(): """ we can convert a string to datetime and back and it will be unchanged """ test_s = "Jan 01 2020, 10:00 AM" assert timestamps.time_to_gui_display( (timestamps.time_from_gui_display(test_s))) == test_s
def test_time_from_gui_display(): test_s = "Jan 01 2020, 10:00 AM" time = timestamps.time_from_gui_display(test_s) assert time.month == 1 assert time.day == 1 assert time.hour == 10
def test_time_to_gui_display_pm(): test_s = "Jan 01, 10:00 PM" time = timestamps.time_from_gui_display(test_s) assert time.month == 1 assert time.day == 1 assert time.hour == 22