Now, we will create a SurfboardMetricManager
class that we will use to persist the SurfboardMetricModel
instances in an in-memory dictionary. Our API methods will call methods for the SurfboardMetricManager
class to retrieve, insert, and delete SurfboardMetricModel
instances.
Stay in the metrics.py
file in the metrics/metrics/models
subfolder. Add the following lines to declare the SurfboardMetricManager
class. The code file for the sample is included in the restful_python_2_09_01
folder, in the Pyramid01/metrics/metrics/models/metrics.py
file:
class SurfboardMetricManager(): last_id = 0 def __init__(self): self.metrics = {} def insert_metric(self, metric): self.__class__.last_id += 1 metric.id = self.__class__.last_id self.metrics[self.__class__.last_id] = metric def get_metric(self, id): return self.metrics[id] def delete_metric(self, id): del self.metrics[id]
The SurfboardMetricManager...