Esempio n. 1
0
def delete_school(id):
    # Get school from db or 404
    school = School.get_or_404(id)
    if request.method == 'POST':
        school.delete()
        flash('School successfully deleted')
        return redirect(url_for('view_all_schools'))
    return render_template('delete_school.html', school=school)
Esempio n. 2
0
def view_school_json(id):
    # Get school or 404
    school = School.get_or_404(id)
    # Extract school info
    school_json = {
        'id':
        school.id,
        'name':
        school.name,
        'url':
        school.url,
        'courses': [{
            'id': course.id,
            'name': course.name,
            'url': course.url,
            'school': course.school.name,
            'category': course.category.name
        } for course in school.courses]
    }
    return jsonify(school_json)
Esempio n. 3
0
def edit_school(id):
    # Get school from db or 404
    school = School.get_or_404(id)
    # Start with no errors
    errors = None
    if request.method == 'POST':
        fields = {'name': request.form['name'], 'url': request.form['url']}
        # Validations that check that no fields are empty
        errors = check_no_blanks(fields=fields)
        if not errors:
            # Check that school name does not match other school names,
            # except if it is the same instance
            if (School.get_by_name(fields['name'])
                    and School.get_by_name(fields['name']).id != school.id):
                errors['name_exists'] = True
            if not errors:
                school.edit(name=fields['name'], url=fields['url'])
                flash('School edited')
                return redirect(url_for('view_school', id=school.id))
    # If it is not a POST rquest, populate field values from database
    else:
        fields = {'name': school.name, 'url': school.url}
    return render_template('edit_school.html', fields=fields, errors=errors)
Esempio n. 4
0
def view_school(id):
    # Get school from db or 404
    school = School.get_or_404(id)
    return render_template('view_school.html', school=school)