Skip to content

Sites.py

Manushi Majumdar edited this page Sep 10, 2020 · 10 revisions

Getting started with sites.py

from arcgishub.hub import Hub
myhub = Hub("url", "<username>", "<password>")  #url could be AGOL or ArcGIS Enterprise deployment
a_Site = myHub.sites.get(itemId)

1. class Site()

"""
Represents a site within a Hub. A site is a container for 
web accessible content.
"""

Attributes

  • itemid: Returns the item id of the site item
  • title: Returns the title of the site item
  • description: Getter/Setter for the site description
  • owner: Returns the owner of the site item
  • tags: Returns the tags of the site item
  • url: Returns the url of the site
  • content_group_id: Returns the groupId for the content group
  • collab_group_id: Returns the groupId for the collaboration group
  • catalog_groups: Return Site catalog groups
  • layout: Return layout of a site
  • pages: The resource manager for an Initiative's indicators. See :class:~hub.sites.PageManager.

Methods

  • def delete(self):

      """
      Deletes the site. If unable to delete, raises a RuntimeException.
      :return:
          A bool containing True (for success) or False (for failure). 
      .. code-block:: python
          USAGE EXAMPLE: Delete a site successfully
          site1 = myHub.sites.get('itemId12345')
          site1.delete()
          >> True
      """
    

Example to delete a site

  • def update(self, site_properties=None, data=None, thumbnail=None, metadata=None):

      """ Updates the site.
      .. note::
          For site_properties, pass in arguments for only the properties you want to be updated.
          All other properties will be untouched.  For example, if you want to update only the
          site's description, then only provide the description argument in site_properties.
      =====================     ====================================================================
      **Argument**              **Description**
      ---------------------     --------------------------------------------------------------------
      site_properties           Required dictionary. See URL below for the keys and values.
      ---------------------     --------------------------------------------------------------------
      data                      Optional string. Either a path or URL to the data.
      ---------------------     --------------------------------------------------------------------
      thumbnail                 Optional string. Either a path or URL to a thumbnail image.
      ---------------------     --------------------------------------------------------------------
      metadata                  Optional string. Either a path or URL to the metadata.
      =====================     ====================================================================
      To find the list of applicable options for argument site_properties - 
      https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.gis.toc.html#arcgis.gis.Item.update
      :return:
         A boolean indicating success (True) or failure (False).
      .. code-block:: python
          USAGE EXAMPLE: Update a site successfully
          site1 = myHub.sites.get('itemId12345')
          site1.update(site_properties={'description':'Description for site.'})
          >> True
      """
    

Example to update a site

  • def add_catalog_group(self, group_id):

      """
      ===============     ====================================================================
      **Argument**        **Description**
      ---------------     --------------------------------------------------------------------
      group_id            Group id to be added to site catalog
      ===============     ====================================================================
      """
    
  • def delete_catalog_group(self, group_id):

      """
      ===============     ====================================================================
      **Argument**        **Description**
      ---------------     --------------------------------------------------------------------
      group_id            Group id to be added to site catalog
      ===============     ====================================================================
      """
    
  • def update_layout(self, layout):

      """ Updates the layout of the site.
      =====================     ====================================================================
      **Argument**              **Description**
      ---------------------     --------------------------------------------------------------------
      layout                    Required dictionary. The new layout dictionary to update to the site.
      =====================     ====================================================================
      :return:
         A boolean indicating success (True) or failure (False).
      .. code-block:: python
          USAGE EXAMPLE: Update a site successfully
          site1 = myHub.sites.get('itemId12345')
          site_layout = site1.layout
          site_layout.sections[0].rows[0].cards.pop(0)
          site1.update_layout(layout = site_layout)
          >> True
      """
    

2.class SiteManager()

"""
Helper class for managing sites within a Hub. This class is not created by users directly. 
An instance of this class, called 'sites', is available as a property of the Hub object. Users
call methods on this 'sites' object to manipulate (add, get, search, etc) sites.
"""

Methods

  • def add(self, title):

      """ 
      Adds a new site.
      ===============     ====================================================================
      **Argument**        **Description**
      ---------------     --------------------------------------------------------------------
      title               Required string.
      ===============     ====================================================================
      :return:
         The site if successfully added, None if unsuccessful.
      .. code-block:: python
          USAGE EXAMPLE: Add an open data site in Hub successfully 
          site1 = myHub.sites.add(title='My first site')
          site1.item
    
      .. code-block:: python
          USAGE EXAMPLE: Add an initiative site successfully 
          initiative_site = initiative1.sites.add(title=title)
          site1.item
      """
    

