コード例 #1
0
    def SetDirtyModels(self, request, context):
        user = self.authenticate(context, required=True)

        dirty_models = utility_pb2.ModelList()

        models = django.apps.apps.get_models()
        for model in models:
            if is_internal_model(model):
                continue
            fieldNames = [x.name for x in model._meta.fields]
            if ("enacted" not in fieldNames) or ("updated" not in fieldNames):
                continue
            if (request.class_name) and (not fnmatch.fnmatch(
                    model.__name__, request.class_name)):
                continue
            objs = model.objects.all()
            for obj in objs:
                try:
                    obj.caller = user
                    obj.save()
                    item = dirty_models.items.add()
                    item.class_name = model.__name__
                    item.id = obj.id
                except Exception as e:
                    item = dirty_models.items.add()
                    item.class_name = model.__name__
                    item.id = obj.id
                    item.info = str(e)

        REQUEST_COUNT.labels("xos-core", "Utilities", "SetDirtyModels",
                             grpc.StatusCode.OK).inc()
        return dirty_models
コード例 #2
0
ファイル: xos_utility_api.py プロジェクト: ttofigh/xos
    def SetDirtyModels(self, request, context):
        user = self.authenticate(context, required=True)

        dirty_models = utility_pb2.ModelList()

        models = django.apps.apps.get_models()
        for model in models:
            if is_internal_model(model):
                continue
            fieldNames = [x.name for x in model._meta.fields]
            if (not "enacted" in fieldNames) or (not "updated" in fieldNames):
                continue
            if (request.class_name) and (not fnmatch.fnmatch(
                    model.__name__, request.class_name)):
                continue
            objs = model.objects.all()
            for obj in objs:
                try:
                    obj.caller = user
                    obj.save()
                except Exception, e:
                    item = dirty_models.items.add()
                    item.class_name = model.__name__
                    item.id = obj.id
                    item.info = str(e)
コード例 #3
0
    def ListDirtyModels(self, request, context):
        dirty_models = utility_pb2.ModelList()

        models = django.apps.apps.get_models()
        for model in models:
            if is_internal_model(model):
                continue
            fieldNames = [x.name for x in model._meta.fields]
            if (not "enacted" in fieldNames) or (not "updated" in fieldNames):
                continue
            if (request.class_name) and (not fnmatch.fnmatch(model.__name__, request.class_name)):
                continue
            objs = model.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
            for obj in objs:
                item = dirty_models.items.add()
                item.class_name = model.__name__
                item.id = obj.id

        return dirty_models
コード例 #4
0
    def ListDirtyModels(self, request, context):
        dirty_models = utility_pb2.ModelList()

        models = django.apps.apps.get_models()
        for model in models:
            if is_internal_model(model):
                continue
            fieldNames = [x.name for x in model._meta.fields]
            if ("enacted" not in fieldNames) or ("updated" not in fieldNames):
                continue
            if (request.class_name) and (not fnmatch.fnmatch(
                    model.__name__, request.class_name)):
                continue
            objs = model.objects.filter(
                Q(enacted__lt=F("updated")) | Q(enacted=None))
            for obj in objs:
                item = dirty_models.items.add()
                item.class_name = model.__name__
                item.id = obj.id

        REQUEST_COUNT.labels("xos-core", "Utilities", "ListDirtyModels",
                             grpc.StatusCode.OK).inc()
        return dirty_models