CoSo is a software that analyzes the behaviour of different polls regarding political elections. It is implemented in Django (version 1.10).
$ cd ~/CoSo
$ git pull
$ 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_
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/
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.
Download Python
On Windows, you may need to modify your PATH if it is not done at the installation
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 (for python) and Python35\Scripts (for pip) repositories on your Path.
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.
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/
"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/
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.
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.
Pre-installed:
- mysql
- You must have the 'coso' database created
- type
python manage.py migrate
- Make the changes in models.py
- For example, if the changes are in the polls app :
$ python manage.py makemigrations polls
- You should see a new file in polls/migrations: polls/migrations/000x.py
- To apply the migration to the Database :
$ python manage.py migrate
How to run tests ? Use the following command
$ python manage.py test polls
to run the tests from polls/tests.py
This command will create the test database and run all the tests. Doc : https://docs.djangoproject.com/en/1.10/intro/tutorial05/
The front-end website has been developped in the polls app.
In order to install the front-end dependencies (Bootstrap), the user must use bower.
Bower is a command line utility. Install it with npm :
$ npm install -g bower
You can find more information here : https://bower.io/
Once bower is installed, install the FE dependencies with :
# installs the project dependencies listed in bower.json
$ bower install