def should_create_new_export(xform, export_type, options, request=None): """ Function that determines whether to create a new export. param: xform param: export_type param: options: additional parameters required for the lookup. remove_group_name: boolean flag group_delimiter: "/" or "." with "/" as the default split_select_multiples: boolean flag binary_select_multiples: boolean flag index_tag: ('[', ']') or ('_', '_') params: request: Get params are used to determine if new export is required """ split_select_multiples = options.get('split_select_multiples', True) if getattr(settings, 'SHOULD_ALWAYS_CREATE_NEW_EXPORT', False): return True if (request and (frozenset(list(request.GET)) & frozenset(['start', 'end', 'data_id']))) or\ not split_select_multiples: return True export_options_kwargs = get_export_options_query_kwargs(options) export_query = Export.objects.filter(xform=xform, export_type=export_type, **export_options_kwargs) if options.get(EXPORT_QUERY_KEY) is None: export_query = export_query.exclude(options__has_key=EXPORT_QUERY_KEY) if export_query.count() == 0 or\ Export.exports_outdated(xform, export_type, options=options): return True return False
def newest_export_for(xform, export_type, options): """ Retrieve the latest export given the following arguments: param: xform param: export_type param: options: additional parameters required for the lookup. remove_group_name: boolean flag group_delimiter: "/" or "." with "/" as the default split_select_multiples: boolean flag binary_select_multiples: boolean flag """ export_options_kwargs = get_export_options_query_kwargs(options) export_query = Export.objects.filter(xform=xform, export_type=export_type, **export_options_kwargs) return export_query.latest('created_on')
def should_create_new_export(xform, export_type, options, request=None): """ Function that determines whether to create a new export. param: xform param: export_type param: options: additional parameters required for the lookup. remove_group_name: boolean flag group_delimiter: "/" or "." with "/" as the default split_select_multiples: boolean flag binary_select_multiples: boolean flag index_tag: ('[', ']') or ('_', '_') params: request: Get params are used to determine if new export is required """ split_select_multiples = options.get('split_select_multiples', True) if getattr(settings, 'SHOULD_ALWAYS_CREATE_NEW_EXPORT', False): return True if (request and (frozenset(list(request.GET)) & frozenset(['start', 'end', 'data_id']))) or\ not split_select_multiples: return True export_options_kwargs = get_export_options_query_kwargs(options) export_query = Export.objects.filter( xform=xform, export_type=export_type, **export_options_kwargs ) if options.get(EXPORT_QUERY_KEY) is None: export_query = export_query.exclude(options__has_key=EXPORT_QUERY_KEY) if export_query.count() == 0 or\ Export.exports_outdated(xform, export_type, options=options): return True return False
def check_pending_export(xform, export_type, options, minutes=getattr(settings, 'PENDING_EXPORT_TIME', 5)): """ Check for pending export done within a specific period of time and returns the export :param xform: :param export_type: :param options: :param minutes :return: """ created_time = timezone.now() - timedelta(minutes=minutes) export_options_kwargs = get_export_options_query_kwargs(options) export = Export.objects.filter(xform=xform, export_type=export_type, internal_status=Export.PENDING, created_on__gt=created_time, **export_options_kwargs).last() return export
def newest_export_for(xform, export_type, options): """ Retrieve the latest export given the following arguments: param: xform param: export_type param: options: additional parameters required for the lookup. remove_group_name: boolean flag group_delimiter: "/" or "." with "/" as the default split_select_multiples: boolean flag binary_select_multiples: boolean flag index_tag: ('[', ']') or ('_', '_') """ export_options_kwargs = get_export_options_query_kwargs(options) export_query = Export.objects.filter( xform=xform, export_type=export_type, **export_options_kwargs ) return export_query.latest('created_on')
def check_pending_export(xform, export_type, options, minutes=getattr(settings, 'PENDING_EXPORT_TIME', 5)): """ Check for pending export done within a specific period of time and returns the export :param xform: :param export_type: :param options: :param minutes :return: """ created_time = timezone.now() - timedelta(minutes=minutes) export_options_kwargs = get_export_options_query_kwargs(options) export = Export.objects.filter( xform=xform, export_type=export_type, internal_status=Export.PENDING, created_on__gt=created_time, **export_options_kwargs ).last() return export