Esempio n. 1
0
    def getDataFromFireBase(self):
        try:

            user = auth.sign_in_with_email_and_password(
                self.login, self.password)
            student = db.child('users').child(
                user['localId']).child('profile').get()
            data = student.val()
            if int(data['countAchievements']) != 0:
                achievements = db.child('users').child(
                    user['localId']).child('achievements').get()
                data = achievements.val()
                i = 0
                for key in data:
                    i += 1
                data2 = {"countAchievements": i}
                db.child('users').child(
                    user["localId"]).child("profile").update(
                        data2, user['idToken'])

            student = db.child('users').child(
                user['localId']).child('profile').get()
            data = student.val()
            self.fill_fields(data['name'], data['surname'], data['class'],
                             data['letter'], data['countAchievements'])
        except Exception as e:
            print(e)
    def update_achievement(self):
        competition_type = self.ui.comboBox_type_work.currentText()
        competition_name = self.ui.lineEdit_competition_name.text()
        work_type = self.ui.comboBox_type_work.currentText()
        type_document = self.ui.comboBox_type_document.currentText()
        place = self.ui.comboBox_place.currentText()
        level_competition = self.ui.comboBox_level_competition.currentText()
        subject = self.ui.comboBox_subject.currentText()
        date = self.ui.dateEdit_event.text()
        new_data = {
            'competition_type': competition_type,
            'competition_name': competition_name,
            'work_type': work_type,
            'type_document': type_document,
            'place': place,
            'level_competition': level_competition,
            'subject': subject,
            'date': date
        }
        print("new_data", new_data)
        if len(self.fpath) > 1:
            print("103 check if path >1")
            d = self.fpath.split(".")
            file_format = d[-1]
            new_data = {
                'competition_type': competition_type,
                'competition_name': competition_name,
                'work_type': work_type,
                'type_document': type_document,
                'place': place,
                'level_competition': level_competition,
                'subject': subject,
                'date': date,
                'file_format': file_format
            }
            storage.child("/" + self.user['localId'] + "/" + d[-2] + "." +
                          file_format).put(self.fpath, self.user['idToken'])

    #авторизируемся и обновляем данные
        print("here")
        try:
            db.child('users').child(
                self.user['localId']).child('achievements').child(
                    self.key).update(new_data)
            print("Update ")
        except Exception as e:
            print("113 change", e)
            print(new_data)
Esempio n. 3
0
    def show_student(self):
        #получение класса и буквы
        class_number = self.ui.comboBox_class_number.currentText()
        class_letter = self.ui.comboBox_class_letter.currentText()

        try:
            self.students = []
            #self.ui.listWidget_students.
            user2 = auth.sign_in_with_email_and_password(
                self.login, self.password)
            all_users = db.child("users").get()
            print(all_users)
            for user in all_users:
                user_new = {'name': '', 'surname': ''}
                if user.val()['profile']['class'] == class_number and user.val(
                )['profile']['letter']:
                    user_new['name'] = user.val()['profile']['name']
                    user_new['surname'] = user.val()['profile']['surname']
                    self.students.append(user_new)
            print(self.students)
            for student in self.students:
                line = student['name'] + " " + student['surname']
                self.add_element(line)
            print(all_users)
        except Exception as e:
            print("Erorr")
            print(e)

        print(class_number, class_letter)
 def getDataFromFireBase(self):
     try:
         user = auth.sign_in_with_email_and_password(self.login, self.password)
         achievements = db.child('users').child(user['localId']).child('achievements').get()
         data = achievements.val()
         self.dict_achievements = list(data)
         for key in data:
             name = data[key]['competition_name']
             self.add_element(name)
     except Exception:
         print("Error getting data from the server")
    def delete_achievement(self):
        user = auth.sign_in_with_email_and_password(self.parent.login,
                                                    self.parent.password)
        try:
            reply = QMessageBox.question(self, 'Предупреждение',
                                         'Удалить достижение?',
                                         QMessageBox.Yes | QMessageBox.No,
                                         QMessageBox.No)
            if reply == QMessageBox.Yes:
                student = db.child('users').child(
                    user['localId']).child('profile').get()
                data = student.val()
                achievements = db.child('users').child(
                    user['localId']).child('achievements').get()
                #storage.child("/" + user['localId'] + "/" + key_achievement + "." + file_format).delete(user['idToken'])
                i1 = int(data["countAchievements"])
                i1 -= 1
                data = {"countAchievements": i1}
                db.child('users').child(
                    user["localId"]).child("profile").update(
                        data, user['idToken'])
                db.child('users').child(
                    user['localId']).child('achievements').child(
                        self.key).remove()
                reply = QMessageBox.question(self, 'Успех!',
                                             'Вы успешно удалили достижение',
                                             QMessageBox.Ok)
                self.hide()

        except Exception as e:
            print(e)
 def getDataFromFireBase(self):
     try:
         login, password, self.key = self.parent.login, self.parent.password, self.parent.numberSelectedItem
         self.user = auth.sign_in_with_email_and_password(login, password)
         achievements = db.child('users').child(
             self.user['localId']).child('achievements').child(
                 self.key).get()
         print(self.key)
         self.data_achievement = achievements.val()
         self.fill_fields()
     except Exception as e:
         print("getdatafirebase")
         print(e)
