def new_class(): form = ClassForm() if form.validate_on_submit(): name = form.name.data description = form.description.data created_class = Class.create(name, current_user, description=description) return redirect(url_for('pages.home')) return render_template('new_class.html', form=form)
def edit_class(class_id): cls = Class(ObjectId(class_id)) cls.flask_validate(edit=True) form = ClassForm(obj=cls.to_struct()) if form.validate_on_submit(): cls.name = form.name.data cls.description = form.description.data return redirect(url_for('pages.view_class', class_id=str(cls.get_id()))) return render_template('edit_class.html', form=form, cls=cls)
def classes(): form = ClassForm() if form.validate_on_submit(): name = form.name.data subject = form.subject.data student_id = form.student_id.data db.session.add(Class(name=name, subject=subject, student_id=int(student_id))) db.session.commit() c = Class.query.all() return render_template('class.html', Title='Classes', form=form, classes=c)
def class_edit(training_id, class_num): if 'username' in session: username = session['username'] if session['role'] == 1 or session[ 'role'] == 2: ##COMPROBAR SI ES ADMIN PARA ENTRAR training = Training.query.get(training_id) edit_class = training.classes.filter_by(number=class_num).first() form = ClassForm(date=edit_class.date, topics=edit_class.topics, topicsNext=edit_class.topicsNext, comments=edit_class.comments) if request.method == 'POST': edit_class.date = form.date.data edit_class.topics = form.topics.data edit_class.topicsNext = form.topicsNext.data edit_class.comments = form.comments.data if not edit_class.date or not edit_class.topics or not edit_class.topicsNext or not edit_class.comments: flash('Debes completar todos los campos.', 'error') else: db.session.commit() flash('Cambio realizado correctamente', 'success') return redirect((url_for('classes', training_id=training.id))) return render_template('class_edit.html', title='Editar clase', form=form) else: return redirect(url_for('forbidden')) return redirect(url_for('login'))
def class_add(request): if request.method == 'POST': form = ClassForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('class')) else: form = ClassForm() context = {'form': form} return render(request, 'appTemp/class/class_add.html', context=context)
def class_edit(request, class_id): if request.method == 'POST': classes = Class.objects.get(pk=class_id) form = ClassForm(request.POST, instance=classes) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('class')) else: classes = Class.objects.get(pk=class_id) fields = model_to_dict(classes) form = ClassForm(initial=fields, instance=classes) context = { 'form': form, 'type': 'edit', } return render(request, 'appTemp/class/class_add.html', context)
def classes(training_id): if 'username' in session: username = session['username'] if session['role'] == 1 or session[ 'role'] == 2: ##COMPROBAR SI ES ADMIN PARA ENTRAR training = Training.query.get(training_id) form = ClassForm() if request.method == 'POST': new_class = Class(date=form.date.data, topics=form.topics.data, topicsNext=form.topicsNext.data, comments=form.comments.data) if len(training.classes.all()) == 0: new_class.number = 1 else: new_class.number = db.session.query(func.max( Class.number)).filter( Class.training_id == training_id).first()[0] + 1 new_class.training = training if not new_class.date or not new_class.topics or not new_class.topicsNext: flash('Debes completar todos los campos.', 'error') return redirect((url_for('classes', training_id=training.id))) else: db.session.add(new_class) db.session.commit() flash('Clase agregada correctamente', 'success') #return redirect((url_for('classes', training_id=training.id))) return render_template('classes.html', title='Seguimiento', classes=training.classes, training_id=training_id, finalizada=training.finalizada, form=form) else: return redirect(url_for('forbidden')) return redirect(url_for('login'))