def festivals(query=None):
    cursor.execute(
        "SELECT * FROM festivals f JOIN PLACES p  ON  f.id_place = p.id_place ORDER BY f.date_start DESC"
    )
    incoming = cursor.fetchall()
    if query:
        incoming = filter_by_query(incoming, query)

    query_form = QueryForm()
    form = FestivalForm()

    cursor.execute("SELECT * FROM places")
    places = cursor.fetchall()
    form.place.choices = BLANK_OPTION + sorted(
        [(place['id_place'], f'{place["city"]} / {place["name"]}')
         for place in places],
        key=lambda x: x[1])

    form.to_edit.choices = Options.EMPTY + sorted(
        [(x['id_festival'], x['festival_name']) for x in incoming],
        key=lambda x: x[1])

    return render_template('festivals.html',
                           incoming=incoming,
                           form=form,
                           query_form=query_form)
Ejemplo n.º 2
0
def musicians(query=None):
    cursor.execute("SELECT * FROM musicians ORDER BY band, name")
    my_musicians = cursor.fetchall()
    if query:
        my_musicians = filter_by_query(my_musicians, query)

    form = MusicianForm()
    query_form = QueryForm()

    cursor.execute("SELECT * FROM bands")
    bands = cursor.fetchall()
    form.band.choices = Options.BLANK + sorted(
        [(band['name'], band['name']) for band in bands], key=lambda x: x[1])

    cursor.execute("SELECT * FROM instruments")
    instruments = cursor.fetchall()
    form.instrument.choices = Options.BLANK + sorted(
        [(instrument['type'], instrument['type'])
         for instrument in instruments],
        key=lambda x: x[1])

    form.to_edit.choices = Options.EMPTY + [(x['name'], x['name'])
                                            for x in my_musicians]

    return render_template('musicians.html',
                           my_musicians=my_musicians,
                           form=form,
                           query_form=query_form)
Ejemplo n.º 3
0
def albums(query=None):
    cursor.execute("SELECT * FROM albums ORDER BY band, name")
    my_albums = cursor.fetchall()
    if query:
        my_albums = filter_by_query(my_albums, query)

    form = AlbumForm()
    query_form = QueryForm()

    cursor.execute("SELECT * FROM bands")
    bands = cursor.fetchall()
    form.band.choices = Options.BLANK + sorted(
        [(band['name'], band['name']) for band in bands], key=lambda x: x[1])

    cursor.execute("SELECT * FROM genres")
    genres = cursor.fetchall()
    form.genre.choices = Options.BLANK + sorted([(genre['name'], genre['name'])
                                                 for genre in genres],
                                                key=lambda x: x[1])

    form.to_edit.choices = Options.EMPTY + sorted(
        [(x['name'], x['name']) for x in my_albums], key=lambda x: x[1])

    return render_template('albums.html',
                           my_albums=my_albums,
                           form=form,
                           query_form=query_form)
Ejemplo n.º 4
0
def appearances(id_festival=None, query=None):

    cursor.execute("SELECT * FROM bands b JOIN appearances a ON b.name = a.band "
                   "WHERE a.id_festival = %s::INTEGER order by b.name", [id_festival])
    my_bands = cursor.fetchall()

    if query:
        my_bands = filter_by_query(my_bands, query)

    form = AppearanceForm()
    query_form = QueryForm()

    cursor.execute("SELECT * FROM bands")
    bands = cursor.fetchall()
    form.band.choices = Options.BLANK + sorted([(band['name'], band['name']) for band in bands], key=lambda x: x[1])

    cursor.execute("SELECT festival_name FROM festivals WHERE id_festival = %s::INTEGER", [id_festival])
    festival = cursor.fetchone()

    return render_template('appearances.html', my_bands=my_bands, query_form=query_form, form=form,
                           id_festival=id_festival, festival_name=festival['festival_name'])
