Skip to content

Commit 20f5df2

Browse files
author
Simeon J Morgan
authored
Merge pull request #1 from commoncode/feature/initial-setup
Initial Setup
2 parents c3ecee0 + 37c64ca commit 20f5df2

19 files changed

Lines changed: 536 additions & 0 deletions

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# The Pacific Connect Community Database
2+
3+
The [Pacific Connect](https://www.icdp.com.au/pacific-connect/) community database provides a
4+
means for participants in Pacific Connect to find details for one another and to maintain their own contact details through a
5+
web portal.
6+
7+
It is being developed as part of the Vanuatu Code Project.
8+
9+
## Getting started
10+
11+
1. Install a git client (such as the GitHub Desktop application from https://desktop.github.com/)
12+
2. Clone this repository. (If using GitHub Desktop, there is [documentation for cloning a
13+
repository](https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/adding-and-cloning-repositories/cloning-a-repository-from-github-to-github-desktop))
14+
3. Open the `Getting Started` documentation in `/docs/getting-started.md` and follow the steps for local development
15+
set-up.

docs/getting-started.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Getting Started
2+
3+
This page describes the steps needed to get the Pacific Connect Community Database set up on your local machine for development. The
4+
approach presented here is the simplest approach, an alternative approach is briefly mentioned under [Alternative
5+
Approach: Pyenv](#alternative-approach-pyenv) at the end.
6+
7+
It assumes that you have already cloned this repository to your own computer (as outlined in the `README.md` file) and
8+
that you have a recent version of Python installed on your local computer.
9+
10+
Python installation instructions for several operating systems can be found at
11+
http://pacific-coding.commoncode.io/getting-started/py-install/ - although you should install version 3.10 if possible
12+
13+
14+
## Requirements
15+
16+
- A Git client (such as GitHub Desktop)
17+
- This repository _cloned_ or your local computer.
18+
- Python 3.8 or later installed
19+
20+
## Setup Steps
21+
22+
To carry out these steps, you will need to be using your computer's _command line_. If you are not familiar with the
23+
concept of the command line an introduction can be found at
24+
http://pacific-coding.commoncode.io/getting-started/terminal/
25+
26+
On the command line, you will need to be in the base directory of this repository on your computer - that is, the
27+
directory that has the `README.md` file in it.
28+
29+
### 1. Create and activate a virtual environment
30+
31+
A _virtual environment_ (or _virtualenv_) in Python keeps the different _libraries_ you install separate for different
32+
projects. That means that if you're working on two different projects, they can have different versions of the same
33+
library (e.g. Django) without affecting each other.
34+
35+
Create the virtual environment for this project:
36+
37+
If using Windows:
38+
```powershell
39+
python -m venv venv
40+
```
41+
42+
If using MacOS or Linux:
43+
```bash
44+
python3 -m venv venv
45+
```
46+
47+
Once you have created your virtual environment, you need to _activate_ it so that Python knows to use the libraries in
48+
your virtual environment.
49+
50+
To activate your virtual environment:
51+
52+
If using Windows:
53+
```powershell
54+
venv\Scripts\activate
55+
```
56+
57+
If using MacOS or Linux:
58+
```
59+
source venv/bin/activate
60+
```
61+
62+
If your virtual environment has been activated, you should see the prefix `(venv)` before the prompt on the command
63+
line.
64+
65+
**NOTE: You will need to activate your virtual environment every time you want to work on this project**.
66+
67+
For more information about virtual environments, see:
68+
- [Why do we need to use virtualenvs](http://pacific-coding.commoncode.io/python-intro/virtualenvs/)
69+
- [Create a Virtual Environment](http://pacific-coding.commoncode.io/python-intro/create-a-venv/)
70+
71+
72+
### 2. Install the Python requirements
73+
74+
This project has a `requirements.txt` file that lists all the Python libraries required to run the project. Once you
75+
have activated your virtual environment, you can install the python libraries with:
76+
77+
```bash
78+
pip install -r requirements.txt
79+
```
80+
81+
This will install all requirements listed in the `requirements.txt` file, and as new requirements are added to the
82+
project they will be added to the `requirements.txt` file.
83+
84+
85+
### 3. Run migrations
86+
87+
Migrations are the way that Django manages changes to the structure of the database over time.
88+
89+
Before running migrations, you will need to change to the directory (`src`) that contains the code. Different projects
90+
have different conventions about the name of the directory where the code is kept, but `src` is a common name.
91+
92+
```bash
93+
cd src
94+
```
95+
96+
To set up your database the first time, run:
97+
98+
Windows:
99+
```bash
100+
python manage.py migrate
101+
```
102+
103+
MacOS or Linux:
104+
```bash
105+
python3 manage.py migrate
106+
```
107+
108+
The first time you run this, you will see a series of messages that look like:
109+
110+
```
111+
Operations to perform:
112+
Apply all migrations: admin, auth, contenttypes, sessions
113+
Running migrations:
114+
Applying contenttypes.0001_initial... OK
115+
Applying auth.0001_initial... OK
116+
Applying admin.0001_initial... OK
117+
Applying admin.0002_logentry_remove_auto_add... OK
118+
...
119+
```
120+
121+
This indicates that the migrations have run and the database is set up.
122+
123+
**NOTE: You will need to run migrations fairly regularly in order to keep your database structure up to date**
124+
125+
A summary about database set-up in Django can be found at:
126+
- [Pacific Coding: Set up a
127+
Database](http://pacific-coding.commoncode.io/django/your-first-django-project/#set-up-a-database)
128+
129+
More information in Migrations can be found at:
130+
- [Django's Migrations documentation](https://docs.djangoproject.com/en/4.0/topics/migrations/)
131+
132+
More information on Models can be found at:
133+
- [MDN's Django Tutorial Part 3](https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Models)
134+
- [Django's Models documentation](https://docs.djangoproject.com/en/4.0/topics/db/models/)
135+
136+
137+
### 4. Continue to _Running the Application_
138+
139+
Now that you have installed all the prerequisites and run migrations for the first time, you can move to
140+
[running-the-application].
141+
142+
## Alternative Approach: Pyenv
143+
144+
This approach is only recommended if you need to run multiple different versions of Python (such as Python 3.8 _and_
145+
Python 3.10) on the same computer.
146+
147+
[Pyenv](https://github.com/pyenv/pyenv) is a tool that allows you to have multiple Python versions installed and switch
148+
between them. When combined with [Pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv) it also provides the
149+
ability to easily switch between named virtual environments.
150+
151+
To install, see the instructions at [Pyenv Installation](https://github.com/pyenv/pyenv#installation) and
152+
[Pyenv-virtualenv Installation](https://github.com/pyenv/pyenv-virtualenv#installation)
153+
154+
155+
156+
[running-the-application]: running-the-application.md

docs/glossary.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Glossary
2+
3+
- **venv**: Virtual environment
4+
- **virtualenv**: Virtual environment

docs/index.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Pacific Connect Community Database
2+
3+
## About
4+
5+
The Pacific Connect Community Database is a web-based directory for Pacific Connect participants. It has been developed by participants in the
6+
Vanuatu Code Project.
7+
8+
## Contents
9+
10+
1. [Getting Started][getting-started] - Step by step instructions to set up your development environment
11+
2. [Running the application][running-the-application] - Step by step instructions to set up your development
12+
environment
13+
3. [Glossary][glossary] - A Glossary of terms and acronyms
14+
15+
[getting-started]: getting-started.md
16+
[running-the-application]: running-the-application.md
17+
[glossary]: glossary.md

docs/running-the-application.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Running the Application
2+
3+
Once you have completed the set-up of the development environment from the [Getting Started][getting-started] page, you
4+
can start and use the application on your local computer.
5+
6+
This page assumes that you are on the _command line_, in the directory containing the `README.md` file for this project.
7+
For more information about the command line, see the [Getting Started][getting-started] page.
8+
9+
If you have just come from the Getting Started documentation, you may be in the `src` directory. To move out of this directory, on the command line do:
10+
11+
```bash
12+
cd ..
13+
```
14+
15+
That command will move you 'up' a directory, out of the `src` directory.
16+
17+
### 1. Activate your virtual environment
18+
19+
If your Python virtual environment is not already activated, activate it:
20+
21+
If using Windows:
22+
```powershell
23+
venv\Scripts\activate
24+
```
25+
26+
If using MacOS or Linux:
27+
```
28+
source venv/bin/activate
29+
```
30+
31+
You will need to do this every time you are working with this project on the command line.
32+
33+
34+
### 2. Run migrations
35+
36+
In _Getting Started_ you will have run migrations for the first time. It is a good practice to run migrations every
37+
time you _pull_ changes from the GitHub repository in case those changes included database migrations.
38+
39+
First, move back into the `src` directory:
40+
41+
```bash
42+
cd src
43+
```
44+
45+
Then run the migrations with:
46+
47+
Windows:
48+
```bash
49+
python manage.py migrate
50+
```
51+
52+
MacOS or Linux:
53+
```bash
54+
python3 manage.py migrate
55+
```
56+
If there are no database changes, you will see a message like:
57+
```
58+
Operations to perform:
59+
Apply all migrations: admin, auth, contenttypes, sessions
60+
Running migrations:
61+
No migrations to apply.
62+
```
63+
64+
Otherwise, if there have been database changes you will see a list of applied migrations, like:
65+
```
66+
Operations to perform:
67+
Apply all migrations: admin, auth, contenttypes, sessions
68+
Running migrations:
69+
Applying contenttypes.0001_initial... OK
70+
...
71+
```
72+
73+
More information in Migrations can be found at:
74+
- [Django's Migrations documentation](https://docs.djangoproject.com/en/4.0/topics/migrations/)
75+
76+
More information on Models can be found at:
77+
- [MDN's Django Tutorial Part 3](https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Models)
78+
- [Django's Models documentation](https://docs.djangoproject.com/en/4.0/topics/db/models/)
79+
80+
81+
### 3. Run the development server
82+
83+
Django incorporates its own development web server. This gives you a way to interact with the application without
84+
needing a server on the Internet running it. In this mode, it will also present you with more detailed error messages.
85+
86+
To start the development server, run:
87+
88+
```bash
89+
python manage.py runserver
90+
```
91+
92+
Once the server has started running, you can open it in your browser (Firefox, Chroma, Safari, Edge, or whatever you
93+
use) by going to this address:
94+
```
95+
http://127.0.0.1:8000/
96+
```
97+
98+
You should now see the ICDP Online Directory application in your web browser.
99+
100+
101+
[getting-started]: getting-started.md

requirements.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# This file is autogenerated by pip-compile with python 3.10
3+
# To update, run:
4+
#
5+
# pip-compile requirements.in
6+
#
7+
asgiref==3.5.2
8+
# via django
9+
black==22.6.0
10+
# via -r requirements.in
11+
click==8.1.3
12+
# via black
13+
django==4.1
14+
# via -r requirements.in
15+
isort==5.10.1
16+
# via -r requirements.in
17+
mypy-extensions==0.4.3
18+
# via black
19+
pathspec==0.9.0
20+
# via black
21+
platformdirs==2.5.2
22+
# via black
23+
sqlparse==0.4.2
24+
# via django
25+
tomli==2.0.1
26+
# via black

src/community_db/__init__.py

Whitespace-only changes.

src/community_db/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

src/community_db/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class CommunityDbConfig(AppConfig):
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "community_db"

src/community_db/migrations/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)