Browse Source

Version test

pull/1/head
Christophe SCAYA 4 years ago
parent
commit
77505b5959
  1. 7
      eduapps_project/settings.py
  2. 1
      eduapps_project/urls.py
  3. 6
      homeapp/templates/homeapp/main.html
  4. 1
      quiz/apps.py
  5. 7
      quiz_atomes/admin.py
  6. 1
      quiz_atomes/apps.py
  7. 31
      quiz_atomes/migrations/0001_initial.py
  8. 13
      quiz_atomes/models.py
  9. 7
      quiz_atomes/static/quiz_atomes/bootstrap.bundle.min.js
  10. 7
      quiz_atomes/static/quiz_atomes/bootstrap.min.css
  11. BIN
      quiz_atomes/static/quiz_atomes/tableau_periodique-couleur.png
  12. 1
      quiz_atomes/static/quiz_atomes/vial-solid.svg
  13. 24
      quiz_atomes/templates/quiz_atomes/home.html
  14. 36
      quiz_atomes/templates/quiz_atomes/quiz_atomes.html
  15. 26
      quiz_atomes/templates/quiz_atomes/resultats.html
  16. 28
      quiz_atomes/templates/quiz_atomes/scores.html
  17. 48
      quiz_atomes/templates/quiz_atomes/settings.html
  18. 10
      quiz_atomes/urls.py
  19. 100
      quiz_atomes/views.py

7
eduapps_project/settings.py

@ -33,6 +33,7 @@ ALLOWED_HOSTS = ["*"] @@ -33,6 +33,7 @@ ALLOWED_HOSTS = ["*"]
INSTALLED_APPS = [
'quiz.apps.QuizConfig',
'quiz_atomes.apps.QuizAtomesConfig',
'homeapp.apps.HomeappConfig',
'django.contrib.admin',
'django.contrib.auth',
@ -60,6 +61,8 @@ STATICFILES_FINDERS = [ @@ -60,6 +61,8 @@ STATICFILES_FINDERS = [
'compressor.finders.CompressorFinder',
]
SESSION_ENGINE = 'django.contrib.sessions.backends.file'
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'django_libsass.SassCompiler'),
)
@ -121,11 +124,11 @@ AUTH_PASSWORD_VALIDATORS = [ @@ -121,11 +124,11 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = 'fr-FR'
TIME_ZONE = 'UTC'
TIME_ZONE = 'Europe/Paris'
USE_I18N = True
USE_TZ = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)

1
eduapps_project/urls.py

@ -20,5 +20,6 @@ from django.views.generic import TemplateView @@ -20,5 +20,6 @@ from django.views.generic import TemplateView
urlpatterns = [
path('', include('homeapp.urls')),
path('quiz/', include('quiz.urls')),
path('quiz_atomes/', include('quiz_atomes.urls')),
path('admin/', admin.site.urls),
]

6
homeapp/templates/homeapp/main.html

@ -23,9 +23,9 @@ @@ -23,9 +23,9 @@
<p>Un quiz de français pour tester tes connaissances en conjugaison.</p><a class="btn text-center btn-block btn-dark" href="quiz">J'y vais !</a>
</div>
<div class="p-4 col-lg-4 col-md-6 bg-dark">
<h4><b>Trivial physique chimie</b></h4>
<p>Le célèbre jeu de société dans une version spéciale physique chimie !</p>
<a class="btn btn-primary text-center btn-block disabled" href="trivial">Bientôt disponible...</a>
<h4><b>Quiz sur les atomes</b></h4>
<p>Un quiz pour tester tes connaissances en symboles chimiques !</p>
<a class="btn btn-primary text-center btn-block" href="quiz_atomes">J'y vais !</a>
</div>
</div>
</div>

1
quiz/apps.py

@ -1,6 +1,5 @@ @@ -1,6 +1,5 @@
from django.apps import AppConfig
class QuizConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'quiz'

7
quiz_atomes/admin.py

