Skip to content
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
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Django #
*.log
*.pot
*.pyc
__pycache__
db.sqlite3
media

# Backup files #
*.bak

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Installation

```
virtualenv venv
source venv/bin/activate

pip install -r requirement.txt

cd nalo_ice_cream

python manage.py migrate

python manage.py runserver
```

Une fois le serveur lancé, l'automate est accessible à cette URL : http://127.0.0.1:8000/ice_cream/
Le panneau d'administration est à cet URL : http://127.0.0.1:8000/ice_cream/admin

# Nalo lance le 1er glacier automate au monde !!

Tu es un nouveau développeur dans l'équipe Nalo, et ta première tâche consiste à développer le nouvel automate de Nalo.
Expand Down
Empty file.
1 change: 1 addition & 0 deletions nalo_ice_cream/ice_cream/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from django.contrib import admin
6 changes: 6 additions & 0 deletions nalo_ice_cream/ice_cream/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class IceCreamConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'ice_cream'
41 changes: 41 additions & 0 deletions nalo_ice_cream/ice_cream/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 5.2 on 2025-05-01 08:58

import django.core.validators
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Command',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(default='WqHsxWBaBMPWSzPMqUkGbx', max_length=22)),
('content', models.JSONField(blank=True, null=True)),
('price', models.PositiveIntegerField(default=0)),
],
),
migrations.CreateModel(
name='Flavour',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=150)),
('img_path', models.CharField(blank=True, max_length=200)),
],
),
migrations.CreateModel(
name='Stock',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('amount', models.PositiveSmallIntegerField(default=40, validators=[django.core.validators.MaxValueValidator(100), django.core.validators.MinValueValidator(1)])),
('flavour', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='ice_cream.flavour')),
],
),
]
23 changes: 23 additions & 0 deletions nalo_ice_cream/ice_cream/migrations/0002_populate_flavour.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.db import migrations, models

def populate_flavour(apps, schema):
Flavour = apps.get_model('ice_cream', 'Flavour')

Flavour.objects.create(name='Cherry', img_path='ice_cream/cherry.jpg')
Flavour.objects.create(name='Chocolate-Orange', img_path='ice_cream/chocolate-orange.jpg')
Flavour.objects.create(name='Pistachio', img_path='ice_cream/pistachio.jpg')
Flavour.objects.create(name='Raspberry', img_path='ice_cream/raspberry.jpg')
Flavour.objects.create(name='Vanilla', img_path='ice_cream/vanilla.jpg')


class Migration(migrations.Migration):

initial = True

dependencies = [
("ice_cream", "0001_initial"),
]

operations = [
migrations.RunPython(populate_flavour)
]
25 changes: 25 additions & 0 deletions nalo_ice_cream/ice_cream/migrations/0003_populate_stock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

from django.db import migrations, models

def populate_stock(apps, schema):
Flavour = apps.get_model('ice_cream', 'Flavour')
Stock = apps.get_model('ice_cream', 'Stock')

for flavour in Flavour.objects.all():
Stock.objects.create(
flavour = flavour,
amount = 40
)


class Migration(migrations.Migration):

initial = True

dependencies = [
("ice_cream", "0002_populate_flavour"),
]

operations = [
migrations.RunPython(populate_stock),
]
Empty file.
26 changes: 26 additions & 0 deletions nalo_ice_cream/ice_cream/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import shortuuid

from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator


class Flavour(models.Model):
name = models.CharField(max_length=150, blank=False, null=False)
img_path = models.CharField(max_length=200, blank=True)


class Stock(models.Model):
flavour = models.OneToOneField('Flavour', on_delete = models.CASCADE)
amount = models.PositiveSmallIntegerField(
default = 40,
validators = [
MaxValueValidator(100),
MinValueValidator(1)
]
)


class Command(models.Model):
code = models.CharField(max_length=22, default=shortuuid.uuid(), blank=False, null=False)
content = models.JSONField(blank=True, null=True)
price = models.PositiveIntegerField(null=False, default=0)
35 changes: 35 additions & 0 deletions nalo_ice_cream/ice_cream/templates/ice_cream/admin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% load static %}
<html><body>
<h1>Super Secure admin panel</h1>
<h2>(Please leave if you are not admin)</h2>
<ul>
<li>Total revenue : {{revenue}} <b>€</b></li>
</ul>
<a href="{% url 'ice_cream:index' %}">Menu</a>

