コード例 #1
0
def gerom(app, manager, user_ds, db):
    """
    Create a test user.
    Gerom has a confirmed account, but is not logged in.
    """
    gerom = user_ds.create_user(
        email="*****@*****.**",
        password=hash_password("password"),
        confirmed_at=datetime.datetime.now(),
        active=True,
    )

    schedule = md.Schedule(
        schd.Schedule(manager.get_default_project_id(),
                      label="GEROM'S SCHEDULE"),
        user=gerom,
    )
    db.session.add(schedule)
    db.session.commit()

    yield gerom

    db.session.delete(schedule)
    db.session.delete(gerom)
    db.session.commit()
コード例 #2
0
    def save_schedule(self, user: md.User, schedule: schd.Schedule):
        """
        Saves a schedule binding it to a user into the database.

        :param user: the user
        :type user: md.User
        :param schedule: the schedule
        :type schedule: schd.Schedule
        :return: the scheduler, with its id updated...

        """
        if schedule.id is None:  # this schedule is not yet saved
            schd_db = md.Schedule(data=schedule, user=user)
            schd_db.data.id = schd_db.id
            self.database.session.commit()
            return schd_db.data

        else:  # this schedule has already been saved
            # TODO: control access levels
            schd_db = user.get_schedule(id=schedule.id)
            if schd_db is None:
                raise ScheduleNotOwnedError
            else:
                schd_db.update_data(schedule)
                return schd_db.data
コード例 #3
0
def jyl(app, manager, user_ds, db):
    """
    Create a test user.
    JYL has a confirmed account and is logged in.
    """
    jyl = user_ds.create_user(
        email="*****@*****.**",
        password=hash_password("password"),
        confirmed_at=datetime.datetime.now(),
        active=True,
    )

    data = schd.Schedule(manager.get_default_project_id(),
                         label="JYL'S SCHEDULE")
    data.add_course("LEPL1104")
    active_schedule = md.Schedule(data, user=jyl)
    db.session.add(active_schedule)

    old_schedule = md.Schedule(schd.Schedule(manager.get_default_project_id(),
                                             label="OLD SCHEDULE"),
                               user=jyl)
    db.session.add(old_schedule)
    db.session.commit()

    # Login user
    @app.login_manager.request_loader
    def load_user_from_request(request):
        utl.init_session()
        session["current_schedule"] = copy.copy(jyl.get_schedules()[0].data)
        return jyl

    yield jyl

    # Logout & delete user
    @app.login_manager.request_loader
    def load_user_from_request(request):
        return None

    db.session.delete(active_schedule)
    db.session.delete(old_schedule)
    db.session.delete(jyl)
    db.session.commit()
コード例 #4
0
def share():
    link = request.args.get('link')
    if link:
        mng = app.config['MANAGER']
        schedule, _ = mng.get_schedule(link)
    else:
        schedule = None

    if schedule is None:
        return _('The schedule you requested does not exist in our database !'), 400
    else:
        session['current_schedule'] = md.Schedule(schedule, user=current_user).data
        g.track_var['schedule share'] = schedule.id
        return redirect(url_for('calendar.index'))
コード例 #5
0
ファイル: manager.py プロジェクト: raftar2097/ADE-Scheduler
    def save_schedule(self, user: md.User, schedule: schd.Schedule, uuid):
        """
        Saves a schedule binding it to a user into the database.

        :param user: the user
        :type user: md.User
        :param schedule: the schedule
        :type schedule: schd.Schedule
        :return: the scheduler, with its id updated...

        """
        if schedule.id is None:  # this schedule is not yet saved
            schd = md.Schedule(data=schedule, user=user)
            schd.data.id = schd.id
            self.database.session.commit()

        else:  # this schedule has already been saved
            schd = md.Schedule.query.filter(
                md.Schedule.id == schedule.id).first()
            if schd is None:
                raise ScheduleNotFountError
            else:
                schd.update_data(schedule)

            if user is not None:
                user_has_schedule = user.get_schedule(
                    id=schedule.id) is not None
            else:
                user_has_schedule = False

            if not user_has_schedule and user is not None:
                user.add_schedule(schd)

        # Update the last person to modify the schedule
        schd.update_last_modified_by(uuid)
        return schd.data