Esempio n. 1
0
 def program_init(row):
     program = Program()
     num = Program.query.filter_by(name=row['Nom']).count()
     if num > 0:
         Program.query.delete()
     subject = Subject.query.filter_by(name=row['Thematique']).first()
     program.name = row['Nom']
     program.description = row['Description']
     program.subject = subject
     return program
Esempio n. 2
0
def add():
    form = ProgramForm()
    form.subject.choices = [(c.id, c.name) for c in Subject.query.all()]
    if form.validate_on_submit():
        program = Program(subject_id=form.subject.data,
                          name=form.name.data,
                          description=form.description.data)
        db.session.add(program)
        db.session.commit()
        flash(_('Nouveau program ajouté avec succèss!'))
        return redirect(url_for('program.detail', id=program.id))
    return render_template('program/form.html', form=form)
def get_program_from_dom(dom: str) -> ProgramSchema:
    soup = BeautifulSoup(dom, 'html.parser')
    all_dom_weeks = soup.select('.card')
    weeks = []
    title = soup.find('h3').string
    for dom_week in all_dom_weeks:
        weeks.append(
            Week(
                workouts=[
                    'https://thenx.com' + workout.attrs['href']
                    for workout in dom_week.find_all('a')
                ],
                title=dom_week.find('h5').string,
            ))
    return Program(title=title, weeks=weeks)
Esempio n. 4
0
 def post(self):
     args = program_parser.parse_args()
     name = ".".join(
         [uuid.uuid4().hex,
          datetime.date.today().isoformat(), "json"])
     filepath = os.path.join(app.config['PROGRAMS_FOLDER'], name)
     with open(filepath, "w") as f:
         json.dump(args["content"], f)
     program = Program(
         filepath=filepath,
         name=args["name"],
         description=args["description"],
     )
     db.session.add(program)
     db.session.commit()
     return program, 201
Esempio n. 5
0
def programs(specialty):
    form = ProgramForm()
    if form.validate_on_submit() and current_user.admin:
        program = Program(name=form.name.data,
                          specialty=form.specialty.data,
                          body=form.body.data,
                          image=form.image.data,
                          state=form.state.data)
        db.session.add(program)
        db.session.commit()
        flash(_('Program added!'))
        return redirect(url_for('main.programs'))
    programs = Program.query.filter_by(specialty=specialty).order_by(
        Program.timestamp.desc())
    return render_template('programs.html',
                           title=_('Programs'),
                           programs=programs,
                           form=form,
                           specialty=specialty)
Esempio n. 6
0
 def generate():
     if current_user.admin:
         with current_app.open_resource('static/data/programs.json') as f:
             data = json.load(f)
             count = 0
             for i in data:
                 specialty = Specialty.query.filter_by(
                     name=i['specialty']).first_or_404()
                 db.session.add(
                     Program(specialty=specialty,
                             name=next(iter(i['program']), None),
                             city=next(iter(i['city']), None),
                             state=next(iter(i['state']), None),
                             accreditation_id=next(
                                 iter(i['accreditation_id']), None),
                             status=next(iter(i['status']), None),
                             url=next(iter(i['url']), None)))
                 db.session.commit()
                 count = count + 1
                 yield (str(count) + " ")
Esempio n. 7
0
def specialty(id):
    session['specialty'] = str(id)
    specialty2 = session.get('specialty')
    form = ProgramForm()
    specialty = Specialty.query.get(id)
    current_user.specialty_id = id
    db.session.commit()
    if form.validate_on_submit() and current_user.admin:
        program = Program(name=form.name.data,
                          specialty=specialty,
                          state=form.state.data)
        db.session.add(program)
        db.session.commit()
        flash(_('Program added!'))
        return redirect(url_for('main.specialty', id=specialty.id))
    return render_template('specialty.html',
                           specialty2=specialty2,
                           specialty=specialty,
                           title=specialty.name,
                           programs=specialty.programs.order_by(
                               Program.name.asc()),
                           form=form)
Esempio n. 8
0
def sign_up():
    """Creates a new user and logs them in"""
    # print("REQUEST FORM: ", request.form.get("username"))
    # print("DIR REQUEST:  ", dir(request.form))
    form = SignUpForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():

        # Create user, default program, and default membership records
        user = User(username=form.data['username'],
                    email=form.data['email'],
                    password=form.data['password'],
                    first_name=form.data['first_name'],
                    last_name=form.data['last_name'],
                    birthday=form.data['birthday'])
        program = Program(
            program=f"{form.data['username']}'s Habits",
            creator=user,
        )
        membership = Member(
            program=program,
            member=user,
            stamper=user,
        )
        db.session.add(user)
        db.session.add(program)
        db.session.add(membership)
        db.session.commit()

        login_user(user)

        # Set cookie
        res = make_response(jsonify(user_schema.dump(user)))
        res.set_cookie("uid_cookie", str(user.id))

        return res
    return {'errors': validation_errors_to_error_messages(form.errors)}
Esempio n. 9
0
    def add(title, display_order):
        program = Program(title=title, display_order=display_order)

        db.session.add(program)
        db.session.commit()
Esempio n. 10
0
def seed():
    Program.seed()
    Section.seed()