commit message
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
**/__pycache__
|
||||
*.pyc
|
||||
venv
|
||||
78
README.md
Normal file
78
README.md
Normal file
@@ -0,0 +1,78 @@
|
||||
## Summary
|
||||
|
||||
Holiday lettings website
|
||||
|
||||
## Local development
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- GitHub account with read access to this repository
|
||||
- Git CLI
|
||||
- SQLite3 CLI
|
||||
- Python interpreter, version 3.6 or higher.
|
||||
|
||||
In the rest of the local development documentation, it is assumed the command `python` in
|
||||
your OS shell runs the above Python interpreter (unless a virtual environment is activated)
|
||||
|
||||
### macOS / Linux
|
||||
|
||||
#### Clone the repository
|
||||
|
||||
- `cd /path/to/put/project/in`
|
||||
- `git clone https://github.com/grking8/oc-lettings-site.git`
|
||||
|
||||
#### Create the virtual environment
|
||||
|
||||
- `cd /path/to/oc-lettings-site`
|
||||
- `python -m venv venv`
|
||||
- `apt-get install python3-venv` (If previous step errors with package not found on Ubuntu)
|
||||
- Activate the environment `source venv/bin/activate`
|
||||
- Confirm the command `python` now runs the Python interpreter in the virtual environment,
|
||||
`which python`
|
||||
- Confirm the version of the Python interpreter is 3.6 or higher `python --version`
|
||||
- Confirm the command `pip` runs the pip executable in the virtual environment, `which pip`
|
||||
- To deactivate the environment, `deactivate`
|
||||
|
||||
#### Run the site
|
||||
|
||||
- `cd /path/to/oc-lettings-site`
|
||||
- `source venv/bin/activate`
|
||||
- `pip install --requirement requirements.txt`
|
||||
- `python manage.py runserver`
|
||||
- Go to `http://localhost:8000` in a browser
|
||||
- Confirm the site is running and can be navigated (you should see several profiles and lettings)
|
||||
|
||||
#### Linting
|
||||
|
||||
- `cd /path/to/oc-lettings-site`
|
||||
- `source venv/bin/activate`
|
||||
- `flake8`
|
||||
|
||||
#### Unit tests
|
||||
|
||||
- `cd /path/to/oc-lettings-site`
|
||||
- `source venv/bin/activate`
|
||||
- `pytest`
|
||||
|
||||
#### Database
|
||||
|
||||
- `cd /path/to/oc-lettings-site`
|
||||
- Open a shell session `sqlite3`
|
||||
- Connect to the database `.open oc-lettings-site.sqlite3`
|
||||
- Display tables in the database `.tables`
|
||||
- Display columns in the profiles table, `pragma table_info(oc_lettings_site_profile);`
|
||||
- Run a query on the profiles table, `select user_id, favorite_city from
|
||||
oc_lettings_site_profile where favorite_city like 'B%';`
|
||||
- `.quit` to exit
|
||||
|
||||
#### Admin panel
|
||||
|
||||
- Go to `http://localhost:8000/admin`
|
||||
- Login with user `admin`, password `Abc1234!`
|
||||
|
||||
### Windows
|
||||
|
||||
Using PowerShell, as above except
|
||||
|
||||
- To activate the virtual environment, `.\venv\Scripts\Activate.ps1`
|
||||
- Replace `which <my-command>` with `(Get-Command <my-command>).Path`
|
||||
19
manage.py
Executable file
19
manage.py
Executable file
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'oc_lettings_site.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
BIN
oc-lettings-site.sqlite3
Normal file
BIN
oc-lettings-site.sqlite3
Normal file
Binary file not shown.
0
oc_lettings_site/__init__.py
Normal file
0
oc_lettings_site/__init__.py
Normal file
10
oc_lettings_site/admin.py
Normal file
10
oc_lettings_site/admin.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import Letting
|
||||
from .models import Address
|
||||
from .models import Profile
|
||||
|
||||
|
||||
admin.site.register(Letting)
|
||||
admin.site.register(Address)
|
||||
admin.site.register(Profile)
|
||||
5
oc_lettings_site/apps.py
Normal file
5
oc_lettings_site/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class OCLettingsSiteConfig(AppConfig):
|
||||
name = 'oc_lettings_site'
|
||||
7
oc_lettings_site/asgi.py
Normal file
7
oc_lettings_site/asgi.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'oc_lettings_site.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
46
oc_lettings_site/migrations/0001_initial.py
Normal file
46
oc_lettings_site/migrations/0001_initial.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# Generated by Django 3.0 on 2020-06-14 09:35
|
||||
|
||||
from django.conf import settings
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Address',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('number', models.PositiveIntegerField(validators=[django.core.validators.MaxValueValidator(9999)])),
|
||||
('street', models.CharField(max_length=64)),
|
||||
('city', models.CharField(max_length=64)),
|
||||
('state', models.CharField(max_length=2, validators=[django.core.validators.MinLengthValidator(2)])),
|
||||
('zip_code', models.PositiveIntegerField(validators=[django.core.validators.MaxValueValidator(99999)])),
|
||||
('country_iso_code', models.CharField(max_length=3, validators=[django.core.validators.MinLengthValidator(3)])),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Profile',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('favorite_city', models.CharField(blank=True, max_length=64)),
|
||||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Letting',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=256)),
|
||||
('address', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='oc_lettings_site.Address')),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
oc_lettings_site/migrations/__init__.py
Normal file
0
oc_lettings_site/migrations/__init__.py
Normal file
31
oc_lettings_site/models.py
Normal file
31
oc_lettings_site/models.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from django.db import models
|
||||
from django.core.validators import MaxValueValidator, MinLengthValidator
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class Address(models.Model):
|
||||
number = models.PositiveIntegerField(validators=[MaxValueValidator(9999)])
|
||||
street = models.CharField(max_length=64)
|
||||
city = models.CharField(max_length=64)
|
||||
state = models.CharField(max_length=2, validators=[MinLengthValidator(2)])
|
||||
zip_code = models.PositiveIntegerField(validators=[MaxValueValidator(99999)])
|
||||
country_iso_code = models.CharField(max_length=3, validators=[MinLengthValidator(3)])
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.number} {self.street}'
|
||||
|
||||
|
||||
class Letting(models.Model):
|
||||
title = models.CharField(max_length=256)
|
||||
address = models.OneToOneField(Address, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
class Profile(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
favorite_city = models.CharField(max_length=64, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.user.username
|
||||
109
oc_lettings_site/settings.py
Normal file
109
oc_lettings_site/settings.py
Normal file
@@ -0,0 +1,109 @@
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'fp$9^593hsriajg$_%=5trot9g!1qa@ew(o-1#@=&4%=hp46(s'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'oc_lettings_site.apps.OCLettingsSiteConfig',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'oc_lettings_site.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [os.path.join(BASE_DIR, 'templates')],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'oc_lettings_site.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'oc-lettings-site.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
2
oc_lettings_site/tests.py
Normal file
2
oc_lettings_site/tests.py
Normal file
@@ -0,0 +1,2 @@
|
||||
def test_letting_view():
|
||||
assert 1
|
||||
13
oc_lettings_site/urls.py
Normal file
13
oc_lettings_site/urls.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
path('lettings/', views.lettings_index, name='lettings_index'),
|
||||
path('lettings/<int:letting_id>/', views.letting, name='letting'),
|
||||
path('profiles/', views.profiles_index, name='profiles_index'),
|
||||
path('profiles/<str:username>/', views.profile, name='profile'),
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
45
oc_lettings_site/views.py
Normal file
45
oc_lettings_site/views.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from django.shortcuts import render
|
||||
from .models import Letting, Profile
|
||||
|
||||
|
||||
|
||||
|
||||
# Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque molestie quam lobortis leo consectetur ullamcorper non id est. Praesent dictum, nulla eget feugiat sagittis, sem mi convallis eros,
|
||||
# vitae dapibus nisi lorem dapibus sem. Maecenas pharetra purus ipsum, eget consequat ipsum lobortis quis. Phasellus eleifend ex auctor venenatis tempus.
|
||||
# Aliquam vitae erat ac orci placerat luctus. Nullam elementum urna nisi, pellentesque iaculis enim cursus in. Praesent volutpat porttitor magna, non finibus neque cursus id.
|
||||
def index(request):
|
||||
return render(request, 'index.html')
|
||||
|
||||
# Aenean leo magna, vestibulum et tincidunt fermentum, consectetur quis velit. Sed non placerat massa. Integer est nunc, pulvinar a
|
||||
# tempor et, bibendum id arcu. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Cras eget scelerisque
|
||||
def lettings_index(request):
|
||||
lettings_list = Letting.objects.all()
|
||||
context = {'lettings_list': lettings_list}
|
||||
return render(request, 'lettings_index.html', context)
|
||||
|
||||
|
||||
#Cras ultricies dignissim purus, vitae hendrerit ex varius non. In accumsan porta nisl id eleifend. Praesent dignissim, odio eu consequat pretium, purus urna vulputate arcu, vitae efficitur
|
||||
# lacus justo nec purus. Aenean finibus faucibus lectus at porta. Maecenas auctor, est ut luctus congue, dui enim mattis enim, ac condimentum velit libero in magna. Suspendisse potenti. In tempus a nisi sed laoreet.
|
||||
# Suspendisse porta dui eget sem accumsan interdum. Ut quis urna pellentesque justo mattis ullamcorper ac non tellus. In tristique mauris eu velit fermentum, tempus pharetra est luctus. Vivamus consequat aliquam libero, eget bibendum lorem. Sed non dolor risus. Mauris condimentum auctor elementum. Donec quis nisi ligula. Integer vehicula tincidunt enim, ac lacinia augue pulvinar sit amet.
|
||||
def letting(request, letting_id):
|
||||
letting = Letting.objects.get(id=letting_id)
|
||||
context = {
|
||||
'title': letting.title,
|
||||
'address': letting.address,
|
||||
}
|
||||
return render(request, 'letting.html', context)
|
||||
|
||||
# Sed placerat quam in pulvinar commodo. Nullam laoreet consectetur ex, sed consequat libero pulvinar eget. Fusc
|
||||
# faucibus, urna quis auctor pharetra, massa dolor cursus neque, quis dictum lacus d
|
||||
def profiles_index(request):
|
||||
profiles_list = Profile.objects.all()
|
||||
context = {'profiles_list': profiles_list}
|
||||
return render(request, 'profiles_index.html', context)
|
||||
|
||||
# Aliquam sed metus eget nisi tincidunt ornare accumsan eget lac
|
||||
# laoreet neque quis, pellentesque dui. Nullam facilisis pharetra vulputate. Sed tincidunt, dolor id facilisis fringilla, eros leo tristique lacus,
|
||||
# it. Nam aliquam dignissim congue. Pellentesque habitant morbi tristique senectus et netus et males
|
||||
def profile(request, username):
|
||||
profile = Profile.objects.get(user__username=username)
|
||||
context = {'profile': profile}
|
||||
return render(request, 'profile.html', context)
|
||||
7
oc_lettings_site/wsgi.py
Normal file
7
oc_lettings_site/wsgi.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'oc_lettings_site.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
django==3.0
|
||||
flake8==3.7.0
|
||||
pytest-django==3.9.0
|
||||
8
setup.cfg
Normal file
8
setup.cfg
Normal file
@@ -0,0 +1,8 @@
|
||||
[flake8]
|
||||
max-line-length = 99
|
||||
exclude = **/migrations/*,oc-lettings-site,oc_lettings_site/views.py
|
||||
|
||||
[tool:pytest]
|
||||
DJANGO_SETTINGS_MODULE = oc_lettings_site.settings
|
||||
python_files = tests.py
|
||||
addopts = -v
|
||||
4
templates/index.html
Normal file
4
templates/index.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<title>Holiday Homes</title>
|
||||
<h1>Welcome to Holiday Homes</h1>
|
||||
<div><a href="{% url 'profiles_index' %}">Profiles</a></div>
|
||||
<div><a href="{% url 'lettings_index' %}">Lettings</a></div>
|
||||
8
templates/letting.html
Normal file
8
templates/letting.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<title>{{ title }}</title>
|
||||
<h1>{{ title }}</h1>
|
||||
<p>{{ address.number }} {{ address.street }}</p>
|
||||
<p>{{ address.city }}, {{ address.state }} {{ address.zip_code }}</p>
|
||||
<p>{{ address.country_iso_code }}</p>
|
||||
<div><a href="{% url 'lettings_index' %}">Back</a></div>
|
||||
<div><a href="{% url 'index' %}">Home</a></div>
|
||||
<div><a href="{% url 'profiles_index' %}">Profiles</a></div>
|
||||
17
templates/lettings_index.html
Normal file
17
templates/lettings_index.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<title>Lettings</title>
|
||||
<h1>Lettings</h1>
|
||||
{% if lettings_list %}
|
||||
<ul>
|
||||
{% for letting in lettings_list %}
|
||||
<li>
|
||||
<a href="{% url 'letting' letting_id=letting.id %}">
|
||||
{{ letting.title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>No lettings are available.</p>
|
||||
{% endif %}
|
||||
<div><a href="{% url 'index' %}">Home</a></div>
|
||||
<div><a href="{% url 'profiles_index' %}">Profiles</a></div>
|
||||
9
templates/profile.html
Normal file
9
templates/profile.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<title>{{ profile.user.username }}</title>
|
||||
<h1>{{ profile.user.username }}</h1>
|
||||
<p>First name: {{ profile.user.first_name }}</p>
|
||||
<p>Last name: {{ profile.user.last_name }}</p>
|
||||
<p>Email: {{ profile.user.email }}</p>
|
||||
<p>Favorite city: {{ profile.favorite_city }}</p>
|
||||
<div><a href="{% url 'profiles_index' %}">Back</a></div>
|
||||
<div><a href="{% url 'index' %}">Home</a></div>
|
||||
<div><a href="{% url 'lettings_index' %}">Lettings</a></div>
|
||||
17
templates/profiles_index.html
Normal file
17
templates/profiles_index.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<title>Profiles</title>
|
||||
<h1>Profiles</h1>
|
||||
{% if profiles_list %}
|
||||
<ul>
|
||||
{% for profile in profiles_list %}
|
||||
<li>
|
||||
<a href="{% url 'profile' username=profile.user.username %}">
|
||||
{{ profile.user.username }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>No profiles are available.</p>
|
||||
{% endif %}
|
||||
<div><a href="{% url 'index' %}">Home</a></div>
|
||||
<div><a href="{% url 'lettings_index' %}">Lettings</a></div>
|
||||
Reference in New Issue
Block a user