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 check_customer_health_status(): logger.info('Executing the task <customer_healthcheck>') positive_users = CustomerManager.retrieve_all_positive() if positive_users is None: # skip computation return for positive_user in positive_users: time_delta = datetime.datetime.utcnow( ) - positive_user.health_status_change_datetime if time_delta >= timedelta(days=14): # unmarking positive_user.set_health_status(False) CustomerManager.update_customer(customer=positive_user) logger.info('Task <customer_healthcheck> finished')
def mark_customer(id): customer = CustomerManager.retrieve_by_id(id) customer.set_health_status(status=True) CustomerManager.update_customer(customer.id) return 200