Exemplo n.º 1
0
 def _createGroupDeviceFunctions(self, properties):
     categories = set(p.Category for p in properties.all())
     functions = []
     for category in categories:
         categoryProperties = properties.filter(Category=category)
         categoryGroupProperties = self._createGroupDeviceProperties(
             categoryProperties)
         function = Function()
         function.Name = category.Name
         function = self.__functionRepository.Save(function)
         for categoryGroupProperty in categoryGroupProperties:
             categoryGroupProperty = self.__propertyRepository.Save(
                 categoryGroupProperty)
             function.Properties.add(categoryGroupProperty)
         self.__functionRepository.Save(function)
         functions.append(function)
     return functions
Exemplo n.º 2
0
    def Save(self, data):
        if type(data) is Function:
            model = data
        else:
            model = Function()
            model.Id = data.get("Id", "")
            model.Name = data.get("Name", "")

        function = self.Get(model.Id)
        status = self.Status(model, function)
        if status is ModelStatus.New:
            model.Id = None
            model.save()
        elif status is ModelStatus.Modified:
            model.save()

        if type(data) is not Function:
            Properties = data['Properties']
            for propertyDict in Properties:
                property = self.__propertyRepo.Save(propertyDict)
                model.Properties.add(property.Id)

        return model