def index(bandsform=None, newbandsform=None): bands = Band.query.filter_by(user_id=current_user.id).all() if not bandsform: bandsform = EditForm(BAND_STATES['approved']) bandsform.fill_area( [b for b in bands if b.state == BAND_STATES['approved']]) if not newbandsform: newbandsform = EditForm(BAND_STATES['queued']) newbandsform.fill_area( [b for b in bands if b.state == BAND_STATES['queued']]) playform = PlayForm() played_bands = PlayedBand.query.filter_by( user_id=current_user.id).order_by( PlayedBand.date.desc()).limit(10).all() played_tags = { t.tags for t in PlayedTags.query.filter_by(user_id=current_user.id).order_by( PlayedTags.date.desc()).limit(10).all() } return render_template('dashboard.jinja2', title='Oblibands', template='dashboard-template', current_user=current_user, playform=playform, bandsform=bandsform, newbandsform=newbandsform, played_bands=played_bands, played_tags=played_tags)
def queue(): newbandsform = EditForm(BAND_STATES['queued']) if newbandsform.validate_on_submit(): try: edited_bands = newbandsform.parse_bands(current_user) edited_bands = [db.session.merge(band) for band in edited_bands] to_delete_bands = [ b for b in current_user.bands if b.state == BAND_STATES['queued'] and b not in edited_bands ] for b in to_delete_bands: db.session.delete(b) db.session.commit() newbandsform.fill_area(edited_bands) except: flash('Cannot save, respect the input format!') else: raise Exception('Should not happend') return index(newbandsform=newbandsform)