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

[Fixes #3600] [GNIP] APIs to decouple import and load of GeoNode Client Libraries #3602

Merged
merged 2 commits into from
Feb 13, 2018

Conversation

afabiani
Copy link
Member

@afabiani afabiani commented Feb 8, 2018

This PR makes some code cleanup, by centralizing some methods and remove code redundancies, but mostly propose a way to make GeoNode GIS client libraries pluggable.

This done through a geonode.client app which should be used not only to collect the GIS client templates provided by default with GeoNode, but also defines a set of templatetags which can be used to easily plugin any other different client into the layer details or map templates.

How to use it. Instead of doing something like this:

  {% if preview == 'geoext' %}
    {% include "layers/layer_geoext_map.html" %}
  {% elif preview == 'OL3' %}
    {% include "layers/layer_ol3_map.html" %}
  {% elif preview == 'react' %}
	{% include 'geonode-client/layer_map.html' %}
  {% else %}
    {% include "layers/layer_leaflet_map.html" %}
  {% endif %}

through this new mechanism you can now do this

...
{% load client_lib_tags %}
...
{% get_layer_detail %}
...

the tag is translated into a method of a HookSet that simply translates the call into a custom template inclusion by passing the context to it.

Plugging in you own Hookset is easy as

  1. Load your new client lib on INSTALLED_APPS
  2. Set the variable GEONODE_CLIENT_HOOKSET pointing to your own Hookset

And that's it. By default, if no GEONODE_CLIENT_HOOKSET is defined, GeoNode will use the GeoExt based one

GEONODE_CLIENT_HOOKSET = "geonode.client.hooksets.GeoExtHookSet"

This is the default one, and it is quite straight. Just defines which templates to include

class GeoExtHookSet(object):

    # Layers
    def layer_detail_template(self, context=None):
        return 'geoext/layers/layer_geoext_map.html'

    def layer_new_template(self, context=None):
        return 'geoext/layers/layer_geoext_map.html'

    def layer_view_template(self, context=None):
        return 'geoext/layers/layer_geoext_map.html'

    def layer_edit_template(self, context=None):
        return 'geoext/layers/layer_geoext_map.html'

    def layer_update_template(self, context=None):
        return 'geoext/layers/layer_geoext_map.html'

    def layer_embed_template(self, context=None):
        return 'geoext/layers/layer_geoext_map.html'

    def layer_download_template(self, context=None):
        return 'geoext/layers/layer_geoext_map.html'

    # Maps
    def map_detail_template(self, context=None):
        return 'geoext/maps/map_include.html'

    def map_new_template(self, context=None):
        return 'geoext/maps/map_geoexplorer.js'

    def map_view_template(self, context=None):
        return 'geoext/maps/map_geoexplorer.js'

    def map_edit_template(self, context=None):
        return 'geoext/maps/map_geoexplorer.js'

    def map_update_template(self, context=None):
        return 'geoext/maps/map_geoexplorer.js'

    def map_embed_template(self, context=None):
        return 'geoext/maps/map_geoexplorer.js'

    def map_download_template(self, context=None):
        return 'geoext/maps/map_geoexplorer.js'

On your own client library, you can manipulate the context as you wish and pass back to your templates any new variable.

Copy link
Member

@francbartoli francbartoli left a comment

Choose a reason for hiding this comment

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

+1 it looks like much cleaner

@afabiani afabiani force-pushed the ISSUE_3600 branch 3 times, most recently from 4c32864 to dcc293c Compare February 8, 2018 10:37
@codecov-io
Copy link

codecov-io commented Feb 8, 2018

Codecov Report

Merging #3602 into master will increase coverage by 0.49%.
The diff coverage is 48.08%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3602      +/-   ##
==========================================
+ Coverage   40.78%   41.28%   +0.49%     
==========================================
  Files         377      385       +8     
  Lines       27750    27659      -91     
  Branches     3551     3481      -70     
==========================================
+ Hits        11319    11418      +99     
+ Misses      15762    15578     -184     
+ Partials      669      663       -6
Impacted Files Coverage Δ
geonode/maps/views.py 45.54% <ø> (ø) ⬆️
geonode/layers/views.py 35.71% <ø> (ø) ⬆️
geonode/context_processors.py 100% <ø> (ø) ⬆️
geonode/qgis_server/helpers.py 67.87% <0%> (ø) ⬆️
...onode/base/management/commands/fixgeofencerules.py 0% <0%> (ø) ⬆️
.../base/management/commands/set_all_layers_public.py 0% <0%> (ø) ⬆️
geonode/client/__init__.py 100% <100%> (ø)
geonode/security/models.py 80% <100%> (+38.87%) ⬆️
geonode/documents/models.py 82.5% <100%> (ø) ⬆️
geonode/client/hooks.py 100% <100%> (ø)
... and 28 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d142c1...ab38f28. Read the comment docs.

capooti
capooti previously approved these changes Feb 10, 2018
Copy link
Member

@capooti capooti left a comment

Choose a reason for hiding this comment

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

Nice!

@afabiani
Copy link
Member Author

@capooti can you please approve again? I had to merge with master branch

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.

4 participants