Exemplo n.º 1
0
    def __init__(self, parent=None, testing=False, teacherId=None):
        # Initialize object using ui_addTeacher
        super(EditTeacherDialog, self).__init__(parent)
        self.ui = Ui_AddTeacherDialog()
        self.ui.setupUi(self)
        
        # Initialize class variables
        self.testing = testing
        if teacherId is None:
            QMessageBox.critical(self, 'Invalid Teacher/Contact', "An invalid teacher/contact was chosen.", QMessageBox.Ok)
            self.reject()
        self.teacherId = teacherId
        self.teacher = dbInteractionInstance.getTeacherFromId(teacherId)

        # Initialize ui with variables
        self.ui.addTeacherBtn.setText("&Update Teacher/Contact")
        self.setWindowTitle("Edit Teacher")
        self.ui.firstNameLineEdit.setText(self.teacher.first)
        self.ui.lastNameLineEdit.setText(self.teacher.last)
        self.ui.addressLineEdit.setText(self.teacher.address)
        self.ui.cityLineEdit.setText(self.teacher.city)
        self.ui.postalCodeLineEdit.setText(humanPostalCodeFormat(self.teacher.postal))
        self.ui.daytimePhoneLineEdit.setText(humanPhoneNumberFormat(self.teacher.daytimePhone))
        self.ui.eveningPhoneLineEdit.setText(humanPhoneNumberFormat(self.teacher.eveningPhone))
        self.ui.emailLineEdit.setText(self.teacher.email)

        # Make the buttons do things
        self.connectSlots()
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
    def chooseTeacherBtn_clicked(self):
        """opens Choose Teacher Dialog"""
        dialog = ChooseTeacherDialog()
        # For Modal dialog
        result = dialog.exec_()

        if result == True:
            self.teacherId = dialog.getTeacherId()
            # Use the id to get the name for displaychoose
            t = dbInteractionInstance.getTeacherFromId(self.teacherId)
            name = name = t.first + " " + t.last
            self.ui.teacherLineEdit.setText(name)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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()