Example to add initiative site and standalone site

  • def clone(self, site, pages=True, title=None): """ Clone allows for the creation of a site that is derived from the current site.

      ===============     ====================================================================
      **Argument**        **Description**
      ---------------     --------------------------------------------------------------------
      site                Required Site object of site to be cloned.
      ---------------     --------------------------------------------------------------------
      pages               Optional Boolean. Decides if pages will be copied. Default is True.
      ---------------     --------------------------------------------------------------------
      title               Optional String.
      ===============     ====================================================================
      :return:
         Site.
      """
    

Example to clone a site in the same AGOL org

Example to clone a site in another AGOL org

Example to clone a site from an enterprise to AGOL org

Example to clone a site from an AGOL to enterprise org

  • def get(self, site_id):

      """ Returns the site object for the specified site_id.
      =======================    =============================================================
      **Argument**               **Description**
      -----------------------    -------------------------------------------------------------
      site_id                    Required string. The site itemid.
      =======================    =============================================================
      :return:
          The site object if the item is found, None if the item is not found.
      .. code-block:: python
          USAGE EXAMPLE: Fetch an initiative successfully
          site1 = myHub.sites.get('itemId12345')
          site1.item
      """
    

Example to fetch a site

  • def search(self, title=None, owner=None, created=None, modified=None, tags=None):

      """ 
      Searches for sites.
      ===============     ====================================================================
      **Argument**        **Description**
      ---------------     --------------------------------------------------------------------
      title               Optional string. Return sites with provided string in title.
      ---------------     --------------------------------------------------------------------
      owner               Optional string. Return sites owned by a username.
      ---------------     --------------------------------------------------------------------
      created             Optional string. Date the site was created.
                          Shown in milliseconds since UNIX epoch.
      ---------------     --------------------------------------------------------------------
      modified            Optional string. Date the site was last modified.
                          Shown in milliseconds since UNIX epoch
      ---------------     --------------------------------------------------------------------
      tags                Optional string. User-defined tags that describe the site.
      ===============     ====================================================================
      :return:
         A list of matching sites.
      """
    

Example to search a site

2.class Page()

"""
Represents a page belonging to a site in Hub. A Page is a layout of 
content that can be rendered within the context of a Site
"""
  • itemid: Returns the item id of the page item

  • title: Returns the title of the page item

  • description: Getter/Setter for the page description

  • owner: Returns the owner of the page item

  • tags: Returns the tags of the page item

  • slug: Returns the page slug

  • def update(self, page_properties=None, slug=None, data=None, thumbnail=None, metadata=None):

      """ Updates the page.
      .. note::
          For page_properties, pass in arguments for only the properties you want to be updated.
          All other properties will be untouched.  For example, if you want to update only the
          page's description, then only provide the description argument in page_properties.
      =====================     ====================================================================
      **Argument**              **Description**
      ---------------------     --------------------------------------------------------------------
      page_properties           Required dictionary. See URL below for the keys and values.
      ---------------------     --------------------------------------------------------------------
      data                      Optional string. Either a path or URL to the data.
      ---------------------     --------------------------------------------------------------------
      thumbnail                 Optional string. Either a path or URL to a thumbnail image.
      ---------------------     --------------------------------------------------------------------
      metadata                  Optional string. Either a path or URL to the metadata.
      =====================     ====================================================================
      To find the list of applicable options for argument page_properties - 
      https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.gis.toc.html#arcgis.gis.Item.update
      :return:
         A boolean indicating success (True) or failure (False).
      .. code-block:: python
          USAGE EXAMPLE: Update a page successfully
          page1 = mySite.pages.get('itemId12345')
          page1.update(page_properties={'description':'Description for page.'})
          >> True
      """
    
  • def delete(self):

      """
      Deletes the page. If unable to delete, raises a RuntimeException.
      :return:
          A bool containing True (for success) or False (for failure). 
      .. code-block:: python
          USAGE EXAMPLE: Delete a page successfully
          page1 = myHub.pages.get('itemId12345')
          page1.delete()
          >> True
      """
    

**4. class PageManager(object)

