Ejemplo n.º 1
0
def new_mural():
    new_mural_form = NewMural()
    artists = firebase.get('/', 'artists')
    if artists is None:
        flash("Must first create an artist")
        return redirect(url_for('all_murals'), code=302)
    sorted_artists = []
    for a in artists:
        sorted_artists.append((artists[a]["uuid"], artists[a]["name"]))
        sorted_artists = sorted(sorted_artists, key=lambda x: x[1])
        new_mural_form.artist.choices = sorted_artists
    if new_mural_form.validate_on_submit():
        uuid_token = uuid.uuid4()

        # the new mural's index = 1 + the number of existing murals
        murals = firebase.get('/', 'murals')
        index = 1 + len(murals or [])

        put_data = {'Photo': new_mural_form.photo.data, 'Lat': new_mural_form.lat.data,
                    'Long': new_mural_form.longitude.data, 'Artist': new_mural_form.artist.data,
                    'Title': new_mural_form.title.data, 'Month': new_mural_form.month.data,
                    'Year': new_mural_form.year.data, 'Description': new_mural_form.description.data,
                    'Medium': new_mural_form.medium.data, 'uuid': str(uuid_token),
                    'Index': index}
        firebase.put('/murals', uuid_token, put_data)
        return redirect(url_for('all_murals'), code=302)
    return render_template('new_mural.html', form=new_mural_form)
Ejemplo n.º 2
0
def all_murals():
    artists = firebase.get('/', 'artists') or []
    murals = firebase.get('/', 'murals') or []

    sorted_keys = sorted(murals, key=lambda mural: murals[mural]["Index"])
    sorted_murals = []
    for m in sorted_keys:
        sorted_murals.append(murals[m])

    return render_template('disp_all_murals.html', artists=artists, murals=sorted_murals)
Ejemplo n.º 3
0
def delete_artist():
    artist = str(request.form["artistid"])

    # Don't delete an artist if they have any murals
    murals = firebase.get('/', 'murals')
    for key in murals:
        if murals[key]["Artist"] == artist:
            flash("Cannot delete an artist with existing murals!")
            return redirect(url_for('all_artists'), code=302)

    firebase.delete('/artists', artist)
    return redirect(url_for('all_artists'), code=302)
Ejemplo n.º 4
0
def edit_mural():
    edit_form = EditMural()
    mural_id = str(request.args["muralid"])
    murals = firebase.get('/', 'murals')
    mural = murals[mural_id]
    artists = firebase.get('/', 'artists')
    sorted_artists = []
    for a in artists:
        sorted_artists.append((artists[a]["uuid"], artists[a]["name"]))
    sorted_artists = sorted(sorted_artists, key=lambda x: x[1])
    edit_form.artist.choices = sorted_artists
    if edit_form.validate_on_submit():
        put_data = {'Photo': edit_form.photo.data, 'Lat': edit_form.lat.data,
                   'Long': edit_form.longitude.data, 'Artist': edit_form.artist.data,
                   'Title': edit_form.title.data, 'Month': edit_form.month.data,
                   'Year': edit_form.year.data, 'Description': edit_form.description.data,
                   'Medium': edit_form.medium.data, 'uuid': str(mural_id),
                   'Index': mural["Index"]}
        firebase.delete('/murals', str(mural_id))
        firebase.put('/murals', mural_id, put_data)
        return redirect(url_for('all_murals'), code=302)
    return render_template('edit_mural.html', form=edit_form, mural=mural, murals=murals, muralid=mural_id)
Ejemplo n.º 5
0
def edit_artist():
    form = EditArtist()
    artist_id = str(request.args["artists"])
    artists = firebase.get('/', 'artists')
    artist = artists[artist_id]
    if form.validate_on_submit():
        put_data = {'name': form.name.data,
                    'city': form.city.data,
                    'bio': form.bio.data,
                    'link': form.link.data,
                    'uuid': str(artist_id)}
        firebase.delete('/artists', str(artist_id))
        firebase.put('/artists', artist_id, put_data)
        return redirect(url_for('all_artists'), code=302)
    return render_template('edit_artist.html', form=form, artist=artist)
Ejemplo n.º 6
0
def change_mural_index():
    mural_id = str(request.form["muralid"])
    up_or_down = str(request.form["upOrDown"])
    murals = firebase.get('/', 'murals')

    # from_mural is the mural corresponding to the muralid
    # to_mural is the mural with the Index that from_mural's Index should be changed to
    from_mural = None
    to_mural = None

    for m in murals:
        if m == mural_id:
            from_mural = murals[m]

    # If the muralID turns out to not be valid
    if from_mural is None:
        return redirect(url_for('all_murals'), code=302)

    from_mural_index = from_mural["Index"]

    to_mural_index = 0
    if up_or_down == "UP":
        to_mural_index = from_mural_index - 1
    elif up_or_down == "DOWN":
        to_mural_index = from_mural_index + 1

    for m in murals:
        if murals[m]["Index"] == to_mural_index:
            to_mural = murals[m]

    # Handles when you want to move to an invalid index
    if to_mural is None:
        return redirect(url_for('all_murals'), code=302)

    from_mural["Index"] = to_mural_index
    to_mural["Index"] = from_mural_index

    # update firebase
    firebase.put('/murals', from_mural["uuid"], from_mural)
    firebase.put('/murals', to_mural["uuid"], to_mural)

    return redirect(url_for('all_murals'), code=302)
Ejemplo n.º 7
0
def delete_mural():
    # reindex all the murals
    murals = firebase.get('/', 'murals')
    key = str(request.form["muralid"])
    removed_index = murals[key]["Index"]

    # if a mural's index is > removed_index, decrement the index
    for m in murals:
        if murals[m]["Index"] > removed_index:
            murals[m]["Index"] -= 1

    # remove the mural
    if key in murals: del murals[key]

    # update firebase
    firebase.delete('/murals', key)
    for id in murals:
        firebase.put('/murals', id, murals[id])

    return redirect(url_for('all_murals'), code=302)
Ejemplo n.º 8
0
    data = json.dumps({
        "email": email,
        "password": password,
        "returnSecureToken": True
    })
    request_object = requests.post(request_ref, headers=headers, data=data)
    current_user = request_object.json()
    try:
        reg = current_user["registered"]
        access_token = current_user["idToken"]
        print current_user

        print "Hello again"
    except KeyError:
        print "KeyError"


print "enter email"
email = raw_input().strip()
print "enter pass"
password = raw_input().strip()

sign_in_with_email_and_password(email, password)
print access_token

firebase.authentication = access_token

# With a janky auth token, this call will be a 401
# With a real auth token, this will actually return murals
print firebase.get('/', 'murals')
Ejemplo n.º 9
0
def all_artists():
    artists = firebase.get('/', 'artists') or []
    return render_template('disp_all_artists.html', artists=artists)