Пример #1
0
def creates(creates_list, whitelist=None):
    if not has_permission("creates"):
        return Exception("Creates not allowed")
    if not creates_list:
        return list()
    responses = list()
    for data in creates_list:
        model = app_utils.find_model_class(data.pop("_model"),
                                           whitelist=whitelist)
        instance = model.objects.create(**data)
        responses.append(instance.pk)
    return responses
Пример #2
0
def deletes(deletes_list, whitelist=None):
    if not has_permission("deletes"):
        raise Exception("Deletes not allowed")
    if not deletes_list:
        return list()
    responses = list()
    for data in deletes_list:
        model = app_utils.find_model_class(data.pop("_model"),
                                           whitelist=whitelist)
        cnt = model.objects.filter(pk=data.pop("_pk")).delete()
        responses.append(cnt)
    return responses
Пример #3
0
def updates(updates_list, whitelist=None):
    if not has_permission("updates"):
        raise Exception("Updates not allowed")
    if not updates_list:
        return []
    responses = []
    for data in updates_list:
        model = app_utils.find_model_class(data.pop("_model"),
                                           whitelist=whitelist)
        cnt = model.objects.filter(pk=data.pop("_pk")).update(**data)
        responses.append(cnt)
    return responses
Пример #4
0
def get_fields(request, modelname):
    model = find_model_class(modelname, whitelist=wl())
    d = get_model_details(model, connections["default"])
    return JsonResponse(d)
Пример #5
0
 def test_find_model_class(self):
     self.assertEqual(find_model_class("Book"), Book)