Giter Club home page Giter Club logo

cti-website-backend's Introduction

CTI-Website-Backend

Maintainability Test Coverage

Contributing

If you would like to contribute to the Civic Tech Index project, please see the issues and project management board in the repository for the React app which uses this Django app as its API backend.

This project uses Django with Django REST Framework. If you are not already familiar with Django, we suggest you work through the Django tutorial and the Django REST Framework tutorial to get familiar with the tools this project uses. (Don't spend too long on these; just use them to get a feel for Django development.)

This project can be run using Docker OR installed directly on your machine.

Project Requirements

This project can be run locally using either Docker, Docker Compose or your local python. If you are running without docker please ensure that the right version of python is installed. We suggest using pyenv to manage multiple versions of python.

Running this project on your machine with Docker

This repository contains a Dockerfile for building a container for running our Django project - in dev and in AWS via FARGATE. To use Docker for development, you will want to use the project's docker-compose.yaml to also create a Postgres database container, a volume for persisting your data, and a network that allows your web container to talk to your database container.

  1. Install Docker
  2. Clone this repository
  3. Copy config/.env.example to config/.env
  4. Build and configure your docker container by running the following command:
    docker-compose up -d --build
    
  5. Our docker-compose.yaml creates a volume for persisting the database information so you should only have to run the migrations, load the data, and create a superuser the first time you create your containers.
    init/setup-db.sh
    
  6. The site is now running at https://localhost:8888/

Running this project directly on your machine (no containers)

Requirements:

  • Python 3.8
  • Postgres 12 or greater

Setup

  1. Install PostgreSQL if you haven't already.

  2. Install Python 3.8. Try pyenv

  3. Clone this repository

  4. Create and activate a virtual environment

  5. Install the packages

    pip install -r requirements.txt
    
  6. Set up a Postgres database and user for this application. Instructions

  7. Copy config/.env.example to config/.env and edit to provide the database credentials your project will use. The contents of your .env file should provide the following information ( do not use the default values in the example ):

    POSTGRES_NAME='<YOUR_DATABASE_NAME>'
    POSTGRES_PASSWORD='<YOUR_PASSWORD>'
    POSTGRES_USER='<YOUR_POSTGRES_USERNAME>'
    POSTGRES_HOST='localhost'
    
  8. Execute the following steps to load the environment variables from above and set up your database. You should only need to do these steps the first time you create a new database.

    source config/.env
    python manage.py migrate
    python manage.py createsuperuser
    python manage.py loaddata init/organizations.json
    pytest
    

    If tests fail please reach out out to the team on the Slack Channel.

  9. Start your web server in the foreground:

    source config/.env
    python manage.py runserver
    
  10. The site is now running at https://localhost:8000/

Using this project

To run the automated tests in this project

If you are running this project using Docker, log into the docker container: docker exec -ti cti-web /bin/bash

From the root of the project, run the tests: pytest

To run tests and see the coverage report run: pytest --cov=civictechindexadmin

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.