def poll_results(poll_id): if 'user_id' not in session: flash('Virhe! Kirjaudu ensin sisään') return redirect(url_for('login')) current_poll = poll.process_get_poll(poll_id) if current_poll is None: flash( 'Virhe! Kyselyä ei löytynyt tai käyttäjällä ei ole oikeuksia kyselyyn' ) return redirect(url_for('index')) user_id = session.get('user_id') is_owner = (current_poll.owner_user_id == user_id) results = [] if current_poll.phase == 2: if is_owner: results = optimization.get_owner_optimization_results(poll_id) else: results = optimization.get_normal_user_optimization_results( poll_id) return render_template('poll_results.html', is_owner=is_owner, optimization_results=results, poll=current_poll)
def poll_times(poll_id, member_id): if 'user_id' not in session: flash('Virhe! Kirjaudu ensin sisään') return redirect(url_for('login')) current_poll = poll.process_get_poll(poll_id) if current_poll is None: flash( 'Virhe! Kyselyä ei löytynyt tai käyttäjällä ei ole oikeuksia kyselyyn' ) return redirect(url_for('index')) user_id = session.get('user_id') is_owner = (current_poll.owner_user_id == user_id) if not (is_owner or member.user_has_access(user_id, member_id)): flash('Virhe! Ei oikeuksia muokata aikoja') return redirect(url_for('route_poll', poll_id=poll_id)) member_details = member.get_member_details(member_id) if member_details.poll_id != current_poll.id: flash('Virhe! Jäsen ei kuulu kyselyyn. Tarkista url.') return redirect(url_for('route_poll', poll_id=poll_id)) member_times = times.get_minute_grades(member_id, poll_id) if member_details.type == 'resource': grade_descriptions = ['Ei käytettävissä', 'Käytettävissä'] else: grade_descriptions = ['Ei sovi', 'Sopii tarvittaessa', 'Sopii hyvin'] view_only = 0 if current_poll.phase >= 1 and not is_owner: view_only = 1 if current_poll.phase == 2: view_only = 1 return render_template( 'poll_times.html', is_owner=is_owner, poll=current_poll, member_id=member_id, time_grades=member_times, grade_descriptions=grade_descriptions, member_type=member_details.type, member_name=member_details.name, reservation_length=member_details.reservation_length, selected_day=request.args.get('selected_day', 0), view_only=view_only)
def poll_optimization(poll_id): if 'user_id' not in session: flash('Virhe! Kirjaudu ensin sisään') return redirect(url_for('login')) # note that we already know that poll_id is an integer current_poll = poll.process_get_poll(poll_id) user_id = session.get('user_id') if (current_poll is None) or (current_poll.owner_user_id != user_id): flash('Virhe! Ei oikeuksia katsoa kyselyn omistajan näkymää') return redirect(url_for('route_poll', poll_id=poll_id)) optimization_results = optimization.get_owner_optimization_results(poll_id) return render_template('poll_optimization.html', is_owner=True, poll=current_poll, optimization_results=optimization_results)
def poll_customers(poll_id): if 'user_id' not in session: flash('Virhe! Kirjaudu ensin sisään') return redirect(url_for('login')) # note that we already know that poll_id is an integer current_poll = poll.process_get_poll(poll_id) user_id = session.get('user_id') if (current_poll is None) or (current_poll.owner_user_id != user_id): flash('Virhe! Ei oikeuksia katsoa kyselyn omistajan näkymää') return redirect(url_for('route_poll', poll_id=poll_id)) new_customer_links = poll.get_new_customer_links(poll_id) customer_access_links = poll.get_customer_access_links(poll_id) customers = poll.get_poll_customers(poll_id) return render_template('poll_customers.html', is_owner=True, poll=current_poll, new_customer_links=new_customer_links, customer_access_links=customer_access_links, customers=customers)
def route_poll(poll_id): if 'user_id' not in session: flash('Virhe! Kirjaudu ensin sisään') return redirect(url_for('login')) # note that we already know that poll_id is an integer current_poll = poll.process_get_poll(poll_id) if current_poll is None: message = 'Kyselyä ei löytynyt tai käyttäjällä ei ole oikeuksia kyselyyn' flash('Virhe! ' + message) return redirect(url_for('index')) user_id = session.get('user_id') is_owner = (current_poll.owner_user_id == user_id) user_customers = poll.get_user_poll_customers(user_id, poll_id) user_resources = poll.get_user_poll_resources(user_id, poll_id) return render_template('poll.html', is_owner=is_owner, poll=current_poll, user_customers=user_customers, user_resources=user_resources)