def entriesByTeacherBtn_clicked(self): """Saves a csv of all the entries sorted by Teacher""" filename = QFileDialog.getSaveFileName(self, "Report Entries by Teacher", exportsPath, "CSV Files (*.csv)") if filename is not None and filename != "": if filename[-4:] != ".csv": filename += ".csv" entries = dbInteractionInstance.getAllEntries() # Get participant and teacher names for entries # Note super bad hack where I replace the ID with a name for entry in entries: participant = dbInteractionInstance.getParticipantFromId(entry.participantID) try: entry.participantID = "{last}, {first}".format(last=participant.last, first=participant.first) except Exception: entry.participantID = "{groupName}".format(groupName=participant.groupName) if entry.teacherID != "": teacher = dbInteractionInstance.getTeacherFromId(entry.teacherID) entry.teacherID = "{last}, {first}".format(last=teacher.last, first=teacher.first) entries.sort(key=lambda x: (x.teacherID, x.participantID, x.discipline, x.classNumber)) fout = open(filename, 'w') fout.write(Entry.reportByTeacherHeader()) for entry in entries: entry.reportByTeacher(fout) fout.close() QMessageBox.information(self, 'Report Entries by Teacher', 'Report saved to ' + filename, QMessageBox.Ok)
def __init__(self, parent=None, testing=False, participantId=None): # Initialize object using ui_addParticipant super(EditParticipantDialog, self).__init__(parent) self.ui = Ui_AddParticipantDialog() self.ui.setupUi(self) # Initialize class variables self.testing = testing if participantId is None: QMessageBox.critical(self, 'Invalid Participant', "An invalid participant was chosen.", QMessageBox.Ok) self.reject() # if participantId[0] == 's': # self.participantId = participantId[1:] # else: # self.participantId = participantId self.participantId = participantId self.participant = dbInteractionInstance.getParticipantFromId(participantId) # Set up the contact self.contactId = self.participant.contact if self.contactId: c = dbInteractionInstance.getTeacherFromId(self.contactId) if c is not None: self.ui.contactPersonLineEdit.setText("{0} {1}".format(c.first, c.last)) # Initialize ui with variables self.ui.addParticipantBtn.setText("&Update Participant") self.setWindowTitle("Edit Participant") self.ui.firstNameLineEdit.setText(self.participant.first) self.ui.lastNameLineEdit.setText(self.participant.last) self.ui.addressLineEdit.setText(self.participant.address) self.ui.cityLineEdit.setText(self.participant.city) self.ui.postalCodeLineEdit.setText(humanPostalCodeFormat(self.participant.postal)) self.ui.homePhoneLineEdit.setText(humanPhoneNumberFormat(self.participant.home)) self.ui.cellPhoneLineEdit.setText(humanPhoneNumberFormat(self.participant.cell)) self.ui.emailLineEdit.setText(self.participant.email) self.ui.dateOfBirthDateEdit.setDate(QDate.fromString(self.participant.dob, "yyyy-MM-dd")) self.ui.ageLabel.setText("Age as of Jan. 1 {0}".format(QDate.currentDate().year())) self.ui.schoolAttendingLineEdit.setText(self.participant.schoolAttending) self.ui.parentLineEdit.setText(self.participant.parent) self.ui.schoolGradeLineEdit.setText(self.participant.schoolGrade) self.ui.groupNameLineEdit.setText(self.participant.groupName) self.ui.numberParticipantsLineEdit.setText(self.participant.numberParticipants) self.ui.schoolGradeLineEdit.setText(self.participant.schoolGrade) self.ui.averageAgeLineEdit.setText(self.participant.averageAge) if self.participant.earliestPerformanceTime != "": self.ui.timeConstraintsGroupBox.setChecked(True) self.ui.earliestPerformanceTimeTimeEdit.setTime(QTime.fromString(self.participant.earliestPerformanceTime, "h:mm A")) self.ui.latestPerformanceTimeTimeEdit.setTime(QTime.fromString(self.participant.latestPerformanceTime, "h:mm A")) self.ui.participantsTextEdit.setText(self.participant.participants) # Set the age display self.dob_changed() # Make the buttons do things self.connectSlots()
def setParticipant(self): """sets all the stuff related to self.participantId""" # Use the id to get the name for display p = dbInteractionInstance.getParticipantFromId(self.participantId) name = "" # Deal with it whether it's a solo or group try: name = p.first + " " + p.last except AttributeError: name = p.groupName self.ui.participantLineEdit.setText(name)
def chooseParticipantBtn_clicked(self): """opens Choose Participant Dialog""" dialog = ChooseParticipantDialog() # For Modal dialog result = dialog.exec_() if result == True: self.participantId = dialog.getParticipantId() # Use the id to get the name for display p = dbInteractionInstance.getParticipantFromId(self.participantId) name = "" # Deal with it whether it's a solo or group if len(p.first) > 0: name = p.first + " " + p.last else: name = p.groupName self.ui.participantLineEdit.setText(name)
def export(self, csvFile, depth=2): """Write this entry to a csv file, padded with <depth> empty columns as indentation. \ csvFile must be an open file with write permissions.""" # super hack from databaseInteraction import dbInteractionInstance participant = dbInteractionInstance.getParticipantFromId(self.participantID) teacher = dbInteractionInstance.getTeacherFromId(self.teacherID) leadingCommas = '' for _ in range(depth): leadingCommas = leadingCommas+',' s = '{indent}"{participantName}","{teacherName}","{discipline}","{level}","{yearsOfInstruction}","{instrument}","{requirements}",'.format( indent=leadingCommas, participantName=participant, teacherName=teacher, discipline=self.discipline, level=self.level, yearsOfInstruction=self.yearsOfInstruction, instrument=self.instrument, requirements=self.schedulingRequirements ) try: s += '"{early}","{late}",'.format( early=participant.earliestPerformanceTime, late=participant.latestPerformanceTime ) except Exception: s += ",," # instead of duplicating all the entry data just have an indented list of all selections for i in range(len(self.selections)): if i != 0: s += '{indent},,,,,,,,,'.format(indent=leadingCommas) s += '"{time}","{title}","{composer}","{musical}"\n'.format( time=self.selections[i]['performanceTime'], title=self.selections[i]['title'], composer=self.selections[i]['composerArranger'], musical=self.selections[i]['titleOfMusical'] ) csvFile.write(s)
def scheduleTableWidget_itemSelectionChanged(self): """Displays the entries of the selected event in entriesTableWidget""" # Make sure something is selected if self.ui.scheduleTableWidget.selectedItems() is not None: # Get which Event is selected col = self.ui.scheduleTableWidget.currentColumn() eventIndex = self.ui.scheduleTableWidget.currentRow() event = self.schedule.sessions[col].eventList[eventIndex] # Set up columns self.ui.entriesTableWidget.setColumnCount(3) tableHeader = ["Title", "Participant", "Performance Time"] self.ui.entriesTableWidget.setHorizontalHeaderLabels(tableHeader) # Set up rows self.ui.entriesTableWidget.setRowCount(len(event.entries)) for row in xrange(len(event.entries)): entry = event.entries[row] if len(entry.selections) > 1: self.ui.entriesTableWidget.setItem(row, 0, QTableWidgetItem("<multiple>")) minutes, seconds = divmod(entry.totalTime().total_seconds(), 60) self.ui.entriesTableWidget.setItem(row, 2, QTableWidgetItem("{:.0f}:{:02d}".format(minutes, int(seconds)))) else: try: self.ui.entriesTableWidget.setItem(row, 0, QTableWidgetItem(entry.selections[0]['title'])) self.ui.entriesTableWidget.setItem(row, 2, QTableWidgetItem(entry.selections[0]['performanceTime'])) except IndexError: # TODO This is only here because some old test data has no selections self.ui.entriesTableWidget.setItem(row, 0, QTableWidgetItem("old test data")) self.ui.entriesTableWidget.setItem(row, 2, QTableWidgetItem("old test data")) participant = dbInteractionInstance.getParticipantFromId(entry.participantID) name = "" if len(participant.first) > 0: name = participant.first + " " + participant.last elif len(participant.participants) > 0: name = participant.participants else: name = participant.groupName self.ui.entriesTableWidget.setItem(row, 1, QTableWidgetItem(name)) else: # Clear table self.ui.entriesTableWidget.setRowCount(0)
def __init__(self, parent=None, testing=False, participantId=None): # Initialize object using ui_addSoloParticipant super(EditSoloParticipantDialog, self).__init__(parent) self.ui = Ui_AddSoloParticipantDialog() self.ui.setupUi(self) # Initialize class variables self.testing = testing if participantId is None: QMessageBox.critical(self, 'Invalid Participant', "An invalid participant was chosen.", QMessageBox.Ok) self.reject() if participantId[0] == 's': self.participantId = participantId[1:] else: self.participantId = participantId self.participant = dbInteractionInstance.getParticipantFromId(participantId) # Initialize ui with variables self.ui.addParticipantBtn.setText("&Update Participant") self.setWindowTitle("Edit Participant") self.ui.firstNameLineEdit.setText(self.participant.first) self.ui.lastNameLineEdit.setText(self.participant.last) self.ui.addressLineEdit.setText(self.participant.address) self.ui.cityLineEdit.setText(self.participant.town) self.ui.postalCodeLineEdit.setText(humanPostalCodeFormat(self.participant.postal)) self.ui.homePhoneLineEdit.setText(humanPhoneNumberFormat(self.participant.home)) self.ui.cellPhoneLineEdit.setText(humanPhoneNumberFormat(self.participant.cell)) self.ui.emailLineEdit.setText(self.participant.email) self.ui.dateOfBirthDateEdit.setDate(QDate.fromString(self.participant.dob, "yyyy-MM-dd")) self.ui.ageLabel.setText("Age as of Jan. 1 {0}".format(QDate.currentDate().year())) self.ui.schoolAttendingLineEdit.setText(self.participant.schoolAttending) self.ui.parentLineEdit.setText(self.participant.parent) self.ui.schoolGradeLineEdit.setText(self.participant.schoolGrade) # Set the age display self.dob_changed() # Make the buttons do things self.connectSlots()
def toWordFile(self, p): """Creates a docx for the printer, document is from docx module""" # super hack from databaseInteraction import dbInteractionInstance participant = dbInteractionInstance.getParticipantFromId(self.participantID) pString = "" if len(participant.first) > 0: # Print soloist name pString = "{0} {1}, ".format(participant.first, participant.last) if participant.schoolAttending != "": pString += participant.schoolAttending else: index = participant.city.find(",") if index > -1: pString += participant.city[:index] else: pString += participant.city else: # Print list of participants in group # if len(Participant.participants) > 0: # actualParticipants = [] # tokens = Participant.participants.split(',') # if tokens[0] != "": # for index in tokens: # sp = dbInteractionInstance.getParticipantFromId(index) # if sp.first != "": # actualParticipants.append("{0} {1}".format(sp.first, sp.last)) # # Correctly "comma-ify" the list of names # pString = ", ".join(actualParticipants) # index = pString.rfind(", ") # if index > -1: # pString = pString[:index-1] + " &" + pString[index+1:] pString = participant.participants # Print the group name if self.discipline in ["Choral", "Band", "Dance"]: if len(participant.participants) > 0: pString += ", " pString += "{0}".format(participant.groupName) elif self.discipline == "Speech" and len(participant.participants) == 0: pString += "{0}".format(participant.groupName) # Print the grade if participant.schoolGrade != "": pString += ", gr. " + participant.schoolGrade p.add_run(pString) # Don't number if only one selection if len(self.selections) == 1: pString = "\n\t\t{0}".format(self.selections[0]['title']) if self.selections[0]['titleOfMusical'] != "": pString += " ({0})".format(self.selections[0]['titleOfMusical']) if self.selections[0]['composerArranger'] != "": pString += " - {0}".format(self.selections[0]['composerArranger']) p.add_run(pString) else: # Number selections like a) for i in range(len(self.selections)): letter = chr(i + ord('a')) # get the choresponding letter from the index pString = ("\n\t\t{0}) {1}".format(letter, self.selections[i]['title'])) if self.selections[0]['titleOfMusical'] != "": pString += " ({0})".format(self.selections[0]['titleOfMusical']) if self.selections[0]['composerArranger'] != "": pString += " - {0}".format(self.selections[0]['composerArranger']) p.add_run(pString)
def dump(self, csvFile): """Write this entry to a csv file, csvFile must be an open file with write permissions.""" # super hack from databaseInteraction import dbInteractionInstance participant = dbInteractionInstance.getParticipantFromId(self.participantID) # Entry data s = '"{classNumber}","{className}","{discipline}","{level}","{yearsOfInstruction}","{instrument}","{requirements}",'.format( classNumber=self.classNumber, className=self.className, discipline=self.discipline, level=self.level, yearsOfInstruction=self.yearsOfInstruction, instrument=self.instrument, requirements=self.schedulingRequirements ) # selection data # separated with slashes in each field time = "" title = "" composer = "" musical = "" for i in range(len(self.selections)): time += self.selections[i]['performanceTime'] title += self.selections[i]['title'] composer += self.selections[i]['composerArranger'] musical += self.selections[i]['titleOfMusical'] if i < len(self.selections)-1: time += '/' title += '/' composer += '/' musical += '/' s += '"{time}","{title}","{composer}","{musical}",'.format( time=time, title=title, composer=composer, musical=musical ) # Participant data # if type(Participant) is SoloParticipant: s += '"{first}","{last}","{address}","{city}","{postal}","{home}","{cell}","{email}","{dob}","{school}","{parent}","{age}","{grade}","{group_name}","{size}","{average_age}","{participants}","{early}","{late}",'.format( first=participant.first, last=participant.last, address=participant.address, city=participant.city, postal=participant.postal, home=participant.home, cell=participant.cell, email=participant.email, dob=participant.dob, school=participant.schoolAttending, parent=participant.parent, age=participant.age, grade=participant.schoolGrade, group_name=participant.groupName, size=participant.numberParticipants, average_age=participant.averageAge, participants=participant.participants, early=participant.earliestPerformanceTime, late=participant.latestPerformanceTime ) s += ',,,,,,,' # else: # pString = "" # tokens = Participant.participants.split(',') # if tokens[0] != "": # for index in tokens: # sp = dbInteractionInstance.getParticipantFromId(index) # pString += "{first} {last}".format(first=sp.first, last=sp.last) # if sp.age != "": # pString += "{age}".format(age=sp.age) # pString += ", " # if pString != "": # # remove final comma space # pString = pString[:-2] # s += ',,,,,,,,,,,,,' # s += '"{name}","{size}","{grade}","{age}","{participants}","{early}","{late}",'.format( # name=Participant.groupName, # size=Participant.groupSize, # grade=Participant.schoolGrade, # age=Participant.averageAge, # participants=pString, # early=Participant.earliestPerformanceTime, # late=Participant.latestPerformanceTime # ) # contact/teacher info try: person = dbInteractionInstance.getTeacherFromId(participant.contact) except Exception: person = dbInteractionInstance.getTeacherFromId(self.teacherID) #print person s += '"{first}","{last}","{address}","{city}","{postal}","{daytimePhone}","{eveningPhone}","{email}"\n'.format( first=person.first, last=person.last, address=person.address, city=person.city, postal=person.postal, daytimePhone=person.daytimePhone, eveningPhone=person.eveningPhone, email=person.email ) csvFile.write(s)
def __init__(self, parent=None, testing=False, entryId=None): # Initialize object super(EditEntryDialog, self).__init__(parent) self.ui = Ui_AddEntryDialog() self.ui.setupUi(self) self.dance() # Slightly cheater way to start the ui properly # TODO may not need the hack here # HACK Make the PieceWidget in the first tab work right self.ui.tabWidget.removeTab(0) # self.ui.tabWidget.addTab(PieceWidget(), "Piece 1") # Initialize class variables self.testing = testing if entryId is None: QMessageBox.critical(self, 'Invalid Entry', "An invalid entry was chosen.", QMessageBox.Ok) self.reject() self.entryId = entryId self.entry = dbInteractionInstance.getEntryFromId(entryId) self.participantId = self.entry.participantID self.teacherId = self.entry.teacherID self.disciplines = {'Dance': self.dance, # For Pythonic switch-case 'Piano': self.piano, 'Choral': self.choral, 'Vocal': self.vocal, 'Instrumental': self.instrumental, 'Band': self.band, 'Speech': self.speech } # Initialize the ui with variables self.ui.addEntryBtn.setText("&Update Entry") self.setWindowTitle("Edit Entry") p = dbInteractionInstance.getParticipantFromId(self.participantId) # TODO this may not work quite right!!! if p is not None: if len(p.first) > 0: self.ui.participantLineEdit.setText("{0} {1}".format(p.first, p.last)) else: self.ui.participantLineEdit.setText(p.groupName) t = dbInteractionInstance.getTeacherFromId(self.teacherId) if t is not None: self.ui.teacherLineEdit.setText("{0} {1}".format(t.first, t.last)) index = self.ui.disciplineComboBox.findText(self.entry.discipline) if index < 0: QMessageBox.critical(self, 'Invalid Discipline', 'This entry has an invalid discipline. Setting to default discipline.', QMessageBox.Ok) self.ui.disciplineComboBox.setCurrentIndex(0) else: self.ui.disciplineComboBox.setCurrentIndex(index) self.ui.classNumberLineEdit.setText(self.entry.classNumber) self.ui.classNameLineEdit.setText(self.entry.className) self.ui.levelLineEdit.setText(self.entry.level) self.ui.yearsOfInstructionLineEdit.setText(self.entry.yearsOfInstruction) self.ui.instrumentLineEdit.setText(self.entry.instrument) self.ui.schedulingLineEdit.setText(self.entry.schedulingRequirements) for i in xrange(0, len(self.entry.selections)): self.ui.tabWidget.addTab(PieceWidget(piece=self.entry.selections[i]), "Selection {0}".format(i+1)) # trigger combobox change to set enabled fields correctly # but this may destroy some info if the discipline messed up # TODO how to handle that self.disciplineComboBox_changed(self.ui.disciplineComboBox.currentText()) # Make the buttons do things self.connectSlots()
def printAdjudicationSheets(self, filename, adjudicator): """Creates a docx of all the adjudication sheets for the schedule""" print "PRINTING ADJUDICATION SHEETS" document = Document() for session in self.sessions: for event in session.eventList: classNumber = event.classNumber className = event.className.title() for entry in event.entries: # Header document.add_picture('2015header.jpg') # header = document.add_paragraph() # header.add_run().add_picture('logo.jpg', width=Inches(0.8)) # run = header.add_run('Rockwood Festival of the Arts\n') # run.bold = True # run.font.size = Pt(24) # run = header.add_run('\t\t\t{location} - {year} Festival'.format(location=location, year=year)) # run.bold = True # run.font.size = Pt(16) # document.add_picture('logo.jpg', width=Inches(1.25)) # document.add_heading('Rockwood Festival of the Arts', 0) # document.add_heading('{location} - {year} Festival'.format(location=location, year=year), level=1) # Entry information participant = dbInteractionInstance.getParticipantFromId(entry.participantID) pString = "" try: # Print soloist name pString = "{0} {1}".format(participant.first, participant.last) except Exception: # Print list of participants in group if len(participant.participants) > 0: actualParticipants = [] tokens = participant.participants.split(',') if tokens[0] != "": for index in tokens: sp = dbInteractionInstance.getParticipantFromId(index) if sp.first != "": actualParticipants.append("{0} {1}".format(sp.first, sp.last)) # Correctly "comma-ify" the list of names pString = ", ".join(actualParticipants) index = pString.rfind(", ") if index > -1: pString = pString[:index] + " &" + pString[index+1:] else: # Print group name pString = "{0}".format(participant.groupName) selString = "" for selection in entry.selections: selString += "{0}".format(selection['title']) if selection['titleOfMusical'] != "": selString += " ({0})".format(selection['titleOfMusical']) if selection['composerArranger'] != "": selString += " - {0}".format(selection['composerArranger']) selString += ", " # Cut off last comma index = selString.rfind(", ") if index > -1: selString = selString[:index] info = document.add_paragraph() # TODO fake some horizontal lines (maybe can do with custom style in ms word?) run = info.add_run("\tClass: {0} {1}\n".format(classNumber, className)) # run.bold = True run.font.size = Pt(10) run = info.add_run("\tParticipant(s): {0}\n".format(pString)) run.bold = True run.font.size = Pt(10) run = info.add_run("\tSelection(s): {0}\n".format(selString)) # run.bold = True run.font.size = Pt(10) # Marking scale marks = document.add_paragraph() # marks.alignment = WD_ALIGN_PARAGRAPH.LEFT run = marks.add_run("STANDARD SCALE OF MARKS\t\t\t\t\t\tMark : ______________________________\n75 represents a performance which is good.\n80 represent Merit.\n85 represents Distinction. \n90 represents Honours.") run.font.size = Pt(8) # markLine = document.add_paragraph() # # markLine.alignment = WD_ALIGN_PARAGRAPH.RIGHT # markLine.add_run("\nMark : ").font.size = Pt(8) # run = markLine.add_run("_"*30) # # run.underline = True # run.font.size = Pt(8) # Adjudicator # footerStyle = document.styles["Footer"] # adj = document.add_paragraph(style=footerStyle) adj = document.add_paragraph() # adj.alignment = WD_ALIGN_PARAGRAPH.RIGHT adj.add_run("\n"*28) run = adj.add_run("_"*100 + "\n") # run.underline = True run.font.size = Pt(8) run = adj.add_run("{adjudicator} - Adjudicator".format(adjudicator=adjudicator)) run.font.size = Pt(8) document.add_page_break() document.save(filename)