Esempio n. 7
0
 def add_achievement_to_firebase(self):
     user = auth.sign_in_with_email_and_password(self.main.login, self.main.password)
     try:
         achievement = {"competition_type": self.ui.comboBox_competition_type.currentText(), "competition_name": self.ui.lineEdit_competition_name.text(), "work_type": self.ui.comboBox_type_work.currentText(),
                        "type_document": self.ui.comboBox_type_document.currentText(), "date": self.ui.dateEdit.text(), "place": self.ui.comboBox_place.currentText(), "level_competition": self.ui.comboBox_level_competition.currentText(),
                        "subject": self.ui.comboBox_subject.currentText(), "scan": "image/1.pdf"}
         results = db.child('users').child(user['localId']).child('achievements').push(achievement)
         reply = QMessageBox.question(self, 'Заметка', 'Вы успешно добавили достижение', QMessageBox.No,
                                      QMessageBox.No)
         self.close()
     except BaseException as e:
         QMessageBox.warning(self, 'Предупреждение', 'Произошла ошибка при добавления достижения')
         print("Произошла ошибка при загрузке достижения")
         print(f'Error: {e}')
Esempio n. 8
0
 def sign_in(self):
     login, password = self.ui.input_login.text(
     ), self.ui.input_password.text()
     if self.check_account(login, password):
         type_user = db.child('users').child(
             self.user['localId']).child('profile').get()
         data = type_user.val()
         if data['type'] == "user":
             self.win_student_profile = student_profile.StudentProfile(
                 login, password)
             self.win_student_profile.show()
             self.close()
         elif data['type'] == "teacher":
             self.win_teacher_class = teacher_class_2.TeacherClass(
                 login, password)
             self.win_teacher_class.show()
             self.close()
Esempio n. 9
0
    def sign_up_student_to_firebase(self):
        try:
            input_code = self.ui.lineEdit_code.text()
            data1 = db.child('hash').get()
            data = data1.val()
            check = 0
            for check_code in data:
                code = data[check_code]['hash']
                if str(input_code) == str(code):
                    check = 1
                    password = self.ui.lineEdit_password.text()
                    login = self.ui.lineEdit_email.text()
                    auth.create_user_with_email_and_password(login, password)
                    user = auth.sign_in_with_email_and_password(
                        login, password)
                    student1 = db.child('hash').child(check_code).child(
                        'student').get()
                    student = student1.val()
                    profile = {
                        "email": login,
                        "name": student["name"],
                        "surname": student["surname"],
                        "class": student["class"],
                        "letter": student["letter"],
                        "countAchievements": "0",
                        "type": "user"
                    }
                    db.child('users').child(
                        user["localId"]).child("profile").set(
                            profile, user['idToken'])
                    db.child('hash').child(code).remove()
                    reply = QMessageBox.question(
                        self, 'Успех!', 'Вы успешно зарегистрировались',
                        QMessageBox.Ok)
                    self.close()
                    self.win_student_profile = student_profile.StudentProfile(
                        login, password)
                    self.win_student_profile.show()
            if check == 0:
                reply = QMessageBox.question(self, 'Неудача!', 'Код неверен',
                                             QMessageBox.Ok)

        except Exception as e:
            print(e)
            reply = QMessageBox.question(
                self, 'Ошибка!',
                "Аккаунт уже зарегистрирован, неверно введена почта или пароль слишком слабый",
                QMessageBox.Ok)
            print("sign_up_student_to_firebase")
