# SmoothGlue Django Map App

This Django app provides backend api to support front end Map features such as Map Imagery Layers, CZML / GeoJSON python helper classes (coming soon), etc.

## Development

### Set Up Virtual Environment and Install Required Packages

This project uses [Poetry](https://python-poetry.org/) for dependency management and packaging.

1. Install Poetry if you haven't already.
2. Run `poetry install` to create a virtual environment and install dependencies.

### Running Management Commands With Your App

- **smoothglue/map/tests/boot_django.py** to set up a Django environment using Django’s settings.configure() and django.setup() to allow interacting with your app outside of a project.

  - The settings.configure() call inside this file takes a list of arguments that are equivalent to the variables defined in a settings.py file. Anything you would need in your settings.py to make your app run gets passed into settings.configure().
  - This file is used by the test runner and other scripts to bootstrap the environment.

- **djangoshell.py** to spawn a Django shell that’s aware of your app
- **loaddata.py "some argument"** load fixture data into your app's database and test out
- **run_test.sh** to run all tests for your app (executes `smoothglue/map/tests/loadtests.py`)
- **makemigrations.py** to create a migration file
- **migrate.py** to perform table migrations

## Using App Package (Locally)

The steps for using your package locally are:

### Build Your App

Run `poetry build` inside the main level of this repo. This creates a directory called `dist` and builds your new package into source and binary formats (e.g., **smoothglue_django_map-<version>.tar.gz** and **smoothglue_django_map-<version>-py3-none-any.whl**).

### Install App Inside a Django Project

1. Before installing the package, make sure that there is a virtual environment set up inside of the Django project you want to install your app into.

2. Then use pip or poetry to install the package:

   ```bash
   # Using pip
   pip install [path to your newly packaged file]

   # Using Poetry
   poetry add [path to your newly packaged file]
   ```

3. Update the `settings.py` file inside that Django project to point to the new app name:

   ```python
   INSTALLED_APPS = [
     "smoothglue.map",
     ...,
   ]
   ```

4. Update the `urls.py` file inside that Django project to point to the new app name: :

   ```python
   urlpatterns = [
     path("", include("smoothglue.map.urls")),
     ...,
   ]
   ```

5. Run the development server to confirm the project continues to work.

   [GIF COMING SOON]

## Install App From Gitlab PyPI Package (Official Use)

1. Before installing the package, make sure that there is a virtual environment set up inside of the Django project you want to install the app into.

2. Use pip and the following command inside the Django project:
   ```python
   pip install <app_name> --index-url https://__token__:<your_personal_token>@code.dsop.structsure.io/api/v4/projects/<project_id>/packages/pypi/simple
   ```

## Other File Descriptions

- MANIFEST.in - Tells the build process which non common files and folders that should be packaged
- pyproject.toml - Package and project metadata / configuration
- tox.ini - Used to configure different types of packages,
