def get_all_topics(): include_appointments = app.config['FEATURE_FLAG_ADVISOR_APPOINTMENTS'] include_deleted = to_bool_or_none(request.args.get('includeDeleted')) if include_appointments: topics = Topic.get_all(include_deleted=include_deleted) else: topics = Topic.get_all(available_in_notes=True, include_deleted=include_deleted) if not app.config['FEATURE_FLAG_ADVISOR_APPOINTMENTS']: for index, topic in enumerate(topics): if not topic.available_in_notes: topics.pop(index) return tolerant_jsonify(_to_api_json(topics))
def test_get_topic_usage_statistics(self, client, fake_auth): """Admin user can update a topic.""" fake_auth.login(admin_uid) api_json = self._api_usage_statistics(client) assert list(api_json.keys()) == ['appointments', 'notes'] assert len(api_json['appointments']) # Verify counts admin_user_id = AuthorizedUser.get_id_per_uid(uid=admin_uid) all_appointments = Appointment.query.filter(Appointment.deleted_at == None).all() # noqa: E711 all_appointments = [a.to_api_json(current_user_id=admin_user_id) for a in all_appointments] for topic_id, count in api_json['appointments'].items(): topic = Topic.find_by_id(topic_id) matches = list(filter(lambda a: topic.topic in a['topics'], all_appointments)) assert len(matches) == count
def create_topic(): params = request.json topic = params.get('topic', '').strip() available_in_notes = to_bool_or_none( params.get('availableInNotes')) or False available_in_appointments = to_bool_or_none( params.get('availableInAppointments')) or False if not topic or not (available_in_notes or available_in_appointments): raise BadRequestError('Required parameters are missing.') topic = Topic.create_topic( topic, available_in_notes=available_in_notes, available_in_appointments=available_in_appointments, ) return tolerant_jsonify(topic.to_api_json())
def get_topics_for_notes(): include_deleted = to_bool_or_none(request.args.get('includeDeleted')) topics = Topic.get_all(available_in_notes=True, include_deleted=include_deleted) return tolerant_jsonify(_to_sorted_json(topics))
def get_all_topics(): include_deleted = to_bool_or_none(request.args.get('includeDeleted')) topics = Topic.get_all(include_deleted=include_deleted) return tolerant_jsonify(_to_sorted_json(topics))
def usage_statistics(): return tolerant_jsonify(Topic.get_usage_statistics())
def undelete_topic(): params = request.json topic_id = params.get('id') Topic.undelete(topic_id=topic_id) return tolerant_jsonify(Topic.find_by_id(topic_id).to_api_json())
def delete_topic(topic_id): Topic.delete(topic_id=topic_id) return tolerant_jsonify({'message': f'Topic {topic_id} deleted'}), 200
def get_topics(): include_deleted = to_bool_or_none(request.args.get('includeDeleted')) topics = Topic.get_all(include_deleted=include_deleted) return tolerant_jsonify([topic.to_api_json() for topic in topics])
def _create_topics(): Topic.create_topic( 'Other / Reason not listed', available_in_notes=True, available_in_appointments=True, ) for index in range(10): true_for_both = index in [1, 5, 7] available_in_appointments = true_for_both or index % 2 == 0 available_in_notes = true_for_both or index % 3 == 0 if true_for_both: topic = f'Topic for all, {index}' elif available_in_appointments: topic = f'Topic for appointments, {index}' else: topic = f'Topic for notes, {index}' Topic.create_topic( topic=topic, available_in_appointments=available_in_appointments, available_in_notes=available_in_notes, ) Topic.delete( Topic.create_topic('Topic for all, deleted', available_in_appointments=True).id) Topic.delete( Topic.create_topic('Topic for appointments, deleted', available_in_appointments=True).id) Topic.delete( Topic.create_topic('Topic for notes, deleted', available_in_notes=True).id) std_commit(allow_test_environment=True)
def create_advising_note_topics(): for i in range(5): Topic.create_topic(f'Topic {i}') delete_me = Topic.create_topic('I am a deleted topic') Topic.delete(delete_me.id) std_commit(allow_test_environment=True)