def comment(obsid): if not logged_in(False): return redirect('/login') check_csfr(request.form["csrf_token"]) # -- REQUEST VALUES -- # comment : string create_comment(obsid, request.form['comment']) return redirect(f'/observations/{obsid}')
def new_observation(): if not logged_in(False): return redirect('/login') if request.method == 'POST': # -- REQUEST VALUES -- # bird : string # location : string # date : string (yyyy-mm-dd) # count-option : string ('one'/'many') # count : string/None # banded-option : string ('true'/'false'/'not_known') # band-serial : string/None # uploadImage : file/None (.apng/.avif/.gif/.jpg/.jpeg/.jfif/.pjpeg/.pjp/.png/.svg/.webp) check_csfr(request.form["csrf_token"]) observation_id = create_observation(request.form) if not observation_id: return redirect('/new-observation') if request.files['uploadImage']: create_image(observation_id, request.files) return redirect(f'/observations/{observation_id}') # ----- GET /new-observation ----- birds = get_birds() locations = get_locations() return render_template('new_observation.html', title='Uusi havainto', birdpattern=birds[1], birds=birds[0], locationpattern=locations[1], locations=locations[0], today=datetime.now().strftime('%Y-%m-%d'))
def edit(obsid): if not authorized_obs(obsid): return redirect('/login') if request.method == 'POST': # -- REQUEST VALUES -- # deleteImg : text ("true"/"false") # uploadImage : file/empty (.apng/.avif/.gif/.jpg/.jpeg/.jfif/.pjpeg/.pjp/.png/.svg/.webp) # date : date # location : text # count : number (1-1000) # (band-serial : text) check_csfr(request.form["csrf_token"]) if request.form['deleteImg'] == 'true': delete_image(obsid) if request.files['uploadImage']: delete_image(obsid) create_image(obsid, request.files) update_observation(obsid, request.form) return redirect(f'/observations/{obsid}') observation = get_observation(obsid) observation['date'] = observation['date'].strftime('%Y-%m-%d') locations = get_locations() return render_template('edit.html', title='Lintuloki - Muokkaa', observation=observation, locationpattern=locations[1], locations=locations[0], comments=get_comments(obsid), today=datetime.now().strftime('%Y-%m-%d'))
def delete_c(): check_csfr(request.form["csrf_token"]) comment_id = request.form['comment'] if authorized_comment(comment_id): delete_comment(comment_id) return redirect(f'/observations/{request.form["obsid"]}')
def delete_o(): check_csfr(request.form["csrf_token"]) obsid = request.form['obsid'] if authorized_obs(obsid): delete_observation(obsid) return redirect('/observations/page/1')