Giter Site home page Giter Site logo

purbeurrewebapp's Introduction

Pur Beurre Web Application Django

This application uses the OpenFoodFacts API to find a better product for your health than the one that you planned to eat (or drink). So, to stay healthy :

Create a PostgreSQL database for the application and a new user

!!! maybe you have to install PostgreSQL !!! Connect to PostgreSQL client, create database and new user with privileges:

$ sudo su - postgres
postgres@somewhere:~$ psql
postgres=# CREATE USER "pur_beurre_web_app";
postgres=# CREATE DATABASE "db_pur_beurre";
postgres=# ALTER USER pur_beurre_web_app WITH PASSWORD 'Hummm';
postgres=# GRANT ALL PRIVILEGES ON DATABASE db_pur_beurre TO pur_beurre_web_app;
postgres=# \q

Clone the application and install the necessary requirements

Clone the folder, go inside, create a virtual environment for Python with virtualenv (!!! maybe you have to install virtualenv !!!), use it, and install all necessary dependencies (django, django-debug-toolbar, django-registration-redux, psycopg2, sqlalchemy, openfoodfacts-python, django-fixture-magic):

$ git clone https://github.com/JBthePenguin/PurBeurreWebApp.git
$ cd PurBeurreWebApp
$ virtualenv -p python3 env
$ source env/bin/activate
(env)$ pip install -r requirements.txt

Create tables

ONLY if you want to start the application without product in database and request the OpenFoodFacts API for each search, use the branch 'without_product_in_db':

(env)$ git checkout without_product_in_db

Make migrations to create the tables:

(env)$ cd pur_beurre_django_app
(env)$ ./manage.py makemigrations
(env)$ ./manage.py migrate

ONLY if you use the branch 'master', insert datas of products:

  • Option 1 : fastest one, with a dump file* (.json) and the django loaddata command
(env)$ wget -O products.json "https://drive.google.com/uc?export=download&id=1esW4xwGNLCk9ah-hcKbuMCZ2iBjFh5FO"
(env)$ ./manage.py loaddata products.json
  • Option 2 : slowest one, with the script that imports datas from the OpenFoodFacts API
(env)$ python insert_products_in_db.py

Start and use the Application**

(env)$ ./manage.py runserver

NOW, with your favorite browser, go to this url http://127.0.0.1:8000/ and enjoy to use application.

Tests

Install selenium...

(env)$ pip install selenium

... and maybe you have to install ChromeWebDriver to use Chrome or GreckoWebdriver to use firefox and set it in all app's test.py line 2:

from selenium.webdriver.chrome.webdriver import WebDriver

or

from selenium.webdriver.firefox.webdriver import WebDriver

During the tests, a temporary DB is creating, so you need to update the role of application:

$ sudo su - postgres
postgres@somewhere:~$ psql
postgres=# ALTER USER pur_beurre_web_app CREATEDB;
postgres=# \q

Run the tests:

(env)$ ./manage.py test

Admin site

Create a "superuser" account, start the server ... :

(env)$ ./manage.py createsuperuser
(env)$ ./manage.py runserver

... and login to the admin site : http://127.0.0.1:8000/admin/ and enter your new superuser name and password.

  • If you use the branch 'without_product_in_db', there is a button to update the database (delete all products that not used in favorite).
๐Ÿค˜

* The default language setting is french, if you want to change, you have to choice the second one, and modify france and fr with an other available languages

  • with the branch 'master' in insert_products_in_db.py line 21.
  • with the branch 'without_product_in_db' in search_request.py line 15 and 61.

** If you want access to the custom 'error 404' page, you have to set DEBUG = False in settings.py line 26, and run the server in insecure mode:

DEBUG = False
(env)$ ./manage.py runserver --insecure

purbeurrewebapp's People

Contributors

jbthepenguin avatar

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.