<commit_before>api-django
==========

Configure PostgreSQL
--------------------

PostgreSQL server needs to be installed and started.

On Ubuntu, this means installing the following packages:

```bash
apt install postgresql-9.6 postgis
```

For production, you need to create a database and a role with owner
rights, and add the `postgis` extension to the database.

```bash
sudo -u postgres psql
# the following commmands should be typed inside psql

CREATE ROLE api;
CREATE DATABASE api WITH owner api;
USE api;
CREATE EXTENSION postgis;
```

For testing, the `api` role need to be a superuser to be able to create
a new test database with the `postgis` extension.

```bash
sudo -u postgres psql
# the following commmands should be typed inside psql

ALTER ROLE api WITH superuser;
```

Install requirements
--------------------

Python 3.6 is recommended.

To install Python dependencies, run :

```bash
pip install -r requirements.txt
```

To run the tests :

```bash
coverage run --source='.' manage.py test
```

in the `src` directory.

Create super user (person)
--------------------------

Run:

```bash
./manage.py createsuperperson
```

Create super user (client)
--------------------------

Open a django console with:

```bash
./manage.py shell
```

Then execute the following commands:

```python
from clients.models import Client
c = Client.objects.create(label='client_login', name='Nom du client')
c.role.set_password('<PASSWORD>')
c.role.is_superuser = True
c.role.save()
```
<commit_msg>add public endpoints description to the README<commit_after>api-django
==========

Configure PostgreSQL
--------------------

PostgreSQL server needs to be installed and started.

On Ubuntu, this means installing the following packages:

```bash
apt install postgresql-9.6 postgis
```

For production, you need to create a database and a role with owner
rights, and add the `postgis` extension to the database.

```bash
sudo -u postgres psql
# the following commmands should be typed inside psql

CREATE ROLE api;
CREATE DATABASE api WITH owner api;
USE api;
CREATE EXTENSION postgis;
```

For testing, the `api` role need to be a superuser to be able to create
a new test database with the `postgis` extension.

```bash
sudo -u postgres psql
# the following commmands should be typed inside psql

ALTER ROLE api WITH superuser;
```

Install requirements
--------------------

Python 3.6 is recommended.

To install Python dependencies, run :

```bash
pip install -r requirements.txt
```

To run the tests :

```bash
coverage run --source='.' manage.py test
```

in the `src` directory.

Create super user (person)
--------------------------

Run:

```bash
./manage.py createsuperperson
```

Create super user (client)
--------------------------

Open a django console with:

```bash
./manage.py shell
```

Then execute the following commands:

```python
from clients.models import Client
c = Client.objects.create(label='client_login', name='Nom du client')
c.role.set_password('<PASSWORD>')
c.role.is_superuser = True
c.role.save()
```

# Public endpoints

## `/events`

The list of all published, upcoming events (paginated).

To get the complete list in one request, use `/events/summary`.

## `/groups`

The list of all published groups.

To get the complete list in one request, use `/groups/summary`.

# Resources filters

Each resource expose a series of filter that you can use to fetch a subset of the resource collection.

Filters can be passed as query parameters, eg `https://api.lafranceinsoumise.fr/legacy/groups/?contact_email=<EMAIL>`

## `groups` and `events`

* `contact_email`
* `nb_path` : path on legacy NationBuilder website
* `close_to` : find events close to a given location. Value must be a JSON Object with
    * `max_distance` : distance in meters
    * `coordinates` : array of coordinates [Longitude, Latitude]

## `events`

* `start_time`: ISO 8601 Datetime, get only events starting after this date

{'fraction_non_alphanumeric': 0.14147828295656592, 'fraction_numerical': 0.003048006096012192, 'mean_word_length': 3.4699205448354142, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1104592', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1130, 'n_words': 487}