mirror of
https://github.com/vale981/vale981_fahrschule
synced 2025-03-04 17:31:42 -05:00
script solution
This commit is contained in:
parent
590b71eb92
commit
3138be9844
5 changed files with 80 additions and 58 deletions
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
|
@ -58,8 +58,11 @@ WSGI_APPLICATION = 'fahrschule_vale981.wsgi.application'
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
'NAME': 'fahrschule_1',
|
||||||
|
'USER': 'postgres',
|
||||||
|
'PASSWORD': 'valentin',
|
||||||
|
'HOST': 'localhost'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,29 +19,15 @@ class Quiz(models.Model) :
|
||||||
def __str__(self): # __unicode__ on Python 2
|
def __str__(self): # __unicode__ on Python 2
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
class Frage(models.Model):
|
|
||||||
|
|
||||||
quiz = models.ManyToManyField(Quiz, blank=True, )
|
|
||||||
|
|
||||||
content = models.CharField(max_length=1000,
|
|
||||||
blank=False,
|
|
||||||
verbose_name='Frage Text',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Admin:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return self.content
|
|
||||||
def __str__(self): # __unicode__ on Python 2
|
|
||||||
return self.content
|
|
||||||
|
|
||||||
class Antwort(models.Model):
|
class Antwort(models.Model):
|
||||||
frage = models.ManyToManyField(Frage, blank=False, )
|
|
||||||
|
|
||||||
content = models.CharField(max_length=1000,
|
content = models.CharField(max_length=1000,
|
||||||
blank=False,
|
blank=False,
|
||||||
|
@ -56,20 +42,35 @@ class Antwort(models.Model):
|
||||||
def __str__(self): # __unicode__ on Python 2
|
def __str__(self): # __unicode__ on Python 2
|
||||||
return self.content
|
return self.content
|
||||||
|
|
||||||
def get_related_to(self, status):
|
|
||||||
return self.related_to.filter(
|
|
||||||
from_people__status=status,
|
|
||||||
from_people__to_person=self)
|
|
||||||
|
|
||||||
class Admin:
|
class Admin:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Frage(models.Model):
|
||||||
|
|
||||||
|
quiz = models.ManyToManyField(Quiz, blank=True, )
|
||||||
|
|
||||||
class Results:
|
content = models.CharField(max_length=1000,
|
||||||
quiz=models.ManyToManyField(Quiz, blank=True, )
|
blank=False,
|
||||||
frage=models.ManyToManyField(User, blank=True, )
|
verbose_name='Frage Text',
|
||||||
user=models.ManyToManyField(User, blank=True, )
|
)
|
||||||
|
antworten = models.ManyToManyField(Antwort, blank=False, verbose_name='Antworten' )
|
||||||
|
|
||||||
|
class Admin:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.content
|
||||||
|
def __str__(self): # __unicode__ on Python 2
|
||||||
|
return self.content
|
||||||
|
|
||||||
|
class Results(models.Model):
|
||||||
|
quiz=models.ForeignKey(Quiz, blank=True, )
|
||||||
|
frage=models.ForeignKey(Frage, blank=True, )
|
||||||
|
user=models.ForeignKey(User, blank=True, )
|
||||||
richtig = models.BooleanField(blank=True)
|
richtig = models.BooleanField(blank=True)
|
||||||
choice = models.ManyToManyField(Antwort)
|
aw = models.ForeignKey(Antwort)
|
||||||
|
choice = models.BooleanField(blank=True)
|
||||||
|
|
||||||
|
|
|
@ -27,15 +27,6 @@ def quiz(request, quiz_id=1):
|
||||||
cs = {}
|
cs = {}
|
||||||
cs.update(csrf(request))
|
cs.update(csrf(request))
|
||||||
|
|
||||||
# AuthorFormSet = modelformset_factory(Results, form=ResultForm)
|
|
||||||
# if request.method == 'POST':
|
|
||||||
# formset = AuthorFormSet(request.POST, request.FILES)
|
|
||||||
# if formset.is_valid():
|
|
||||||
# formset.save()
|
|
||||||
# # do something.
|
|
||||||
# else:
|
|
||||||
# formset = AuthorFormSet(queryset=Frage.objects.filter(quiz=quiz_id))
|
|
||||||
|
|
||||||
height=75*Frage.objects.count()
|
height=75*Frage.objects.count()
|
||||||
height_menu = height + 10
|
height_menu = height + 10
|
||||||
if Frage.objects.count() == 0:
|
if Frage.objects.count() == 0:
|
||||||
|
@ -43,23 +34,33 @@ def quiz(request, quiz_id=1):
|
||||||
height_menu = height
|
height_menu = height
|
||||||
|
|
||||||
len_quiz = len(Quiz.objects.get(id=quiz_id).title)
|
len_quiz = len(Quiz.objects.get(id=quiz_id).title)
|
||||||
|
count=Frage.objects.filter(quiz=quiz_id).count
|
||||||
|
count_aw = 0
|
||||||
|
aw = Frage.objects.filter(quiz=quiz_id)
|
||||||
|
|
||||||
cs.update({'quiz': Quiz.objects.get(id=quiz_id),
|
cs.update({'quiz': Quiz.objects.get(id=quiz_id),
|
||||||
'Frage': Frage.objects.filter(quiz=quiz_id),
|
'Frage': Frage.objects.filter(quiz=quiz_id),
|
||||||
'len': len_quiz,
|
'len': len_quiz,
|
||||||
'hg': height,
|
'hg': height,
|
||||||
'hg_m': height_menu,
|
'hg_m': height_menu,
|
||||||
'user': request.user,
|
'user': request.user,
|
||||||
'aw': Antwort.objects.all()})
|
'aw': Antwort.objects.all(),
|
||||||
|
'count': count,
|
||||||
|
'count_aw': count_aw})
|
||||||
return render_to_response('quiz.html', cs)
|
return render_to_response('quiz.html', cs)
|
||||||
|
|
||||||
def check_view(request):
|
def check_view(request):
|
||||||
check = request.POST.get('aw_check', '')
|
check = request.POST.get('aw_check', '')
|
||||||
user = request.POST.get('user_log', '')
|
user_id = request.POST.get('user_log', '')
|
||||||
frage = request.POST.get('frage', '')
|
user_act = User.objects.get(id=user_id)
|
||||||
antwort = request.POST.get('antwort', '')
|
frage_id = request.POST.get('frage', '')
|
||||||
|
frage = Frage.objects.get(id=frage_id)
|
||||||
|
antwort_id = request.POST.get('antwort', '')
|
||||||
|
antwort = Antwort.objects.get(id=antwort_id)
|
||||||
richtig = request.POST.get('richtig', '')
|
richtig = request.POST.get('richtig', '')
|
||||||
quiz_get = request.POST.get('quiz', '')
|
quiz_id = request.POST.get('quiz', '')
|
||||||
res = Results(quiz=quiz_get, frage=frage, user=user, richtig=richtig, choice=check)
|
quiz = Quiz.objects.get(id=quiz_id)
|
||||||
|
res = Results(quiz=quiz, frage=frage, user=user_act, richtig=richtig, choice=check, aw=antwort)
|
||||||
res.save()
|
res.save()
|
||||||
return HttpResponseRedirect('/quiz/all/')
|
return HttpResponseRedirect('/quiz/all/')
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
{% extends 'quizzes.html' %}
|
{% extends 'quizzes.html' %}
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
@ -5,6 +6,7 @@
|
||||||
{% load staticfiles %}
|
{% load staticfiles %}
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'css/quizz.css' %}" />
|
<link rel="stylesheet" type="text/css" href="{% static 'css/quizz.css' %}" />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
{% block header %}
|
{% block header %}
|
||||||
{% if len >= 20 %}
|
{% if len >= 20 %}
|
||||||
<div style="font-size: 20px">{{ quiz.title }}</div>
|
<div style="font-size: 20px">{{ quiz.title }}</div>
|
||||||
|
@ -22,30 +24,45 @@
|
||||||
<ol>
|
<ol>
|
||||||
{% for Frage in Frage %}
|
{% for Frage in Frage %}
|
||||||
<li><div id="frage">{{Frage.content}}</div></li>
|
<li><div id="frage">{{Frage.content}}</div></li>
|
||||||
{% comment %}<form method="post" action="">
|
{% for aw in Frage.antworten.all %}
|
||||||
{{ formset }}
|
<form action="/quiz/check/" name="{{ aw.content }}" method="post">{% csrf_token %}
|
||||||
</form>{% endcomment %}
|
|
||||||
{% for aw in aw %}
|
|
||||||
{% if aw.frage.get == Frage %}
|
|
||||||
<form action="/quiz/check/" method="post">{% csrf_token %}
|
|
||||||
<label for="aw_check">{{ aw.content }}</label>
|
<label for="aw_check">{{ aw.content }}</label>
|
||||||
<input type="checkbox" name="aw_check" id="aw_check">
|
<input type="checkbox" name="aw_check" id="aw_check">
|
||||||
<input type="hidden" name="user_log" value="{{ user.get }}">
|
<input type="hidden" name="user_log" value="{{ user.id }}">
|
||||||
<input type="hidden" name="frage" value="{{ Frage }}">
|
<input type="hidden" name="frage" value="{{ Frage.id }}">
|
||||||
<input type="hidden" name="antwort" value="{{ aw }}">
|
<input type="hidden" name="antwort" value="{{ aw.id }}">
|
||||||
<input type="hidden" name="quiz" value="{{ quiz }}">
|
<input type="hidden" name="quiz" value="{{ quiz.id }}">
|
||||||
|
|
||||||
{% if aw.richtig %}
|
{% if aw.richtig %}
|
||||||
<input type="hidden" name="richtig" value=True>
|
<input type="hidden" name="richtig" value=True>
|
||||||
{% else %}
|
{% else %}
|
||||||
<input type="hidden" name="richtig" value=False>
|
<input type="hidden" name="richtig" value=False>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<br><input type="submit" value="Abgeben" />
|
<input type="submit" value="Abgeben" />
|
||||||
{% endif %}
|
<br>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</form></ol>
|
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
|
||||||
|
<script language="javascript">
|
||||||
|
function call_submitforms(){
|
||||||
|
{% for Frage in Frage %}
|
||||||
|
{% for aw in Frage.antworten.all %}
|
||||||
|
setTimeout("document.{{ aw.content }}.submit()",1000);
|
||||||
|
{{ check.it }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<input type="button" value="Abschicken" onclick="call_submitforms()" />
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue