* Kommentare wenn Dan/Kyu Punktabzüge verringert werden um nicht unter

0 zu fallen.
* Neue Middleware die REMOTE_IP aus dem X-Forward-For Header setzt.
  Damit funktioniert das Kommentarsystem nun auch hinter nginx.
This commit is contained in:
2017-12-29 10:03:08 +01:00
parent fdbf819092
commit 0b2e040fc9
8 changed files with 3199 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
#!/bin/bash
SSH_LOGIN="kasu@s21.wservices.ch"
SYNC_ASSESTS="requirements"
SYNC_ASSESTS="requirements static"
SYNC_SOURCECODE="src"
EXCLUDE_FILES="*.pyc"
@@ -19,5 +19,5 @@ rsync -r --copy-links --delete ${SYNC_SOURCECODE} ${SSH_LOGIN}:~/ --exclude 'src
echo "Rebuild and reload django..."
ssh ${SSH_LOGIN} "rm src/kasu/settings/development.*"
ssh ${SSH_LOGIN} "virtualenv/bin/python ~/src/manage.py collectstatic -l --noinput -v1"
ssh ${SSH_LOGIN} "~/virtualenv/bin/python ~/src/manage.py collectstatic -l --noinput -v1"
ssh ${SSH_LOGIN} "~/init/kasu restart"

View File

@@ -80,6 +80,7 @@ MIDDLEWARE_CLASSES = [
'django.middleware.locale.LocaleMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'utils.middleware.SetRemoteAddrFromForwardedFor',
'mahjong_ranking.middleware.DenormalizationUpdateMiddleware',
]

File diff suppressed because one or more lines are too long

View File

@@ -21,8 +21,6 @@ def recalculate(modeladmin, request, queryset): # Ignore PyLintBear (W0613)
for ladder_ranking in queryset:
set_dirty(user=ladder_ranking.user_id,
season=ladder_ranking.season)
recalculate.short_description = _("Recalculate")

View File

@@ -56,7 +56,7 @@ def export_season_rankings(workbook, until):
def export_kyu_dan_rankings(workbook, until):
KyuDanRanking.objects.update(until=until)
KyuDanRanking.objects.update(until=until, force_recalc=True)
object_list = KyuDanRanking.objects.all()
title = "Kyū & Dan Rankings"
columns_settings = (

View File

@@ -566,11 +566,15 @@ class KyuDanRanking(models.Model):
if self.dan:
# Only substract so much points that player has 0 Points:
if self.dan_points + hanchan.dan_points < 0:
hanchan.player_comment = 'Spieler unterschreitet 0 Punkte.' \
'(Original {} Punkte)'.format(hanchan.dan_points)
hanchan.dan_points -= (self.dan_points + hanchan.dan_points)
self.dan_points += hanchan.dan_points
else:
# Only substract so much points that player has 0 Points:
if self.kyu_points + hanchan.kyu_points < 0:
hanchan.player_comment = 'Spieler unterschreitet 0 Punkte.' \
'(Original {} Punkte)'.format(hanchan.kyu_points)
hanchan.kyu_points -= (self.kyu_points + hanchan.kyu_points)
self.kyu_points += hanchan.kyu_points

View File

@@ -240,7 +240,7 @@ class PlayerDanScore(PlayerScore):
{'col': 'L', 'title': 'Dan Punkte', 'attr': 'dan_points',
'style': 'Integer', 'width': 12,
'footer': self.kyu_dan_ranking.legacy_dan_points},
{'col': 'M', 'title': 'Anmerkung', 'attr': 'comment',
{'col': 'M', 'title': 'Anmerkung', 'attr': 'player_comment',
'style': 'Content', 'width': 20, 'footer': 'Legacy Dan Punkte'},
)

View File

@@ -4,14 +4,14 @@ from django.utils.html import strip_spaces_between_tags
class CompressHtmlMiddleware(object):
"""This Middleware compresses strips the spaces between tags, and at the
"""This Middleware compresses strips the spaces between tags, and at the
beginning and the end of the content."""
# TODO: Port to django 1.10 and upward
def __init__(self, get_response):
"""
:param get_response:
:param get_response:
"""
self.get_response = get_response
regex = ">[\s]*<"
@@ -19,8 +19,8 @@ class CompressHtmlMiddleware(object):
def __call__(self, request):
"""
:param request:
:return:
:param request:
:return:
"""
# Code to be executed for each request before
@@ -31,3 +31,15 @@ class CompressHtmlMiddleware(object):
response.content = strip_spaces_between_tags(
response.content).strip()
return response
class SetRemoteAddrFromForwardedFor(object):
def process_request(self, request):
try:
real_ip = request.META['HTTP_X_FORWARDED_FOR']
real_ip = real_ip.split(",")[0]
except KeyError:
pass
else:
# HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.
# Take just the first one.
request.META['REMOTE_ADDR'] = real_ip