Skip to content
Snippets Groups Projects
Commit 605a0d5f authored by Philip ABBET's avatar Philip ABBET
Browse files

[website] Allows the creation of a new version of binary algorithms

parent f88db749
No related branches found
No related tags found
No related merge requests found
...@@ -590,7 +590,11 @@ function setupEditor(algorithm, dataformats, libraries) ...@@ -590,7 +590,11 @@ function setupEditor(algorithm, dataformats, libraries)
<div class="row"> <div class="row">
<div class="col-sm-offset-1 col-sm-10 contribution_editor" style="display: none;"> <div class="col-sm-offset-1 col-sm-10 contribution_editor" style="display: none;">
<div class="alert alert-info"> <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> <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> </div>
</div> </div>
......
...@@ -988,6 +988,40 @@ class AlgorithmCreation(AlgorithmsAPIBase): ...@@ -988,6 +988,40 @@ class AlgorithmCreation(AlgorithmsAPIBase):
self.assertEqual(algorithm.source_code, algorithm.fork_of.source_code) 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): class AlgorithmUpdate(AlgorithmsAPIBase):
def setUp(self): def setUp(self):
super(AlgorithmUpdate, self).setUp() super(AlgorithmUpdate, self).setUp()
......
...@@ -75,12 +75,18 @@ def create(request, name=None): ...@@ -75,12 +75,18 @@ def create(request, name=None):
description = previous_version.description description = previous_version.description
parameters['algorithm_version'] = previous_version.version + 1 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['declaration'] = previous_version.declaration_file.read().replace('\n', '') parameters['short_description'] = previous_version.short_description
parameters['short_description'] = previous_version.short_description parameters['description'] = description.replace('\n', '\\n')
parameters['description'] = description.replace('\n', '\\n') parameters['html_description'] = restructuredtext(description).replace('\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: else:
parameters['source_code'] = prototypes.binary_load('algorithm.py') \ parameters['source_code'] = prototypes.binary_load('algorithm.py') \
.replace('\n\n # TODO: Implement this algorithm\n\n', .replace('\n\n # TODO: Implement this algorithm\n\n',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment