README.md
author Riwad Salim
Tue, 05 Jun 2018 18:36:39 +0200
changeset 3 12fb6a535aa6
parent 1 309def3c05dc
child 18 a8b07497ae4b
permissions -rw-r--r--
Add specific templates to iconolab-mcc and edit docker settings

## ICONOLAB-MCC 

### 1. Configuration and setup for development  

### virtualenv

- Install pip
- Create a virtualenv for the project (using virtualenvwrapper is a good idea if possible). Python version is 3.6.5

Example
```
virtualenv -p python3.6 ./virtualenv
. virtualenv/bin/activate

cd src/
pip install -r requirements/dev.txt
```


### Django project setup

- Install iconolab
    pip install -e path/iconolab

- Copy iconolab/src/settings/dev.py.tmpl into iconolab-mcc/src/iconolab_mcc/settings/dev.py, adapt content to configuration
- cd into iconolab-mcc/src folder and run

    python manage.py migrate

to create database tables

- Run

    python manage.py createsuperuser

to create an admin user


- Collect static files

    python manage.py collectstatic
    

- Use Docker adress for HOST in settings

- don't use os.path.join(BASE_DIR, 'media') in settings

- make JS_DEV_MODE afalse (if not, it will not connect correctly on server)


### Iconolab to Iconolab-mcc

- Create uploads and cache repertories 
    MEDIA_ROOT/uploads and MEDIA_ROOT/cache

- Move the run directory into iconolab-mcc

- Create static directory

- Edit the settings in dev.py (using absolute path is better)
    BASE_DIR = '../iconolab-mcc/src/iconolab_mcc'

    STATIC_ROOT =  '../iconolab-mcc/run/web/static/site'
    MEDIA_ROOT = '../iconolab-mcc/run/web/media'

- Create templates and views directories

    iconolab-mcc/src/iconolab_mcc/templates
    iconolab-mcc/src/iconolab_mcc/views


- Add the charter, credits and legalmentions templates and it views and URLs (the URLs need to be on top)

    exemple for credits view in iconolab-mcc/src/iconolab_mcc/views/misc.py : 
    
    class CreditsView(TemplateView):
    template_name='iconolab_mcc/misc/credits.html'

    exemple for credits url in iconolab-mcc/src/urls.py  : 

    path('credits/', views.misc.CreditsView.as_view(), name="iconolab_mcc_credits"),


- Add line "from iconolab_mcc import" views in file iconolab_mcc/urls.py to access views


- Change "from iconolab.settings import *" into "from iconolab_mcc.settings import *" in the settings


- Add help and footer templates

    iconolab-mcc/src/iconolab_mcc/templates/misc/help.html
    iconolab-mcc/src/iconolab_mcc/templates/partials/footer.html




- Add logo_mcc_footer in src/iconolab_mcc/static/iconolab_mcc/img



### Docker 

Migrate the file docker-compose.yml in iconolab-mcc project

- Create containers

    docker-compose up

- Run containers
    
    docker-compose start


### Elasticsearch

Some objects in Iconolab are indexed and searched using ElasticSearch. You need to configure Haystack (see dev.py.tmpl, HAYSTACK_CONNECTIONS) and run:

    python manage.py rebuild_index


### 2. Python server

- cd into the iconolab/src folder and run

    python manage.py runserver

By default, the app is accessible through http://127.0.0.1:8000/home


### 3. Importing initial data from CSV

Make sure to have the following in the same folder:

* All the images to import. The image names must match their respective item inventory number.
* A csv file that contains the metadata for the items you will import
* A json file for initializing the collection in the database. (Optional if you want to import images in an existing collection)
* A json file for the metacategories that will be linked to the collection.
* Ensure the folder settings.MEDIA_ROOT+/uploads/ exists

The following django manage.py command is used to import collection data and images:

```
python manage.py importimages <:export-csv-path> --delimiter <:delimiter> --encoding <:encoding> --collection-json <:collection_fixture_FILENAME> (OR --collection-id <:collection_id> if collection already exists in db) --metacategories-json <:metacategories_json_FILENAME>
```

Options:
- ```--delimiter```: the delimiter for the csv file. For special ascii characters add a # before the code. Supported special chars are 9 (tab), 29 (Group separator), 30 (Record separator), 31 (Unit separator)
- ```--encoding```: the encoding provided if the csv is not in utf-8. Exemple: 8859 for ISO-8859
- ```--collection-json```: the json file to create the collection from
- ```--collection-id```: the id of the collection to import into, it must already exist
- ```--metacategories-json```: the json file to create metacategories on the collection we're importing into
- ```--jpeg-quality```: the jpeg quality: default to the setting IMG_JPG_DEFAULT_QUALITY
- ```--no-jpg-conversion```: set to True so the command will not convert the images to jpg. Useful for pre-converted jpeg and especially when importing large image banks
- ```--img-filename-identifier```: the column from which the command will try to find images in the folder: use keys from the setting IMPORT_FIELDS_DICT. Default is "INV".
- ```--filename-regexp-prefix```: allows you to customize the way the command try to find images by specifying a regexp pattern to match *before* the identifier provided in img-filename-identifier. Defaults to .*
- ```--filename-regexp-suffix```: allows you to customize the way the command try to find images by specifying a regexp pattern to match *after* the identifier provided in img-filename-identifier. Defaults to [\.\-_].*

Notes:
* The export csv path will be used to find everything else (images and fixtures files).
* If the csv file is not encoded in utf-8, you MUST provide --encoding so the csv file can be read
* You MUST provide either --collection-json or --collection-id, else the command doesn't know to which collection the objects will belong to.
* To find all images for a given item, the command will try to match filenames according to the pattern build from the 3 options: filename-regexp-prefix+<value of img-filename-identifier>+filename-regexp-suffix. For instance by default, for an object with an INV of MIC.3.10, the files MIC.3.10.jpg and MIC.3.10.verso.jpg would be matched and linked to the object.
* The command will first parse the csv, then create the objects in the database (Item and ItemMetadata), then move the images to the settings.MEDIA_ROOT+/uploads/ folder after converting them to JPEG, then create the database objects for the images. The command will ignore any csv row that lacks an image or any csv row that already has a database entry for the collection (by default INV number is used to test if a database entry exists).
    

### 4. Updating already existing data

Another management command allows for editing data using only a .csv file. The command will go through the csv and update the metadatas for every objects it finds in the database with the csv row content.

```
python manage.py updatecollection --collection-id=<:id> --delimiter=<:delimiter> --encoding=<:encoding>
```

Options:
- ```--delimiter```: the delimiter for the csv file. For special ascii characters add a # before the code. Supported special chars are 9 (tab), 29 (Group separator), 30 (Record separator), 31 (Unit separator)
- ```--encoding```: the encoding provided if the csv is not in utf-8. Exemple: 8859 for ISO-8859
- ```--collection-id```: the id of the collection to import into, it must already exist


 * document the test import command  : `python manage.py importimages --collection-json dossierImportMontauban/montauban_collection.json --metacategories-json dossierImportMontauban/montauban_metacategories_import.json --encoding "UTF-8" --delimiter "," dossierImportMontauban/ExportMontauban.csv`