"""Handler utility functions.""" from analytics.models import streams as streams_model def parse_date_values(request_args): """Return the date values from the request query string.""" start_date = request_args.get('from_date') end_date = request_args.get('to_date') return start_date, end_date def parse_artist_store_and_isrc_values(request_args, default_store_ids=None): """Return the artist_ids, store_ids and isrcs from request query string.""" # TODO remove the default_store_id logic once the calls to this endpoint # TODO always contain one or multiple storeids artist_ids = request_args.get('artist_ids') if artist_ids: artist_ids = artist_ids.split(',') isrcs = request_args.get('isrcs') if isrcs: isrcs = isrcs.split(',') if request_args.get('stores', '') == '': if not default_store_ids: store_ids = streams_model.Store.get_available_stores() else: store_ids = default_store_ids else: store_ids = request_args.get('stores').split(',') return artist_ids, store_ids, isrcs