Ejemplo n.º 1
0
def major_detail(id):
    major = get_object_or_404(Major, Major.id == id)
    minors = Minor.listWithStats(id)
    num_items = 0
    for minor in minors:
        num_items += minor.count
    return render_template('major.html', 
            major=major, minors=minors, num_items=num_items)
Ejemplo n.º 2
0
def major_detail(id):
    major = get_object_or_404(Major, Major.id == id)
    minors = Minor.listWithStats(id)
    num_items = 0
    for minor in minors:
        num_items += minor.count
    return render_template('major.html',
                           major=major,
                           minors=minors,
                           num_items=num_items)
Ejemplo n.º 3
0
def major_add():
    if request.method == 'POST':
        if request.form.get('major_id'):
            major = get_object_or_404(Major, Major.id == request.form['major_id'])
            minors = Minor.listWithStats(request.form['major_id'])
            major.name = request.form['name']
            major.income = bool(request.form.get('income'))
            major.save()
            flash('Category #%d updated successfully.' % major.id, 'success')
        else: 
            major = Major.create(name=request.form['name'],
                                 income=bool(request.form.get('income')))
            minors = []
            for minor_name in string.split(request.form['minors'], ','):
                if len(minor_name) > 0:
                    minor = Minor.create(name=string.strip(minor_name), major=major)
                    minors.append(minor)
            flash('A category created successfully.', 'success')
        return render_template('major.html', major=major, minors=minors)
    return render_template('major.html')
Ejemplo n.º 4
0
def major_add():
    if request.method == 'POST':
        if request.form.get('major_id'):
            major = get_object_or_404(Major,
                                      Major.id == request.form['major_id'])
            minors = Minor.listWithStats(request.form['major_id'])
            major.name = request.form['name']
            major.income = bool(request.form.get('income'))
            major.save()
            flash('Category #%d updated successfully.' % major.id, 'success')
        else:
            major = Major.create(name=request.form['name'],
                                 income=bool(request.form.get('income')))
            minors = []
            for minor_name in string.split(request.form['minors'], ','):
                if len(minor_name) > 0:
                    minor = Minor.create(name=string.strip(minor_name),
                                         major=major)
                    minors.append(minor)
            flash('A category created successfully.', 'success')
        return render_template('major.html', major=major, minors=minors)
    return render_template('major.html')