Exemple #1
0
def quarantined_report(request):
    qobjects = QuarantinedReportData.objects.all()

    response_data = {}
    response_data['list'] = qobjects
    
    return create_response(response_data)
Exemple #2
0
def report_form_rhics(request):
    """
    Update the rhic select box based on the selection of the contract

    @param request: http
    """

    _LOG.info("report_form_rhics called by method: %s" % (request.method))

    if request.method == 'POST':
        form = ProductUsageForm(request.POST)
        if form.is_valid():
            pass
        else:
            form = ProductUsageForm()

    user = str(request.user)
    account = Account.objects.filter(login=user)[0].account_id
    if request.POST['contract_number'] == "All":
        list_of_rhics = list(RHIC.objects.filter(account_id=account))    
    else:
        contract_number = json.loads(request.POST['contract_number'])
        list_of_rhics = list(RHIC.objects.filter(contract=str(contract_number)))

    response_data = {}
    response_data['list_of_rhics'] = [(str(r.uuid), r.name)
                                      for r in list_of_rhics]

    _LOG.info(response_data)

    return create_response(response_data)
Exemple #3
0
def default_report(request):
    
    _LOG.info("default_report called by method: %s" % (request.method))

    user = str(request.user)
    account = Account.objects.filter(login=user)[0].account_id
    data = data_from_post(request)
    start, end = get_dates_from_request(request)
    environment = data['env']
    list_of_rhics = []
    
    list_of_rhics = list(RHIC.objects.filter(account_id=account))
    args = {'start': start,
            'end': end,
            'list_of_rhics': list_of_rhics,
            'environment': environment,
            'return_failed_only': True
            }
    usuage_compliance = hours_per_consumer(**args)
    
    fact_compliance = system_fact_compliance_list(account)

    format = constants.full_format
    response_data = {}
    response_data['list'] = usuage_compliance
    response_data['biz_list'] = fact_compliance
    response_data['account'] = account
    response_data['start'] = start.strftime(format)
    response_data['end'] = end.strftime(format)

    return create_response(response_data)
Exemple #4
0
    def post_list(self, request, **kwargs):
        _LOG.info("FilterResource::post() ")
        user = str(request.user)
        start, end = utils.get_dates_from_request(request)
        data = utils.data_from_post(request)

        start = "%s/%s/%s" % (start.month, start.day, start.year)
        end = "%s/%s/%s" % (end.month, end.day, end.year)
        filter_name = data["filter_name"]
        filter_description = data["filter_description"]
        if "org" in data:
            environment = data["org"]
        else:
            environment = "All"

        status = data["status"]

        filter = Filter(
            filter_name=filter_name,
            filter_description=filter_description,
            owner=user,
            status=status,
            environment=environment,
            start_date=start,
            end_date=end,
        )
        filter.save()

        user_filters = Filter.objects.filter(owner=str(request.user))
        response_data = {}
        response_data["filters"] = user_filters

        return utils.create_response(response_data)
Exemple #5
0
def report(request):
    
    _LOG.info("report called by method: %s" % (request.method))
    user = str(request.user)
       
    start, end = get_dates_from_request(request)
    data = data_from_post(request)
    
    if 'env' in data:
        environment = data["env"]
    else:
        environment = "All"

    status = data["status"]
    results = []
    _LOG.info("status =" + status)
    if status == "All":
        results  = MarketingReportData.objects.filter(date__gt=start, date__lt=end)
        #r  = MarketingReportData.objects.all()
    elif status == "valid":
        results = MarketingReportData.objects.filter(status='valid', date__gt=start, date__lt=end)
    elif status == "invalid":
        results = MarketingReportData.objects.filter(status='invalid', date__gt=start, date__lt=end)
    elif status == "partial":
        results = MarketingReportData.objects.filter(status='partial', date__gt=start, date__lt=end)
    elif status == "Failed":
        invalid = MarketingReportData.objects.filter(status='invalid', date__gt=start, date__lt=end)
        partial = MarketingReportData.objects.filter(status='partial', date__gt=start, date__lt=end)
        if invalid:
            results.append(invalid[0])
        if partial:
            results.append(partial[0])

    if results:
        _LOG.info(len(results))

    num_valid = MarketingReportData.objects.filter(status='valid', date__gt=start, date__lt=end).count()
    num_invalid = MarketingReportData.objects.filter(status='invalid', date__gt=start, date__lt=end).count()
    num_partial = MarketingReportData.objects.filter(status='partial', date__gt=start, date__lt=end).count()
    
    format = constants.full_format


    response_data = {}
    
    if 'page' in request.GET:
        page = request.GET.get('page')

    else:
        response_data['list'] = results

    
    response_data['start'] = start.strftime(format)
    response_data['end'] = end.strftime(format)
    response_data['num_valid'] = str(num_valid)
    response_data['num_invalid'] = str(num_invalid)
    response_data['num_partial'] = str(num_partial)

    return create_response(response_data)