@ -1,3 +1,10 @@ @@ -1,3 +1,10 @@
from django.contrib import admin
# Register your models here.
from .models import Atome, Score
class AtomeAdmin(admin.ModelAdmin):
list_display = ('pk','nom', 'symbole')
admin.site.register(Atome, AtomeAdmin)
admin.site.register(Score)

1
quiz_atomes/apps.py

@ -1,6 +1,5 @@ @@ -1,6 +1,5 @@
from django.apps import AppConfig
class QuizAtomesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'quiz_atomes'

31
quiz_atomes/migrations/0001_initial.py

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
# Generated by Django 4.0.1 on 2022-03-28 13:37
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Atome',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nom', models.CharField(max_length=20)),
('symbole', models.CharField(max_length=3)),
],
),
migrations.CreateModel(
name='Score',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('pseudo', models.CharField(max_length=20)),
('score', models.IntegerField(default=0)),
('score_date', models.DateTimeField(verbose_name='Date du score')),
],
),
]

13
quiz_atomes/models.py

@ -1,3 +1,14 @@ @@ -1,3 +1,14 @@
from django.db import models
# Create your models here.
class Atome(models.Model):
nom = models.CharField(max_length=20)
symbole = models.CharField(max_length=3)
def __str__(self):
return self.nom+" ("+self.symbole+")"
class Score(models.Model):
pseudo = models.CharField(max_length=20)
score = models.IntegerField(default=0)
score_date = models.DateTimeField('Date du score')
def __str__(self):
return self.pseudo+" - "+str(self.score)+" - "+self.score_date.strftime("%Y-%m-%d %H:%M")

7
quiz_atomes/static/quiz_atomes/bootstrap.bundle.min.js vendored

File diff suppressed because one or more lines are too long

7
quiz_atomes/static/quiz_atomes/bootstrap.min.css vendored

File diff suppressed because one or more lines are too long

BIN
quiz_atomes/static/quiz_atomes/tableau_periodique-couleur.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

1
quiz_atomes/static/quiz_atomes/vial-solid.svg

@ -0,0 +1 @@ @@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 6.1.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M502.6 169.4l-160-160C336.4 3.125 328.2 0 320 0s-16.38 3.125-22.62 9.375c-12.5 12.5-12.5 32.75 0 45.25l6.975 6.977l-271.4 271c-38.75 38.75-45.13 102-9.375 143.5C44.08 500 72.76 512 101.5 512h.4473c26.38 0 52.75-9.1 72.88-30.12l275.2-274.6l7.365 7.367C463.6 220.9 471.8 224 480 224s16.38-3.125 22.62-9.375C515.1 202.1 515.1 181.9 502.6 169.4zM310.6 256H200.2l149.3-149.1l55.18 55.12L310.6 256z"/></svg>

After

Width:  |  Height:  |  Size: 640 B

24
quiz_atomes/templates/quiz_atomes/home.html

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
{% extends 'basic_template.html' %}{% block 'body' %}{% load static %}
<nav class="navbar navbar-light">
<div class="container">
<a class="navbar-brand text-primary" href="/">
<i class="fa fa-university"></i>
<b>Edu.apps</b>
</a>
</div>
</nav>
<div id="scoring" class="d-flex justify-content-center align-items-center">
<div class="py-3 d-flex flex-column align-items-center">
<h1 class="display-4"><b>LE QUIZ DES ATOMES</b>&nbsp;<i class="fa fa-vial"></i></h1>
<p class="py-3 w-50">Ta mission pour ce jeu ?<br/>
Connaître les symboles chimiques des atomes qui constituent l'univers. Chaque bonne réponse te rapporte 20 points. Une mauvaise t'en enlève 10 et une absence de réponse t'en enlève 5. Attention au temps ! Chaque seconde passée sur la partie t'enlèvera un point au moment de calculer ton score.<br/>Pour t'entraîner, aide toi de <a href="{% static 'quiz_atomes/tableau_periodique-couleur.png' %}">ce tableau</a>. Bon courage !</p>
<div class="d-inline">
<a href="{% url "quiz_atomes" %}">
<input type="button" value="JOUER" href=>
</a>
<a href="{% url "scores" %}">
<input type="button" value="Scores">
</a>
</div>
</div>
</div>{% endblock %}

36
quiz_atomes/templates/quiz_atomes/quiz_atomes.html

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
{% extends 'basic_template.html' %}{% block 'body' %}
<nav class="navbar navbar-light">
<div class="container">
<a class="navbar-brand text-primary" href="{% url "home" %}">
<i class="fa fa-home"></i>
</a>
<div class="navbar-brand text-primary">
<b>{{pseudo}}</b>
</div>
<a class="navbar-brand text-primary" href="{% url "settings" %}">
<i class="fa fa-gear"></i>
</a>
</div>
</nav>
<div class="d-flex justify-content-center align-items-center">
<form action="{% url "quiz_atomes" %}" method="POST" id="quiz" name="quiz">
{% csrf_token %}
<table class="table table-striped w-auto table-responsive-lg">
<thead>
<tr>
<th scope="col">Atome</th>
<th scope="col">Symbole</th>
</tr>
</thead>
<tbody>{% if atome_list %}{% for atome in atome_list %}
<tr>
<td>{{atome.nom}}</td>
<td><input name="input{{ forloop.counter }}" maxlength="3" value=""></td>
</tr>{% endfor %}{% endif %}
<tr>
<td colspan="2"><input type="submit" name="ok" value="OK"></td>
</tr>
</tbody>
</table>
</form>
</div>{% endblock %}

26
quiz_atomes/templates/quiz_atomes/resultats.html

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
{% extends 'basic_template.html' %}{% block 'body' %}
<nav class="navbar navbar-light">
<div class="container">
<a class="navbar-brand text-primary" href="{% url "home" %}">
<i class="fa fa-home"></i>
</a>
</div>
</nav>
<div id="scoring" class="d-flex justify-content-center align-items-center">
<div class="py-2 d-flex flex-column align-items-center">
<h4 id="points"><b>POINTS : {{points}}</b></h4>
<h4 id="dt"><b>TEMPS : {{dt}}</b></h4>
<h1 id="score"><b>SCORE : {{score}}</b></h1>{% if best_score %}
<h4><i class="fa-solid fa-star"></i><b>&nbsp;Nouveau&nbsp;<i class="fa-solid fa-star"></i><br/>meilleur score !</b>&nbsp;</h4>{% else %}
<h4><b>Essaie encore !</b></h4>
{% endif %}
<div class="d-inline">
<a href="{% url "scores" %}">
<input type="button" value="Scores">
</a>
<a href="{% url "quiz_atomes" %}">
<input type="button" value="Rejouer">
</a>
</div>
</div>
</div>{% endblock %}

28
quiz_atomes/templates/quiz_atomes/scores.html

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
{% extends 'basic_template.html' %}{% block 'body' %}
<nav class="navbar navbar-light">
<div class="container">
<a class="navbar-brand text-primary" href="{% url "home" %}">
<i class="fa fa-home"></i>
</a>
</div>
</nav>
<div class="d-flex justify-content-center align-items-center">
<table class="table table-striped w-auto table-responsive-lg">
<thead>
<tr>
<th scope="col">Rang</th>
<th scope="col">Score</th>
<th scope="col">Pseudo</th>
<th scope="col">Date</th>
</tr>
</thead>
<tbody>{% if score_list %}{% for score in score_list %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ score.score }}</td>
<td>{{ score.pseudo }}</td>
<td>{{ score.score_date }}</td>
</tr>{% endfor %}{% endif %}
</tbody>
</table>
</div>{% endblock %}

