Esempio n. 1
0
def delete_data_senders(request):
    manager = get_database_manager(request.user)
    organization = get_organization(request)
    entity_type = request.POST['entity_type']
    all_ids = data_sender_short_codes(request, manager)
    superusers = rep_id_name_dict_of_users(manager)
    non_superuser_rep_ids = [
        id for id in all_ids if id not in superusers.keys()
    ]
    transport_info = TransportInfo("web", request.user.username, "")

    delete_datasenders_from_project(manager, non_superuser_rep_ids)
    delete_entity_instance(manager, non_superuser_rep_ids, entity_type,
                           transport_info)
    delete_datasender_users_if_any(non_superuser_rep_ids, organization)
    if organization.in_trial_mode:
        delete_datasender_for_trial_mode(manager, non_superuser_rep_ids,
                                         entity_type)
    log_activity(
        request,
        DELETED_DATA_SENDERS,
        "%s: [%s]" %
        (entity_type.capitalize(), ", ".join(non_superuser_rep_ids)),
    )
    messages = get_success_message(entity_type)
    return HttpResponse(json.dumps({'success': True, 'message': messages}))
Esempio n. 2
0
def delete_subjects(request):
    manager = get_database_manager(request.user)
    entity_type = request.POST['entity_type']
    form_model = get_form_model_by_entity_type(manager, [entity_type])
    all_ids = _subject_short_codes_to_delete(request, form_model, entity_type)
    hard_delete_unique_ids = _get_unique_ids_to_hard_delete(
        all_ids, entity_type, manager)
    _hard_delete_unique_ids(hard_delete_unique_ids, manager, form_model,
                            request)
    unique_ids_to_soft_delete = list(
        set(all_ids) - set(hard_delete_unique_ids))
    _soft_delete_unique_ids(unique_ids_to_soft_delete, entity_type, manager,
                            request)
    message = get_success_message(entity_type)
    return HttpResponse(json.dumps({'success': True, 'message': message}))