From 04b7b345b3b01047209a177c95584689550132df Mon Sep 17 00:00:00 2001 From: Samuel Gaist <samuel.gaist@idiap.ch> Date: Wed, 29 Aug 2018 15:21:58 +0200 Subject: [PATCH] [toolchains][views] Fix handling of description and error With python 3 we get bytes, ensure we are working on strings. --- beat/web/toolchains/views.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/beat/web/toolchains/views.py b/beat/web/toolchains/views.py index 55ffa8b42..5033ee831 100644 --- a/beat/web/toolchains/views.py +++ b/beat/web/toolchains/views.py @@ -32,11 +32,13 @@ from django.contrib.auth.decorators import login_required from django.conf import settings from django.contrib.auth.models import User from django.db.models.functions import Coalesce +from django.utils import six from .models import Toolchain from ..team.models import Team from ..reports.models import Report from ..common.texts import Messages +from ..common.utils import ensure_string from ..ui.templatetags.markup import restructuredtext from beat.core import prototypes @@ -72,7 +74,7 @@ def create(request, name=None): previous_version = previous_versions[0] - description = previous_version.description + description = ensure_string(previous_version.description) parameters['toolchain_version'] = previous_version.version + 1 parameters['declaration'] = previous_version.declaration_string.replace('\n', '') @@ -103,7 +105,8 @@ def fork(request, author, name, version): version=int(version) ) - description = fork_of.description + description = ensure_string(fork_of.description) + errors = ensure_string(fork_of.errors) parameters = {'toolchain_author': request.user.username, 'toolchain_name': name, @@ -112,7 +115,7 @@ def fork(request, author, name, version): 'declaration': fork_of.declaration_string.replace('\n', ''), 'short_description': fork_of.short_description, 'description': description.replace('\n', '\\n'), - 'errors': fork_of.errors.replace('\n', '\\n') if fork_of.errors is not None else '', + 'errors': errors.replace('\n', '\\n'), 'edition': False, 'messages': Messages, } @@ -139,7 +142,8 @@ def edit(request, author, name, version): version=int(version) ) - description = toolchain.description + description = ensure_string(toolchain.description) + errors = ensure_string(toolchain.errors) # Render the page return render(request, @@ -151,7 +155,7 @@ def edit(request, author, name, version): 'short_description': toolchain.short_description, 'description': description.replace('\n', '\\n'), 'html_description': restructuredtext(description).replace('\n', ''), - 'errors': toolchain.errors.replace('\n', '\\n') if toolchain.errors is not None else '', + 'errors': errors.replace('\n', '\\n'), 'edition': True, 'messages': Messages, }) -- GitLab