Skip to content

Commit 5942e9a

Browse files
committed
Add part 1
1 parent 34dba25 commit 5942e9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+7246642
-0
lines changed

.gitignore

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
98+
__pypackages__/
99+
100+
# Celery stuff
101+
celerybeat-schedule
102+
celerybeat.pid
103+
104+
# SageMath parsed files
105+
*.sage.py
106+
107+
# Environments
108+
.env
109+
.venv
110+
env/
111+
venv/
112+
ENV/
113+
env.bak/
114+
venv.bak/
115+
116+
# Spyder project settings
117+
.spyderproject
118+
.spyproject
119+
120+
# Rope project settings
121+
.ropeproject
122+
123+
# mkdocs documentation
124+
/site
125+
126+
# mypy
127+
.mypy_cache/
128+
.dmypy.json
129+
dmypy.json
130+
131+
# Pyre type checker
132+
.pyre/
133+
134+
# pytype static type analyzer
135+
.pytype/
136+
137+
# Cython debug symbols
138+
cython_debug/

part1/docker-compose.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: "3.8"
2+
3+
services:
4+
5+
database:
6+
container_name: perusable-database
7+
environment:
8+
- POSTGRES_DB=perusable
9+
- POSTGRES_USER=perusable
10+
- POSTGRES_PASSWORD=perusable
11+
image: postgres:13.2
12+
ports:
13+
- "5433:5432"
14+
volumes:
15+
- perusable-database:/var/lib/postgresql/data
16+
17+
server:
18+
build:
19+
context: ./server
20+
container_name: perusable-server
21+
depends_on:
22+
- database
23+
environment:
24+
- SQL_ENGINE=django.db.backends.postgresql
25+
- SQL_DATABASE=perusable
26+
- SQL_USER=perusable
27+
- SQL_PASSWORD=perusable
28+
- SQL_HOST=perusable-database
29+
- SQL_PORT=5432
30+
command: [ "bash", "start.sh" ]
31+
ports:
32+
- 8003:8000
33+
volumes:
34+
- ./server:/usr/src/app
35+
36+
volumes:
37+
perusable-database:

part1/server/.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.dockerignore
2+
*.pyc
3+
__pycache__
4+
env

part1/server/Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM python:3.9
2+
3+
WORKDIR /usr/src/app
4+
5+
ENV PYTHONUNBUFFERED 1
6+
7+
ENV PYTHONDONTWRITEBYTECODE 1
8+
9+
COPY ./requirements.txt .
10+
11+
RUN pip install --upgrade pip
12+
13+
RUN pip install -r requirements.txt

part1/server/catalog/__init__.py

Whitespace-only changes.

part1/server/catalog/admin.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.contrib import admin
2+
3+
from .models import Wine
4+
5+
6+
@admin.register(Wine)
7+
class WineAdmin(admin.ModelAdmin):
8+
fields = ('id', 'country', 'description', 'points', 'price', 'variety', 'winery',)
9+
list_display = ('id', 'country', 'points', 'price', 'variety', 'winery',)
10+
list_filter = ('country', 'variety', 'winery',)
11+
ordering = ('variety',)
12+
readonly_fields = ('id',)

part1/server/catalog/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class CatalogConfig(AppConfig):
5+
name = 'catalog'

part1/server/catalog/filters.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from django.db.models import Q
2+
3+
from django_filters.rest_framework import CharFilter, FilterSet
4+
5+
from .models import Wine
6+
7+
8+
class WineFilterSet(FilterSet):
9+
query = CharFilter(method='filter_query')
10+
11+
def filter_query(self, queryset, name, value):
12+
search_query = Q(
13+
Q(variety__contains=value) |
14+
Q(winery__contains=value) |
15+
Q(description__contains=value)
16+
)
17+
return queryset.filter(search_query)
18+
19+
class Meta:
20+
model = Wine
21+
fields = ('query', 'country', 'points',)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[
2+
{
3+
"model": "catalog.Wine",
4+
"fields": {
5+
"country": "US",
6+
"description": "A delicious bottle of wine.",
7+
"id": "58ba903f-85ff-45c2-9bac-6d0732544841",
8+
"points": 90,
9+
"price": 100.00,
10+
"variety": "Cabernet Sauvignon",
11+
"winery": "Stag's Leap"
12+
}
13+
},
14+
{
15+
"model": "catalog.Wine",
16+
"fields": {
17+
"country": "US",
18+
"description": "Another good wine.",
19+
"id": "21e40285-cec8-417c-9a26-4f6748b7fa3a",
20+
"points": 87,
21+
"price": 18.00,
22+
"variety": "Merlot",
23+
"winery": "Barnard Griffin"
24+
}
25+
},
26+
{
27+
"model": "catalog.Wine",
28+
"fields": {
29+
"country": "France",
30+
"description": "A spicy, toasty, fruity wine.",
31+
"id": "0082f217-3300-405b-abc6-3adcbecffd67",
32+
"points": 90,
33+
"price": 43.00,
34+
"variety": "Chardonnay",
35+
"winery": "Au Pied du Mont Chauve"
36+
}
37+
}
38+
]

0 commit comments

Comments
 (0)