Exemple #6
0
def max_report(request):
    data = utils.data_from_post(request);

    response_data = MaxUsage.get_MDU_MCU(**data)
    
    response_data['start'] = data['start'] 
    response_data['end'] = data["end"]
    response_data['description'] = data["description"]
    response_data['filter_args'] = data["filter_args_dict"]
    
    return create_response(response_data)
Exemple #7
0
def system_fact_compliance(request):
    """
    Search through ReportData.objects and find any objects that do not meet the
    criteria in the business rules as defined in 
    """
    user = str(request.user)
    account = Account.objects.filter(login=user)[0].account_id    
    response_data = {}
    response_data['list'] = system_fact_compliance_list(account)
    
    return create_response(response_data)
Exemple #8
0
def subscription_detail(request):
    data = utils.data_from_post(request)
    product_id = data["product_id"]
    result = Pool.objects.filter(product_id=product_id)[0]
    provided_products = json.dumps(result['provided_products'])
    product_attributes = json.dumps(result['product_attributes'])
    response_data = {}
    response_data['pool_detail'] = result
    response_data['provided_products'] = provided_products
    response_data['product_attributes'] = product_attributes
    

    return create_response(response_data)
Exemple #9
0
def create_export_report(request):
    _LOG.info("report called by method: %s" % (request.method))

    user = str(request.user)
    account = Account.objects.filter(login=user)[0].account_id
    start, end = get_dates_from_request(request)
    
    if 'env' in request.GET:
        environment = request.GET['env']
    else:
        environment = "All"
        
    rhic = request.GET['rhic']
    contract = request.GET['contract_number']    
    list_of_rhics = []
    
    if contract == 'All' and (rhic == 'All' or rhic == 'null'):
        list_of_rhics = list(RHIC.objects.filter(account_id=account))
        results = hours_per_consumer(start,
                                     end, 
                                     list_of_rhics=list_of_rhics,
                                     environment=environment)

    elif rhic != 'null':
        if rhic == "All":
            list_of_rhics = list(RHIC.objects.filter(contract=contract))
        else:
            my_uuid = rhic
            list_of_rhics = list(RHIC.objects.filter(uuid=my_uuid))
        results = hours_per_consumer(start,
                                     end,
                                     list_of_rhics,
                                     environment=environment)

    else:
        list_of_rhics = list(RHIC.objects.filter(account_id=account))
        results = hours_per_consumer(start,
                                     end,
                                     list_of_rhics=list_of_rhics,
                                     environment=environment)

    format = constants.full_format

    response_data = {}
    response_data['list'] = results
    response_data['account'] = account
    response_data['start'] = start.strftime(format)
    response_data['end'] = end.strftime(format)

    #return create_response(utils.to_json(response_data))
    return create_response(response_data)
Exemple #10
0
def report(request):
    
    _LOG.info("report called by method: %s" % (request.method))

    user = str(request.user)
    account = Account.objects.filter(login=user)[0].account_id
       
    start, end = get_dates_from_request(request)
    data = data_from_post(request)
    
    if 'env' in data:
        environment = data["env"]
    else:
        environment = "All"

    rhic = data["rhic"]
    contract = data["contract_number"]
    list_of_rhics = []

    if contract == 'All' and (rhic == 'All' or rhic == 'null'):
        list_of_rhics = list(RHIC.objects.filter(account_id=account))

    elif rhic != 'null':
        if rhic == "All":
            list_of_rhics = list(RHIC.objects.filter(contract=contract))
        else:
            my_uuid = data['rhic']
            list_of_rhics = list(RHIC.objects.filter(uuid=my_uuid))

    else:
        list_of_rhics = list(RHIC.objects.filter(account_id=account))

    args = {'start': start,
            'end': end,
            'list_of_rhics': list_of_rhics,
            'environment': environment
            } 
    results = hours_per_consumer(**args)

    format = constants.full_format

    response_data = {}
    response_data['list'] = results
    response_data['account'] = account
    response_data['start'] = start.strftime(format)
    response_data['end'] = end.strftime(format)

    return create_response(response_data)
