-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
286 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
|
||
jobs: | ||
Deployment: | ||
if: github.ref == 'refs/heads/main' | ||
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
release: django-admin migrate --noinput | ||
web: gunicorn adventurers_inventory.wsgi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.forms import ModelForm | ||
from main.models import Item | ||
|
||
class ItemForm(ModelForm): | ||
class Meta: | ||
model = Item | ||
fields = ["name", "amount", "description", "price", "item_level", "use"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block content %} | ||
<h1>Add New Item</h1> | ||
|
||
<form method="POST"> | ||
{% csrf_token %} | ||
<table> | ||
{{ form.as_table }} | ||
<tr> | ||
<td></td> | ||
<td> | ||
<input type="submit" value="Add Item"/> | ||
</td> | ||
</tr> | ||
</table> | ||
</form> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,44 @@ | ||
<h1>{{app_name}}</h1> | ||
{% extends 'base.html' %} | ||
|
||
<h5>Nama: </h5> | ||
<p>{{ name }}</p> <!-- Ubahlah sesuai dengan nama kamu --> | ||
<h5>Kelas: </h5> | ||
<p>{{ class }} </p> <!-- Ubahlah sesuai dengan kelas kamu --> | ||
{% block content %} | ||
<h1>{{app_name}}</h1> | ||
|
||
<h5>Name:</h5> | ||
<p>{{name}}</p> | ||
|
||
<h5>Class:</h5> | ||
<p>{{class}}</p> | ||
|
||
<table> | ||
<tr> | ||
<th>Name</th> | ||
<th>Amount</th> | ||
<th>Description</th> | ||
<th>Price</th> | ||
<th>iLvl</th> | ||
<th>Use</th> | ||
</tr> | ||
|
||
{% comment %} Berikut cara memperlihatkan data produk di bawah baris ini {% endcomment %} | ||
|
||
{% for product in products %} | ||
<tr> | ||
<td>{{product.name}}</td> | ||
<td>{{product.amount}}</td> | ||
<td>{{product.description}}</td> | ||
<td>{{product.price}}</td> | ||
<td>{{product.item_level}}</td> | ||
<td>{{product.use}}</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
|
||
<br /> | ||
|
||
<a href="{% url 'main:create_item' %}"> | ||
<button> | ||
Add New Item | ||
</button> | ||
</a> | ||
|
||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
from django.urls import path, include | ||
from main.views import show_main | ||
from main.views import show_main, create_item, show_xml, show_json, show_xml_by_id, show_json_by_id | ||
|
||
|
||
|
||
|
||
app_name = 'main' | ||
|
||
urlpatterns = [ | ||
path('', show_main, name='show_main') | ||
path('', show_main, name='show_main'), | ||
path('create-item', create_item, name='create_item'), | ||
path('xml/', show_xml, name='show_xml'), | ||
path('json/', show_json, name='show_json'), | ||
path('xml/<int:id>/', show_xml_by_id, name='show_xml_by_id'), | ||
path('json/<int:id>/', show_json_by_id, name='show_json_by_id') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,46 @@ | ||
from django.shortcuts import render | ||
from django.http import HttpResponseRedirect | ||
from main.forms import ItemForm | ||
from django.urls import reverse | ||
from main.models import Item | ||
from django.http import HttpResponse | ||
from django.core import serializers | ||
|
||
# Create your views here. | ||
def show_main(request): | ||
item = Item.objects.all() | ||
|
||
context = { | ||
'app_name': 'Adventurer\'s Inventory', | ||
'name': 'Daffa Mohamad Fathoni', | ||
'class': 'PBP E' | ||
'class': 'PBP E', | ||
'Item': item | ||
} | ||
|
||
return render(request, "main.html", context) | ||
return render(request, "main.html", context) | ||
|
||
def create_item(request): | ||
form = ItemForm(request.POST or None) | ||
|
||
if form.is_valid() and request.method == "POST": | ||
form.save() | ||
return HttpResponseRedirect(reverse('main:show_main')) | ||
|
||
context = {'form': form} | ||
return render(request, "create_item.html", context) | ||
|
||
def show_xml(request): | ||
data = Item.objects.all() | ||
return HttpResponse(serializers.serialize("xml", data), content_type="application/xml") | ||
|
||
def show_json(request): | ||
data = Item.objects.all() | ||
return HttpResponse(serializers.serialize("json", data), content_type="application/json") | ||
|
||
def show_xml_by_id(request, id): | ||
data = Item.objects.filter(pk=id) | ||
return HttpResponse(serializers.serialize("xml", data), content_type="application/xml") | ||
|
||
def show_json_by_id(request, id): | ||
data = Item.objects.filter(pk=id) | ||
return HttpResponse(serializers.serialize("json", data), content_type="application/json") |
Oops, something went wrong.