Giter Site home page Giter Site logo

mycoso's Introduction

CoSo : Comportement Sondage

CoSo is a software that analyzes the behaviour of different polls regarding political elections. It is implemented in Django (version 1.10).

1. Git commands :

To get last modifications :

$ cd ~/CoSo
$ git pull

To create a new branch from master

$ git checkout master
$ git fetch
$ git pull (to get the last version of master)
$ git branch _name-of-the-branch_
$ git checkout _name-of-the-branch_

To add your modifications

First check that you are not working on master, and then : $ cd ~/CoSo
$ git add .
$ git status
$ git commit -m "message detailing the modifications"
$ git push

In order to write some git commit messages, we will follow the rules from http://chris.beams.io/posts/git-commit/

2. Setting up the development environment with virtualenv

virtualenv is a tool to create isolated Python environments. virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need.

2.1. Installation

2.1.1 Python, pip

Download Python

On Windows, you will need to modify your PATH
To do this, go on Control Panel > System > Advanced System Settings
This will open a new window. Click on Environment Variable. Highlight the Path variable in the "System variables" section and click the Edit button. Then add the Python35 repository and Python35\Scripts on your Path.

2.1.2 Virtualenv

Install virtualenv via pip:
$ pip install virtualenv

Basic Usage - Create a virtual environment for a project:
$ cd my_project_folder
$ virtualenv ENV
virtualenv ENV will create a folder in the current directory which will contain the Python executable files, and a copy of the pip library which you can use to install other packages. The name of the virtual environment (in this case, it was ENV) can be anything; omitting the name will place the files in the current directory instead.

This creates a copy of Python in whichever directory you ran the command in, placing it in a folder named ENV.

2.2. Usage of the virtual environment

To begin using the virtual environment, it needs to be activated (everytime the project is being run):
$ source ENV/bin/activate
The name of the current virtual environment will now appear on the left of the prompt (e.g. (ENV)Your-Computer:your_project UserName$) to let you know that it’s active. From now on, any package that you install using pip will be placed in the ENV folder, isolated from the global Python installation.

Install packages as usual, for example: $ pip install -r requirements.txt
If you are done working in the virtual environment for the moment, you can deactivate it:
$ deactivate

Find more at : http://docs.python-guide.org/en/latest/dev/virtualenvs/

2.3. Requirements files

"Requirements files" are files containing a list of items to be installed using pip install like so:

$ pip install -r requirements.txt

Requirements File Format:

Logically, a Requirements file is just a list of pip install arguments placed in a file. Note that you should not rely on the items in the file being installed by pip in any particular order.

Requirements files are used to hold the result from pip freeze for the purpose of achieving repeatable installations (for example when sharing code on a project). In this case, your requirement file contains a pinned version of everything that was installed when pip freeze was run.

How to add a new item to be installed for the project :

$ pip install package1
$ pip freeze -r requirements.txt

Requirements files are used to force pip to properly resolve dependencies.

Find more at : https://pip.pypa.io/en/stable/user_guide/

3. The development server (to run the Backend)

Install MySQL Server, and create a database called 'coso'.
To verify that Django project works : change into the outer coso directory $ cd coso/, if you haven’t already, and run the following commands:

$ python manage.py runserver
You’ll see the following output on the command line:

November 25, 2016 - 15:50:53
Django version 1.10, using settings 'coso.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Now that the server’s running, visit http://127.0.0.1:8000/polls with your Web browser.

3. Django project organisation

coso/

  • coso/
  • init.py
  • settings.py
  • urls.py
  • wsgi.py
  • polls/
  • init.py
  • admin.py
  • apps.py
  • migrations/
    • init.py
  • models.py
  • tests.py
  • views.py
  • manage.py

These files were automatically created by Django, they are:

coso/ : root directory is just a container for your project.
manage.py: A command-line utility that lets you interact with this Django project in various ways. coso/coso/ directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it (e.g. coso.urls).
coso/init.py: An empty file that tells Python that this directory should be considered a Python package.
coso/settings.py: Settings/configuration for this Django project. Django settings will tell you all about how settings work.
coso/urls.py: The URL declarations for this Django project; a “table of contents” of your Django-powered site. You can read more about URLs in URL dispatcher.
mysite/wsgi.py: An entry-point for WSGI-compatible web servers to serve your project.

4. Database

4.1. Setting up the database

Pre-installed:

  • mysql
  1. You must have the 'coso' database created
  2. type python manage.py migrate

4.2. How to add a new class to the database or modify an existing one

  1. Make the changes in models.py
  2. For example, if the changes are in the polls app : $ python manage.py makemigrations polls
  3. You should see a new file in polls/migrations: polls/migrations/000x.py
  4. To apply the migration to the Database : $ python manage.py migrate

mycoso's People

Contributors

nicolasparent avatar

Watchers

James Cloos avatar  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.