Untitled

 avatar
unknown
python
3 years ago
2.3 kB
6
Indexable
import mysql
from mysql.connector import connection
from Note import NoteValue, Note, ExamType, Term
from Student import Student
import enum
import uuid
from enum import Enum
from datetime import date
from sqlalchemy import create_engine, Column, column, text, String, Integer, ForeignKey, select, and_, or_, not_, between, func
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

# Tworzenie silnika ->
database_url = 'mysql+mysqlconnector://root:haslomaslo123@localhost:3306/students'
eng = create_engine(database_url)
# Zadeklarowanie bazy, na ktorej pracujemy
base = declarative_base()


class Students(base):

    __tablename__ = 'students'
    uuid = Column(Integer, primary_key=True, nullable=False)
    name = Column(String(255), nullable=False)
    surname = Column(String(255), nullable=False)
    notes = Column(list, nullable=False)

base.metadata.create_all(eng)

Session = sessionmaker(bind=eng)
session = Session()

class StudentService:

    def __init__(self):
        self.students_list = []


    def add_student_to_database(self, name, surname):

        pass


    def delete_student(elf, id):

        for student in self.students_list:
            if student.id == id:
                self.students_list.remove(student)


    def show_students_list(self):

        for student in self.students_list:
            print(student.__repr__())



    def update_student(self, id, name, surname):

        for student in self.students_list:
            if student.id == id:
                student.name = name
                student.surname = surname

    def show_student_by_id(self, uuid):

        if student.uuid == uuid:
            print(student.__repr__())


    def show_notes_by_uuid(self, uuid):


        if student.uuid == uuid:

            print(f"Student: {student.name} {student.surname}, notes: {student.notes}")




service = StudentService()


# student = Student('Izabela', 'Greszta')
#
# note = Note(NoteValue.THREE_ZERO, ExamType.EXAM, Term.FIRST, uuid.uuid4(), date.today())
#
# student.add_note(note)
#
# #note.update_note_by_uuid(note.uuid, NoteValue.FIVE_ZERO)
#
# student.add_note(note)
#
#
# service.show_student_by_id(student.uuid)

student = Student('Marta', 'Sommer')
service.show_student_by_id(student.uuid)


Editor is loading...