"""
Helper class for managing pages within a Hub. This class is not created by users directly. 
An instance of this class, called 'pages', is available as a property of the Site object. Users
call methods on this 'pages' object to manipulate (add, get, search, etc) pages for a site.
"""
  • def add(self, title, site=None):

      """ 
      Returns the pages linked to the specific site.
      =======================    =============================================================
      **Argument**               **Description**
      -----------------------    -------------------------------------------------------------
      title                      Required string. The title of the new page.
      -----------------------    -------------------------------------------------------------
      site                       Optional string. The site object to add the page to.
      =======================    =============================================================
      :return:
         The page if successfully added, None if unsuccessful.
      .. code-block:: python
          USAGE EXAMPLE: Add a page to a site successfully 
          page1 = mySite.pages.add(title='My first page')
          page1.item
    
      .. code-block:: python
          USAGE EXAMPLE: Add a page successfully 
          page2 = myHub.pages.add(title='My second page', site=mySite)
          page2.item
      """
    
  • def clone(self, page, site=None):

      """
      Clone allows for the creation of a page that is derived from the current page.
    
      ===============     ====================================================================
      **Argument**        **Description**
      ---------------     --------------------------------------------------------------------
      page                Required Page object of page to be cloned.
      ---------------     --------------------------------------------------------------------
      site                Optional Site object.
      ===============     ====================================================================
      :return:
         Page.
      """
    
  • def get(self, page_id):

      """ 
      Returns the page object for the specified page_id.
      =======================    =============================================================
      **Argument**               **Description**
      -----------------------    -------------------------------------------------------------
      page_id                    Required string. The page itemid.
      =======================    =============================================================
      :return:
          The page object if the item is found, None if the item is not found.
      .. code-block:: python
          USAGE EXAMPLE: Fetch a page successfully
          page1 = myHub.pages.get('itemId12345')
          page1.item
      """
    
  • def link(self, page, site=None, slug=None):

      """ 
      Links the page to the specific site.
      =======================    =============================================================
      **Argument**               **Description**
      -----------------------    -------------------------------------------------------------
      page                       Required string. The page object to link.
      -----------------------    -------------------------------------------------------------
      site                       Optional string. The site object to link page to.
      -----------------------    -------------------------------------------------------------
      slug                       Optional string. The slug reference of the page in this site.
      =======================    =============================================================
      :return:
          A bool containing True (for success) or False (for failure).
      .. code-block:: python
          USAGE EXAMPLE: Link a page successfully for specific site
          mySite.pages.link(page_id='itemId12345')
          >> True
          
      .. code-block:: python
          USAGE EXAMPLE: Link a page successfully for site object passed as param
          myHub.pages.link(page_id='itemId12345', site=mySite)
          >> True
      """
    
  • def unlink(self, page, site=None):

      """ 
      Unlinks the page from the specific site.
      =======================    =============================================================
      **Argument**               **Description**
      -----------------------    -------------------------------------------------------------
      page                       Required string. The page object to unlink.
      -----------------------    -------------------------------------------------------------
      site                       Optional string. The site object to unlink page from.
      =======================    =============================================================
      :return:
          A bool containing True (for success) or False (for failure).
      .. code-block:: python
          USAGE EXAMPLE: Unlink a page successfully from specific site
          mySite.pages.unlink(page_id='itemId12345')
          >> True
          
      .. code-block:: python
          USAGE EXAMPLE: Unlink a page successfully from site object passed as param
          myHub.pages.unlink(page_id='itemId12345', site=mySite)
          >> True
      """
    
  • def search(self, title=None, owner=None, created=None, modified=None, tags=None):

      """ 
      Searches for pages.
      ===============     ====================================================================
      **Argument**        **Description**
      ---------------     --------------------------------------------------------------------
      title               Optional string. Return pages with provided string in title.
      ---------------     --------------------------------------------------------------------
      owner               Optional string. Return pages owned by a username.
      ---------------     --------------------------------------------------------------------
      created             Optional string. Date the page was created.
                          Shown in milliseconds since UNIX epoch.
      ---------------     --------------------------------------------------------------------
      modified            Optional string. Date the page was last modified.
                          Shown in milliseconds since UNIX epoch
      ---------------     --------------------------------------------------------------------
      tags                Optional string. User-defined tags that describe the page.
      ===============     ====================================================================
      :return:
         A list of matching pages.
      """
    
Clone this wiki locally