Skip to content

Commit

Permalink
Don't store IP addresses
Browse files Browse the repository at this point in the history
We don't need them for anything, so don't store them
  • Loading branch information
knatten committed Mar 19, 2023
1 parent 43402f6 commit 08e92c8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion quiz/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def view_on_site(self, obj):


class UsersAnswerAdmin(admin.ModelAdmin):
list_display = ('question', 'result', 'answer', 'correct', 'ip', 'date_time')
list_display = ('question', 'result', 'answer', 'correct', 'date_time')
list_filter = ('question',)


Expand Down
5 changes: 1 addition & 4 deletions quiz/answer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from quiz.models import UsersAnswer
from quiz.util import get_client_ip


class Answer:
Expand All @@ -9,12 +8,10 @@ def __init__(self, question, request):
self.given_result = request.GET.get('result', '').strip()
self.correct = self.given_result == self.question.result and\
(self.question.result != 'OK' or self.given_answer == self.question.answer.strip())
self.ip = get_client_ip(request)

def register_given_answer(self):
UsersAnswer.objects.create(
question=self.question,
answer=self.given_answer,
result=self.given_result,
correct=self.correct,
ip=self.ip)
correct=self.correct)
3 changes: 1 addition & 2 deletions quiz/integration_tests/test_fixed_quiz.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import datetime
import re

from django.test import TestCase
from django.urls import reverse
from django.utils import timezone

from quiz.models import Quiz, Question, UsersAnswer
from quiz.models import Quiz, UsersAnswer
from quiz.test_helpers import *
from quiz import fixed_quiz

Expand Down
17 changes: 17 additions & 0 deletions quiz/migrations/0021_remove_usersanswer_ip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.1.7 on 2023-03-19 14:01

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('quiz', '0020_auto_20230308_0904'),
]

operations = [
migrations.RemoveField(
model_name='usersanswer',
name='ip',
),
]
1 change: 0 additions & 1 deletion quiz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class UsersAnswer(models.Model):
question = models.ForeignKey('Question', on_delete=models.PROTECT)
result = models.CharField(max_length=2, default='OK', choices=Question.RESULT_CHOICES)
answer = models.CharField(max_length=200, default='', blank=True)
ip = models.CharField(max_length=45, default='', blank=True)
date_time = models.DateTimeField(auto_now_add=True)
correct = models.BooleanField(default=False)

Expand Down
16 changes: 0 additions & 16 deletions quiz/quiz_in_progress.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import logging

from quiz.answer import Answer
from quiz.models import Quiz
from quiz import util


class QuestionStats:
Expand Down Expand Up @@ -53,20 +49,12 @@ def get_total_nof_questions(self):
return self.quiz.questions.count()

def is_finished(self, request):
debug_string = "IP:%s, quiz:%s, is finished? (%d/%d/%d)" % \
(util.get_client_ip(request), self.quiz.key, self.nof_answered_questions(),
len(self.answers), self.quiz.questions.count())
logging.getLogger('quiz').debug(debug_string)
return self.quiz.questions.count() == self.nof_answered_questions()

def score(self):
return float(sum([q.score() for q in self.answers]))

def answer(self, request):
debug_string = "IP:%s, quiz:%s, result:%s, answer:%s, answers:%d" %\
(util.get_client_ip(request), self.quiz.key, request.GET.get(
'result', ''), request.GET.get('answer', ''), len(self.answers))
logging.getLogger('quiz').debug(debug_string)
answer = Answer(self.get_current_question(), request)
answer.register_given_answer()
if answer.correct:
Expand All @@ -77,10 +65,6 @@ def answer(self, request):
else:
self.previous_result = 'incorrect'
self.attempts += 1
debug_string = "IP:%s, quiz:%s, question:#%d (%d/%d), given_result:%s, given_answer:%s, correct:%s" % \
(answer.ip, self.quiz.key, answer.question.pk, len(self.answers),
self.quiz.questions.count(), answer.given_result, answer.given_answer, answer.correct)
logging.getLogger('quiz').debug(debug_string)
return

def use_hint(self):
Expand Down
7 changes: 0 additions & 7 deletions quiz/views.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import difflib
import logging
import random

from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.template import RequestContext
from django.shortcuts import render, get_object_or_404
from django.core.mail import mail_admins
from django.contrib.admin.views.decorators import staff_member_required
from django.db.models import Count, Q
from django.views.decorators.cache import never_cache

from quiz import fixed_quiz
from quiz.models import *
from quiz.forms import QuestionForm
from quiz.answer import Answer
from quiz.game_data import *
from quiz.quiz_in_progress import *
from quiz.util import get_published_questions
Expand Down Expand Up @@ -150,9 +146,6 @@ def quiz(request, quiz_key):
quiz_in_progress.use_hint()
d['hint'] = True
if quiz_in_progress.is_finished(request):
debug_string = "IP:%s, quiz:%s was served the finished-screen " % (
util.get_client_ip(request), quiz_in_progress.quiz.key)
logging.getLogger('quiz').debug(debug_string)
return render(request, 'quiz/finished.html', d)
d['question'] = quiz_in_progress.get_current_question()
d['question'].mark_viewed()
Expand Down

0 comments on commit 08e92c8

Please sign in to comment.