From a7fe6f4ab90cba3980f3bdefabc6c1ad4bc8fd17 Mon Sep 17 00:00:00 2001 From: raykendo Date: Wed, 29 Jul 2020 15:12:57 -0500 Subject: [PATCH 1/5] Update links in readme to correct url --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index af1f709..b1c06cb 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ In order to install Python, install the bundle that comes with the Anaconda dist Execute the following command in the terminal -``` pip install -e git+https://github.com/esridc/hub-py.git#egg=arcgishub ``` +``` pip install -e git+https://github.com/esri/hub-py.git#egg=arcgishub ``` Once installed, test it by launching an instance of Jupyter Notebook and importing the package @@ -22,7 +22,7 @@ Once installed, test it by launching an instance of Jupyter Notebook and importi Execute the following command in the terminal -``` pip install -e git+https://github.com/esridc/hub-py.git#egg=arcgishub ``` +``` pip install -e git+https://github.com/esri/hub-py.git#egg=arcgishub ``` Once installed, test it by launching an instance of Jupyter Notebook and importing the package @@ -47,15 +47,15 @@ initiatives = myHub.initiatives.search() print(initiatives) ``` -fetches a list containing all the initiatives within this Hub. Click [here](https://github.com/esridc/hub-py/wiki) for more information and API reference about the functionality supported. +fetches a list containing all the initiatives within this Hub. Click [here](https://github.com/esri/hub-py/wiki) for more information and API reference about the functionality supported. ### User Guides -Example notebooks for using this API to work with your Hub are provided in the [examples](https://github.com/esridc/hub-py/tree/master/examples) directory. +Example notebooks for using this API to work with your Hub are provided in the [examples](https://github.com/esri/hub-py/tree/master/examples) directory. -If you are working with `arcgishub` >=v2.1.0, you will find the above examples and functionality supported in this API under the [For arcgishub](https://github.com/esridc/hub-py/tree/master/examples/For%20arcgishub) folder. +If you are working with `arcgishub` >=v2.1.0, you will find the above examples and functionality supported in this API under the [For arcgishub](https://github.com/esri/hub-py/tree/master/examples/For%20arcgishub) folder. -Older versions of this API can also be found in the [ArcGIS API for Python](https://developers.arcgis.com/python/). You can find user guides to access Hub using it, under the [For ArcGIS API for Python](https://github.com/esridc/hub-py/tree/master/examples/For%20ArcGIS%20API%20for%20Python) subdirectory. +Older versions of this API can also be found in the [ArcGIS API for Python](https://developers.arcgis.com/python/). You can find user guides to access Hub using it, under the [For ArcGIS API for Python](https://github.com/esri/hub-py/tree/master/examples/For%20ArcGIS%20API%20for%20Python) subdirectory. -We encourage you to provide feedback/issues in implementation, under GitHub [issues](https://github.com/esridc/hub-py/issues) for this repo. +We encourage you to provide feedback/issues in implementation, under GitHub [issues](https://github.com/esri/hub-py/issues) for this repo. From 09f9555417a0405c432454d98a0b7c5f68e3d3b8 Mon Sep 17 00:00:00 2001 From: raykendo Date: Wed, 29 Jul 2020 17:20:27 -0500 Subject: [PATCH 2/5] Fix a minor spelling error --- .../Accessing events and plotting them on a map.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/For arcgishub/Accessing events and plotting them on a map.ipynb b/examples/For arcgishub/Accessing events and plotting them on a map.ipynb index 1bd3e39..c2b383d 100644 --- a/examples/For arcgishub/Accessing events and plotting them on a map.ipynb +++ b/examples/For arcgishub/Accessing events and plotting them on a map.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Accessign events in your Hub and plotting them on a map" + "### Accessing events in your Hub and plotting them on a map" ] }, { @@ -319,4 +319,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} +} \ No newline at end of file From 1999083f1bf17629b211d283756d1aefa8c07eab Mon Sep 17 00:00:00 2001 From: raykendo Date: Wed, 29 Jul 2020 17:21:19 -0500 Subject: [PATCH 3/5] Adding search functionality within Hub object --- arcgishub/hub.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arcgishub/hub.py b/arcgishub/hub.py index 8ded03b..8160af8 100644 --- a/arcgishub/hub.py +++ b/arcgishub/hub.py @@ -51,6 +51,7 @@ def __init__(self, url, username=None, password=None): self._password = password self.url = url self.gis = GIS(self.url, self._username, self._password) + self.search = self._instance_search try: self._gis_id = self.gis.properties.id except AttributeError: @@ -144,6 +145,36 @@ def community_org_url(self): print("Hub does not exist or is inaccessible.") raise + @staticmethod + def search(query='', url=None, username=None, password=None, **kwargs): + """ + Returns a list of hubs based on a search query of GIS content + """ + gis = GIS(url, username, password) + item_type = 'Hub *' + + if 'query' in kwargs: + if query == None or query == '': + query = kwargs['query'] + del kwargs['query'] + if 'item_type' in kwargs: + if len(kwargs['item_type']) > 0: + item_type = kwargs['item_type'] + del kwargs['item_type'] + + return gis.content.search(query=query, item_type=item_type, **kwargs) + + def _instance_search(self, query='', **kwargs): + """ + Provides search functionality within the organization's hub + """ + item_type = 'Hub *' + if 'item_type' in kwargs: + if len(kwargs['item_type']) > 0: + item_type = kwargs['item_type'] + del kwargs['item_type'] + return self.gis.content.search(query=query, item_type=item_type, **kwargs) + @_lazy_property def initiatives(self): """ From 08a968669f96c3dc00b78521bdd3ad1637ccdd9b Mon Sep 17 00:00:00 2001 From: raykendo Date: Fri, 25 Sep 2020 09:09:23 -0500 Subject: [PATCH 4/5] Adding search capability within Hub --- arcgishub/hub.py | 103 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 71 insertions(+), 32 deletions(-) diff --git a/arcgishub/hub.py b/arcgishub/hub.py index 8160af8..4a0f645 100644 --- a/arcgishub/hub.py +++ b/arcgishub/hub.py @@ -2,7 +2,7 @@ from arcgis.features import FeatureLayer from arcgis.geocoding import geocode from arcgis._impl.common._mixins import PropertyMap -from arcgishub.sites import SiteManager, PageManager +from arcgishub.sites import Site, SiteManager, Page, PageManager from arcgis.features.enrich_data import enrich_layer from datetime import datetime from collections import OrderedDict @@ -51,7 +51,6 @@ def __init__(self, url, username=None, password=None): self._password = password self.url = url self.gis = GIS(self.url, self._username, self._password) - self.search = self._instance_search try: self._gis_id = self.gis.properties.id except AttributeError: @@ -144,36 +143,6 @@ def community_org_url(self): except: print("Hub does not exist or is inaccessible.") raise - - @staticmethod - def search(query='', url=None, username=None, password=None, **kwargs): - """ - Returns a list of hubs based on a search query of GIS content - """ - gis = GIS(url, username, password) - item_type = 'Hub *' - - if 'query' in kwargs: - if query == None or query == '': - query = kwargs['query'] - del kwargs['query'] - if 'item_type' in kwargs: - if len(kwargs['item_type']) > 0: - item_type = kwargs['item_type'] - del kwargs['item_type'] - - return gis.content.search(query=query, item_type=item_type, **kwargs) - - def _instance_search(self, query='', **kwargs): - """ - Provides search functionality within the organization's hub - """ - item_type = 'Hub *' - if 'item_type' in kwargs: - if len(kwargs['item_type']) > 0: - item_type = kwargs['item_type'] - del kwargs['item_type'] - return self.gis.content.search(query=query, item_type=item_type, **kwargs) @_lazy_property def initiatives(self): @@ -203,6 +172,76 @@ def pages(self): """ return PageManager(self.gis) + def search(self, title=None, owner=None, created=None, modified=None, tags=None, scope=None): + """ + Provides search functionality within the organization's hub. Results will be organized + as either Initiatives + + =============== ==================================================================== + **Argument** **Description** + --------------- -------------------------------------------------------------------- + title Optional string. Return hub items with provided string in title. + --------------- -------------------------------------------------------------------- + owner Optional string. Return hub items owned by a username. + --------------- -------------------------------------------------------------------- + created Optional string. Date the hub item was created. + Shown in milliseconds since UNIX epoch. + --------------- -------------------------------------------------------------------- + modified Optional string. Date the hub item was last modified. + Shown in milliseconds since UNIX epoch + --------------- -------------------------------------------------------------------- + tags Optional string. User-defined tags that describe the hub item. + --------------- -------------------------------------------------------------------- + scope Optional string. Defines the scope of search. + Valid values are 'official', 'community' or 'all'. + =============== ==================================================================== + """ + resultList = [] + #Build search query + query = 'typekeywords:hub' + if title!=None: + query += ' AND title:'+title + if owner!=None: + query += ' AND owner:'+owner + if created!=None: + query += ' AND created:'+created + if modified!=None: + query += ' AND modified:'+modified + if tags!=None: + query += ' AND tags:'+tags + + #Apply org scope and search + if scope is None or self.gis.url=='https://www.arcgis.com': + items = self.gis.content.search(query=query, item_type='Hub *', max_items=5000) + elif scope.lower()=='official': + query += ' AND access:public' + _gis = GIS(self.enterprise_org_url) + items = _gis.content.search(query=query, item_type='Hub *', max_items=5000) + elif scope.lower()=='community': + query += ' AND access:public' + _gis = GIS(self.community_org_url) + items = _gis.content.search(query=query, item_type='Hub *', max_items=5000) + elif scope.lower()=='all': + items = self.gis.content.search(query=query, item_type='Hub *', outside_org=True, max_items=5000) + else: + raise Exception("Invalid value for scope") + + for item in items: + if "hubInitiative" in item.typeKeywords: + resultList.append(Initiative(self, item)) + elif "hubSite" in item.typeKeywords: + resultList.append(Site(self.gis, item)) + elif "hubPage" in item.typeKeywords: + resultList.append(Page(self.gis, item)) + elif "hubInitiativeTemplate" in item.typeKeywords: + # leaving room for an InitiativeTemplate object. + # In the mean time, treat it as an item + resultList.append(item) + else: + # not sure what this is. Will just send back the item + resultList.append(item) + return resultList + class Initiative(OrderedDict): """ Represents an initiative within a Hub. An Initiative supports From aebcd5031a2be43c725f7453682bcb01169080fc Mon Sep 17 00:00:00 2001 From: raykendo Date: Fri, 25 Sep 2020 10:32:23 -0500 Subject: [PATCH 5/5] Allow Page layout updates the same as Sites --- arcgishub/sites.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arcgishub/sites.py b/arcgishub/sites.py index 9633810..6abbd60 100644 --- a/arcgishub/sites.py +++ b/arcgishub/sites.py @@ -763,6 +763,15 @@ def slug(self): Returns the page slug """ return self.title.replace(' ', '-').lower() + + @property + def layout(self): + """ + Return layout of a page + """ + if self.definition is None: + return None + return InsensitiveDict(self.definition['values']['layout']) def update(self, page_properties=None, slug=None, data=None, thumbnail=None, metadata=None): """ Updates the page. @@ -797,6 +806,30 @@ def update(self, page_properties=None, slug=None, data=None, thumbnail=None, met _page_data[key] = value return self.item.update(_page_data, data, thumbnail, metadata) + def update_layout(self, layout): + """ Updates the layout of the page. + ===================== ==================================================================== + **Argument** **Description** + --------------------- -------------------------------------------------------------------- + layout Required dictionary. The new layout dictionary to update to the page. + ===================== ==================================================================== + :return: + A boolean indicating success (True) or failure (False). + .. code-block:: python + USAGE EXAMPLE: Update a page successfully + page1 = myHub.pages.get('itemId12345') + page_layout = page1.layout + page_layout.sections[0].rows[0].cards.pop(0) + page1.update_layout(layout = page_layout) + >> True + """ + if self.definition is None: + # no page definition, for some reason + return False + self.definition['values']['layout'] = layout._json() + self.definition['values']['updatedBy'] = self._gis.users.me.username + return self.item.update(item_properties={'text': self.definition}) + def delete(self): """ Deletes the page. If unable to delete, raises a RuntimeException.