This repository contains the Transport Nantes website code.
This program is distributed under the GNU GPL v3 licence. See the file LICENCE for its text.
(to come)
You will need the following softwares:
Vagrant and VirtualBox are optional (but recommended) if you use Linux. Those two software will be used to create a virtual machine on which you will run the website. This machine is will be running Ubuntu 20.04, and Vagrant is used to script the installation of requirements on it. The following instructions assume you have installed all the softwares listed above. For Mac users, VirtualBox won't run on the new M1 chips(i.e. M1, M1 Pro, M1 Max) so follow the instructions below for Mac users.
At the end of those instructions, you should be able to run a local version of the website.
-
Fork the repository on GitHub. Let's assume you have created a new repository called
mobilitains
in/Documents/mobilitains
. -
Use the
cd
command to change the current directory to the repository. E.g. :cd /Documents/mobilitains/
-
Use
vagrant up --provision
to create the virtual machine. This can take some times depending on your internet connection. It creates an Ubuntu environnement with all requirements to run the website (Django etc.). -
Use
vagrant ssh
to connect to the virtual machine. You can check that if your terminal displaysvagrant@ubuntu-focal:~$
. -
Use
cd /vagrant/
to move to the website directory. You can find the website's code in this folder. -
Enter the vagrant's virtual environnement by using
source venv.vagrant/bin/activate
. You can confirm it works by seeing the(venv.vagrant) vagrant@ubuntu-focal:/vagrant$
in your terminal. -
Enter the website's directory by using
cd transport_nantes/transport_nantes
. Your current directory should now be(venv.vagrant) vagrant@ubuntu-focal:/vagrant/transport_nantes/transport_nantes$
-
Create a file called
settings_local.py
and fill it with the content ofsettings_local.py.DEV.template
. This file isn't tracked on GitHub, so you can edit it without affecting the repository. It's mandatory to create this file in order to run the website. The content ofsettings_local.py.DEV.template
is a base that defines the settings for the development environment. -
Go one folder up using
cd ..
, you're current directory should now be(venv.vagrant) vagrant@ubuntu-focal:/vagrant/transport_nantes$
-
You're ready to run the website, you can use
python manage.py runserver 0.0.0.0:8000
to run the server. If you open your browser athttp://localhost:8000/
or0.0.0.0:8000
, you should see the website. However at this point, you should see a message saying you have X unapplied migrations in your console, and a 404 error.
Indeed, even though your configuration is fine, you don't have the database created yet.
-
Fork the repository on GitHub. Let's assume you have created a new repository called
mobilitains
in/Documents/mobilitains
. -
Use the
cd
command to change the current directory to the repository. E.g. :cd /Documents/mobilitains/
. -
Create a python virtual environment in the
mobilitains
folder withpython -m venv venv
. Activate the environment withsource venv/bin/activate
and clone your forked repo tomobilitains
. -
Use
cd
to change directory totn_web
. E.g. :cd /Documents/mobilitains/tn_web
. Install project dependencies withpip install -r requirements.txt
. If this doesn't work install dependencies manually. E.g. :pip install django, pip install requests, etc
. -
Create a folder for yor logs in your root folder. Let's assume you created a new folder
mbt_logs
in/mobilitains/mbt_logs
. Next, create atn_web.log
file inside thembt_logs
folder. E.g. :/mobilitains/mbt_logs/tn_web.log
. -
Enter the website's directory by using
cd transport_nantes/transport_nantes
. Your current directory should now bemobilitains/tn_web/transport_nantes/transport_nantes
. -
Create a file called
settings_local.py
and fill it with the content ofsettings_local.py.DEV.template
. This file isn't tracked on GitHub, so you can edit it without affecting the repository. It's mandatory to create this file in order to run the website. The content ofsettings_local.py.DEV.template
is a base that defines the settings for the development environment. -
In
settings_local.py
, above theLOG_DIR
variable, create apath
variable and add your file path to themobilitains
directory. I.e.path = "/Users/name/Documents/mobilitains"
. Next, replace the path in theLOG_DIR
variable withos.path.join(path, "mbt_logs/")
. -
Go one folder up using
cd ..
, you're current directory should now be/mobilitains/tn_web/transport_nantes
. -
You're ready to run the website, you can use
python manage.py runserver
to run the server. If you open your browser athttp://127.0.0.1:8000/
, you should see the website. However at this point, you should see a message saying you have X unapplied migrations in your console, or some kind of database error on the live site.
Indeed, even though your configuration is fine, you don't have the database created yet.
-
Start by running the
python manage.py migrate
command. You should now see a new file nameddb.sqlite3
in your current directory. -
Run
python manage.py createsuperuser
to create a superuser, you will use this to connect to Django's admin interface.
The database is set but still empty. Let's display a "Hello, world!" message in the landing page of your local version of the website !
-
Run
python manage.py runserver 0.0.0.0:8000
to run the server. -
Open your browser at
http://localhost:8000/admin
or0.0.0.0:8000/admin
. You're facing Django Admin's interface. Use the credentials you created to connect to it.
The landing page is an instance of an app named "topicblog", however because your database is empty, you will also need to create 1 item before you can see the landing page :
- Edition of the landing page
[todo]
Congratulations, you customized your first page on the website ! You can now see it athttp://localhost:8000/
or0.0.0.0:8000/
!
Make sure your code is well formatted.
This means : Complies to PEP8 (https://www.python.org/dev/peps/pep-0008/) and PEP257 (https://www.python.org/dev/peps/pep-0257/).
You can use linters such as flake8
and pylint
to check your code.
It must be written in English.
- Your commits should be short and concise.
- Use the present tense ("Add feature" not "Added feature")
- Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
- Reference issues and pull requests liberally after the first line
Thank you for your interest in contributing to this project. The simplest way for you to contribute is to fork the repository and start a pull request.
If you want to report a bug, please open an issue on GitHub.
You can send your questions to this address.