diff --git a/beat/web/algorithms/templates/algorithms/edition.html b/beat/web/algorithms/templates/algorithms/edition.html index 92818d047bd657e792d33d4dba5769347878654b..f97dfb546a03de4a79d5d6b3a6a81576eddd84be 100644 --- a/beat/web/algorithms/templates/algorithms/edition.html +++ b/beat/web/algorithms/templates/algorithms/edition.html @@ -590,7 +590,11 @@ function setupEditor(algorithm, dataformats, libraries) <div class="row"> <div class="col-sm-offset-1 col-sm-10 contribution_editor" style="display: none;"> <div class="alert alert-info"> + {% if new_version %} + <i class="fa fa-info"></i> <span>The algorithm is implemented in <strong>{{ algorithm_language_name }}</strong>, compiled as a <strong>shared library</strong>. The new algorithm version that will be created will copy the original shared library.</span> + {% else %} <i class="fa fa-info"></i> <span>The original algorithm is implemented in <strong>{{ algorithm_language_name }}</strong>, compiled as a <strong>shared library</strong>. The forked algorithm that will be created will copy the original shared library.</span> + {% endif %} </div> </div> </div> diff --git a/beat/web/algorithms/tests/tests_api.py b/beat/web/algorithms/tests/tests_api.py index dd1a6e98bbf45cb48b17a25c111ccb8523515d7c..1a25f26fa20eae20830ba18d87b6885c088f6e10 100755 --- a/beat/web/algorithms/tests/tests_api.py +++ b/beat/web/algorithms/tests/tests_api.py @@ -988,6 +988,40 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.assertEqual(algorithm.source_code, algorithm.fork_of.source_code) + def test_cxx_algorithm_version(self): + self.client.login(username='jackdoe', password='1234') + + response = self.client.post(self.url, + json.dumps({ + 'name': 'binary_personal', + 'description': 'blah', + 'declaration': AlgorithmsAPIBase.CXX_DECLARATION, + 'previous_version': 'jackdoe/binary_personal/1', + }), content_type='application/json') + + url = reverse('api_algorithms:object', args=['jackdoe', 'binary_personal', 2]) + content = self.checkResponse(response, 201, + content_type='application/json', + location=url) + + self.assertTrue(isinstance(content, dict)) + self.assertEqual(content['name'], 'binary_personal') + self.assertTrue(content['url'].endswith(url)) + + try: + algorithm = Algorithm.objects.get(author__username='jackdoe', name='binary_personal', version=2) + except: + self.assertTrue(False) + + self.assertEqual(algorithm.short_description, '') + self.assertEqual(algorithm.description, 'blah') + self.assertEqual(algorithm.language, Code.CXX) + self.assertTrue(algorithm.valid()) + self.checkAlgorithm(algorithm, declaration=AlgorithmsAPIBase.CXX_DECLARATION, code=None) + + self.assertEqual(algorithm.source_code, algorithm.previous_version.source_code) + + class AlgorithmUpdate(AlgorithmsAPIBase): def setUp(self): super(AlgorithmUpdate, self).setUp() diff --git a/beat/web/algorithms/views.py b/beat/web/algorithms/views.py index d7a0c9a58ae0d71af23d43de20bca3b1819434cc..a42fd4699a1395964f3b43bf31379653193b4d34 100755 --- a/beat/web/algorithms/views.py +++ b/beat/web/algorithms/views.py @@ -75,12 +75,18 @@ def create(request, name=None): description = previous_version.description - parameters['algorithm_version'] = previous_version.version + 1 - parameters['source_code'] = previous_version.source_code_file.read() - parameters['declaration'] = previous_version.declaration_file.read().replace('\n', '') - parameters['short_description'] = previous_version.short_description - parameters['description'] = description.replace('\n', '\\n') - parameters['html_description'] = restructuredtext(description).replace('\n', '') + parameters['algorithm_version'] = previous_version.version + 1 + parameters['declaration'] = previous_version.declaration_file.read().replace('\n', '') + parameters['short_description'] = previous_version.short_description + parameters['description'] = description.replace('\n', '\\n') + parameters['html_description'] = restructuredtext(description).replace('\n', '') + parameters['algorithm_language'] = previous_version.json_language + parameters['algorithm_language_name'] = previous_version.language_fullname() + parameters['binary'] = previous_version.is_binary() + parameters['new_version'] = True + + if not previous_version.is_binary(): + parameters['source_code'] = previous_version.source_code_file.read() else: parameters['source_code'] = prototypes.binary_load('algorithm.py') \ .replace('\n\n # TODO: Implement this algorithm\n\n',