Ejemplo n.º 5
0
def concerts(days=None, query=None):
    days = days or 30
    query = None if query == 'none' else query
    cursor.execute(
        "SELECT * FROM getConcertsByDate(days_number := %s::INTEGER) NATURAL JOIN PLACES "
        "ORDER BY concert_date DESC", (days, ))
    incoming = cursor.fetchall()
    if query:
        incoming = filter_by_query(incoming, query)

    form = ConcertForm()
    query_form = ConcertsQueryForm()

    cursor.execute("SELECT * FROM bands")
    bands = cursor.fetchall()
    form.band.choices = Options.BLANK + sorted(
        [(band['name'], band['name']) for band in bands], key=lambda x: x[1])

    cursor.execute("SELECT * FROM places")
    places = cursor.fetchall()
    form.place.choices = Options.BLANK + sorted(
        [(place['id_place'], f'{place["city"]} / {place["name"]}')
         for place in places],
        key=lambda x: x[1])

    # form.to_edit.choices = Options.EMPTY + sorted([(x['id_concert'], x['id_concert']) for x in incoming], key=lambda x: x[1])
    form.to_edit.choices = Options.EMPTY + sorted(
        [(x['id_concert'],
          f'{x["concert_date"]} / {x["band"]} / {x["name"]} / {x["city"]}')
         for x in incoming],
        key=lambda x: x[1],
        reverse=True)

    return render_template('concerts.html',
                           incoming=incoming,
                           form=form,
                           query_form=query_form)
Ejemplo n.º 6
0
def awards(query=None):
    cursor.execute("SELECT * FROM awards ORDER BY name ASC")
    awards = cursor.fetchall()

    if query:
        awards = filter_by_query(awards, query)

    query_form = QueryForm()
    form = AwardForm()

    form.to_edit.choices = Options.EMPTY + sorted(
        [(x['name'], x['name']) for x in awards], key=lambda x: x[1])

    return render_template('awards.html',
                           awards=awards,
                           form=form,
                           query_form=query_form)
Ejemplo n.º 7
0
def bands(query=None):
    cursor.execute("SELECT * FROM bands ORDER BY name")
    my_bands = cursor.fetchall()

    if query:
        my_bands = filter_by_query(my_bands, query)

    query_form = QueryForm()
    form = BandForm()

    form.to_edit.choices = Options.EMPTY + [(x['name'], x['name'])
                                            for x in my_bands]

    return render_template('bands.html',
                           my_bands=my_bands,
                           form=form,
                           query_form=query_form)
def instruments(query=None):
    cursor.execute("SELECT * FROM INSTRUMENTS ORDER BY TYPE ASC")
    instruments = cursor.fetchall()

    if query:
        instruments = filter_by_query(instruments, query)

    query_form = QueryForm()
    form = InstrumentForm()

    form.to_edit.choices = Options.EMPTY + sorted(
        [(x['type'], x['type']) for x in instruments], key=lambda x: x[1])

    return render_template('instruments.html',
                           instruments=instruments,
                           form=form,
                           query_form=query_form)
Ejemplo n.º 9
0
def places(query=None):
    cursor.execute("SELECT * FROM PLACES ORDER BY CITY ASC, NAME ASC")
    places = cursor.fetchall()

    if query:
        places = filter_by_query(places, query)

    query_form = QueryForm()
    form = PlaceForm()

    form.to_edit.choices = Options.EMPTY + sorted(
        [(x['id_place'], f'{x["name"]}/{x["city"]}') for x in places],
        key=lambda x: x[1])

    return render_template('places.html',
                           places=places,
                           form=form,
                           query_form=query_form)
Ejemplo n.º 10
0
def genres(query=None):
    cursor.execute("SELECT * FROM genres ORDER BY name ASC")
    genres = cursor.fetchall()

    if query:
        genres = filter_by_query(genres, query)

    query_form = QueryForm()
    form = GenreForm()

    form.supergenre.choices = Options.BLANK + sorted(
        [(x['name'], x['name']) for x in genres], key=lambda x: x[1])
    form.to_edit.choices = Options.EMPTY + sorted(
        [(x['name'], x['name']) for x in genres], key=lambda x: x[1])

    return render_template('genres.html',
                           genres=genres,
                           form=form,
                           query_form=query_form)
Ejemplo n.º 11
0
def songs(id_album):
    cursor.execute(
        "SELECT * FROM songs WHERE id_album = %s::INTEGER order by position",
        [id_album])
    my_songs = cursor.fetchall()

    cursor.execute(
        "SELECT name, band FROM albums WHERE id_album = %s::INTEGER",
        [id_album])
    album_info = cursor.fetchone()

    form = SongForm()

    form.to_edit.choices = Options.EMPTY + sorted(
        [(x['name'], x['position']) for x in my_songs], key=lambda x: x[1])

    return render_template('songs.html',
                           my_songs=my_songs,
                           id_album=id_album,
                           album_name=album_info['name'],
                           band=album_info['band'],
                           form=form)