Code Monkey home page Code Monkey logo

lcc-toolkit's Introduction

Law Climate Change Toolkit

A web application which stands as a toolkit for climate change law assessment.

Travis Coverage Docker

Prerequisites

Installing the application

  1. Get the source code:

     git clone https://github.com/eaudeweb/lcc-toolkit
     cd lcc-toolkit
    
  2. Customize the environment files:

     cp docker/postgres.env.example docker/postgres.env
     cp docker/web.env.example docker/web.env
     cp docker/init.sql.example docker/init.sql
    

    Depending on the installation mode, create the docker-compose.override.yml file:

     cp docker-compose.override.[prod|dev].yml docker-compose.override.yml
    
  3. Start the application stack:

     docker-compose up -d
     docker-compose logs
    
  4. Attach to the web service:

     docker-compose run web
    
  5. Create a superuser (for Ansible see https://gist.github.com/elleryq/9c70e08b1b2cecc636d6)

     python manage.py createsuperuser
    

That's it. If you installed in production mode, you should be able to access the app at http://localhost:8000. If you installed in development mode, follow the next steps.

Development setup

Make sure you have the following settings configured correctly (these are the default values in the .example files, so you shouldn't have to change anything).

  • DEBUG=on in web.env file.

  • The docker-compose.override.yml file's web section includes this:

    build:
      context: .
      args:
        REQFILE: requirements-dev.txt
    entrypoint: bash
    

To create and run the develop stack: docker-compose up -d docker-compose ps docker exec -it lcct.web bash

and run the following:

python manage.py migrate
python manage.py load_fixtures
python manage.py createsuperuser
python manage.py search_index --rebuild
python manage.py runserver 0.0.0.0:8000

Now you should be able to access the app in development mode at http://localhost:8000 By default, there will be no Legislation in the database. In order to generate some fake legislation for testing/debugging purposes, you can run the following command:

python manage.py generate_fake_legislation [N]

Where [N] is the number of Legislation objects to generate.

If you need to make front-end changes, make sure to run:

grunt dev

Testing

Allow the user to create a database: docker exec -it lcct.db bash psql -U postgres ALTER USER demo CREATEDB;

To execute the test suite, attach to the web service and run the following:

python manage.py test

Configuration variables

The application expects configuration via environment variables:

DEBUG Turns on debugging behaviour if set to on. Not secure for use in production.

SECRET_KEY Random secret used for Django browser sessions.

DATABASE_URL Django database connector.

ALLOWED_HOSTS A list of host/domain names that this Django site can serve.

SENTRY_DSN, SENTRY_PUBLIC_DSN URL of Sentry server to report errors. Optional.

GA_TRACKING_ID Google Analytics tracking code. Optional.

POSTGRES_PASSWORD PostgreSQL superuser password.

NODE_ENV Define different environments for nodejs. Possible values are: prod, dev.

Migrating data to a different server

To create a Postgresql dump directly from the running lcct.db container, the following command should be used:

docker exec lcct.db pg_dump -U lcct lcct > <backup-file-name>

The -U lcct part refers to the database user, while the last lcct in the docker exec command refers to the database name.

To restore the backed-up data to a fresh install of the lcc-toolkit stack, the following command should be used:

docker exec lcct.db psql -U lcct lcct < <backup-file-name>
The psql parameters are the same as those used for the above pg_dump command.

Migrating Elastic Search from 5.4 to Elastic Search 7.14:

  1. For keeping the volume, you will first need to update to Elastic Search 6.8. The first step is to use the followin elastic search image: docker.elastic.co/elasticsearch/elasticsearch:6.8.18

  2. Add Kibana in the stack: docker.elastic.co/kibana/kibana:6.8.18

  3. Install python packages for Elastic Search version 6.8.18

pip install django-elasticsearch-dsl==6.5.0
pip install elasticsearch-dsl==6.4.0
pip install elasticsearch==6.8.2
  1. Reindex the data
python manage.py search_index --rebuild
  1. Use Kibana Upgrade Assistant to reindex the other nodes that weren't indexed by the python package

  2. Use Kibana console to upgrade the watches index: POST /_xpack/migration/upgrade/.watches

  3. Set elasticsearch to image docker.elastic.co/elasticsearch/elasticsearch:7.14.1 and add the following variable to the environment: discovery.type=single-node

  4. Install the python packages required for ElasticSearch 7.4:

pip install django-elasticsearch-dsl==7.2.0
pip install elasticsearch-dsl==7.3.0
pip install elasticsearch==7.13.3
  1. Reindex one last time from the python shell to check if everything is working as expected:
python manage.py search_index --rebuild

Generate documentation

The application documentation is generated from Sphinx. The following commands should be run on production every time the documentation is changed:

cd docs/
make html

lcc-toolkit's People

Contributors

arielpontes avatar catalinjitea avatar david-batranu avatar dependabot[bot] avatar dianaboiangiu avatar gabrielastrezea avatar mihai-macaneata avatar nico4 avatar sorinstelian avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

catalinjitea

lcc-toolkit's Issues

Remove extra whitespaces from LegisPro-imported articles text

Investors in electric power shall enjoy legal rights and interests with regard to the
              power generated with the help of their investment. They shall have priority in the use
              of the power incorporated into the power networks and authority over the control over
              and use of the power plants for self-supply that are not incorporated in power
              networks.

Restrict Article permissions

It appears that reviewers have the option to delete and add Articles to the toolkit. Fortunately, to our knowledge, no reviewer has taken advantage of these privileges. However, to prevent accidental deletions and insertions, would it be possible to de-link these privileges from the access of reviewers?

Only accept numbers in article number

Legislation (ID) LAW NO.22/2001 Petroleum and Natural Gas Indonesia - Article Article 50 was created.
Legislation (ID) LAW NO.22/2001 Petroleum and Natural Gas Indonesia - Article a. was updated.
Legislation (ID) LAW NO.22/2001 Petroleum and Natural Gas Indonesia - Article b. was updated.
Legislation (ID) LAW NO.22/2001 Petroleum and Natural Gas Indonesia - Article c. was updated.
Legislation (ID) LAW NO.22/2001 Petroleum and Natural Gas Indonesia - Article d. was updated.
Legislation (ID) LAW NO.22/2001 Petroleum and Natural Gas Indonesia - Article e. was updated.
Legislation (ID) LAW NO.22/2001 Petroleum and Natural Gas Indonesia - Article f. was updated.
Legislation (ID) LAW NO.22/2001 Petroleum and Natural Gas Indonesia - Article g. was updated.

Point a, b, c... should be in article body.

Result sorting in Legislation Explorer

A search using the legislation explorer should be able to sort results using the following criteria:
(a) by relevance of the result;
(b) by date of promulgation, with the option to sort from the latest law promulgated to the earliest law promulgated and vice versa; or
(c) by country (in alphabetical order).

Order articles

Currently, Legislation Articles are ordered by id in article list pages, which sometimes yields confusing results. It should be possible to enforce an order based on something more reliable.

Error when importing some laws from LegisPro

Due probably to inexistent countries.

Warning Legislation (BM) 2009 Energy Act generated the folowing error: null value in column "country_id" violates not-null constraint
DETAIL:  Failing row contains (161, English, Law, 2009, null, , null, (BM) 2009 Energy Act, null, null, National, null, Official, null, null, {}, {}, 2019-04-25 15:07:17.351952+00, 2019-04-25 15:07:17.351967+00, t, akn-bm-doc-2009_Energy_Act.xml).
Warning Legislation (AU) 2008 National Gas Act generated the folowing error: null value in column "country_id" violates not-null constraint
DETAIL:  Failing row contains (166, English, Law, 2008, null, , null, (AU) 2008 National Gas Act, null, null, National, null, Official, null, null, {}, {}, 2019-04-25 15:08:13.121655+00, 2019-04-25 15:08:13.12167+00, t, akn-au-act-2008_National_Gas_Act.xml).

Add assessment page filtering

Suggestions for gaps should be filtered to only come from countries with similar metadata to the assessment's country. More details on exact metadata used will come later.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.