48
quiz_atomes/templates/quiz_atomes/settings.html

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
{% extends 'basic_template.html' %}{% block 'body' %}
<nav class="navbar navbar-light">
<div class="container"> <a class="navbar-brand text-primary" href="{% url "quiz_atomes" %}">
<i class="fa fa-arrow-left"></i>
</a>
</div>
</nav>
<div class="d-flex justify-content-center align-items-center">
<div class="py-2 d-flex flex-column align-items-center">
<h2><b>Paramètres du quiz</b></h2>
<form action="{% url "settings" %}" method="POST" name="settings">{% csrf_token %}
<table class="table w-auto table-responsive-lg">
<tr>
<td>NOM :</td>
<td><input id="nom" name="nom" maxlength="20"></td>
</tr>
<tr>
<td>Prénom :</td>
<td><input id="prenom" name="prenom" maxlength="20"></td>
</tr>
<tr>
<td>Nombre<br/>d'atomes :</td>
<td class="align-middle">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="nb" id="inlineRadio1" value="10" checked>
<label class="form-check-label" for="inlineRadio1">10</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="nb" id="inlineRadio1" value="20">
<label class="form-check-label" for="inlineRadio2">20</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="nb" id="inlineRadio1" value="30">
<label class="form-check-label" for="inlineRadio1">30</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="nb" id="inlineRadio1" value="40">
<label class="form-check-label" for="inlineRadio2">40</label>
</div>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="OK"></td>
</tr>
</table>
</form>
</div>
</div>{% endblock %}

10
quiz_atomes/urls.py

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='home'),
path('quiz_atomes/', views.quiz_atomes, name='quiz_atomes'),
path('settings/', views.settings, name='settings'),
path('scores/', views.scores, name='scores'),
]

100
quiz_atomes/views.py

@ -1,3 +1,99 @@ @@ -1,3 +1,99 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.template.response import TemplateResponse
from django.template import loader
from .models import Atome, Score
from random import shuffle
from datetime import datetime
from django.shortcuts import redirect
import time
from django.views.decorators.cache import never_cache
from django.db.models import Min
# Create your views here.
def home(request):
return TemplateResponse(request, 'quiz_atomes/home.html', {'favicon':'vial-solid.svg'})
def settings(request):
if request.method =='POST':
if not request.POST.get('prenom') or not request.POST.get('nom'):
request.session['pseudo'] = "Anonyme"
else:
request.session['pseudo'] = request.POST.get('prenom')[0].upper()+". "+request.POST.get('nom').upper()
request.session['difficulte'] = request.POST.get('nb')
return redirect('quiz_atomes')
else:
return TemplateResponse(request, 'quiz_atomes/settings.html', {'favicon':'vial-solid.svg'})
@never_cache
def quiz_atomes(request):
if request.POST.get('ok'):
return resultats(request)
if 'pseudo' not in request.session or 'difficulte' not in request.session:
return redirect('settings')
atome_list = Atome.objects.all()
random_list = list(atome_list)
shuffle(random_list)
random_list = random_list[:int(request.session['difficulte'])]
symbole_list = []
for x in random_list:
symbole_list.append(x.symbole)
request.session['quiz'] = symbole_list
request.session['time'] = time.time()
template = loader.get_template('quiz_atomes/quiz_atomes.html')
context = {
'pseudo': request.session['pseudo'],
'diff': request.session['difficulte'],
'atome_list': random_list,
'favicon':'vial-solid.svg'
}
return HttpResponse(template.render(context, request))
def resultats(request):
points = 0
dt = round(time.time()-request.session['time'])*-1
for i in range(int(request.session['difficulte'])):
if request.POST.get('input'+str(i+1)).casefold()==request.session['quiz'][i].casefold():
points+=20
elif request.POST.get('input'+str(i+1)).casefold()=="":
points-=5
else:
points-=10
points=points*10
score=points+dt
best_score=0
if score>0:
score_list = Score.objects.all().order_by('-score')[:10]
min_selection_score = score_list.aggregate(Min("score")).get('score__min')
if score>=min_selection_score:
new_score = Score(pseudo=request.session['pseudo'], score=int(score), score_date=datetime.now())
new_score.save()
best_score=1
template = loader.get_template('quiz_atomes/resultats.html')
context = {
'points': points,
'dt': dt,
'score': score,
'best_score': best_score,
'favicon':'vial-solid.svg'
}
return HttpResponse(template.render(context, request))
def scores(request):
score_list = Score.objects.all().order_by('-score')[:10]
template = loader.get_template('quiz_atomes/scores.html')
context = {
'score_list': score_list,
'favicon':'vial-solid.svg'
}
return HttpResponse(template.render(context, request))

Loading…
Cancel
Save