def mark_positive(customer_id): """Through this method the health authority can set the health status of a specific user to "positive". Args: customer_id ([int]): univocal id of the user Returns: Redirects the view to the health authority's home page """ if current_user is not None and current_user.type == 'authority': if request.method == 'POST': customer = CustomerManager.retrieve_by_id(id_=customer_id) if customer is not None and customer.health_status: flash("Customer is already set to positive!") elif customer is not None: customer.set_health_status(status=True) CustomerManager.update_customer(customer.id) schedule_revert_customer_health_status(customer.id) notify_restaurant_owners_about_positive_past_customer( customer.id) notify_restaurant_owners_about_positive_booked_customer( customer.id) notify_customers_about_positive_contact(customer.id) flash("Customer set to positive!") return redirect( url_for('auth.authority', id=current_user.id, positive_id=0))
def revert_customer_health_status(customer_id): customer = CustomerManager.retrieve_by_id(customer_id) if customer: customer.set_health_status(False) CustomerManager.update_customer(customer=customer) return else: raise ValueError('Customer does not exist anymore')
def contact_tracing(contact_id): """This method allows the health authority to retrieve the list of contacts, given a positive user Args: contact_id (id): univocal id of the user Returns: Redirects the view to the health authority's home page """ if current_user is not None and current_user.type == 'authority': customer = CustomerManager.retrieve_by_id(id_=contact_id) if customer is not None: pos_reservations = ReservationManager.retrieve_by_customer_id( user_id=customer.id) cust_contacts = [] restaurant_contacts = [] date_contacts = [] for res in pos_reservations: contacts = ReservationManager.retrieve_all_contact_reservation_by_id( res.id) for c in contacts: cust = CustomerManager.retrieve_by_id(c.user_id) cust_contacts.append(cust) restaurant_contacts.append( RestaurantManager.retrieve_by_id(c.restaurant_id).name) date_contacts.append(c.start_time.date()) return render_template('contact_tracing_positive.html', customer=customer, pos_contact=cust_contacts, res_contact=restaurant_contacts, date_contact=date_contacts) else: return redirect( url_for('auth.authority', id=current_user.id, positive_id=0)) else: return redirect(url_for('home.index'))
def my_profile(): """This method allows the customer to see its personal page Returns: Redirects the view to personal page of the customer """ reservations = ReservationManager.retrieve_by_customer_id(current_user.id) form = ReservationForm() social_form = AddSocialNumberForm() customer = CustomerManager.retrieve_by_id(current_user.id) restaurants = RestaurantManager.retrieve_all() return render_template('customer_profile.html', customer=customer, reservations=reservations, restaurants=restaurants, form=form, social_form=social_form)
def reservation_details(restaurant_id, reservation_id): """ Given a restaurant, this method returns all its reservations Args: restaurant_id (int): univocal identifier of the restaurant reservation_id (int): univocal identifier of the reservations Returns: [type]: [description] """ reservation = ReservationManager.retrieve_by_id(reservation_id) user = CustomerManager.retrieve_by_id(reservation.user.id) table = reservation.table restaurant = reservation.restaurant return render_template("reservation_details.html", reservation=reservation, user=user, table=table, restaurant=restaurant)
def authority(id, positive_id): """This method allows the Health Authority to see its personal page. Args: id (int): the univocal identifier for the Health Authority positive_id (int): the identifier of the positive user Returns: Redirects to the page of the Health Authority """ if current_user.id == id: authority = AuthorityManager.retrieve_by_id(id) ha_form = AuthorityForm() pos_customers = CustomerManager.retrieve_all_positive() search_customer = CustomerManager.retrieve_by_id(positive_id) return render_template('authority_profile.html', current_user=authority, form=ha_form, pos_customers=pos_customers, search_customer=search_customer) return redirect(url_for('home.index'))
def profile(id): """This method allows the customer to see its personal page Args: id (int): univocal identifier of the customer Returns: Redirects the view to personal page of the customer """ if current_user.id == id: reservations = ReservationManager.retrieve_by_customer_id(id) form = ReservationForm() social_form = AddSocialNumberForm() customer = CustomerManager.retrieve_by_id(id) restaurants = RestaurantManager.retrieve_all() return render_template('customer_profile.html', customer=customer, reservations=reservations, restaurants=restaurants, form=form, social_form=social_form) return redirect(url_for('home.index'))
def mark_customer(id): customer = CustomerManager.retrieve_by_id(id) customer.set_health_status(status=True) CustomerManager.update_customer(customer.id) return 200