Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add optional model for map layers #3

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open

Conversation

finnus
Copy link

@finnus finnus commented May 24, 2023

The idea behind the PR is to put more configuration of the map layers into django models.
That would have some advantages (more flexible, no need to change code when changing minor things or even adding/removing layers/choropleths/popups).

This is a first guess into that direction, with a few downsides:

  • the MapLayerModel does not yet fully replace the layers that have to be defined in the settings file. It only replaces the choropleth and popup configuration.
  • it nevertheless can also hold the information for the other layers (can be useful to generate the on/off switches in the frontend)
  • the MapLayerModel needs to have the fields "choropleth_field" and "popup_fields". If we further investigate this approach, we might rather add an abstract model for the MapLayerModel.
  • there is no real validation when entering information into the two above mentioned fields. When the inserted information is wrong, the displaying will just not work.

As this approach looks still promising to me, I added the respective code. If no MapLayerModel is defined in the settings, it should work as before.

@finnus finnus requested a review from henhuy May 24, 2023 12:22
Copy link
Contributor

@henhuy henhuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to move MapLayerModel to mapengine models.py.

if settings.MAP_ENGINE_MAPLAYER_MODEL:
# get MapLayerModel from settings
try:
MapLayerModel = apps.get_model(app_label='map', model_name=settings.MAP_ENGINE_MAPLAYER_MODEL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the MapLayerModel would be integrated in mapengine's models.py ?
This would make model available in all projects which use mapengine automatically.
Also this would remove need for app.get_model and currently hardcoded "map" namespace.


# get choropleth fields
try:
model_field = MapLayerModel._meta.get_field("choropleth_field")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also be obsolete, as we make sure field exists by providing model from within mapengine

@Josephine-Marie
Copy link
Contributor

Hi @finnus , when you create the model please add a placeholder for unit in case some models dont have one

@henhuy henhuy force-pushed the optional_map_layer_model branch from 56b7cdf to d6dd963 Compare June 9, 2023 11:29
@finnus finnus mentioned this pull request Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants