예제 #1
0
    def activate(self, database: orm.session.Session) -> None:
        for other_session in database.query(PacuSession).filter(PacuSession.id != self.id):
            other_session.is_active = False
            database.add(other_session)

        self.is_active = True
        database.add(self)

        database.commit()
예제 #2
0
파일: mixins.py 프로젝트: yorkeyanyy/pacu
    def update(self, database: orm.session.Session, commit: bool = True, **kwargs) -> None:
        """ Instead of requiring three lines to update a single field inside
        a database session, this method updates a single field in one line.

        Example usage:
            session.update(database, field_name={'json': ...}) """

        for key, value in kwargs.items():
            value = stringify_datetime(value)
            setattr(self, key, value)

        database.add(self)

        if commit:
            database.commit()
예제 #3
0
def prep_db(session: orm.session.Session):
    doctor1 = Doctor(id=1, name='Айболит')
    doctor2 = Doctor(id=2, name='Сеченов')
    doctor3 = Doctor(id=96881373, name='EugenyBobylev')
    session.bulk_save_objects([doctor1, doctor2, doctor3])
    session.commit()

    job1 = IncartJob(id='1', snippet='job_1')
    job2 = IncartJob(id='2', snippet='job_2')
    session.bulk_save_objects([job1, job2])
    session.commit()

    job_doctor: JobDoctor = JobDoctor(job_id="1", doctor_id=1)
    job_doctor.request_id = '1'
    session.add(job_doctor)
    session.commit()

    job_doctor2 = JobDoctor(job_id="1", doctor_id=2)
    job_doctor2.request_id = '2'
    job_doctor2.request_sended = datetime.datetime.utcnow()
    session.add(job_doctor2)
    session.commit()
def placeholders(session: orm.session.Session):
    # Users
    users = [
        User(418878871, "teadove", "Петер", "Ибрагимов Петер Ильгизович",
             "+79778725196"),
        User(346235776, "tainella", "Amelia Zagadka",
             "Полей-Добронравова Амелия Вадимовна", "+79262895840"),
        User(1409549287, "teameekey", "Петер 2.0", "Иванов Иван Иванович"),
        User(1624330498, 'elfen_clan', 'Каэде', "Антон Семёнов")
    ]
    session.add_all(users)

    # Spheres
    spheres = [
        Sphere("Дизайн"),
        Sphere('SMM'),
        Sphere("Разработка ПО под Windows"),
        Sphere("Мобильная разработка"),
        Sphere("Консультирование"),
        Sphere("CRM"),
        Sphere("Разработка телеграм ботов"),
        Sphere("Фронтенд")
    ]
    session.add_all(spheres)

    # Specialist
    specialist = Specialist(users[0])
    session.add(specialist)

    # Spheres to specialist
    spheres_to_specialist = [
        SphereToSpecialist(spheres[0], specialist),
        SphereToSpecialist(spheres[2], specialist),
        SphereToSpecialist(spheres[4], specialist),
        SphereToSpecialist(spheres[3], specialist),
        SphereToSpecialist(spheres[-1], specialist)
    ]

    session.add_all(spheres_to_specialist)

    # Representative
    representatives = [
        Representative(users[1], "ООО название компании"),
        Representative(users[3], "ООО моя оборона")
    ]

    session.add_all(representatives)

    # Moderator
    moderator = Moderator(users[2], is_admin=True)
    session.add(moderator)

    # Task
    tasks = [
        Task(
            "Разработать телеграм бота", representatives[0],
            "Разработать ТГ бота для ведения учёта посещений "
            "собраний, полное ТЗ при контакте"),
        Task(
            "Разработать дизайн для сайта",
            representatives[0],
            "Разработать дизайн для сайта НКО для сборов пожертвований для бездомных",
            specialist=specialist,
            status='in_work'),
        Task("Разработать сайт для НКО",
             representatives[0],
             status="awaiting_specialist")
    ]
    session.add_all(tasks)

    # SphereToTask
    sphere_to_tasks = [
        SphereToTask(spheres[-2], tasks[0]),
        SphereToTask(spheres[-1], tasks[1]),
        SphereToTask(spheres[0], tasks[1])
    ]
    session.add_all(sphere_to_tasks)

    session.commit()