def save(self): self.db.competition.name = sanitize(self.field_name.text()) self.db.competition.location = sanitize(self.field_location.text()) self.db.competition.event_date = ( self.calendar_competition_event.selectedDate().toString( 'yyyy-MM-dd 00:00:00')) self.db.competition.deadline = ( self.calendar_competition_deadline.selectedDate().toString( 'yyyy-MM-dd 00:00:00')) self.db.competition.competition_type = ( self.selector_competition_type.currentIndex()) self.db.t.competition.update(self.db.competition) self.main_window.set_competition() self.changes_made = False self.hide()
def save_button(self, sender=None): self.table_judges.setFocus() row = 0 while row < self.table_judges.rowCount(): judge_id = int(self.table_judges.item(row, 2).text()) judge = self.db.t.judge.get(judge_id) judge.first_name = sanitize(self.table_judges.item(row, 0).text()) judge.last_name = sanitize(self.table_judges.item(row, 1).text()) if self.db.s.verbose: print('Saving judge %s %s [%d] to competition %d(%d)' % (judge.first_name, judge.last_name, judge.iid, self.competition_id, judge.competition)) self.db.t.judge.update(judge) row += 1 self.changes_made = False self.hide()
def import_file(self): row = 0 self.column_names = [] while row < self.table_columns.rowCount(): selector_column = self.table_columns.cellWidget(row, 1) self.column_names.append(selector_column.currentText()) row += 1 categories = self.db.t.category.get_all() categories_names = [cat.name for cat in categories] categories_ids = [cat.iid for cat in categories] with open(self.filename, newline='') as csvfile: dict_reader = csv.DictReader(csvfile) # ['First Name', 'Last Name', 'Competitor Number', 'Street Address', 'City', 'State/Province', 'Zip/Postal Code', 'Phone Number', # 'Email', 'ScotDance Number', 'Birthdate', 'Age', 'Teacher', 'Teacher Email', 'Date Entry was Received', # 'Primary Competitor Group', 'Secondary Competitor Group', 'Tertiary Competitor Group'] for row in dict_reader: # dancer = sc.Dancer(0,'','','','','','','','',0,'','','','','','',0,0,self.competition.iid) dancer = self.db.t.dancer.new(self.competition.iid) if self.column_names[0] != '': dancer.first_name = sanitize(row[self.column_names[0]]) if self.column_names[1] != '': dancer.last_name = sanitize(row[self.column_names[1]]) if self.column_names[2] != '': dancer.competitor_num = sanitize(row[self.column_names[2]]) if self.column_names[3] != '': dancer.street = sanitize(row[self.column_names[3]]) if self.column_names[4] != '': dancer.city = sanitize(row[self.column_names[4]]) if self.column_names[5] != '': dancer.state = sanitize(row[self.column_names[5]]) if self.column_names[6] != '': dancer.zip = sanitize(row[self.column_names[6]]) if self.column_names[7] != '': dancer.phone_num = sanitize(row[self.column_names[7]]) if self.column_names[8] != '': dancer.email = sanitize(row[self.column_names[8]]) if self.column_names[9] != '': dancer.scot_dance_num = sanitize(row[self.column_names[9]]) if self.column_names[10] != '': cat_name, _ = process.extractOne( row[self.column_names[10]], categories_names) dancer.dancer_category = categories_ids[ categories_names.index(cat_name)] - 1 if self.column_names[11] != '': dancer.birthdate = row[self.column_names[11]] if self.column_names[12] != '': if row[self.column_names[12]].isdigit(): dancer.age = int(row[self.column_names[12]]) if self.column_names[13] != '': dancer.teacher = sanitize(row[self.column_names[13]]) if self.column_names[14] != '': dancer.teacher_email = sanitize(row[self.column_names[14]]) if self.column_names[15] != '': dancer.registered_date = row[self.column_names[15]] if self.column_names[16] != '': dancer_grp1 = row[self.column_names[16]] dancer_group_1 = self.db.t.group.get_or_new( self.competition.iid, dancer_grp1) self.db.t.group.join(dancer.iid, dancer_group_1.iid) # else: # dancer_grp1 = '' if self.column_names[17] != '': dancer_grp2 = row[self.column_names[17]] dancer_group_2 = self.db.t.group.get_or_new( self.competition.iid, dancer_grp2) self.db.t.group.join(dancer.iid, dancer_group_2.iid) # else: # dancer_grp2 = '' if self.column_names[18] != '': dancer_grp3 = row[self.column_names[18]] dancer_group_3 = self.db.t.group.get_or_new( self.competition.iid, dancer_grp3) self.db.t.group.join(dancer.iid, dancer_group_3.iid) # else: # dancer_grp3 = '' # dancer_group_1 = self.db.tables.groups.get_by_abbrev( # dancer_grp1) # dancer_group_2 = self.db.tables.groups.get_by_abbrev( # dancer_grp2) # dancer_group_3 = self.db.tables.groups.get_by_abbrev( # dancer_grp3) # dancer = self.db.tables.dancers.insert(dancer) # if dancer_group_1 is not None: # self.db.tables.groups.join(dancer.iid, dancer_group_1.iid) # if dancer_group_2 is not None: # self.db.tables.groups.join(dancer.iid, dancer_group_2.iid) # if dancer_group_3 is not None: # self.db.tables.groups.join(dancer.iid, dancer_group_3.iid) self.db.t.dancer.update(dancer) # xxx doesn't seem to put dancers into dancer_groups. Why? self.hide()
def save_button(self, sender=None): self.setFocus() self.dancer_group.name = sanitize(self.field_name.text()) self.dancer_group.abbrev = sanitize(self.field_abbrev.text()) if (self.field_age_min.text().isdigit()): self.dancer_group.age_min = int(self.field_age_min.text()) if (self.field_age_max.text().isdigit()): self.dancer_group.age_max = int(self.field_age_max.text()) self.dancer_group.dancer_category = (self.selector_dancer_category .currentIndex()) self.db.t.group.update(self.dancer_group) row = 0 self.dancers_in_group = self.db.t.dancer.get_by_group( self.dancer_group.iid) self.dancer_ids = [] for dancer in self.dancers_in_group: if dancer is not None: self.dancer_ids.append(dancer.iid) while row < self.table_dancers.rowCount(): checkbox_in_group = self.table_dancers.cellWidget(row, 0) dancer_id_text = self.table_dancers.item(row, 4).text() if dancer_id_text != '': dancer_id = int(dancer_id_text) else: dancer_id = 9999999999999999999 if checkbox_in_group.checkState() == 0 and (dancer_id in self.dancer_ids): if self.db.s.verbose: print('dancer [%d] in row %d is in group %d but should be '\ 'removed' % (dancer_id, row, self.dancer_group.iid)) self.db.t.group.unjoin(dancer_id, self.dancer_group.iid) elif checkbox_in_group.checkState() == 2 and (dancer_id not in self.dancer_ids): if self.db.s.verbose: print('dancer [%d] in row %d is not in group %d but should '\ 'be added' % (dancer_id, row, self.dancer_group.iid)) self.db.t.group.join(dancer_id, self.dancer_group.iid) row += 1 row = 0 while row < self.table_events.rowCount(): event_id = int(self.table_events.item(row, 4).text()) event = self.db.t.event.get(event_id) selector_dance = self.table_events.cellWidget(row, 0) event.name = ('%s - %s' % (self.dancer_group.name, selector_dance.currentText())) if self.db.s.verbose: print(event.name) dances = self.db.t.dance.get_all() index = 999999 for dance in dances: if dance.iid < index: index = dance.iid event.dance = selector_dance.currentIndex() + index if self.table_events.item(row, 2).text().isdigit(): event.num_places = int(self.table_events.item(row, 2).text()) checkbox_counts = self.table_events.cellWidget(row, 1) if checkbox_counts.checkState() == 2: event.counts_for_overall = 1 else: event.counts_for_overall = 0 checkbox_stamp = self.table_events.cellWidget(row, 3) if checkbox_stamp.checkState() == 2: event.earns_stamp = 1 else: event.earns_stamp = 0 self.db.t.event.update(event) row += 1 self.changes_made = False
def save_button(self, sender=None): self.table_dancers.setFocus() row = 0 while row < self.table_dancers.rowCount(): dancer_id = int(self.table_dancers.item(row, 17).text()) dancer = self.db.t.dancer.get(dancer_id) dancer.first_name = sanitize( self.table_dancers.item(row, 0).text()) dancer.last_name = sanitize(self.table_dancers.item(row, 1).text()) dancer.competitor_num = sanitize( self.table_dancers.item(row, 2).text()) dancer.scot_dance_num = sanitize( self.table_dancers.item(row, 5).text()) dancer.street = sanitize(self.table_dancers.item(row, 6).text()) dancer.city = sanitize(self.table_dancers.item(row, 7).text()) dancer.state = sanitize(self.table_dancers.item(row, 8).text()) dancer.zip = sanitize(self.table_dancers.item(row, 9).text()) dancer.birthdate = self.table_dancers.item(row, 10).text() dancer_age = self.table_dancers.item(row, 11).text() if dancer_age.isdigit(): dancer.age = int(dancer_age) dancer.registered_date = self.table_dancers.item(row, 12).text() dancer.phone_num = sanitize( self.table_dancers.item(row, 13).text()) dancer.email = sanitize(self.table_dancers.item(row, 14).text()) dancer.teacher = sanitize(self.table_dancers.item(row, 15).text()) dancer.teacher_email = sanitize( self.table_dancers.item(row, 16).text()) selector_category = self.table_dancers.cellWidget(row, 3) if selector_category.currentIndex() > 0: dancer.dancer_category = selector_category.currentIndex() dancer_groups_text = self.table_dancers.item(row, 4).text() dancer_groups_text = ''.join(dancer_groups_text.split()) if dancer_groups_text != '': dancer_groups_abbrev = dancer_groups_text.split(',') already_in_groups = self.db.t.group.get_by_dancer(dancer_id) already_in_abbrevs = [] for group in already_in_groups: if group is not None: already_in_abbrevs.append(group.abbrev) for abbrev in dancer_groups_abbrev: if abbrev in already_in_abbrevs: if self.db.settings.verbose: print('Dancer %s %s is already in group [%s] and '\ 'should remain' % (dancer.first_name, dancer.last_name, abbrev)) else: if self.db.settings.verbose: print( 'Dancer %s %s is not in group [%s] and ' 'should be added' % (dancer.first_name, dancer.last_name, abbrev)) dancer_group = self.db.t.group.get_by_abbrev( abbrev, self.competition_id) if dancer_group is not None: self.db.t.group.join(dancer.iid, dancer_group.iid) for abbrev in already_in_abbrevs: if abbrev in dancer_groups_abbrev: if self.db.settings.verbose: print( 'Dancer %s %s is already in group [%s] and ' 'should remain' % (dancer.first_name, dancer.last_name, abbrev)) else: if self.db.settings.verbose: print( 'Dancer %s %s is in group [%s] and should ' 'be removed' % (dancer.first_name, dancer.last_name, abbrev)) dancer_group = self.db.t.group.get_by_abbrev( abbrev, self.competition_id) if dancer_group is not None: self.db.t.group.unjoin(dancer.iid, dancer_group.iid) self.db.t.dancer.update(dancer) row += 1 self.changes_made = False