<form action="{% url 'ice_cream:admin' %}" method="post">
{% csrf_token %}
<fieldset>
<legend><h1>Stocks</h1></legend>
<h2>Flavours</h2>
<ul>
{% for stock in stocks %}
<li>
<table>
<tr><td>
<label><b>{{stock.flavour.name}}</b></label><br>
<img src="{% static stock.flavour.img_path %}" alt={{stock.flavour.name}} width=200 height=200/>
</td>
<td>
{% if stock.amount <= 0 %}<label style="color: red"><b>OUT OF STOCK</b></label><br>{% endif %}
<label>Stock : {% widthratio stock.amount 40 100 %} %</label><br>
<button name={{stock.flavour.name}}>Refill</button>
</td>
</tr>
</table>
</li>
{% endfor %}
</ul>
</fieldset>
</form>
</body></html>
27 changes: 27 additions & 0 deletions nalo_ice_cream/ice_cream/templates/ice_cream/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% load static %}
<head>
<style>
.center {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<html>
<body>
<h1>Command n° {{ command.pk }}</h1>
<ul>
<li>Command code : <b>{{command.code}}</b><br></li>
<li>Price : {{command.price}} <b>€</b></li>
</ul>
<a href="{% url 'ice_cream:index' %}">Menu</a>


<h2>The ice cream should probably look like this :</h2><br>
{% for scoop in scoops %}
<img src="{% static scoop.img_path %}" alt={{scoop.name}}/ style="border-radius: 50%" width=200 height=200 class='center'><br>
{% endfor %}
<img src="{% static 'ice_cream/cone.png' %}" alt='cone' class='center'/><br>
</body>
</html>
15 changes: 15 additions & 0 deletions nalo_ice_cream/ice_cream/templates/ice_cream/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% load static %}
<html><body>
<ul>
<li><a href="{% url 'ice_cream:new' %}">New ice cream</a></li>
<li>
<form action="{% url 'ice_cream:detail' %}" method="post">
{% csrf_token %}
<label>Get your ice cream</label>
<input type="text" id="command_code" name="command_code">
<input type="submit" value="Get">
{% if error_message %}<label style="color: red">{{ error_message }}</label>{% endif %}
</form>
</li>
</ul>
</body></html>
29 changes: 29 additions & 0 deletions nalo_ice_cream/ice_cream/templates/ice_cream/new.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% load static %}

<html><body>
<form action="{% url 'ice_cream:create' %}" method="post">
{% csrf_token %}
<fieldset>
<legend><h1>Create a new ice cream</h1></legend>
<h2>Flavours</h2>
{% if error_message %}<label style="color: red">{{ error_message }}</label>{% endif %}
<ul>
{% for stock in stocks %}
<li>
<label><b>{{stock.flavour.name}}</b></label>
{% if stock.amount <= 0 %}
<label style="color: red"><b>OUT OF STOCK</b></label>
{% endif %}
<br>
<img src="{% static stock.flavour.img_path %}" alt={{stock.flavour.name}} width=200 height=200/>
<input type="number" id={{stock.flavour.name}} value=0 name={{stock.flavour.name}} min="0" max={{stock.amount}} {% if stock.amount <= 0 %}disabled{% endif %}>
</li>
{% endfor %}
</ul>
</fieldset>
<input type="submit" value="Create">
</form>

<a href="{% url 'ice_cream:index' %}">Menu</a>
<html><body>

8 changes: 8 additions & 0 deletions nalo_ice_cream/ice_cream/templates/ice_cream/result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html><body>
<h1>Command n° {{ command.pk }}</h1>
<ul>
<li>Command code : <b>{{command.code}}</b><br></li>
<li>Price : {{command.price}} <b>€</b></li>
</ul>
<a href="{% url 'ice_cream:index' %}">Menu</a>
<html><body>
Loading