Exemple #11
0
def instance_detail(request):
    data = utils.data_from_post(request)
    user = str(request.user)
    account = Account.objects.filter(login=user)[0].account_id
    instance = data['instance']
    filter_args_dict = data['filter_args_dict']
    date = get_date_object(data['date'])
    day = date.strftime(constants.day_fmt)

    results = ReportData.objects.filter(
        instance_identifier=instance, day=day, **filter_args_dict)

    response_data = {}
    response_data['list'] = results
    response_data['account'] = account

    return create_response(response_data)
Exemple #12
0
def instance_detail(request):
    data = utils.data_from_post(request)
    user = str(request.user)
    #account = Account.objects.filter(login=user)[0].account_id
    instance = data["instance"]
    date = convert_to_datetime(data["date"])
    results = MarketingReportData.objects.filter(instance_identifier=instance, date=date)[0]


    response_data = {}
    response_data['space_hostname'] = config.CONFIG.get('spacewalk', 'db_host')
    response_data['facts'] = results["facts"]
    response_data['product_info'] = results["product_info"]
    response_data['status'] = results["status"]
    response_data['splice_server'] = results["splice_server"]
    response_data['system_id'] = results["systemid"]
    response_data['instance_identifier'] = results["instance_identifier"]
    response_data['date'] = results["date"]

    return create_response(response_data)
Exemple #13
0
def detailed_report(request):
    data = utils.data_from_post(request)
    
    filter_args_dict = data['filter_args_dict']
    date = datetime.strptime(data['date'], constants.just_date)
    day = date.strftime(constants.day_fmt)

    results = []
    instances = ReportData.objects.filter(day=day, **filter_args_dict).distinct('instance_identifier')
    for i in instances:
        count = ReportData.objects.filter(instance_identifier=i, day=day, **filter_args_dict).count()
        results.append({'instance': i, 'count': count})

    

    response_data = {}
    response_data['list'] = results
    response_data['date'] = get_date_epoch(date)
    response_data['this_filter'] = filter_args_dict
    response_data['description'] = data['description']

    return create_response(response_data)
Exemple #14
0
def create_export_report(request):
    """
    This is now used by "Export Report" and should be the "GET" equiv
    of report

    @param request: http

    generate the data for the report.
    data is generated from hours_per_consumer
    
    Returns:
    Content-Disposition:attachment; filename=reportdata.csv
    Content-Type:text/csv

    """
    _LOG.info("report called by method: %s" % (request.method))

    user = str(request.user)
    account = Account.objects.filter(login=user)[0].account_id
    start, end = get_dates_from_request(request)
    
    if 'env' in request.GET:
        environment = request.GET['env']
    else:
        environment = "All"
        
    rhic = request.GET['rhic']
    contract = request.GET['contract_number']    
    list_of_rhics = []
    
    if contract == 'All' and (rhic == 'All' or rhic == 'null'):
        list_of_rhics = list(RHIC.objects.filter(account_id=account))
        results = hours_per_consumer(start,
                                     end, 
                                     list_of_rhics=list_of_rhics,
                                     environment=environment)

    elif rhic != 'null':
        if rhic == "All":
            list_of_rhics = list(RHIC.objects.filter(contract=contract))
        else:
            my_uuid = rhic
            list_of_rhics = list(RHIC.objects.filter(uuid=my_uuid))
        results = hours_per_consumer(start,
                                     end,
                                     list_of_rhics,
                                     environment=environment)

    else:
        list_of_rhics = list(RHIC.objects.filter(account_id=account))
        results = hours_per_consumer(start,
                                     end,
                                     list_of_rhics=list_of_rhics,
                                     environment=environment)

    format = constants.full_format

    response_data = {}
    response_data['list'] = results
    response_data['account'] = account
    response_data['start'] = start.strftime(format)
    response_data['end'] = end.strftime(format)

    #return create_response(utils.to_json(response_data))
    return create_response(response_data)
Exemple #15
0
def unauthorized_pem():
    results = ReportData.objects.filter()

    response_data = {}
    response_data['list'] = results
    return create_response(response_data)
Exemple #16
0
def execute_import(request):
    quarantined, results = import_data()
    response_data = {}
    response_data['time'] = results
    
    return create_response(response_data)