Esempio n. 10
0
    def save_scan(self, key):
        #брать key из гет текста и передавать его
        if self.ui.checkBox_scan.isChecked():
            d = self.user['localId'] #upper token, profile token
            achievements = db.child('users').child(self.user['localId']).child('achievements').get()
            data = achievements.val()
            try:
                upper_path = f'{d}/'
                file_name_base = f'{key}.{data[key]["file_format"]}'
                file_format = data[key]["file_format"]
                storage.child(f"{upper_path}{file_name_base}").download(f"{self.download_folder}/",
                                                                               f"{self.download_folder}/{self.name}.{file_format}",
                                                                               token=self.user['idToken'])

                new_arch = f'{self.download_folder}/{self.name}.{file_format}'
                self.zip.write(new_arch, f"{self.name}.{file_format}")
                os.remove(f"{self.download_folder}/{self.name}.{file_format}")
            except Exception as e:
                print(e)
                print("Except save_scan")
Esempio n. 11
0
    def show_student(self):
        #получение класса и буквы
        class_number = self.ui.comboBox_class_number.currentText()
        class_letter = self.ui.comboBox_class_letter.currentText()

        try:
            self.ui.listWidget_students.clear()
            self.users = db.child("users").get().val()
            print(self.users)

            for user in self.users:
                if self.users[user]["profile"]["type"] == "user" and self.users[user]["profile"]["class"] == class_number \
                        and self.users[user]["profile"]["letter"] == class_letter.lower():
                    name_surname = f'{self.users[user]["profile"]["name"]} {self.users[user]["profile"]["surname"]}'
                    self.add_element(name_surname)

        except Exception as e:
            print("Erorr")
            print(e)

        print(class_number, class_letter)
Esempio n. 12
0
    def add_achievement_to_firebase(self):
        user = auth.sign_in_with_email_and_password(self.main.login, self.main.password)
        try:
            student = db.child('users').child(user['localId']).child('profile').get()
            data = student.val()
            i1 = int(data["countAchievements"])
            i1 += 1
            data = {"countAchievements": i1}
            if self.fpath != 0:
                d = self.fpath.split(".")
                file_format = d[-1]
                # storage.child("image3/").download("C:\\", user['idToken'])
                achievement = {"competition_type": self.ui.comboBox_competition_type.currentText(),
                               "competition_name": self.ui.lineEdit_competition_name.text(),
                               "work_type": self.ui.comboBox_type_work.currentText(),
                               "type_document": self.ui.comboBox_type_document.currentText(),
                               "date": self.ui.dateEdit.text(),
                               "place": self.ui.comboBox_place.currentText(),
                               "level_competition": self.ui.comboBox_level_competition.currentText(),
                               "subject": self.ui.comboBox_subject.currentText(),
                               'file_format': file_format}
                db.child('users').child(user['localId']).child('achievements').push(achievement)
                achievements = db.child('users').child(user['localId']).child('achievements').get()
                data3 = achievements.val()
                name = self.ui.lineEdit_competition_name.text()
                for key in data3:
                    name2 = data3[key]['competition_name']
                    if name2 == name:
                        key_achievement = key
                storage.child("/" + user['localId'] + "/" + key_achievement + "." + file_format).put(self.fpath, user['idToken'])
                db.child('users').child(user["localId"]).child("profile").update(data, user['idToken'])
                reply = QMessageBox.question(self, 'Успех!', 'Вы успешно добавили достижение', QMessageBox.Ok,
                                             QMessageBox.Ok)
                self.hide()
            else:
                reply = QMessageBox.warning(self, 'Неудача!', 'Вы не добавили путь до скана!')
                self.select_file

                self.add_achievement_to_firebase
        except BaseException as e:
            QMessageBox.warning(self, 'Предупреждение', 'Произошла ошибка при добавления достижения')
            print("Произошла ошибка при загрузке достижения")
            print(f'Error: {e}')