From 3b58804ca939e319ed20721907d0eabb339dd79e Mon Sep 17 00:00:00 2001 From: nesnoj Date: Wed, 12 Jun 2019 17:47:29 +0200 Subject: [PATCH] simplify generic serial result layer view GeoJSONResultLayerData #38 instead of passing model_name and custom_property via init it's is now taken from subclass attribute --- views/serial_views.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/views/serial_views.py b/views/serial_views.py index 9318d61f..a7db2879 100644 --- a/views/serial_views.py +++ b/views/serial_views.py @@ -480,36 +480,41 @@ class GeoJSONResultLayerData(GeoJSONResponseMixin, ListView): creating GeoJSON response. Municipalities (model RegMun) is used as base model. - Notes - ----- Different from static serial layer views (examples see above) which use a specific model each, this view uses the dummy model :class:`stemp_abw.models.ResultLayerModel` on initialization. The property "model" which is required by djgeojson is set dynamically using class method :meth:`stemp_abw.models.ResultLayerModel.name_init`. + + Attributes + ---------- + model_name : :obj:`str` + Name string of model (used as property "name" in dummy model + :class:`stemp_abw.models.ResultLayerModel), see model for detailed + description. + custom_property : :obj:`str` + Property (column) to be added to model, must be a column in + layer results DataFrame results_df. + properties : :obj:`list` of :obj:`str` + Properties for each feature to be contained in the GeoJSON. + + Notes + ----- + Attributes `model_name` and `custom_property` must be attributes of + subclass. """ + model_name = None custom_property = None properties = [] - def __init__(self, model_name, custom_property, *args, **kwargs): + def __init__(self, *args, **kwargs): """Instantiate with custom `model_name` and `custom_property` - - Parameters - ---------- - model_name : :obj:`str` - Name string of model (used as property "name" in dummy model - :class:`stemp_abw.models.ResultLayerModel), see model for detailed - description. - custom_property : :obj:`str` - Property (column) to be added to model, must be a column in - layer results DataFrame results_df. """ self.model = models.ResultLayerModel.name_init( - name=model_name) - self.custom_property = custom_property + name=self.model_name) self.properties = ['name', 'gen', - custom_property] + self.custom_property] super(GeoJSONResultLayerData, self).__init__(*args, **kwargs)