Friday, 16 September 2022

call functions based on dynamic list from the user

I have a report generating API in my django app which takes name of reports as input from the user, user can multiselect different reports from the dropdown

    reports = request.GET['reports'].split(',')

example:

    print("selected reports", reports)

    >>seleceted reports ['AS', 'DD', 'IS', 'LM']

now this reports can vary according to the user and I have a dictionary of all the functions to create these reports

master = {
        'AS': Summary(df, description_dict, emp),
        'AH': lastSeenMissingAsset(df, emp, description_dict),
        'MS': missingScans(df, emp),
        'IS': individualScans(df),
        'LM': tagMismatch(df, emp),
        'MAS': missingAssets(df, emp, description_dict, deployed_df),
        'MAU': missingAudit(df, pd.to_datetime(tt).date()),
        'DD': dumpData(df)
          }                 ###this calls every report first   

How can I call the functions from the dictionary based on the dynamic list I get from user?

I tried:

    final={}
    print("selected reports", reports)
    for i in reports:
        final[i] = master[i]
    print("final", final)

This works but all of the functions are called first because of the dictionary, how do I make it to call only the selected reports ?



from call functions based on dynamic list from the user

No comments:

Post a Comment