Esempio n. 1
0
def reportitem_post_save_system_case(sender, instance, *args, **kwargs):
    """ link system to case if system's reportitem was set to case """

    # improve readability
    reportitem = instance

    # reportitem was linked with a case
    if reportitem.case:

        # improve readability
        reportitem_case = reportitem.case
        reportitem_system = reportitem.system

        # check whether reportitem's system is linked with reportitem's case
        if not reportitem_case in reportitem_system.case.all():

            # link reportitem's system with reportitem's case
            reportitem_system.case.add(reportitem_case)

            # get all users
            all_users = User.objects.all()

            # call message for all users
            message_users(
                all_users,
                f"System '{reportitem_system.system_name}' was assigned to case '{reportitem_case.case_name}' due to reportitem assignment.",
                constants.SUCCESS
            )

            # call logger
            info_logger('signal', f' SYSTEM_CASE_ASSIGNMENT system_id:{reportitem_system.system_id}|system_name:{reportitem_system.system_name}|case_id:{reportitem_case.case_id}|case_name:{reportitem_case.case_name}|reason:reportitem_assignment')
Esempio n. 2
0
def error_message_cron(message_text):
    """ error message for all users if function was called from 'artifact_cron' / 'system_cron' (w/o request) """

    # get all users
    all_users = User.objects.all()

    # call message for all users
    message_users(all_users,
                  f'[Scheduled task spreadsheet exporter] {message_text}',
                  constants.ERROR)

    # return to calling function in 'checks'
    return
Esempio n. 3
0
def final_messages_cron(systems_created_counter, systems_updated_counter,
                        systems_skipped_counter, systems_multiple_counter,
                        systems_multiple_list, starttime, endtime):
    """ final messages if function was called from 'system_cron' (w/o request) """

    # get all users
    all_users = User.objects.all()

    # call message for all users
    message_users(
        all_users, f'System CSV importer:'
        f' created: {systems_created_counter}'
        f' | updated: {systems_updated_counter}'
        f' | skipped: {systems_skipped_counter}'
        f' | multiple: {systems_multiple_counter}'
        f' [{starttime} - {endtime}]', constants.SUCCESS)

    # show systems_multiple_list
    if systems_multiple_list:
        if systems_multiple_counter == 1:
            # call message for all users
            message_users(
                all_users,
                f'{systems_multiple_counter} system was skipped because it existed several times. {systems_multiple_list}',
                constants.WARNING)
        else:
            # call message for all users
            message_users(
                all_users,
                f'{systems_multiple_counter} systems were skipped because they existed several times. {systems_multiple_list}',
                constants.WARNING)

    # return to 'csv_main.system_handler'
    return