Skip to content

Commit

Permalink
Merge pull request #3 from fahmi-ramadhan/dev3
Browse files Browse the repository at this point in the history
Dev3
  • Loading branch information
fahmi-ramadhan authored Oct 11, 2023
2 parents 2b65031 + 1081998 commit ec8b603
Show file tree
Hide file tree
Showing 152 changed files with 33,680 additions and 67 deletions.
32 changes: 32 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
**/*.pyc
**/*.pyo
**/*.mo
**/*.db
**/*.css.map
**/*.egg-info
**/*.sql.gz
**/__pycache__/
.cache
.project
.idea
.pydevproject
.idea/workspace.xml
.DS_Store
.git/
.sass-cache
.vagrant/
dist
docs
env
logs
src/{{ project_name }}/settings/local.py
src/node_modules
web/media
web/static/CACHE
stats
Dockerfile
.gitignore
Dockerfile
db.sqlite3
**/*.md
logs/
26 changes: 26 additions & 0 deletions .github/workflows/pbp-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Deploy

on:
push:
branches:
- main
- master

jobs:
Deployment:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- name: Cloning repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Push to Dokku server
uses: dokku/github-action@master
with:
branch: 'main'
git_remote_url: ssh://dokku@${{ secrets.DOKKU_SERVER_IP }}/${{ secrets.DOKKU_APP_NAME }}
ssh_private_key: ${{ secrets.DOKKU_SSH_PRIVATE_KEY }}


32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM python:3.10-slim-buster

WORKDIR /app

ENV PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
DJANGO_SETTINGS_MODULE=shopping_list.settings \
PORT=8000 \
WEB_CONCURRENCY=2

# Install system packages required Django.
RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

RUN addgroup --system django \
&& adduser --system --ingroup django django

# Requirements are installed here to ensure they will be cached.
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt

# Copy project code
COPY . .

RUN python manage.py collectstatic --noinput --clear

# Run as non-root user
RUN chown -R django:django /app
USER django

# Run application
# CMD gunicorn shopping_list.wsgi:application
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
release: django-admin migrate --noinput
web: gunicorn library_app.wsgi
569 changes: 568 additions & 1 deletion README.md

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion library_app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@
"""

from pathlib import Path
import environ
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

env = environ.Env()

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-1c#l(dh4=!b6kfdu(#y(wckrf&qjfx-5d9x&29mmsd1&=u&fd+'

# Automatically determine environment by detecting if DATABASE_URL variable.
# DATABASE_URL is provided by Heroku if a database add-on is added (e.g. Heroku Postgres).
PRODUCTION = env.bool('PRODUCTION', False)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

Expand All @@ -37,7 +44,10 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main'
'main',
'tailwind',
'theme',
'django_browser_reload',
]

MIDDLEWARE = [
Expand All @@ -48,6 +58,7 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_browser_reload.middleware.BrowserReloadMiddleware',
]

ROOT_URLCONF = 'library_app.urls'
Expand Down Expand Up @@ -81,6 +92,12 @@
}
}

# Set database settings automatically using DATABASE_URL.
if PRODUCTION:
DATABASES = {
'default': env.db('DATABASE_URL')
}
DATABASES["default"]["ATOMIC_REQUESTS"] = True

# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
Expand Down Expand Up @@ -118,7 +135,17 @@

STATIC_URL = 'static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

TAILWIND_APP_NAME = 'theme'

INTERNAL_IPS = [
"127.0.0.1",
]

NPM_BIN_PATH = r"C:\Program Files\nodejs\npm.cmd"
1 change: 1 addition & 0 deletions library_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('main.urls')),
path("__reload__/", include("django_browser_reload.urls")),
]
22 changes: 22 additions & 0 deletions main/migrations/0004_item_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.5 on 2023-09-23 03:56

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('main', '0003_rename_book_item'),
]

operations = [
migrations.AddField(
model_name='item',
name='user',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
preserve_default=False,
),
]
2 changes: 2 additions & 0 deletions main/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.db import models
from django.contrib.auth.models import User

class Item(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
author = models.CharField(max_length=255)
category = models.CharField(max_length=255)
Expand Down
33 changes: 20 additions & 13 deletions main/templates/add_book.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{% extends 'base.html' %}

{% block content %}
<h1>Add New Book</h1>
<div class="flex justify-center items-center h-screen">

<form method="POST">
{% csrf_token %}
<table>
{{ form.as_table }}
<tr>
<td></td>
<td>
<input type="submit" value="Add Book"/>
</td>
</tr>
</table>
</form>
<div class = "add_book bg-blue-50 p-8 rounded shadow-md w-full md:w-1/3">

<h1 class="text-2xl font-bold mb-4">Add New Book</h1>

<form method="POST">
{% csrf_token %}
<table class="w-full mb-4">
{{ form.as_table }}
</table>
<div class="flex justify-end">
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" type="submit">
Add Book
</button>
</div>
</form>

</div>

</div>

{% endblock %}
50 changes: 50 additions & 0 deletions main/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% extends 'base.html' %}

{% block meta %}
<title>Login</title>
{% endblock meta %}

{% block content %}

<div class="flex justify-center items-center h-screen">

<div class = "login bg-white p-8 rounded shadow-md w-full md:w-1/2 lg:w-1/3">

<h1 class="text-2xl font-bold mb-4">Login</h1>

<form method="POST" action="">
{% csrf_token %}
<div class="mb-4">
<label class="block font-bold mb-2" for="username">
Username:
</label>
<input type="text" name="username" placeholder="Username" class="form-control w-full rounded-md shadow-md px-1 border-gray-500 border" id="username">
</div>
<div class="mb-4">
<label class="block font-bold mb-2" for="password">
Password:
</label>
<input type="password" name="password" placeholder="Password" class="form-control w-full rounded-md shadow-md px-1 border-gray-500 border" id="password">
</div>
<div class="flex justify-end">
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" type="submit">
Login
</button>
</div>
</form>

{% if messages %}
<ul class="mt-4">
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}

<p class="mt-4">Don't have an account yet? <a href="{% url 'main:register' %}" class="text-blue-500">Register Now</a></p>

</div>

</div>

{% endblock content %}
Loading

0 comments on commit ec8b603

Please sign in to comment.