Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update .gitignore and base.py #16

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .envs/.local/.django
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
SECRET_KEY=secret-key
DEBUG=True
ALLOWED_HOSTS=localhost
ALLOWED_HOSTS=localhost,127.0.0.1
DATABASE_URL=postgres://postgres:postgres@db:5432/pizzitalia
DB_HOST=db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=pizzitalia
SENDGRID_API=haha
RECAPTCHA_PUBLIC=public-key
RECAPTCHA_PRIVATE=private-key
STRIPE_KEY=stripe-key
PLACES_API_KEY=AIzaSyCPNm1C3d-T9z8rd_dj_kjsCpxeWpahOEw
PLACES_API_KEY=AIzaSyBzjkB8I36fDz82-zKRREXQ-2A79BVty7s
DEFAULT_FROM_EMAIL=mail@example.com
DJANGO_SETTINGS_MODULE=pizzashop.settings.local


10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"master"
],
"DockerRun.DisableDockerrc": true,
"DockerRun.Containers": [
"7c091114ee45",
"21a697479a56"
]
}
35 changes: 26 additions & 9 deletions compose/local/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
# Use a specific version of Python
FROM python:3.7-slim-buster

# Environment variables for Python behavior
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1

# Set the working directory inside the container
WORKDIR /app

# Install necessary packages and dependencies
RUN apt-get update \
# dependencies for building Python packages
&& apt-get install -y build-essential \
# psycopg2 dependencies
&& apt-get install -y libpq-dev \
# Additional dependencies
&& apt-get install -y telnet netcat \
# cleaning up unused files
&& apt-get install -y build-essential libpq-dev telnet netcat postgresql-client \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/*

# Upgrade pip
RUN pip install --upgrade pip

COPY ./requirements .
RUN pip install -r local.txt
# Install Python dependencies
COPY ./requirements /app/requirements
RUN pip install -r /app/requirements/local.txt

# Copy and adjust permissions for the start script
COPY ./compose/local/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

# Copy and adjust permissions for the wait_for_db script
COPY ./compose/local/wait_for_db.sh /wait_for_db.sh
RUN sed -i 's/\r$//' /wait_for_db.sh
RUN chmod +x /wait_for_db.sh

# Copy application source code
COPY ./src /app

# Default command to run the start script
CMD ["/start"]







7 changes: 7 additions & 0 deletions compose/local/django/start
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ set -o errexit
set -o pipefail
set -o nounset

# Wait for the database to be ready
/wait_for_db.sh

# Run database migrations
python /app/manage.py migrate

# Load initial data
python /app/manage.py loaddata init

# Start the Django development server
python /app/manage.py runserver 0.0.0.0:8000
14 changes: 14 additions & 0 deletions compose/local/wait_for_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

set -e

host="$DB_HOST"
cmd="$@"

until pg_isready -h "$host" -U "$POSTGRES_USER"; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done

>&2 echo "Postgres is up - executing command"
exec $cmd
15 changes: 7 additions & 8 deletions local.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: '3.8'

services:
django:
Expand All @@ -10,26 +10,25 @@ services:
ports:
- "8000:8000"
depends_on:
- "db"
- db
env_file:
- ./src/.env
command: /start
- .envs/.local/.django
command: "/start"
volumes:
- media:/app/media/
- ./src:/app # Ensure the source code is mounted correctly

db:
restart: always
image: postgres:12
container_name: pizza_db
ports:
- "5432"
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_DB=pizzitalia
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres

- POSTGRES_PASSWORD=postgres

volumes:
postgres_data:
Expand Down
2 changes: 1 addition & 1 deletion src/.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SECRET_KEY=secret-key
DEBUG=False
ALLOWED_HOSTS=localhost
DATABASE_URL=postgres://pizzitalia:pizzitalia@pizza_db:5432/postgres
DATABASE_URL=postgres://pizzitalia:So0898705!@pizza_db:5432/pizzitalia
SENDGRID_API=haha
RECAPTCHA_PUBLIC=public-key
RECAPTCHA_PRIVATE=private-key
Expand Down
46 changes: 6 additions & 40 deletions src/menu/admin.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,16 @@
from django.contrib import admin
from .models import RegularPizza, SicilianPizza

from .models import (Extra, Pasta, Platter, RegularPizza, Salad, SicilianPizza,
Sub, Topping)

# Register your models here.


class SaladAdmin(admin.ModelAdmin):
class RegularPizzaAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'price')
list_display_links = ('name',)
ordering = ('id',)


class PlatterAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'small_price', 'large_price')
list_display_links = ('name',)
search_fields = ('name',)
list_per_page = 24
ordering = ('id',)


class ToppingAdmin(admin.ModelAdmin):
list_display = ('id', 'name')
list_display_links = ('name', 'id')
search_fields = ('name', )
ordering = ('id',)


class PastaAdmin(admin.ModelAdmin):
class SicilianPizzaAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'price')
list_display_links = ('name',)
ordering = ('id',)


class PizzaAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'small_price',
'large_price', 'no_of_toppings')
list_display_links = ('name',)
ordering = ('id',)


admin.site.register(Salad, SaladAdmin)
admin.site.register(Platter, PlatterAdmin)
admin.site.register(Topping, ToppingAdmin)
admin.site.register(Pasta, PastaAdmin)
admin.site.register(Sub, PlatterAdmin)
admin.site.register(Extra, ToppingAdmin)
admin.site.register(RegularPizza, PizzaAdmin)
admin.site.register(SicilianPizza, PizzaAdmin)
admin.site.register(RegularPizza, RegularPizzaAdmin)
admin.site.register(SicilianPizza, SicilianPizzaAdmin)
# Other model registrations
Loading