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 %}