Skip to content

Project set up cheat sheet

Solomiia Lenio edited this page Jul 29, 2019 · 26 revisions

This cheat-sheet will help you to set up your workspace for a better development process.

Table of Contents

For Linux OS

We highly suggest choosing Linux OS while working on Portfolio-APPS as you will be able to use all the libraries and packages needed as well as omit database errors etc.

Prerequisities

At the beginning check all the prerequisites:

   sudo apt-get install python3-pip
   sudo pip3 install virtualenv

Database set up

As this project uses PostgreSQL database, you need to install it and create your local database:

   sudo apt-get install postgresql postgresql-contrib 
   sudo update-rc.d postgresql enable
   service postgresql start   # enable PostreSQL service on your device
   su - postgres   # switch to postres user
   psql   # enter PostgreSQL shell

In the PostgreSQL shell type

   CREATE DATABASE portfoliouser;
   # check the spelling of database name, it should be exact like the one written in settings.py 

Check if the database have been successfully created by typing

  \l   # lists all the postgres databases 

in the shell. Exit PostgreSQL shell by typing

   \q

You can switch to your user or root by

   exit

For a detailed tutorial check on PostgreSQL official documentation.

Virtual environment creation

For a more convenient development process create virtual environment with the following command in your project directory:

   virtualenv venv -p /usr/bin/python3.5

Use

   source venv/bin/activate

to activate your virtual environment.

Project set up

After activating your virtual environment you need to install the libraries needed

   pip3 install -r requirements.txt

Create directories for static files

   mkdir -p static/media static/static static/static-only

In project root directory create .env file consisting environment variables listed

   export USER="database_user_name"   # usually postgres
   export PASSWORD="database_user_password"
   export EMAIL_HOST_USER="email_adress"
   export EMAIL_HOST_PASSWORD="email_password"

P.S. If you use gmail email for Portfolio-APPS development don't forget to activate less secure option for your account, otherwise the app won't be able to send any mesages. To finally start the app you need to update environment variables

   . .env

make database migrations, collect statics and start the server.

   chmod +x manage.py
   ./manage.py makemigrations
   ./manage.py migrate
   ./manage.py collectstatic
   ./manage.py runserver

If you get errors like this
   django.db.utils.OperationalError: FATAL:  role "solia" does not exist

go into the portfolio/settings.py file and edit the value of environment variables by hands like this

   DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'portfoliouser',
        'USER': 'username',  # your username
        'PASSWORD': 'password',   # your user password
        'HOST': 'localhost',
        'PORT': '',
    }

WARNING: don't commit your edited settings.py file to the repository!


Social login set up

After you started the app, the final step is to set up social login service. Create an admin account for your app

   ./manage.py createsuperuser

Enter the username, e-mail address, and password.

Start the app and log in as admin at http://127.0.0.1:8000/admin

Go into Social accounts section and find Social application.

Visit Google developers console and create your own OAuth app. After that enter Client id and Secret key in the Django administrator page.

Follow this tutorial for better help.

You are now fully ready to work on Portfolio-APPS!


For Windows OS

If you work with Windows OS, be ready for some troubles, as you won't be ble to install all the libraries and there might be some troubles with database set up. Still, follow this cheat-sheet for a little help :)

Prerequisities

At the beginning check all the prerequisites:

   pip install virtualenv

Database set up

To create and manage PostgreSQL database you need to download PostgreSQL installer and following all the instructions given install PostgreSQL service on your device.

You can follow this tutorial if you have any struggles during the installation process.

After successful installation, open PostgreSQL shell and type the following command to create the database:

   CREATE DATABASE portfoliouser;  
   # check the spelling of database name, it should be exact like the one written in settings.py 

You can check if the database was created by typing

   \l   # lists all the PostgreSQL databases

Virtual environment creation

For a more convenient development process create virtual environment with the following command in your project directory:

   virtualenv venv

Use

   \path\to\env\Scripts\activate.bat

to activate your virtual environment.

Project set up

After activating your virtual environment you need to install the libraries needed

   pip install -r requirements.txt

Create directories for static files

   mkdir static/media
   mkdir static/static
   mkdir static/static-only

Now,you need to set up the values of environment variables.

Go into the portfolio/settings.py file and edit the value of environment variables by hands like this

   DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'portfoliouser',
        'USER': 'username',  # your username
        'PASSWORD': 'password',   # your user password
        'HOST': 'localhost',
        'PORT': '',
    }

Edit, as well, values of

   'EMAIL_HOST_USER': 'your_email',
   'EMAIL_HOST_PASSWORD': 'email_password',

WARNING: don't commit your edited settings.py file to the repository!

If you want to use gmail email for Portfolio-APPS development don't forget to activate less secure option for your account, otherwise, the app won't be able to send any mesages.

To finally start the app you need to make database migrations, collect statics and start the server.

   python manage.py makemigrations
   python manage.py migrate
   python manage.py collectstatic
   python manage.py runserver

Social login set up

Go and check Social login set up cheat-sheet for Linux.

It works for Windows and for any other OS as well.