From 6aaa106affc25691a062f9aec905bddb594eeaec Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 10 Jan 2018 18:08:27 +0800 Subject: [PATCH] =?UTF-8?q?[Bugfix]=20=E4=BF=AE=E5=A4=8D=E4=BB=A5=E4=B8=8B?= =?UTF-8?q?bug=201.=20=E6=9F=A5=E7=9C=8B=E6=89=A7=E8=A1=8C=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E5=BC=82=E5=B8=B8=202.=20=E7=94=A8=E6=88=B7=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E8=B5=84=E4=BA=A7=E9=A1=B5=E6=98=BE=E7=A4=BAmessage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ops/models.py | 4 ++-- apps/ops/serializers.py | 4 ++-- apps/templates/_message.html | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/ops/models.py b/apps/ops/models.py index accdfe78f..3c96f5146 100644 --- a/apps/ops/models.py +++ b/apps/ops/models.py @@ -218,8 +218,8 @@ class AdHoc(models.Model): history.result = raw history.summary = summary return raw, summary - except: - return {}, {} + except Exception as e: + return {}, {"dark": {"all": str(e)}, "contacted": []} finally: history.date_finished = timezone.now() history.timedelta = time.time() - time_start diff --git a/apps/ops/serializers.py b/apps/ops/serializers.py index 86a029c12..a395a427e 100644 --- a/apps/ops/serializers.py +++ b/apps/ops/serializers.py @@ -43,8 +43,8 @@ class AdHocRunHistorySerializer(serializers.ModelSerializer): def get_stat(obj): return { "total": len(obj.adhoc.hosts), - "success": len(obj.summary["contacted"]), - "failed": len(obj.summary["dark"]), + "success": len(obj.summary.get("contacted", [])), + "failed": len(obj.summary.get("dark", [])), } def get_field_names(self, declared_fields, info): diff --git a/apps/templates/_message.html b/apps/templates/_message.html index 29a25e963..046f48ae6 100644 --- a/apps/templates/_message.html +++ b/apps/templates/_message.html @@ -1,6 +1,6 @@ {% load i18n %} {% block first_login_message %} - {% if user.is_authenticated and user.is_first_login %} + {% if request.user.is_authenticated and request.user.is_first_login %}
{% url 'users:user-first-login' as first_login_url %} {% blocktrans %} @@ -10,7 +10,7 @@ {% endif %} {% endblock %} {% block update_public_key_message %} - {% if user.is_authenticated and not user.is_public_key_valid %} + {% if request.user.is_authenticated and not request.user.is_public_key_valid %}
{% url 'users:user-pubkey-update' as user_pubkey_update %} {% blocktrans %}