From d020631536d1c707d80b5eac3dda172210dcbadb Mon Sep 17 00:00:00 2001 From: Philip ABBET <philip.abbet@idiap.ch> Date: Thu, 19 Oct 2017 14:08:13 +0200 Subject: [PATCH] Force 4-spaces indentation --- beat/web/accounts/api.py | 2 +- beat/web/accounts/forms.py | 2 +- .../commands/block_rejected_users.py | 2 +- .../clean_blocked_users_expired_requests.py | 2 +- .../commands/clean_invalid_users.py | 2 +- .../commands/year_revalidation_users.py | 2 +- beat/web/accounts/models.py | 6 +- beat/web/accounts/tests.py | 4 +- beat/web/algorithms/admin.py | 106 +-- beat/web/algorithms/api.py | 16 +- beat/web/algorithms/api_urls.py | 56 +- beat/web/algorithms/apps.py | 2 +- beat/web/algorithms/models.py | 54 +- beat/web/algorithms/serializers.py | 12 +- beat/web/algorithms/signals.py | 18 +- .../algorithms/templatetags/algorithm_tags.py | 16 +- beat/web/algorithms/tests/core.py | 58 +- beat/web/algorithms/tests/tests.py | 4 +- beat/web/algorithms/tests/tests_api.py | 696 +++++++++--------- beat/web/algorithms/tests/tests_team.py | 2 +- beat/web/algorithms/views.py | 54 +- beat/web/attestations/admin.py | 4 +- beat/web/attestations/api.py | 16 +- .../management/commands/clean_attestations.py | 2 +- .../send_attestation_cleanup_warning.py | 4 +- beat/web/attestations/models.py | 6 +- .../templatetags/attestation_tags.py | 18 +- beat/web/attestations/tests.py | 112 +-- beat/web/attestations/urls.py | 12 +- beat/web/attestations/views.py | 44 +- beat/web/backend/admin.py | 54 +- beat/web/backend/api.py | 8 +- beat/web/backend/helpers.py | 32 +- .../management/commands/cleanup_cache.py | 22 +- .../web/backend/management/commands/qsetup.py | 82 +-- beat/web/backend/models/job.py | 8 +- beat/web/backend/models/queue.py | 4 +- beat/web/backend/state.py | 12 +- beat/web/backend/templatetags/backend_tags.py | 16 +- beat/web/backend/tests/common.py | 4 +- beat/web/backend/tests/test_cache.py | 6 +- beat/web/backend/tests/test_setup.py | 228 +++--- beat/web/backend/urls.py | 12 +- beat/web/backend/utils.py | 28 +- beat/web/backend/views.py | 32 +- beat/web/code/api.py | 12 +- beat/web/code/models.py | 26 +- beat/web/code/serializers.py | 4 +- beat/web/common/admin.py | 28 +- beat/web/common/api.py | 10 +- beat/web/common/managers.py | 34 +- beat/web/common/models.py | 18 +- beat/web/common/serializers.py | 22 +- beat/web/common/texts.py | 4 +- beat/web/common/utils.py | 4 +- beat/web/databases/admin.py | 102 +-- beat/web/databases/api.py | 18 +- .../migrations/0002_scheduler_addons.py | 8 +- beat/web/databases/models.py | 76 +- beat/web/databases/serializers.py | 16 +- beat/web/databases/signals.py | 26 +- .../databases/templatetags/database_tags.py | 16 +- beat/web/databases/tests.py | 28 +- beat/web/databases/views.py | 16 +- beat/web/dataformats/admin.py | 86 +-- beat/web/dataformats/forms.py | 88 +-- beat/web/dataformats/models.py | 64 +- .../templatetags/dataformat_tags.py | 38 +- beat/web/dataformats/tests/core.py | 36 +- beat/web/dataformats/tests/tests.py | 16 +- beat/web/dataformats/tests/tests_api.py | 472 ++++++------ beat/web/dataformats/views.py | 76 +- beat/web/experiments/admin.py | 208 +++--- beat/web/experiments/api.py | 40 +- .../commands/cleanup_orphaned_caches.py | 4 +- .../migrations/0002_scheduler_addons.py | 2 +- .../migrations/0003_scheduler_addons_2.py | 8 +- .../migrations/0004_scheduler_addons_3.py | 46 +- .../migrations/0005_scheduler_addons_4.py | 44 +- .../migrations/0006_block_order.py | 10 +- .../migrations/0007_cachedfile_status.py | 6 +- beat/web/experiments/models/block.py | 8 +- beat/web/experiments/models/block_input.py | 4 +- beat/web/experiments/models/cached_file.py | 8 +- beat/web/experiments/models/experiment.py | 132 ++-- beat/web/experiments/models/result.py | 2 +- beat/web/experiments/serializers.py | 14 +- .../templatetags/experiment_tags.py | 92 +-- beat/web/experiments/tests.py | 504 ++++++------- beat/web/experiments/views.py | 116 +-- beat/web/libraries/admin.py | 94 +-- beat/web/libraries/api.py | 4 +- beat/web/libraries/models.py | 50 +- .../libraries/templatetags/library_tags.py | 18 +- beat/web/libraries/tests/core.py | 38 +- beat/web/libraries/tests/tests_api.py | 568 +++++++------- beat/web/libraries/tests/tests_team.py | 2 +- beat/web/libraries/views.py | 114 +-- beat/web/navigation/admin.py | 8 +- beat/web/navigation/context_processors.py | 6 +- beat/web/navigation/models.py | 8 +- beat/web/navigation/signals.py | 2 +- beat/web/navigation/urls.py | 6 +- beat/web/navigation/views.py | 16 +- beat/web/plotters/admin.py | 162 ++-- beat/web/plotters/api.py | 6 +- .../migrations/0002_plotter_sample_data.py | 2 +- beat/web/plotters/models.py | 90 +-- beat/web/plotters/serializers.py | 12 +- .../web/plotters/templatetags/plotter_tags.py | 156 ++-- beat/web/plotters/tests.py | 38 +- beat/web/plotters/urls.py | 6 +- beat/web/plotters/views.py | 290 ++++---- beat/web/reports/admin.py | 48 +- .../management/commands/clean_report.py | 2 +- ...send_report_cleanup_warning_and_cleanup.py | 6 +- .../migrations/0004_auto_20170410_1121.py | 16 +- beat/web/reports/models.py | 30 +- beat/web/reports/templatetags/report_tags.py | 36 +- beat/web/reports/tests.py | 250 +++---- beat/web/reports/urls.py | 12 +- beat/web/reports/views.py | 66 +- beat/web/scripts/localhost.py | 42 +- beat/web/scripts/process.py | 14 +- beat/web/search/admin.py | 86 +-- beat/web/search/api.py | 20 +- .../commands/update_leaderboards.py | 18 +- .../migrations/0002_scheduler_addons.py | 10 +- beat/web/search/models.py | 42 +- beat/web/search/signals.py | 16 +- beat/web/search/templatetags/search_tags.py | 66 +- beat/web/search/urls.py | 6 +- beat/web/search/utils.py | 20 +- beat/web/search/views.py | 86 +-- beat/web/settings/settings.py | 44 +- beat/web/settings/test.py | 2 +- beat/web/statistics/admin.py | 4 +- .../templatetags/statistics_tags.py | 4 +- beat/web/statistics/tests.py | 12 +- beat/web/statistics/urls.py | 6 +- beat/web/statistics/views.py | 112 +-- beat/web/team/models.py | 2 +- beat/web/team/templatetags/team_tags.py | 8 +- beat/web/team/tests.py | 2 +- beat/web/team/views.py | 50 +- beat/web/toolchains/admin.py | 72 +- beat/web/toolchains/api.py | 2 +- beat/web/toolchains/models.py | 16 +- .../toolchains/templatetags/toolchain_tags.py | 26 +- beat/web/toolchains/tests.py | 490 ++++++------ beat/web/toolchains/views.py | 68 +- beat/web/ui/forms.py | 24 +- beat/web/ui/registration/forms.py | 36 +- beat/web/ui/registration/models.py | 2 +- beat/web/ui/registration/views.py | 10 +- beat/web/ui/templatetags/markup.py | 4 +- beat/web/ui/templatetags/ui_tags.py | 64 +- beat/web/ui/urls.py | 16 +- beat/web/ui/views.py | 114 +-- beat/web/ui/widgets.py | 38 +- beat/web/urls.py | 54 +- beat/web/utils/management/commands/backup.py | 38 +- beat/web/utils/management/commands/install.py | 172 ++--- beat/web/utils/management/commands/restore.py | 18 +- .../utils/management/commands/xdumpdata.py | 44 +- buildout.cfg | 1 + 166 files changed, 4309 insertions(+), 4308 deletions(-) diff --git a/beat/web/accounts/api.py b/beat/web/accounts/api.py index a56b2e4d9..873d8d8d0 100644 --- a/beat/web/accounts/api.py +++ b/beat/web/accounts/api.py @@ -393,7 +393,7 @@ class SuperviseeAddGodfatherView(BaseCreateSupervisionTrackViewSupervisee): supervisee = supervisee, godfather = godfather, is_valid = False, - ) + ) #Assign key to supervision track supervisiontrack.supervision_key = supervisee.profile.supervision_key diff --git a/beat/web/accounts/forms.py b/beat/web/accounts/forms.py index 5ea60f35b..0a0adc716 100644 --- a/beat/web/accounts/forms.py +++ b/beat/web/accounts/forms.py @@ -36,4 +36,4 @@ class AccountSettingsForm(ModelForm): 'experiment_mail_notifications_enabled', 'database_notifications_enabled', 'environment_notifications_enabled', - ] + ] diff --git a/beat/web/accounts/management/commands/block_rejected_users.py b/beat/web/accounts/management/commands/block_rejected_users.py index a00ffddf7..9613bc83e 100644 --- a/beat/web/accounts/management/commands/block_rejected_users.py +++ b/beat/web/accounts/management/commands/block_rejected_users.py @@ -48,7 +48,7 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--noinput', action='store_false', dest='interactive', default=False, - help=('Tells Django to NOT prompt the user for input of any kind.')) + help=('Tells Django to NOT prompt the user for input of any kind.')) def handle(self, *args, **options): diff --git a/beat/web/accounts/management/commands/clean_blocked_users_expired_requests.py b/beat/web/accounts/management/commands/clean_blocked_users_expired_requests.py index 98cdeb8fc..a18167f69 100644 --- a/beat/web/accounts/management/commands/clean_blocked_users_expired_requests.py +++ b/beat/web/accounts/management/commands/clean_blocked_users_expired_requests.py @@ -48,7 +48,7 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--noinput', action='store_false', dest='interactive', default=False, - help=('Tells Django to NOT prompt the user for input of any kind.')) + help=('Tells Django to NOT prompt the user for input of any kind.')) def handle(self, *args, **options): diff --git a/beat/web/accounts/management/commands/clean_invalid_users.py b/beat/web/accounts/management/commands/clean_invalid_users.py index 36c3059e2..70cb41cdd 100644 --- a/beat/web/accounts/management/commands/clean_invalid_users.py +++ b/beat/web/accounts/management/commands/clean_invalid_users.py @@ -48,7 +48,7 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--noinput', action='store_false', dest='interactive', default=False, - help=('Tells Django to NOT prompt the user for input of any kind.')) + help=('Tells Django to NOT prompt the user for input of any kind.')) def handle(self, *args, **options): diff --git a/beat/web/accounts/management/commands/year_revalidation_users.py b/beat/web/accounts/management/commands/year_revalidation_users.py index b00a3669c..5d6badcc4 100644 --- a/beat/web/accounts/management/commands/year_revalidation_users.py +++ b/beat/web/accounts/management/commands/year_revalidation_users.py @@ -53,7 +53,7 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--noinput', action='store_false', dest='interactive', default=False, - help=('Tells Django to NOT prompt the user for input of any kind.')) + help=('Tells Django to NOT prompt the user for input of any kind.')) def handle(self, *args, **options): diff --git a/beat/web/accounts/models.py b/beat/web/accounts/models.py index ae35b2a05..2009ca6c9 100644 --- a/beat/web/accounts/models.py +++ b/beat/web/accounts/models.py @@ -51,9 +51,9 @@ class SupervisionTrack(models.Model): #_____ Fields __________ supervisee = models.ForeignKey(User, on_delete=models.CASCADE, - related_name='supervisors') + related_name='supervisors') godfather = models.ForeignKey(User, on_delete=models.CASCADE, - related_name='supervisees') + related_name='supervisees') is_valid = models.BooleanField(default=False) start_date = models.DateTimeField(null=True, blank=True) expiration_date = models.DateTimeField(null=True, blank=True) @@ -105,7 +105,7 @@ class Profile(models.Model): def _generate_current_supervision_key(self): length = 40 return ''.join(random.choice(string.ascii_letters + string.digits) for _ - in range(length)) + in range(length)) @receiver(post_save, sender=User) def create_user_profile(sender, instance, created, **kwargs): diff --git a/beat/web/accounts/tests.py b/beat/web/accounts/tests.py index 81a61ce82..6cd2c849a 100644 --- a/beat/web/accounts/tests.py +++ b/beat/web/accounts/tests.py @@ -99,7 +99,7 @@ class AccountTestCase(APITestCase): start_date = now, expiration_date = now + expiration_date_delta, last_validation_date = now - ) + ) #Assign key to supervision track supervisiontrack.supervision_key = self.accepteduser.profile.supervision_key @@ -125,7 +125,7 @@ class AccountTestCase(APITestCase): start_date = now, expiration_date = now + expiration_date_delta, last_validation_date = now - ) + ) #Assign key to supervision track supervisiontrack.supervision_key = self.yearrevalidationuser.profile.supervision_key diff --git a/beat/web/algorithms/admin.py b/beat/web/algorithms/admin.py index f03412a9e..e1d4789f0 100755 --- a/beat/web/algorithms/admin.py +++ b/beat/web/algorithms/admin.py @@ -31,7 +31,7 @@ from django.core.files.base import ContentFile from django.utils import six from ..ui.forms import CodeMirrorPythonFileField, CodeMirrorRSTFileField, \ - CodeMirrorJSONFileField, CodeMirrorJSONCharField + CodeMirrorJSONFileField, CodeMirrorJSONCharField from ..common.texts import Messages @@ -50,45 +50,45 @@ import simplejson as json class AlgorithmModelForm(forms.ModelForm): name = NameField( - widget=forms.TextInput(attrs=dict(size=80)), - help_text=Messages['algo_name'], - ) + widget=forms.TextInput(attrs=dict(size=80)), + help_text=Messages['algo_name'], + ) declaration_file = CodeMirrorJSONFileField( - label='Declaration', - help_text=Messages['json'], - ) + label='Declaration', + help_text=Messages['json'], + ) source_code_file = CodeMirrorPythonFileField( - label='Source code', - help_text=Messages['code'], - ) + label='Source code', + help_text=Messages['code'], + ) description_file = CodeMirrorRSTFileField( - label='Description', - required=False, - allow_empty_file=True, - help_text=Messages['description'], - ) + label='Description', + required=False, + allow_empty_file=True, + help_text=Messages['description'], + ) parameters = CodeMirrorJSONCharField( - readonly=True, - required=False, - ) + readonly=True, + required=False, + ) result_dataformat = CodeMirrorJSONCharField( - readonly=True, - required=False, - ) + readonly=True, + required=False, + ) class Meta: model = AlgorithmModel exclude = [] widgets = { - 'short_description': forms.TextInput( - attrs=dict(size=100), - ), - } + 'short_description': forms.TextInput( + attrs=dict(size=100), + ), + } def __init__(self, *args, **kwargs): @@ -156,7 +156,7 @@ rehash_algorithm.short_description = 'Rehash selected algorithms' class Algorithm(admin.ModelAdmin): list_display = ( - 'id', + 'id', 'author', 'name', 'version', @@ -168,17 +168,17 @@ class Algorithm(admin.ModelAdmin): 'fork_of', 'sharing', 'hash' - ) + ) search_fields = [ - 'author__username', + 'author__username', 'name', 'short_description', 'previous_version__author__username', 'previous_version__name', 'fork_of__author__username', 'fork_of__name' - ] + ] list_filter = ('sharing', ) list_display_links = ('id', 'name') readonly_fields = ('hash', 'splittable', 'short_description') @@ -189,7 +189,7 @@ class Algorithm(admin.ModelAdmin): actions = [ rehash_algorithm, - ] + ] form = AlgorithmModelForm @@ -203,40 +203,40 @@ class Algorithm(admin.ModelAdmin): fieldsets = ( (None, - dict( - fields=('name', 'author',), - ), + dict( + fields=('name', 'author',), + ), ), ('Documentation', - dict( - classes=('collapse',), - fields=('short_description', 'description_file',), - ), + dict( + classes=('collapse',), + fields=('short_description', 'description_file',), + ), ), ('Versioning', - dict( - classes=('collapse',), - fields=('version', 'previous_version', 'fork_of'), - ), + dict( + classes=('collapse',), + fields=('version', 'previous_version', 'fork_of'), + ), ), ('Sharing', - dict( - classes=('collapse',), - fields=('sharing', 'shared_with', 'shared_with_team', 'usable_by', 'usable_by_team'), - ), + dict( + classes=('collapse',), + fields=('sharing', 'shared_with', 'shared_with_team', 'usable_by', 'usable_by_team'), + ), ), ('Cached Information (read-only)', - dict( - classes=('collapse',), - fields=('parameters', 'result_dataformat', 'referenced_libraries'), - ), + dict( + classes=('collapse',), + fields=('parameters', 'result_dataformat', 'referenced_libraries'), + ), ), ('Definition', - dict( - fields=('hash', 'splittable', 'declaration_file', 'language', 'source_code_file'), - ), + dict( + fields=('hash', 'splittable', 'declaration_file', 'language', 'source_code_file'), + ), ), - ) + ) def get_form(self, request, obj=None, **kwargs): if obj.is_binary(): diff --git a/beat/web/algorithms/api.py b/beat/web/algorithms/api.py index 11a1e03fb..bba70cf42 100755 --- a/beat/web/algorithms/api.py +++ b/beat/web/algorithms/api.py @@ -43,7 +43,7 @@ from ..code.api import ShareCodeView, RetrieveUpdateDestroyCodeView from ..code.serializers import CodeDiffSerializer from ..common.api import (CheckContributionNameView, ListContributionView, - ListCreateContributionView) + ListCreateContributionView) from ..code.api import DiffView @@ -112,7 +112,7 @@ class RetrieveUpdateDestroyAlgorithmsView(RetrieveUpdateDestroyCodeView): if modified: # Delete existing experiments using the algorithm (code changed) experiments = list(set(map(lambda x: x.experiment, - algorithm.blocks.iterator()))) + algorithm.blocks.iterator()))) for experiment in experiments: experiment.delete() return modified, algorithm @@ -142,14 +142,14 @@ def binary(request, author_name, object_name, version=None): # Retrieves the algorithm if version: algorithm = get_object_or_404( - Algorithm, - author__username__iexact=author_name, - name__iexact=object_name, - version=int(version), - ) + Algorithm, + author__username__iexact=author_name, + name__iexact=object_name, + version=int(version), + ) else: algorithm = Algorithm.objects.filter(author__username__iexact=author_name, - name__iexact=object_name).order_by('-version') + name__iexact=object_name).order_by('-version') if not algorithm: raise Http404() else: diff --git a/beat/web/algorithms/api_urls.py b/beat/web/algorithms/api_urls.py index c0e84a2a1..15419a86a 100755 --- a/beat/web/algorithms/api_urls.py +++ b/beat/web/algorithms/api_urls.py @@ -31,49 +31,49 @@ import api urlpatterns = [ - url(r'^$', - api.ListAlgorithmsView.as_view(), - name='all', + url(r'^$', + api.ListAlgorithmsView.as_view(), + name='all', ), - url(r'^check_name/$', - api.CheckAlgorithmNameView.as_view(), - name='check_name', + url(r'^check_name/$', + api.CheckAlgorithmNameView.as_view(), + name='check_name', ), - url(r'^diff/(?P<author1>\w+)/(?P<name1>[-\w]+)/(?P<version1>\d+)/(?P<author2>\w+)/(?P<name2>[-\w]+)/(?P<version2>\d+)/$', - api.DiffAlgorithmView.as_view(), - name='diff', + url(r'^diff/(?P<author1>\w+)/(?P<name1>[-\w]+)/(?P<version1>\d+)/(?P<author2>\w+)/(?P<name2>[-\w]+)/(?P<version2>\d+)/$', + api.DiffAlgorithmView.as_view(), + name='diff', ), - url(r'^(?P<author_name>\w+)/(?P<object_name>[-\w]+)/(?P<version>\d+)/share/$', - api.ShareAlgorithmView.as_view(), - name='share', + url(r'^(?P<author_name>\w+)/(?P<object_name>[-\w]+)/(?P<version>\d+)/share/$', + api.ShareAlgorithmView.as_view(), + name='share', ), - url(r'^(?P<author_name>\w+)/$', - api.ListCreateAlgorithmsView.as_view(), - name='list_create', + url(r'^(?P<author_name>\w+)/$', + api.ListCreateAlgorithmsView.as_view(), + name='list_create', ), - url(r'^(?P<author_name>\w+)/(?P<object_name>[-\w]+)/(?P<version>\d+)/$', - api.RetrieveUpdateDestroyAlgorithmsView.as_view(), - name='object', + url(r'^(?P<author_name>\w+)/(?P<object_name>[-\w]+)/(?P<version>\d+)/$', + api.RetrieveUpdateDestroyAlgorithmsView.as_view(), + name='object', ), - url(r'^(?P<author_name>\w+)/(?P<object_name>[-\w]+)/$', - api.RetrieveUpdateDestroyAlgorithmsView.as_view(), - name='object', + url(r'^(?P<author_name>\w+)/(?P<object_name>[-\w]+)/$', + api.RetrieveUpdateDestroyAlgorithmsView.as_view(), + name='object', ), - url(r'^(?P<author_name>\w+)/(?P<object_name>[-\w]+)/(?P<version>\d+)/binary/$', - api.binary, - name='binary', + url(r'^(?P<author_name>\w+)/(?P<object_name>[-\w]+)/(?P<version>\d+)/binary/$', + api.binary, + name='binary', ), - url(r'^(?P<author_name>\w+)/(?P<object_name>[-\w]+)/binary/$', - api.binary, - name='binary', + url(r'^(?P<author_name>\w+)/(?P<object_name>[-\w]+)/binary/$', + api.binary, + name='binary', ), - ] +] diff --git a/beat/web/algorithms/apps.py b/beat/web/algorithms/apps.py index 3f5754993..97c03eb5f 100644 --- a/beat/web/algorithms/apps.py +++ b/beat/web/algorithms/apps.py @@ -36,7 +36,7 @@ class AlgorithmsConfig(CommonAppConfig): super(AlgorithmsConfig, self).ready() from .signals import (create_endpoints, delete_endpoints, - auto_delete_file_on_delete, auto_delete_file_on_change) + auto_delete_file_on_delete, auto_delete_file_on_change) from actstream import registry registry.register(self.get_model('Algorithm')) diff --git a/beat/web/algorithms/models.py b/beat/web/algorithms/models.py index c4ddf0554..15c44ef09 100755 --- a/beat/web/algorithms/models.py +++ b/beat/web/algorithms/models.py @@ -111,35 +111,35 @@ class Algorithm(Code): #_____ Fields __________ declaration_file = models.FileField( - storage=AlgorithmStorage(), - upload_to=get_contribution_declaration_filename, - blank=True, null=True, - max_length=200, - db_column='declaration' - ) + storage=AlgorithmStorage(), + upload_to=get_contribution_declaration_filename, + blank=True, null=True, + max_length=200, + db_column='declaration' + ) description_file = models.FileField( - storage=AlgorithmStorage(), - upload_to=get_contribution_description_filename, - blank=True, null=True, - max_length=200, - db_column='description' - ) + storage=AlgorithmStorage(), + upload_to=get_contribution_description_filename, + blank=True, null=True, + max_length=200, + db_column='description' + ) source_code_file = models.FileField( - storage=AlgorithmStorage(), - upload_to=get_contribution_source_code_filename, - blank=True, null=True, - max_length=200, - db_column='source_code' - ) + storage=AlgorithmStorage(), + upload_to=get_contribution_source_code_filename, + blank=True, null=True, + max_length=200, + db_column='source_code' + ) # Read-only parameters that are updated at every save(), if required parameters = models.TextField(blank=True, null=True) result_dataformat = models.TextField(blank=True, null=True) splittable = models.BooleanField(default=False, help_text='Defines if the code can be executed ' \ - 'in multiple instances') + 'in multiple instances') referenced_libraries = models.ManyToManyField(Library, blank=True, related_name='used_by_algorithms', @@ -153,27 +153,27 @@ class Algorithm(Code): def get_absolute_url(self): return reverse( - 'algorithms:view', + 'algorithms:view', args=(self.author.username, self.name, self.version,), - ) + ) def get_api_update_url(self): '''Returns the endpoint to update this object''' return reverse( - 'api_algorithms:object', + 'api_algorithms:object', args=(self.author.username, self.name, self.version,), - ) + ) def get_api_share_url(self): '''Returns the endpoint to share this object''' return reverse( - 'api_algorithms:share', + 'api_algorithms:share', args=(self.author.username, self.name, self.version,), - ) + ) def environments(self): @@ -202,7 +202,7 @@ class Algorithm(Code): envs = Environment.objects.filter(blocks__in=self.blocks.filter( Q(experiment__status=Experiment.DONE) | \ ((~Q(experiment__status=Experiment.DONE)) & Q(status=Block.DONE)) - )).annotate(itemcount=Count('id')).order_by('-creation_date').distinct() + )).annotate(itemcount=Count('id')).order_by('-creation_date').distinct() return [(k, k.itemcount) for k in envs] @@ -222,7 +222,7 @@ class Algorithm(Code): "default_value": details.get('default'), "comment": details.get('description', ''), "type": details['type'], - } + } ) if 'choice' in details: diff --git a/beat/web/algorithms/serializers.py b/beat/web/algorithms/serializers.py index 6b166b448..0c1feb03e 100644 --- a/beat/web/algorithms/serializers.py +++ b/beat/web/algorithms/serializers.py @@ -76,17 +76,17 @@ class AlgorithmSerializer(CodeSerializer): def get_inputs(self, obj): return map(lambda x: { - 'name': x.name, + 'name': x.name, 'dataformat': x.dataformat.fullname(), 'channel': x.channel - }, obj.endpoints.filter(input=True).order_by('name')) + }, obj.endpoints.filter(input=True).order_by('name')) def get_outputs(self, obj): return map(lambda x: { - 'name': x.name, + 'name': x.name, 'dataformat': x.dataformat.fullname(), 'channel': x.channel, - }, obj.endpoints.filter(input=False).order_by('name')) + }, obj.endpoints.filter(input=False).order_by('name')) def get_referencing_experiments(self, obj): user = self.context.get('user') @@ -96,9 +96,9 @@ class AlgorithmSerializer(CodeSerializer): # Put the pending experiments first ordered_result = filter(lambda x: x['creation_date'] is None, \ - referencing_experiments) + referencing_experiments) ordered_result += filter(lambda x: x['creation_date'] is not None, \ - referencing_experiments) + referencing_experiments) return ordered_result diff --git a/beat/web/algorithms/signals.py b/beat/web/algorithms/signals.py index 079a9b25b..c74bfa313 100644 --- a/beat/web/algorithms/signals.py +++ b/beat/web/algorithms/signals.py @@ -106,18 +106,18 @@ def create_endpoints(sender, instance, **kwargs): (df_author, df_name, df_version) = formatname.split('/') df = DataFormat.objects.get( - author__username=df_author, - name=df_name, - version=df_version, - ) + author__username=df_author, + name=df_name, + version=df_version, + ) endpoint = AlgorithmEndpoint.objects.filter( - algorithm = instance, - input = isinput, - name = name, - #channel = channel_name, + algorithm = instance, + input = isinput, + name = name, + #channel = channel_name, dataformat = df, - ) + ) if not endpoint: endpoint = AlgorithmEndpoint() diff --git a/beat/web/algorithms/templatetags/algorithm_tags.py b/beat/web/algorithms/templatetags/algorithm_tags.py index fb6caf386..5a0fe0cd6 100755 --- a/beat/web/algorithms/templatetags/algorithm_tags.py +++ b/beat/web/algorithms/templatetags/algorithm_tags.py @@ -51,11 +51,11 @@ def algorithm_table(context, objects, owner, panel_id): ''' return { - 'request': context['request'], + 'request': context['request'], 'objects': objects, 'owner': owner, 'panel_id': panel_id, - } + } @register.inclusion_tag('algorithms/panels/actions.html', takes_context=True) @@ -75,23 +75,23 @@ def algorithm_actions(context, obj, display_count): ''' request = context['request'] return { - 'request': request, + 'request': request, 'object': obj, 'display_count': display_count, 'open_source': obj.open_source(request.user), - } + } @register.inclusion_tag('algorithms/panels/editor.html', takes_context=True) def algorithm_editor(context, obj): request = context['request'] return { - 'owner': request.user == obj.author, + 'owner': request.user == obj.author, 'object': obj, 'texts': Texts, 'open_source': obj.open_source(request.user), 'downloadable': obj.is_binary() and ((request.user == obj.author) or (obj.sharing == Shareable.PUBLIC)), - } + } @register.inclusion_tag('algorithms/panels/sharing.html', takes_context=True) @@ -105,12 +105,12 @@ def algorithm_sharing(context, obj): ''' return { - 'request': context['request'], + 'request': context['request'], 'object': obj, 'owner': context['request'].user == obj.author, 'users': context['users'], 'teams': context['teams'], - } + } @register.assignment_tag(takes_context=True) diff --git a/beat/web/algorithms/tests/core.py b/beat/web/algorithms/tests/core.py index 8bebec3fe..0d2c43a90 100755 --- a/beat/web/algorithms/tests/core.py +++ b/beat/web/algorithms/tests/core.py @@ -64,14 +64,14 @@ class AlgorithmsCreationFunction(AlgorithmsBaseTestCase): author=user, name='algorithm1', short_description='some description', - ) + ) assert algorithm, errors self.assertEqual(algorithm.endpoints.count(), 0) storage = Storage(settings.PREFIX, - algorithm.fullname()) + algorithm.fullname()) storage.language = 'python' assert storage.exists() @@ -126,7 +126,7 @@ class AlgorithmsCreationFunction(AlgorithmsBaseTestCase): author=user, name='single_integer', short_description='short description 1', - ) + ) assert dataformat1, errors @@ -135,12 +135,12 @@ class AlgorithmsCreationFunction(AlgorithmsBaseTestCase): name='algorithm1', declaration=declaration, code=code, - ) + ) assert algorithm, errors storage = Storage(settings.PREFIX, - algorithm.fullname()) + algorithm.fullname()) storage.language = 'python' assert storage.exists() @@ -174,8 +174,8 @@ class AlgorithmsCreationFunction(AlgorithmsBaseTestCase): expected = json.loads(declaration) assert in_storage == expected, "There are differences on the " \ - "declaration (beyond white spaces): %r != %r" % \ - (in_storage, expected) + "declaration (beyond white spaces): %r != %r" % \ + (in_storage, expected) # set storage language so it can find the code storage.language = in_storage['language'] @@ -184,7 +184,7 @@ class AlgorithmsCreationFunction(AlgorithmsBaseTestCase): expected = code assert in_storage == expected, "There are differences on the " \ - "code code: %r != %r" % (in_storage, expected) + "code code: %r != %r" % (in_storage, expected) class AlgorithmsTestCase(AlgorithmsBaseTestCase): @@ -203,7 +203,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert algorithm, errors # Usable by one user @@ -213,7 +213,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert algorithm, errors algorithm.share(public=False, users=[user2]) @@ -225,7 +225,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert algorithm, errors algorithm.share(public=False, teams=[team1]) @@ -237,7 +237,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert algorithm, errors algorithm.share(public=False, teams=[team1, team2]) @@ -249,7 +249,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert algorithm, errors algorithm.share(public=False) @@ -261,7 +261,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert algorithm, errors # algorithm.shared_with.add(user2) @@ -274,7 +274,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert algorithm, errors # algorithm.shared_with_team.add(team1) @@ -287,7 +287,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert algorithm, errors algorithm.share(public=True, teams=[team1, team2]) @@ -299,7 +299,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert algorithm, errors algorithm.share(public=True) @@ -318,7 +318,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): name='binary_personal', short_description='', declaration=declaration, - ) + ) assert algorithm, errors assert not algorithm.valid() @@ -333,7 +333,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): name='binary_usable_by_one_user', short_description='', declaration=declaration, - ) + ) assert algorithm, errors algorithm.source_code = binary_data @@ -347,7 +347,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): name='binary_usable_by_one_team', short_description='', declaration=declaration, - ) + ) assert algorithm, errors algorithm.source_code = binary_data @@ -361,7 +361,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): name='binary_usable_by_teams', short_description='', declaration=declaration, - ) + ) assert algorithm, errors algorithm.source_code = binary_data @@ -375,7 +375,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): name='binary_usable_by_all', short_description='', declaration=declaration, - ) + ) assert algorithm, errors algorithm.source_code = binary_data @@ -389,7 +389,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): name='binary_public_for_one_user', short_description='', declaration=declaration, - ) + ) assert algorithm, errors algorithm.source_code = binary_data @@ -403,7 +403,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): name='binary_public_for_one_team', short_description='', declaration=declaration, - ) + ) assert algorithm, errors algorithm.source_code = binary_data @@ -417,7 +417,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): name='binary_public_for_teams', short_description='', declaration=declaration, - ) + ) assert algorithm, errors algorithm.source_code = binary_data @@ -431,7 +431,7 @@ class AlgorithmsTestCase(AlgorithmsBaseTestCase): name='binary_public_for_all', short_description='', declaration=declaration, - ) + ) assert algorithm, errors algorithm.source_code = binary_data @@ -485,7 +485,7 @@ class AlgorithmsAccessibilityFunctionsBase(AlgorithmsTestCase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=user1, name='public_for_all', - ) + ) assert dataformat, errors dataformat.share() @@ -591,7 +591,7 @@ class AlgorithmsAPIBase(AlgorithmsTestCase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=user2, name='single_integer', - ) + ) assert dataformat, errors dataformat.share() @@ -604,7 +604,7 @@ class AlgorithmsAPIBase(AlgorithmsTestCase): short_description='', declaration=AlgorithmsAPIBase.DECLARATION, code=AlgorithmsAPIBase.CODE, - ) + ) assert algorithm, errors algorithm.previous_version = None diff --git a/beat/web/algorithms/tests/tests.py b/beat/web/algorithms/tests/tests.py index 3b0edf3cb..1e0d16367 100644 --- a/beat/web/algorithms/tests/tests.py +++ b/beat/web/algorithms/tests/tests.py @@ -84,7 +84,7 @@ class DependencyTests(AlgorithmsBaseTestCase): name='algorithm1', declaration=algorithm_declaration, code=algorithm_code, - ) + ) assert algorithm, errors @@ -93,7 +93,7 @@ class DependencyTests(AlgorithmsBaseTestCase): name='library1', declaration=library_declaration, code=library_code, - ) + ) assert library, errors diff --git a/beat/web/algorithms/tests/tests_api.py b/beat/web/algorithms/tests/tests_api.py index 1a25f26fa..33b1f215d 100755 --- a/beat/web/algorithms/tests/tests_api.py +++ b/beat/web/algorithms/tests/tests_api.py @@ -447,7 +447,7 @@ class AlgorithmsNameCheck(AlgorithmsAPIBase): author=user, name='algorithm-4', short_description='short description 4' - ) + ) assert version4, errors @@ -468,10 +468,10 @@ class AlgorithmsNameCheck(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'private': True - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'private': True + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -484,10 +484,10 @@ class AlgorithmsNameCheck(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name_1 #due-to{}%&é', - 'private': True - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name_1 #due-to{}%&é', + 'private': True + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -500,10 +500,10 @@ class AlgorithmsNameCheck(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'usable_by_one_user', - 'private': True - }), content_type='application/json') + json.dumps({ + 'name': 'usable_by_one_user', + 'private': True + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -516,10 +516,10 @@ class AlgorithmsNameCheck(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'algorithm 4', - 'private': True - }), content_type='application/json') + json.dumps({ + 'name': 'algorithm 4', + 'private': True + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -541,7 +541,7 @@ class AlgorithmCreation(AlgorithmsAPIBase): author=user, name='algorithm-4', short_description='short description 4' - ) + ) assert version4, errors @@ -552,15 +552,15 @@ class AlgorithmCreation(AlgorithmsAPIBase): code = code or default.code storage = beat.core.algorithm.Storage(settings.PREFIX, - algorithm.fullname()) + algorithm.fullname()) assert storage.exists in_storage = json.loads(storage.json.load()) expected = json.loads(declaration) assert in_storage == expected, "There are differences on the " \ - "declaration (beyond white spaces): %r != %r" % \ - (in_storage, expected) + "declaration (beyond white spaces): %r != %r" % \ + (in_storage, expected) if in_storage['language'] == 'python': self.assertTrue(algorithm.valid()) @@ -572,7 +572,7 @@ class AlgorithmCreation(AlgorithmsAPIBase): expected = code assert in_storage == expected, "There are differences on the " \ - "code: %r != %r" % (in_storage, expected) + "code: %r != %r" % (in_storage, expected) def test_no_creation_for_anonymous_user(self): @@ -599,10 +599,10 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'description': 'blah' - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'description': 'blah' + }), content_type='application/json') url = reverse('api_algorithms:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, @@ -627,9 +627,9 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1' - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1' + }), content_type='application/json') url = reverse('api_algorithms:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, @@ -653,10 +653,10 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name1', - 'description': 'blah' - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name1', + 'description': 'blah' + }), content_type='application/json') url = reverse('api_algorithms:object', args=['jackdoe', 'invalid-name1', 1]) content = self.checkResponse(response, 201, @@ -681,9 +681,9 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name1' - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name1' + }), content_type='application/json') url = reverse('api_algorithms:object', args=['jackdoe', 'invalid-name1', 1]) content = self.checkResponse(response, 201, @@ -707,12 +707,12 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'description': 'blah', - 'declaration':AlgorithmsAPIBase.DECLARATION, - 'code': AlgorithmsAPIBase.CODE - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'description': 'blah', + 'declaration':AlgorithmsAPIBase.DECLARATION, + 'code': AlgorithmsAPIBase.CODE + }), content_type='application/json') url = reverse('api_algorithms:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, @@ -731,18 +731,18 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.assertEqual(algorithm.short_description, '') self.assertEqual(algorithm.description, 'blah') self.checkAlgorithm(algorithm, AlgorithmsAPIBase.DECLARATION, - AlgorithmsAPIBase.CODE) + AlgorithmsAPIBase.CODE) def test_not_used_valid_name__no_description(self): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'declaration': AlgorithmsAPIBase.DECLARATION, - 'code': AlgorithmsAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'declaration': AlgorithmsAPIBase.DECLARATION, + 'code': AlgorithmsAPIBase.CODE, + }), content_type='application/json') url = reverse('api_algorithms:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, @@ -760,19 +760,19 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.assertEqual(algorithm.short_description, '') self.checkAlgorithm(algorithm, AlgorithmsAPIBase.DECLARATION, - AlgorithmsAPIBase.CODE) + AlgorithmsAPIBase.CODE) def test_not_used_invalid_name(self): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name1', - 'description': 'blah', - 'declaration': AlgorithmsAPIBase.DECLARATION, - 'code': AlgorithmsAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name1', + 'description': 'blah', + 'declaration': AlgorithmsAPIBase.DECLARATION, + 'code': AlgorithmsAPIBase.CODE, + }), content_type='application/json') url = reverse('api_algorithms:object', args=['jackdoe', 'invalid-name1', 1]) content = self.checkResponse(response, 201, @@ -791,18 +791,18 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.assertEqual(algorithm.short_description, '') self.assertEqual(algorithm.description, 'blah') self.checkAlgorithm(algorithm, AlgorithmsAPIBase.DECLARATION, - AlgorithmsAPIBase.CODE) + AlgorithmsAPIBase.CODE) def test_not_used_invalid_name__no_description(self): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name1', - 'declaration': AlgorithmsAPIBase.DECLARATION, - 'code': AlgorithmsAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name1', + 'declaration': AlgorithmsAPIBase.DECLARATION, + 'code': AlgorithmsAPIBase.CODE, + }), content_type='application/json') url = reverse('api_algorithms:object', args=['jackdoe', 'invalid-name1', 1]) content = self.checkResponse(response, 201, @@ -820,17 +820,17 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.assertEqual(algorithm.short_description, '') self.checkAlgorithm(algorithm, AlgorithmsAPIBase.DECLARATION, - AlgorithmsAPIBase.CODE) + AlgorithmsAPIBase.CODE) def test_used_valid_name_no_code(self): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'usable_by_one_user', - 'description': 'blah' - }), content_type='application/json') + json.dumps({ + 'name': 'usable_by_one_user', + 'description': 'blah' + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -839,9 +839,9 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'usable_by_one_user' - }), content_type='application/json') + json.dumps({ + 'name': 'usable_by_one_user' + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -850,10 +850,10 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'algorithm 4', - 'description': 'blah' - }), content_type='application/json') + json.dumps({ + 'name': 'algorithm 4', + 'description': 'blah' + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -862,9 +862,9 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'algorithm 4' - }), content_type='application/json') + json.dumps({ + 'name': 'algorithm 4' + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -873,12 +873,12 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'usable_by_one_user', - 'description': 'blah', - 'declaration': AlgorithmsAPIBase.DECLARATION, - 'code': AlgorithmsAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'name': 'usable_by_one_user', + 'description': 'blah', + 'declaration': AlgorithmsAPIBase.DECLARATION, + 'code': AlgorithmsAPIBase.CODE, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -887,11 +887,11 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'usable_by_one_user', - 'declaration': AlgorithmsAPIBase.DECLARATION, - 'code': AlgorithmsAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'name': 'usable_by_one_user', + 'declaration': AlgorithmsAPIBase.DECLARATION, + 'code': AlgorithmsAPIBase.CODE, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -900,12 +900,12 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'algorithm 4', - 'description': 'blah', - 'declaration': AlgorithmsAPIBase.DECLARATION, - 'code': AlgorithmsAPIBase.CODE - }), content_type='application/json') + json.dumps({ + 'name': 'algorithm 4', + 'description': 'blah', + 'declaration': AlgorithmsAPIBase.DECLARATION, + 'code': AlgorithmsAPIBase.CODE + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -914,11 +914,11 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'algorithm 4', - 'declaration': AlgorithmsAPIBase.DECLARATION, - 'code': AlgorithmsAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'name': 'algorithm 4', + 'declaration': AlgorithmsAPIBase.DECLARATION, + 'code': AlgorithmsAPIBase.CODE, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -927,11 +927,11 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'description': 'blah', - 'declaration': AlgorithmsAPIBase.CXX_DECLARATION, - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'description': 'blah', + 'declaration': AlgorithmsAPIBase.CXX_DECLARATION, + }), content_type='application/json') url = reverse('api_algorithms:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, @@ -958,12 +958,12 @@ class AlgorithmCreation(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'description': 'blah', - 'declaration': AlgorithmsAPIBase.CXX_DECLARATION, - 'fork_of': 'jackdoe/binary_personal/1', - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'description': 'blah', + 'declaration': AlgorithmsAPIBase.CXX_DECLARATION, + 'fork_of': 'jackdoe/binary_personal/1', + }), content_type='application/json') url = reverse('api_algorithms:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, @@ -992,12 +992,12 @@ class AlgorithmCreation(AlgorithmsAPIBase): 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') + 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, @@ -1030,11 +1030,11 @@ class AlgorithmUpdate(AlgorithmsAPIBase): def test_no_update_for_anonymous_user(self): response = self.client.put(self.url, - json.dumps({ - 'description': 'blah', - 'declaration': AlgorithmsAPIBase.DECLARATION, - 'code': AlgorithmsAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': AlgorithmsAPIBase.DECLARATION, + 'code': AlgorithmsAPIBase.CODE, + }), content_type='application/json') self.checkResponse(response, 403) @@ -1044,11 +1044,11 @@ class AlgorithmUpdate(AlgorithmsAPIBase): url = reverse('api_algorithms:object', args=['unknown', 'personal', 1]) response = self.client.put(url, - json.dumps({ - 'description': 'blah', - 'declaration': AlgorithmsAPIBase.DECLARATION, - 'code': AlgorithmsAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': AlgorithmsAPIBase.DECLARATION, + 'code': AlgorithmsAPIBase.CODE, + }), content_type='application/json') self.checkResponse(response, 403) @@ -1058,11 +1058,11 @@ class AlgorithmUpdate(AlgorithmsAPIBase): url = reverse('api_algorithms:object', args=['jackdoe', 'unknown', 1]) response = self.client.put(url, - json.dumps({ - 'description': 'blah', - 'declaration': AlgorithmsAPIBase.DECLARATION, - 'code': AlgorithmsAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': AlgorithmsAPIBase.DECLARATION, + 'code': AlgorithmsAPIBase.CODE, + }), content_type='application/json') self.checkResponse(response, 404) @@ -1077,10 +1077,10 @@ class AlgorithmUpdate(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'description': 'blah', - 'declaration': AlgorithmsAPIBase.UPDATE - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': AlgorithmsAPIBase.UPDATE + }), content_type='application/json') self.checkResponse(response, 204) @@ -1088,7 +1088,7 @@ class AlgorithmUpdate(AlgorithmsAPIBase): self.assertEqual(algorithm.description, 'blah') storage = beat.core.algorithm.Storage(settings.PREFIX, - algorithm.fullname()) + algorithm.fullname()) storage.language = 'python' assert storage.exists() self.assertEqual(storage.json.load(), AlgorithmsAPIBase.UPDATE) @@ -1098,9 +1098,9 @@ class AlgorithmUpdate(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'description': 'blah', - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + }), content_type='application/json') self.checkResponse(response, 204) @@ -1112,16 +1112,16 @@ class AlgorithmUpdate(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': AlgorithmsAPIBase.UPDATE - }), content_type='application/json') + json.dumps({ + 'declaration': AlgorithmsAPIBase.UPDATE + }), content_type='application/json') self.checkResponse(response, 204) algorithm = Algorithm.objects.get(author__username='jackdoe', name='personal', version=1) storage = beat.core.algorithm.Storage(settings.PREFIX, - algorithm.fullname()) + algorithm.fullname()) storage.language = 'python' assert storage.exists() self.assertEqual(storage.json.load(), AlgorithmsAPIBase.UPDATE) @@ -1148,9 +1148,9 @@ class AlgorithmUpdate(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 204) @@ -1194,15 +1194,15 @@ class AlgorithmUpdate(AlgorithmsAPIBase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=User.objects.get(username='jackdoe'), name='single_float', - ) + ) assert dataformat, errors self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 204) @@ -1252,10 +1252,10 @@ class AlgorithmUpdate(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': declaration, - 'code': code, - }), content_type='application/json') + json.dumps({ + 'declaration': declaration, + 'code': code, + }), content_type='application/json') self.checkResponse(response, 204) @@ -1299,15 +1299,15 @@ class AlgorithmUpdate(AlgorithmsAPIBase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=User.objects.get(username='jackdoe'), name='single_float', - ) + ) assert dataformat, errors self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': declaration - }), content_type='application/json') + json.dumps({ + 'declaration': declaration + }), content_type='application/json') self.checkResponse(response, 204) @@ -1352,9 +1352,9 @@ class AlgorithmUpdate(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 204) @@ -1401,9 +1401,9 @@ class AlgorithmUpdate(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 204) @@ -1444,9 +1444,9 @@ class AlgorithmUpdate(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 204) @@ -1522,18 +1522,18 @@ class AlgorithmUpdate(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': declaration1, - 'code': code, - }), content_type='application/json') + json.dumps({ + 'declaration': declaration1, + 'code': code, + }), content_type='application/json') self.checkResponse(response, 204) response = self.client.put(self.url, - json.dumps({ - 'declaration': declaration2, - 'code': code, - }), content_type='application/json') + json.dumps({ + 'declaration': declaration2, + 'code': code, + }), content_type='application/json') self.checkResponse(response, 204) @@ -1578,9 +1578,9 @@ class AlgorithmUpdate(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 204) @@ -1653,18 +1653,18 @@ class AlgorithmUpdate(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': declaration1, - 'code': code, - }), content_type='application/json') + json.dumps({ + 'declaration': declaration1, + 'code': code, + }), content_type='application/json') self.checkResponse(response, 204) response = self.client.put(self.url, - json.dumps({ - 'declaration': declaration2, - 'code': code, - }), content_type='application/json') + json.dumps({ + 'declaration': declaration2, + 'code': code, + }), content_type='application/json') self.checkResponse(response, 204) @@ -1702,9 +1702,9 @@ class AlgorithmBinaryUpdate(AlgorithmsAPIBase): def test_no_update_for_anonymous_user(self): response = self.client.post(self.url, - { - 'binary': self.updated_binary_file, - }) + { + 'binary': self.updated_binary_file, + }) self.checkResponse(response, 403) @@ -1714,9 +1714,9 @@ class AlgorithmBinaryUpdate(AlgorithmsAPIBase): url = reverse('api_algorithms:binary', args=['unknown', 'personal', 1]) response = self.client.post(url, - { - 'binary': self.updated_binary_file, - }) + { + 'binary': self.updated_binary_file, + }) self.checkResponse(response, 404) @@ -1726,9 +1726,9 @@ class AlgorithmBinaryUpdate(AlgorithmsAPIBase): url = reverse('api_algorithms:binary', args=['jackdoe', 'unknown', 1]) response = self.client.post(url, - { - 'binary': self.updated_binary_file, - }) + { + 'binary': self.updated_binary_file, + }) self.checkResponse(response, 404) @@ -1736,26 +1736,26 @@ class AlgorithmBinaryUpdate(AlgorithmsAPIBase): def test_no_update_without_content(self): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - { - }) + { + }) self.checkResponse(response, 400) def test_no_update_with_invalid_filename(self): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - { - 'unknown': self.updated_binary_file, - }) + { + 'unknown': self.updated_binary_file, + }) self.checkResponse(response, 400) def test_no_update_with_invalid_file_content(self): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - { - 'binary': None, - }) + { + 'binary': None, + }) self.checkResponse(response, 400) @@ -1763,9 +1763,9 @@ class AlgorithmBinaryUpdate(AlgorithmsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - { - 'binary': self.updated_binary_file, - }) + { + 'binary': self.updated_binary_file, + }) self.checkResponse(response, 204) @@ -2190,9 +2190,9 @@ class AlgorithmSharingAPI_Failures(AlgorithmSharingAPIBase): def test_fail_sharing_for_anonymous_user(self): response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + }), content_type='application/json') self.checkResponse(response, 403) @@ -2200,9 +2200,9 @@ class AlgorithmSharingAPI_Failures(AlgorithmSharingAPIBase): def test_fail_sharing_for_unauthorized_user(self): self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + }), content_type='application/json') self.checkResponse(response, 403) @@ -2211,10 +2211,10 @@ class AlgorithmSharingAPI_Failures(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['doejack'], - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['doejack'], + }), content_type='application/json') data = self.checkResponse(response, 400, content_type='application/json') self.assertTrue(data is not None) @@ -2225,10 +2225,10 @@ class AlgorithmSharingAPI_Failures(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['doejack'], - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['doejack'], + }), content_type='application/json') data = self.checkResponse(response, 400, content_type='application/json') self.assertTrue(data is not None) @@ -2239,9 +2239,9 @@ class AlgorithmSharingAPI_Failures(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'notknownstatus', - }), content_type='application/json') + json.dumps({ + 'status': 'notknownstatus', + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -2256,9 +2256,9 @@ class NotSharedAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2274,10 +2274,10 @@ class NotSharedAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['johndoe'], - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['johndoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2295,10 +2295,10 @@ class NotSharedAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['johndoe', 'janedoe'], - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['johndoe', 'janedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2316,9 +2316,9 @@ class NotSharedAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - }), content_type='application/json') + json.dumps({ + 'status': 'public', + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2334,10 +2334,10 @@ class NotSharedAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['johndoe'], - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['johndoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2355,10 +2355,10 @@ class NotSharedAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['johndoe', 'janedoe'], - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['johndoe', 'janedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2383,9 +2383,9 @@ class UsableByOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2401,10 +2401,10 @@ class UsableByOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['johndoe'], - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['johndoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2422,10 +2422,10 @@ class UsableByOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2442,10 +2442,10 @@ class UsableByOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['janedoe', 'jacquelinedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['janedoe', 'jacquelinedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2463,9 +2463,9 @@ class UsableByOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - }), content_type='application/json') + json.dumps({ + 'status': 'public', + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2481,10 +2481,10 @@ class UsableByOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2501,10 +2501,10 @@ class UsableByOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2522,10 +2522,10 @@ class UsableByOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['janedoe', 'jacquelinedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['janedoe', 'jacquelinedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2550,9 +2550,9 @@ class UsableByAllAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable' - }), content_type='application/json') + json.dumps({ + 'status': 'usable' + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2568,10 +2568,10 @@ class UsableByAllAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users': ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users': ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2587,10 +2587,10 @@ class UsableByAllAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users': ['johndoe', 'janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users': ['johndoe', 'janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2606,9 +2606,9 @@ class UsableByAllAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public' - }), content_type='application/json') + json.dumps({ + 'status': 'public' + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2624,10 +2624,10 @@ class UsableByAllAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2644,10 +2644,10 @@ class UsableByAllAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['johndoe', 'janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['johndoe', 'janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2671,9 +2671,9 @@ class PublicForOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2690,10 +2690,10 @@ class PublicForOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2710,10 +2710,10 @@ class PublicForOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2731,10 +2731,10 @@ class PublicForOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['janedoe', 'jacquelinedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['janedoe', 'jacquelinedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2752,9 +2752,9 @@ class PublicForOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public' - }), content_type='application/json') + json.dumps({ + 'status': 'public' + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2770,10 +2770,10 @@ class PublicForOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2790,10 +2790,10 @@ class PublicForOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2810,10 +2810,10 @@ class PublicForOneUserAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['janedoe', 'jacquelinedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['janedoe', 'jacquelinedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2837,9 +2837,9 @@ class PublicForAllAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable' - }), content_type='application/json') + json.dumps({ + 'status': 'usable' + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2855,10 +2855,10 @@ class PublicForAllAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users': ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users': ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2874,10 +2874,10 @@ class PublicForAllAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users': ['johndoe', 'janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users': ['johndoe', 'janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2893,9 +2893,9 @@ class PublicForAllAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public' - }), content_type='application/json') + json.dumps({ + 'status': 'public' + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2911,10 +2911,10 @@ class PublicForAllAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users': ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users': ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -2930,10 +2930,10 @@ class PublicForAllAlgorithm_SharingAPI(AlgorithmSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users': ['johndoe', 'janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users': ['johndoe', 'janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') diff --git a/beat/web/algorithms/tests/tests_team.py b/beat/web/algorithms/tests/tests_team.py index 173946850..2e11d6814 100644 --- a/beat/web/algorithms/tests/tests_team.py +++ b/beat/web/algorithms/tests/tests_team.py @@ -541,7 +541,7 @@ class TeamDeletionPropagation(AlgorithmsAccessibilityFunctionsBase): name='algorithm1', short_description='some description', declaration=DECLARATION, - ) + ) assert algorithm, errors algorithm.share(True, teams=[team_to_delete]) diff --git a/beat/web/algorithms/views.py b/beat/web/algorithms/views.py index a42fd4699..62f3ace9d 100755 --- a/beat/web/algorithms/views.py +++ b/beat/web/algorithms/views.py @@ -65,9 +65,9 @@ def create(request, name=None): # Retrieves the existing algorithm (if necessary) if name is not None: previous_versions = Algorithm.objects.filter( - author=request.user, - name__iexact=name, - ).order_by('-version') + author=request.user, + name__iexact=name, + ).order_by('-version') if len(previous_versions) == 0: raise Http404() @@ -89,8 +89,8 @@ def create(request, name=None): 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', - '\n # TODO: Implement this algorithm\n') + .replace('\n\n # TODO: Implement this algorithm\n\n', + '\n # TODO: Implement this algorithm\n') declaration, errors = prototypes.load('algorithm') declaration['language'] = 'python' parameters['declaration'] = json.dumps(declaration) @@ -171,7 +171,7 @@ def edit(request, author, name, version): if not algorithm.modifiable(): return HttpResponseForbidden('Algorithm %s is not modifiable' % \ - algorithm.fullname()) + algorithm.fullname()) description = algorithm.description @@ -209,14 +209,14 @@ def view(request, author, name, version=None): # Retrieves the algorithm if version: algorithm = get_object_or_404( - Algorithm, - author__username__iexact=author, - name__iexact=name, - version=int(version), - ) + Algorithm, + author__username__iexact=author, + name__iexact=name, + version=int(version), + ) else: algorithm = Algorithm.objects.filter(author__username__iexact=author, - name__iexact=name).order_by('-version') + name__iexact=name).order_by('-version') if not algorithm: raise Http404() else: @@ -274,17 +274,17 @@ def ls(request, author_name): # orders algorithms so that the latest information is displayed first objects = Algorithm.objects.from_author_and_public(request.user, - author_name).order_by('-creation_date') + author_name).order_by('-creation_date') objects = Algorithm.filter_latest_versions(objects) return render_to_response('algorithms/list.html', - dict( - objects=objects, - author=author, - owner=(request.user==author), - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=author, + owner=(request.user==author), + ), + context_instance=RequestContext(request), + ) #---------------------------------------------------------- @@ -298,10 +298,10 @@ def public_ls(request): objects = Algorithm.filter_latest_versions(objects) return render_to_response('algorithms/list.html', - dict( - objects=objects, - author=request.user, #anonymous - owner=False, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=request.user, #anonymous + owner=False, + ), + context_instance=RequestContext(request), + ) diff --git a/beat/web/attestations/admin.py b/beat/web/attestations/admin.py index 02ce7c5c2..fcbe8d0f3 100644 --- a/beat/web/attestations/admin.py +++ b/beat/web/attestations/admin.py @@ -34,13 +34,13 @@ class Attestation(admin.ModelAdmin): list_display = ('id', 'number', 'experiment', 'locked', 'creation_date', 'expiration_date', 'publication_date',) search_fields = [ - 'number', + 'number', 'experiment__name', 'experiment__author__username', 'experiment__toolchain__author__username', 'experiment__toolchain__name', 'experiment__toolchain__version', - ] + ] list_filter = ('locked', ) list_display_links = ('id', 'number') diff --git a/beat/web/attestations/api.py b/beat/web/attestations/api.py index e8aff1cce..8a3139cf0 100644 --- a/beat/web/attestations/api.py +++ b/beat/web/attestations/api.py @@ -72,7 +72,7 @@ class CreateAttestationView(APIView): return BadRequestResponse('Invalid field type: "experiment" must be a string') declaration_id = beat.core.experiment.Storage(settings.PREFIX, - data['experiment']) + data['experiment']) # Check that the user is the author of the experiment if declaration_id.username != request.user.username: @@ -82,14 +82,14 @@ class CreateAttestationView(APIView): # Retrieve the experiment try: toolchain_id = beat.core.toolchain.Storage(settings.PREFIX, - declaration_id.toolchain) + declaration_id.toolchain) experiment = Experiment.objects.get( - author__username=declaration_id.username, - toolchain__author__username=toolchain_id.username, - toolchain__name=toolchain_id.name, - toolchain__version=toolchain_id.version, - name=declaration_id.name - ) + author__username=declaration_id.username, + toolchain__author__username=toolchain_id.username, + toolchain__name=toolchain_id.name, + toolchain__version=toolchain_id.version, + name=declaration_id.name + ) except: return Response(status=404) diff --git a/beat/web/attestations/management/commands/clean_attestations.py b/beat/web/attestations/management/commands/clean_attestations.py index 5c29af8ae..d9df5aa1d 100644 --- a/beat/web/attestations/management/commands/clean_attestations.py +++ b/beat/web/attestations/management/commands/clean_attestations.py @@ -41,7 +41,7 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--noinput', action='store_false', dest='interactive', default=True, - help=('Tells Django to NOT prompt the user for input of any kind.')) + help=('Tells Django to NOT prompt the user for input of any kind.')) def handle(self, *args, **options): diff --git a/beat/web/attestations/management/commands/send_attestation_cleanup_warning.py b/beat/web/attestations/management/commands/send_attestation_cleanup_warning.py index 932174edd..fbe9df83d 100644 --- a/beat/web/attestations/management/commands/send_attestation_cleanup_warning.py +++ b/beat/web/attestations/management/commands/send_attestation_cleanup_warning.py @@ -60,10 +60,10 @@ class Command(BaseCommand): send_mail(subject, render_to_string(template_path, { - 'attestation': attestation, + 'attestation': attestation, 'beat_version': __version__, 'site': current_site, - } + } ), settings.DEFAULT_FROM_EMAIL, [attestation.experiment.author.email]) diff --git a/beat/web/attestations/models.py b/beat/web/attestations/models.py index 39e5c0924..c9222cd22 100644 --- a/beat/web/attestations/models.py +++ b/beat/web/attestations/models.py @@ -100,11 +100,11 @@ class Attestation(models.Model): def get_absolute_url(self): return reverse( - 'attestations:view', + 'attestations:view', args=( self.number, - ), - ) + ), + ) def modifiable(self): return not(self.locked) and super(Attestation, self).modifiable() diff --git a/beat/web/attestations/templatetags/attestation_tags.py b/beat/web/attestations/templatetags/attestation_tags.py index dfa26e3d1..65bc5849c 100644 --- a/beat/web/attestations/templatetags/attestation_tags.py +++ b/beat/web/attestations/templatetags/attestation_tags.py @@ -49,11 +49,11 @@ def attestation_table(context, objects, owner, id): ''' return dict( - request=context['request'], - objects=objects, - owner=owner, - panel_id=id, - ) + request=context['request'], + objects=objects, + owner=owner, + panel_id=id, + ) @register.inclusion_tag('attestations/panels/actions.html', takes_context=True) @@ -72,10 +72,10 @@ def attestation_actions(context, object, display_count): ''' return dict( - request=context['request'], - object=object, - display_count=display_count, - ) + request=context['request'], + object=object, + display_count=display_count, + ) @register.assignment_tag diff --git a/beat/web/attestations/tests.py b/beat/web/attestations/tests.py index baea5e956..48846297c 100755 --- a/beat/web/attestations/tests.py +++ b/beat/web/attestations/tests.py @@ -99,51 +99,51 @@ class AttestationsAPIBase(BaseTestCase): """ TOOLCHAIN_DECLARATION={ - "blocks": [ { - "name": "block1", + "blocks": [ { + "name": "block1", "inputs": [ "in", - ], - "outputs": [ + ], + "outputs": [ "out" - ], - "synchronized_channel": "dataset1" - } ], + "synchronized_channel": "dataset1" + } + ], "datasets": [ { "name": "dataset1", "outputs": [ "out" - ] - } - ], + ] + } + ], "connections": [ { "from": "dataset1.out", "to": "block1.in", "channel": "dataset1" - }, + }, { "from": "block1.out", "to": "analyzer1.in", "channel": "dataset1" - } - ], + } + ], "analyzers": [ { "inputs": [ "in" - ], + ], "synchronized_channel": "dataset1", "name": "analyzer1" - } - ], + } + ], "representation": { "connections": {}, "blocks": {}, "channel_colors": {}, - }, - } + }, + } EXPERIMENT_DECLARATION = { "blocks": { @@ -178,7 +178,7 @@ class AttestationsAPIBase(BaseTestCase): } DATABASE = { - "root_folder": "/path/to/root/folder", + "root_folder": "/path/to/root/folder", "protocols": [ { "name": "protocol1", @@ -190,12 +190,12 @@ class AttestationsAPIBase(BaseTestCase): "view": "dummy", "outputs": { "out": settings.SYSTEM_ACCOUNT + "/float/1" - } } - ] - } - ] - } + } + ] + } + ] + } def setUp(self): @@ -236,7 +236,7 @@ class AttestationsAPIBase(BaseTestCase): database, errors = Database.objects.create_database( 'database1', declaration=self.DATABASE, - ) + ) assert database, errors # Create an algorithm @@ -246,7 +246,7 @@ class AttestationsAPIBase(BaseTestCase): short_description='', declaration=AttestationsAPIBase.ALGORITHM_TOOLCHAIN_DECLARATION, code=AttestationsAPIBase.ALGORITHM_CODE, - ) + ) assert algorithm1, errors # Create an analyzer @@ -256,7 +256,7 @@ class AttestationsAPIBase(BaseTestCase): short_description='', declaration=AttestationsAPIBase.ANALYZER_TOOLCHAIN_DECLARATION, code=AttestationsAPIBase.ANALYZER_CODE, - ) + ) assert algorithm2, errors # Create a toolchain @@ -264,7 +264,7 @@ class AttestationsAPIBase(BaseTestCase): author=user, name='personal', declaration=AttestationsAPIBase.TOOLCHAIN_DECLARATION, - ) + ) assert toolchain, errors # Create an experiment @@ -273,7 +273,7 @@ class AttestationsAPIBase(BaseTestCase): toolchain=toolchain, name='experiment1', declaration=AttestationsAPIBase.EXPERIMENT_DECLARATION, - ) + ) assert toolchain_instance, errors assert experiment, errors @@ -319,9 +319,9 @@ class AttestationCreationAPI(AttestationsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'experiment': 'jackdoe/personal/1/unknown', - }), content_type='application/json') + json.dumps({ + 'experiment': 'jackdoe/personal/1/unknown', + }), content_type='application/json') self.checkResponse(response, 404) @@ -330,9 +330,9 @@ class AttestationCreationAPI(AttestationsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'experiment': 'jackdoe/personal/1/experiment1', - }), content_type='application/json') + json.dumps({ + 'experiment': 'jackdoe/personal/1/experiment1', + }), content_type='application/json') data = self.checkResponse(response, 201, content_type='application/json') @@ -375,9 +375,9 @@ class AttestationUnlockingAPI(AttestationsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(reverse('api_attestations:create'), - json.dumps({ - 'experiment': 'jackdoe/personal/1/experiment1', - }), content_type='application/json') + json.dumps({ + 'experiment': 'jackdoe/personal/1/experiment1', + }), content_type='application/json') data = self.checkResponse(response, 201, content_type='application/json') @@ -389,8 +389,8 @@ class AttestationUnlockingAPI(AttestationsAPIBase): def test_no_access_for_anonymous_user(self): response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') self.checkResponse(response, 403) @@ -409,8 +409,8 @@ class AttestationUnlockingAPI(AttestationsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(reverse('api_attestations:unlock', args=[self.number - 1]), - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') self.checkResponse(response, 404) @@ -419,8 +419,8 @@ class AttestationUnlockingAPI(AttestationsAPIBase): self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') self.checkResponse(response, 403) @@ -429,9 +429,9 @@ class AttestationUnlockingAPI(AttestationsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'toolchain_shared_name': 'shared', - }), content_type='application/json') + json.dumps({ + 'toolchain_shared_name': 'shared', + }), content_type='application/json') self.checkResponse(response, 204) @@ -461,10 +461,10 @@ class AttestationUnlockingAPI(AttestationsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'visible_algorithms': ['jackdoe/algorithm1/1'], - 'toolchain_shared_name': 'shared', - }), content_type='application/json') + json.dumps({ + 'visible_algorithms': ['jackdoe/algorithm1/1'], + 'toolchain_shared_name': 'shared', + }), content_type='application/json') self.checkResponse(response, 204) @@ -494,9 +494,9 @@ class AttestationDeletionAPI(AttestationsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(reverse('api_attestations:create'), - json.dumps({ - 'experiment': 'jackdoe/personal/1/experiment1', - }), content_type='application/json') + json.dumps({ + 'experiment': 'jackdoe/personal/1/experiment1', + }), content_type='application/json') data = self.checkResponse(response, 201, content_type='application/json') @@ -508,8 +508,8 @@ class AttestationDeletionAPI(AttestationsAPIBase): def test_no_access_for_anonymous_user(self): response = self.client.delete(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') self.checkResponse(response, 403) diff --git a/beat/web/attestations/urls.py b/beat/web/attestations/urls.py index 9cea66161..4c83d806c 100644 --- a/beat/web/attestations/urls.py +++ b/beat/web/attestations/urls.py @@ -31,21 +31,21 @@ from . import views urlpatterns = [ url( - r'^$', + r'^$', views.public_ls, name='public-list', - ), + ), url( - r'^(?P<number>\d+)/$', + r'^(?P<number>\d+)/$', views.view, name='view', - ), + ), url( - r'^(?P<author_name>\w+)/$', + r'^(?P<author_name>\w+)/$', views.ls, name='list', - ), + ), ] diff --git a/beat/web/attestations/views.py b/beat/web/attestations/views.py index 0bd318992..64e73a0ed 100644 --- a/beat/web/attestations/views.py +++ b/beat/web/attestations/views.py @@ -47,12 +47,12 @@ def view(request, number): # Render the page return render_to_response('attestations/view.html', - dict( - attestation=attestation, - has_access=has_access, - owner=(attestation.experiment.author == request.user), - ), - context_instance=RequestContext(request)) + dict( + attestation=attestation, + has_access=has_access, + owner=(attestation.experiment.author == request.user), + ), + context_instance=RequestContext(request)) def ls(request, author_name): @@ -66,23 +66,23 @@ def ls(request, author_name): if request.user == author: # list all of the users attestations objects = Attestation.objects.filter(Q(experiment__author=author) | \ - Q(locked=False)) + Q(locked=False)) else: # list all unlocked (public) attestations from a given user objects = Attestation.objects.filter(experiment__author=author, - locked=False) + locked=False) objects = objects.order_by('-locked', 'expiration_date') return render_to_response('attestations/list.html', - dict( - objects=objects, - author=author, - owner=(request.user==author), - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=author, + owner=(request.user==author), + ), + context_instance=RequestContext(request), + ) def public_ls(request): @@ -92,10 +92,10 @@ def public_ls(request): objects = Attestation.objects.filter(locked=False).order_by('-publication_date') return render_to_response('attestations/list.html', - dict( - objects=objects, - author=request.user, #anonymous - owner=False, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=request.user, #anonymous + owner=False, + ), + context_instance=RequestContext(request), + ) diff --git a/beat/web/backend/admin.py b/beat/web/backend/admin.py index ea6b8001b..317042386 100755 --- a/beat/web/backend/admin.py +++ b/beat/web/backend/admin.py @@ -45,23 +45,23 @@ from ..common.admin import Django18ProofGuardedModelAdmin, notify_by_email class EnvironmentModelForm(forms.ModelForm): description = CodeMirrorRSTCharField( - required=False, - help_text=Messages['description'], - ) + required=False, + help_text=Messages['description'], + ) class Meta: model = EnvironmentModel exclude = [] widgets = { - 'name': forms.TextInput( - attrs=dict(size=100), - ), + 'name': forms.TextInput( + attrs=dict(size=100), + ), 'version': forms.TextInput( attrs=dict(size=40), - ), + ), 'short_description': forms.TextInput( attrs=dict(size=100), - ), + ), } @@ -78,19 +78,19 @@ class Environment(admin.ModelAdmin): 'sharing', 'active', 'short_description', - ) + ) search_fields = [ 'name', 'version', 'short_description', 'description', - ] + ] list_display_links = ( 'id', 'name', - ) + ) inlines = [ EnvironmentLanguageInline @@ -105,27 +105,27 @@ class Environment(admin.ModelAdmin): actions = [ notify_by_email('environment_notifications_enabled'), - ] + ] fieldsets = ( (None, - dict( - fields=('name', 'version', 'previous_version', 'active'), - ), + dict( + fields=('name', 'version', 'previous_version', 'active'), + ), ), ('Documentation', - dict( - classes=('collapse',), - fields=('short_description', 'description',), - ), + dict( + classes=('collapse',), + fields=('short_description', 'description',), + ), ), ('Sharing', - dict( - classes=('collapse',), - fields=('sharing', 'shared_with', 'shared_with_team'), - ), + dict( + classes=('collapse',), + fields=('sharing', 'shared_with', 'shared_with_team'), + ), ), - ) + ) admin.site.register(EnvironmentModel, Environment) @@ -158,9 +158,9 @@ class Worker(admin.ModelAdmin): list_display_links = ('id', 'name') actions = [ - activate_workers, - deactivate_workers, - ] + activate_workers, + deactivate_workers, + ] admin.site.register(WorkerModel, Worker) diff --git a/beat/web/backend/api.py b/beat/web/backend/api.py index 54803dda8..65c34e880 100755 --- a/beat/web/backend/api.py +++ b/beat/web/backend/api.py @@ -50,7 +50,7 @@ def accessible_environments_list(request): # Retrieve the list of environments environments = Environment.objects.filter(active=True).order_by('name', - 'version') + 'version') result = [] for environment in environments.iterator(): @@ -107,9 +107,9 @@ def start_local_scheduler(request): for worker in Worker.objects.all(): (pid, _) = local_scheduler.start_worker(worker.name, settings.PREFIX, - settings.CACHE_ROOT, - full_address, - use_docker=use_docker) + settings.CACHE_ROOT, + full_address, + use_docker=use_docker) LocalSchedulerProcesses(name=worker.name, pid=pid).save() diff --git a/beat/web/backend/helpers.py b/beat/web/backend/helpers.py index 573c2192c..ab2100a66 100755 --- a/beat/web/backend/helpers.py +++ b/beat/web/backend/helpers.py @@ -76,17 +76,17 @@ def schedule_experiment(experiment): for block in experiment.blocks.all(): if block.queue is None: raise RuntimeError("Block `%s' does not have a queue assigned " \ - "- this normally indicates the originally selected " \ - "queue was deleted since the experiment was first " \ - "configured. Re-configure this experiment and select a new " \ - "default or block-specific queue" % block.name) + "- this normally indicates the originally selected " \ + "queue was deleted since the experiment was first " \ + "configured. Re-configure this experiment and select a new " \ + "default or block-specific queue" % block.name) if block.environment is None: raise RuntimeError("Block `%s' does not have an environment " \ - "assigned - this normally indicates the originally selected " \ - "environment was deleted since the experiment was first " \ - "configured. Re-configure this experiment and select a new " \ - "default or block-specific environment" % block.name) + "assigned - this normally indicates the originally selected " \ + "environment was deleted since the experiment was first " \ + "configured. Re-configure this experiment and select a new " \ + "default or block-specific environment" % block.name) # Process all the blocks of the experiment @@ -204,7 +204,7 @@ def split_new_jobs(): # if the processing mark any other job as a candidate one, process it too, # recursively, until no candidate job is left candidate_jobs = Job.objects.annotate(nb_splits=Count('splits')).filter( - runnable_date__isnull=False, mirror=False, nb_splits=0) + runnable_date__isnull=False, mirror=False, nb_splits=0) while len(candidate_jobs) > 0: candidate_jobs = _process(candidate_jobs) @@ -624,7 +624,7 @@ def update_job(job): header = '' if split.start_index is not None: header = 'Split #%d (from indices %d to %d):' % ( - split.split_index, split.start_index, split.end_index) + split.split_index, split.start_index, split.end_index) header += '\n' + ('=' * len(header)) + '\n' stdout = split.result.stdout if split.result.stdout != '\n' else '' @@ -658,9 +658,9 @@ def update_job(job): if job.block.required_slots > 1: cached_files_infos['speed_up_real'] = float(cached_files_infos['linear_execution_time']) / \ - (job.end_date - job.start_date).total_seconds() + (job.end_date - job.start_date).total_seconds() cached_files_infos['speed_up_maximal'] = float(cached_files_infos['linear_execution_time']) / \ - max(split_durations) + max(split_durations) return cached_files_infos @@ -934,17 +934,17 @@ def load_results_from_cache(block, cached_file): data_source = beat.core.data.CachedDataSource() data_source.setup(os.path.join(settings.CACHE_ROOT, - beat.core.hash.toPath(cached_file.hash)), + beat.core.hash.toPath(cached_file.hash)), settings.PREFIX) output_data = data_source.next()[0] if output_data is not None: algorithm = beat.core.algorithm.Algorithm( - settings.PREFIX, block.algorithm.fullname()) + settings.PREFIX, block.algorithm.fullname()) for field, value in output_data.as_dict().items(): res, _ = CacheResult.objects.get_or_create( - name=field, cache=cached_file) + name=field, cache=cached_file) res.primary = algorithm.results[field]['display'] res.type = algorithm.results[field]["type"] @@ -952,7 +952,7 @@ def load_results_from_cache(block, cached_file): res.data_value = str(value) else: res.data_value = simplejson.dumps( - value, indent=4, cls=NumpyJSONEncoder) + value, indent=4, cls=NumpyJSONEncoder) res.save() diff --git a/beat/web/backend/management/commands/cleanup_cache.py b/beat/web/backend/management/commands/cleanup_cache.py index 2adec94db..60217e790 100644 --- a/beat/web/backend/management/commands/cleanup_cache.py +++ b/beat/web/backend/management/commands/cleanup_cache.py @@ -44,19 +44,19 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--olderthan', type=int, metavar='MINUTES', - default=0, help='All files which are older than this value ' \ - 'in *minutes* and are not locked or being used by active ' \ - 'experiments (running or scheduled) will be deleted ' \ - '[default: %(default)s]') + default=0, help='All files which are older than this value ' \ + 'in *minutes* and are not locked or being used by active ' \ + 'experiments (running or scheduled) will be deleted ' \ + '[default: %(default)s]') parser.add_argument('--delete', action='store_true', default=False, - help='By default we only list cache files that will ' \ - 'be erased. If you pass this flag, then we really erase them') + help='By default we only list cache files that will ' \ + 'be erased. If you pass this flag, then we really erase them') parser.add_argument('--path', default=settings.CACHE_ROOT, - help='By default, we erase the CACHE path on your settings. Set ' \ - 'this flag if you want to operate on a different path ' \ - '[default: %(default)s]') + help='By default, we erase the CACHE path on your settings. Set ' \ + 'this flag if you want to operate on a different path ' \ + '[default: %(default)s]') def handle(self, *ignored, **arguments): @@ -69,8 +69,8 @@ class Command(BaseCommand): elif arguments['verbosity'] >= 2: logger.setLevel(logging.DEBUG) deleted = cleanup_cache(arguments['path'], - age_in_minutes=arguments['olderthan'], - delete=arguments['delete']) + age_in_minutes=arguments['olderthan'], + delete=arguments['delete']) if not arguments['delete']: print("%d cache files can be deleted" % len(deleted)) diff --git a/beat/web/backend/management/commands/qsetup.py b/beat/web/backend/management/commands/qsetup.py index 7d3a7f21e..df60ee83b 100755 --- a/beat/web/backend/management/commands/qsetup.py +++ b/beat/web/backend/management/commands/qsetup.py @@ -50,53 +50,53 @@ HOSTNAME = socket.gethostname() DEFAULT_CONFIGURATION = { "queues": { - "queue": { - "memory-limit": RAM/CORES, - "time-limit": 1440, #1 day - "cores-per-slot": 1, - "max-slots-per-user": CORES, - "environments": [CXX_ENVKEY, ENVKEY], - "slots": { - HOSTNAME: { - "quantity": CORES, - "priority": 0 - } - }, - "groups": [ - "Default", - ], - } + "queue": { + "memory-limit": RAM/CORES, + "time-limit": 1440, #1 day + "cores-per-slot": 1, + "max-slots-per-user": CORES, + "environments": [CXX_ENVKEY, ENVKEY], + "slots": { + HOSTNAME: { + "quantity": CORES, + "priority": 0 + } + }, + "groups": [ + "Default", + ], + } }, "environments": { - ENVKEY: { - "name": ENVIRONMENT['name'], - "version": ENVIRONMENT['version'], - "languages": ['python'], - "short_description": "Local python interpreter", - "description": "Automatically generated local python " \ + ENVKEY: { + "name": ENVIRONMENT['name'], + "version": ENVIRONMENT['version'], + "languages": ['python'], + "short_description": "Local python interpreter", + "description": "Automatically generated local python " \ "interpreter environment", }, CXX_ENVKEY: { - "name": CXX_ENVIRONMENT['name'], - "version": CXX_ENVIRONMENT['version'], - "languages": ['cxx'], - "short_description": "C++ backend", - "description": "C++ backend running in a docker container", + "name": CXX_ENVIRONMENT['name'], + "version": CXX_ENVIRONMENT['version'], + "languages": ['cxx'], + "short_description": "C++ backend", + "description": "C++ backend running in a docker container", }, - }, + }, "workers": { - HOSTNAME: { - "cores": CORES, - "memory": RAM - } + HOSTNAME: { + "cores": CORES, + "memory": RAM + } } - } +} RESET_CONFIGURATION = { "queues": {}, "environments": {}, "workers": {} - } +} class Command(BaseCommand): @@ -107,17 +107,17 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--dump', action='store_true', dest='dump', - default=False, help='Dump all environment/worker/queues ' \ - 'configuration and exits') + default=False, help='Dump all environment/worker/queues ' \ + 'configuration and exits') parser.add_argument('--reset', action='store_true', dest='reset', - default=False, help='Delete all environment/worker/queues ' \ - 'before setting the given configuration') + default=False, help='Delete all environment/worker/queues ' \ + 'before setting the given configuration') parser.add_argument('config', type=str, nargs='?', - help='Optional custom queue configuration to use. If not ' \ - 'passed, uses an internal default with a single ' \ - 'queue/worker/%d slots' % CORES) + help='Optional custom queue configuration to use. If not ' \ + 'passed, uses an internal default with a single ' \ + 'queue/worker/%d slots' % CORES) def handle(self, *ignored, **arguments): diff --git a/beat/web/backend/models/job.py b/beat/web/backend/models/job.py index 590b9b5a0..6b9d054eb 100755 --- a/beat/web/backend/models/job.py +++ b/beat/web/backend/models/job.py @@ -98,10 +98,10 @@ class Job(models.Model): def __str__(self): return "Job(%s, %s, key=%s, mirror=%s, splits=%d, cores=%d)" % \ - (self.block.name, self.block.experiment.name, - self.key, str(self.mirror), - self.block.required_slots, - self.block.queue.cores_per_slot) + (self.block.name, self.block.experiment.name, + self.key, str(self.mirror), + self.block.required_slots, + self.block.queue.cores_per_slot) #---------------------------------------------------------- diff --git a/beat/web/backend/models/queue.py b/beat/web/backend/models/queue.py index d87ae84b3..139bf61c3 100755 --- a/beat/web/backend/models/queue.py +++ b/beat/web/backend/models/queue.py @@ -120,7 +120,7 @@ class Queue(models.Model): from ..models import Job running = JobSplit.objects.filter(job__block__in=self.blocks.all(), - status=JobSplit.PROCESSING).count() + status=JobSplit.PROCESSING).count() return max(self.number_of_slots() - running, 0) @@ -140,7 +140,7 @@ class Queue(models.Model): ''' workers = [(k.worker, -k.priority, k.worker.load(), k.worker.name) \ - for k in self.slots.filter(worker__active=True)] + for k in self.slots.filter(worker__active=True)] workers = sorted(workers, key=operator.itemgetter(1,2,3)) diff --git a/beat/web/backend/state.py b/beat/web/backend/state.py index bfd69e657..1086f1119 100755 --- a/beat/web/backend/state.py +++ b/beat/web/backend/state.py @@ -57,7 +57,7 @@ def cache(): 'capacity-in-megabytes': df.total / MB, 'free': df.free / MB, 'percent-used': df.percent, - } + } def jobs(): @@ -69,7 +69,7 @@ def jobs(): cancelled=JobSplit.objects.filter(status=JobSplit.CANCELLED).count(), completed=JobSplit.objects.filter(status=JobSplit.COMPLETED).count(), failed=JobSplit.objects.filter(status=JobSplit.FAILED).count(), - ) + ) def experiments(): @@ -78,7 +78,7 @@ def experiments(): running=Experiment.objects.filter(status=Experiment.RUNNING).count(), scheduled=Experiment.objects.filter(status=Experiment.SCHEDULED).count(), ls=Experiment.objects.filter(status__in=(Experiment.RUNNING, - Experiment.SCHEDULED)).order_by('author__username', - 'toolchain__author__username', 'toolchain__name', - 'toolchain__version', 'name'), - ) + Experiment.SCHEDULED)).order_by('author__username', + 'toolchain__author__username', 'toolchain__name', + 'toolchain__version', 'name'), + ) diff --git a/beat/web/backend/templatetags/backend_tags.py b/beat/web/backend/templatetags/backend_tags.py index 37b725d8d..ccf18e912 100755 --- a/beat/web/backend/templatetags/backend_tags.py +++ b/beat/web/backend/templatetags/backend_tags.py @@ -50,10 +50,10 @@ def environment_table(context, objects, id): ''' return dict( - request=context['request'], - objects=objects, - panel_id=id, - ) + request=context['request'], + objects=objects, + panel_id=id, + ) @register.inclusion_tag('backend/panels/environment_actions.html', takes_context=True) @@ -73,10 +73,10 @@ def environment_actions(context, object, display_count): ''' return dict( - request=context['request'], - object=object, - display_count=display_count, - ) + request=context['request'], + object=object, + display_count=display_count, + ) @register.assignment_tag(takes_context=True) diff --git a/beat/web/backend/tests/common.py b/beat/web/backend/tests/common.py index 943a70e40..a35016259 100755 --- a/beat/web/backend/tests/common.py +++ b/beat/web/backend/tests/common.py @@ -196,8 +196,8 @@ class BackendUtilitiesMixin(object): end = indices[1] sink.write({ - 'value': value, - }, + 'value': value, + }, start_data_index = start, end_data_index = end ) diff --git a/beat/web/backend/tests/test_cache.py b/beat/web/backend/tests/test_cache.py index 2cafb1149..0f9bdee69 100755 --- a/beat/web/backend/tests/test_cache.py +++ b/beat/web/backend/tests/test_cache.py @@ -83,7 +83,7 @@ class CacheCleanUp(TestCase): self.prepare_cleanup_full() management.call_command('cleanup_cache', path=self.cache, - verbosity=0, delete=True) + verbosity=0, delete=True) self.check_cleanup_full() @@ -118,7 +118,7 @@ class CacheCleanUp(TestCase): self.prepare_cleanup_aged() management.call_command('cleanup_cache', path=self.cache, - verbosity=0, olderthan=2, delete=True) + verbosity=0, olderthan=2, delete=True) self.check_cleanup_aged() @@ -156,5 +156,5 @@ class CacheCleanUp(TestCase): self.prepare_cleanup_lock() management.call_command('cleanup_cache', path=self.cache, - verbosity=0, delete=True) + verbosity=0, delete=True) self.check_cleanup_lock() diff --git a/beat/web/backend/tests/test_setup.py b/beat/web/backend/tests/test_setup.py index 4cc8bbb9e..e2f0a7420 100755 --- a/beat/web/backend/tests/test_setup.py +++ b/beat/web/backend/tests/test_setup.py @@ -46,165 +46,165 @@ from ..management.commands import qsetup # Example configuration with 3 queues with an increasing amount of resources # running on the same host QUEUES_WITHOUT_PRIORITY = { - "queues": collections.OrderedDict([ - ("q1", { - "memory-limit": 4*1024, - "time-limit": 180, #3 hours - "cores-per-slot": 1, - "max-slots-per-user": 4, - "environments": ['Python 2.7 (1.2.0)'], - "groups": [ - "Default", - ], - "slots": { - "node1": { - "quantity": 4, - "priority": 0 + "queues": collections.OrderedDict([ + ("q1", { + "memory-limit": 4*1024, + "time-limit": 180, #3 hours + "cores-per-slot": 1, + "max-slots-per-user": 4, + "environments": ['Python 2.7 (1.2.0)'], + "groups": [ + "Default", + ], + "slots": { + "node1": { + "quantity": 4, + "priority": 0 + } } } - } - ), - ("q2", { - "memory-limit": 8*1024, - "time-limit": 360, #6 hours - "cores-per-slot": 2, - "max-slots-per-user": 2, - "environments": ['Python 2.7 (1.2.0)'], - "groups": [ - "Default", - ], - "slots": { - "node1": { - "quantity": 2, - "priority": 0 - }, + ), + ("q2", { + "memory-limit": 8*1024, + "time-limit": 360, #6 hours + "cores-per-slot": 2, + "max-slots-per-user": 2, + "environments": ['Python 2.7 (1.2.0)'], + "groups": [ + "Default", + ], + "slots": { + "node1": { + "quantity": 2, + "priority": 0 + }, + } } - } - ), - ("q4", { - "memory-limit": 16*1024, - "time-limit": 720, #12 hours - "cores-per-slot": 4, - "max-slots-per-user": 1, - "environments": ['Python 2.7 (1.2.0)'], - "groups": [ - "Default", - ], - "slots": { - "node1": { - "quantity": 1, - "priority": 0 - }, + ), + ("q4", { + "memory-limit": 16*1024, + "time-limit": 720, #12 hours + "cores-per-slot": 4, + "max-slots-per-user": 1, + "environments": ['Python 2.7 (1.2.0)'], + "groups": [ + "Default", + ], + "slots": { + "node1": { + "quantity": 1, + "priority": 0 + }, + } } - } - ) - ]), + ) + ]), "workers": { - "node1": { - "cores": 4, - "memory": 16*1024, + "node1": { + "cores": 4, + "memory": 16*1024, } }, "environments": { - 'Python 2.7 (1.2.0)': { - "name": 'Python 2.7', - "version": '1.2.0', - "short_description": "Test", - "description": "Test environment", - "languages": "python", + 'Python 2.7 (1.2.0)': { + "name": 'Python 2.7', + "version": '1.2.0', + "short_description": "Test", + "description": "Test environment", + "languages": "python", }, }, - } +} # Example configuration with 3 queues sharing slots on 2 hosts PRIORITY_QUEUES = { "queues": collections.OrderedDict([ - ("q1", { - "memory-limit": 4*1024, - "time-limit": 180, #3 hours - "cores-per-slot": 1, - "max-slots-per-user": 2, - "environments": ['Python 2.7 (1.2.0)'], - "groups": [ - "Default", - ], - "slots": { - "node1": { - "quantity": 4, - "priority": 5 - }, - "node2": { - "quantity": 4, - "priority": 0 - }, - } + ("q1", { + "memory-limit": 4*1024, + "time-limit": 180, #3 hours + "cores-per-slot": 1, + "max-slots-per-user": 2, + "environments": ['Python 2.7 (1.2.0)'], + "groups": [ + "Default", + ], + "slots": { + "node1": { + "quantity": 4, + "priority": 5 + }, + "node2": { + "quantity": 4, + "priority": 0 + }, + } }, - ), + ), ("q2", { - "memory-limit": 8*1024, + "memory-limit": 8*1024, "time-limit": 360, #6 hours "cores-per-slot": 2, "max-slots-per-user": 1, "environments": ['Python 2.7 (1.2.0)'], "groups": [ - "Default", - ], + "Default", + ], "slots": { - "node1": { - "quantity": 2, - "priority": 0 + "node1": { + "quantity": 2, + "priority": 0 }, "node2": { - "quantity": 2, - "priority": 10 + "quantity": 2, + "priority": 10 } - } - }, - ), + } + }, + ), ("q1_special", { - "memory-limit": 4*1024, + "memory-limit": 4*1024, "time-limit": 180, #3 hours "cores-per-slot": 1, "max-slots-per-user": 8, "environments": ['Python 2.7 (1.2.0)'], "groups": [ - "Default", - ], + "Default", + ], "slots": { - "node1": { - "quantity": 4, - "priority": 0 + "node1": { + "quantity": 4, + "priority": 0 }, "node2": { - "quantity": 4, - "priority": 5 + "quantity": 4, + "priority": 5 } - } } - ), + } + ), ]), "workers": collections.OrderedDict([ - ("node1", { - "cores": 4, - "memory": 32*1024, + ("node1", { + "cores": 4, + "memory": 32*1024, } - ), + ), ("node2", { - "cores": 4, + "cores": 4, "memory": 16*1024, - } - ) + } + ) ]), "environments": { 'Python 2.7 (1.2.0)': { - "name": 'Python 2.7', + "name": 'Python 2.7', "version": '1.2.0', "short_description": "Test", "description": "Test environment", "languages": "python", - }, }, - } + }, +} @@ -221,7 +221,7 @@ class BackendSetup(BaseBackendTestCase): self.assertEqual(worker.available_cores(), qsetup.CORES) self.assertEqual(list(worker.slots.values_list('id', flat=True)), - list(queue.slots.values_list('id', flat=True))) + list(queue.slots.values_list('id', flat=True))) # worker has no job splits assigned to it self.assertEqual(worker.splits.count(), 0) @@ -320,8 +320,8 @@ class BackendSetup(BaseBackendTestCase): self.assertEqual(worker1.slots.count(), 3) self.assertEqual(set(worker1.slots.all()), - set(list(q1.slots.all()) + list(q2.slots.all()) + \ - list(q3.slots.all()))) + set(list(q1.slots.all()) + list(q2.slots.all()) + \ + list(q3.slots.all()))) avail1 = q1.worker_availability() self.assertEqual(avail1, [worker1]) @@ -388,7 +388,7 @@ class BackendSetup(BaseBackendTestCase): self.assertEqual(q1.environments.first(), q2.environments.first()) self.assertEqual(q2.environments.first(), - q1_special.environments.first()) + q1_special.environments.first()) env = q1.environments.first() diff --git a/beat/web/backend/urls.py b/beat/web/backend/urls.py index e09f3f990..d81b784c9 100644 --- a/beat/web/backend/urls.py +++ b/beat/web/backend/urls.py @@ -31,22 +31,22 @@ from . import views urlpatterns = [ url( - r'^scheduler/$', + r'^scheduler/$', views.scheduler, name='scheduler', - ), + ), url( - r'^cancel-experiments/$', + r'^cancel-experiments/$', views.cancel_all_experiments, name='cancel-experiments', - ), + ), url( - r'^update-workers/$', + r'^update-workers/$', views.update_workers, name='update-workers', - ), + ), url( r'^environments/(?P<name>[-\.\w\s]+)/(?P<version>[-\.\w]+)/$', diff --git a/beat/web/backend/utils.py b/beat/web/backend/utils.py index 8822e0080..5805b2645 100755 --- a/beat/web/backend/utils.py +++ b/beat/web/backend/utils.py @@ -90,7 +90,7 @@ def cleanup_cache(path, age_in_minutes=0, delete=False): cutoff_access_time = time.time() - (60*age_in_minutes) logger.info("Running `%s' clean-up: set file-access cutoff time to `%s'", - path, time.ctime(cutoff_access_time)) + path, time.ctime(cutoff_access_time)) # Gets a list of cache files for active experiments: blocks = Block.objects.filter(experiment__in=Experiment.objects.filter(status__in=(Experiment.SCHEDULED, Experiment.RUNNING))) @@ -134,7 +134,7 @@ def cleanup_cache(path, age_in_minutes=0, delete=False): removed_files.append(fullpath) else: logger.debug("[skip] `%s' (%f >= %f)", fullpath, - os.path.getatime(fullpath), cutoff_access_time) + os.path.getatime(fullpath), cutoff_access_time) for d in dirs: #also remove empty directories fullpath = os.path.join(p, d) @@ -170,12 +170,12 @@ def setup_backend(d): # 1. We get a list of all current queue/environment combinations q_envs = set([(q.name, str(e)) \ - for q in Queue.objects.all() for e in q.environments.all()]) + for q in Queue.objects.all() for e in q.environments.all()]) # 2. We get a list of new queue/environment combinations config_q_envs = set([(qname, envkey) \ - for qname, qpar in d['queues'].items() \ - for envkey in qpar['environments']]) + for qname, qpar in d['queues'].items() \ + for envkey in qpar['environments']]) # 3. We figure out which combinations of queue/environment's need to be # deleted. @@ -184,7 +184,7 @@ def setup_backend(d): # 4. We figure out which combinations of queue/environment's are currently # used by queued jobs. used_q_envs = set([(job.block.queue.name, str(job.block.environment)) \ - for job in Job.objects.filter(start_date__isnull=True)]) + for job in Job.objects.filter(start_date__isnull=True)]) # 5. We request that no jobs should be either executing or scheduled for # execution on queue/environment combinations that need to be deleted. @@ -225,7 +225,7 @@ def setup_backend(d): short_description=attrs.get('short_description'), description=attrs.get('description'), sharing=Shareable.PUBLIC, - ) + ) logger.info("Creating `%s'...", env) env.save() @@ -233,7 +233,7 @@ def setup_backend(d): lang = EnvironmentLanguage( language=Code.language_db(language), environment=env - ) + ) lang.save() # 8.1 Create new workers @@ -248,7 +248,7 @@ def setup_backend(d): active=False, cores=attrs['cores'], memory=attrs['memory'], - ) + ) logger.info("Creating `%s'...", worker) worker.save() @@ -275,7 +275,7 @@ def setup_backend(d): time_limit=attrs['time-limit'], cores_per_slot=attrs['cores-per-slot'], max_slots_per_user=attrs['max-slots-per-user'], - ) + ) logger.info("Creating `%s'...", queue) queue.save() @@ -292,7 +292,7 @@ def setup_backend(d): worker=worker, priority=priority, quantity=par['quantity'], - ) + ) logger.info("Creating `%s'...", slot) slot.save() @@ -328,7 +328,7 @@ def setup_backend(d): queue=queue, priority=priority, quantity=par['quantity'], - ) + ) logger.info("Creating `%s'...", slot) slot.save() @@ -364,7 +364,7 @@ def dump_backend(): queues=dict([(k.name, k.as_dict()) for k in Queue.objects.all()]), environments=environments, workers=dict([(k.name, k.as_dict()) for k in Worker.objects.all()]), - ) + ) def resolve_process_path(): @@ -375,7 +375,7 @@ def resolve_process_path(): if not os.path.exists(r): raise RuntimeError("Cannot find `process.py' at `%s' - please check " \ - "your installation" % basedir) + "your installation" % basedir) return r diff --git a/beat/web/backend/views.py b/beat/web/backend/views.py index a6c2820a9..94a71e551 100755 --- a/beat/web/backend/views.py +++ b/beat/web/backend/views.py @@ -82,17 +82,17 @@ def scheduler(request): refreshing_period = int(request.GET['period']) return render_to_response('backend/scheduler.html', - dict( - jobs=state.jobs(), - experiments=state.experiments(), - workers=Worker.objects.order_by('-active', 'name'), - queues=Queue.objects.order_by('memory_limit', 'max_slots_per_user'), - cache_chart_data=simplejson.dumps(cache_chart_data), - cache_gb=cache_gb, - helper_panel=getattr(settings, 'SCHEDULING_PANEL', False), - refreshing_period=refreshing_period, - ), - context_instance=RequestContext(request)) + dict( + jobs=state.jobs(), + experiments=state.experiments(), + workers=Worker.objects.order_by('-active', 'name'), + queues=Queue.objects.order_by('memory_limit', 'max_slots_per_user'), + cache_chart_data=simplejson.dumps(cache_chart_data), + cache_gb=cache_gb, + helper_panel=getattr(settings, 'SCHEDULING_PANEL', False), + refreshing_period=refreshing_period, + ), + context_instance=RequestContext(request)) #------------------------------------------------ @@ -103,7 +103,7 @@ def environment(request, name, version): # Retrieve the data base environment = get_object_or_404(Environment, - name__iexact=name, version__iexact=version) + name__iexact=name, version__iexact=version) if not environment.accessibility_for(request.user)[0]: raise Http404() @@ -111,7 +111,7 @@ def environment(request, name, version): # Render the page return render_to_response('backend/environment.html', { - 'environment': environment, + 'environment': environment, }, context_instance=RequestContext(request)) @@ -126,14 +126,14 @@ def list_environments(request): # Render the page return render_to_response( - 'backend/environment_list.html', + 'backend/environment_list.html', dict( objects=objects, author=request.user, owner=True, - ), + ), context_instance=RequestContext(request), - ) + ) diff --git a/beat/web/code/api.py b/beat/web/code/api.py index b778eb7ac..61c4f505a 100755 --- a/beat/web/code/api.py +++ b/beat/web/code/api.py @@ -64,15 +64,15 @@ class DiffView(generics.RetrieveAPIView): # Retrieve the objects try: object1 = self.model.objects.get(author__username__iexact=author1, - name__iexact=name1, - version=int(version1)) + name__iexact=name1, + version=int(version1)) except: return Response('%s/%s/%s' % (author1, name1, version1), status=404) try: object2 = self.model.objects.get(author__username__iexact=author2, - name__iexact=name2, - version=int(version2)) + name__iexact=name2, + version=int(version2)) except: return Response('%s/%s/%s' % (author2, name2, version2), status=404) @@ -80,12 +80,12 @@ class DiffView(generics.RetrieveAPIView): # Check that the user can access them has_access, open_source, _ = object1.accessibility_for(request.user) if not ((request.user == object1.author) or \ - (has_access and open_source)): + (has_access and open_source)): return ForbiddenResponse("You cannot access the source-code of \"%s\"" % object1.fullname()) has_access, open_source, _ = object2.accessibility_for(request.user) if not ((request.user == object2.author) or \ - (has_access and open_source)): + (has_access and open_source)): return ForbiddenResponse("You cannot access the source-code of \"%s\"" % object2.fullname()) # Compute the diff diff --git a/beat/web/code/models.py b/beat/web/code/models.py index c7053c6bf..2521aea02 100755 --- a/beat/web/code/models.py +++ b/beat/web/code/models.py @@ -63,16 +63,16 @@ class CodeManager(StoredContributionManager): def for_user(self, user, add_public=False): if user.is_anonymous(): query = Q(sharing=Code.PUBLIC) |\ - (Q(sharing=Code.USABLE) & (Q(shared_with=None) & Q(shared_with_team=None))) + (Q(sharing=Code.USABLE) & (Q(shared_with=None) & Q(shared_with_team=None))) return self.filter(query).distinct() teams = Team.objects.filter(members=user) query = Q(author=user) |\ - Q(sharing=Code.USABLE) |\ - Q(usable_by=user) |\ - Q(usable_by_team__in=teams) |\ - Q(shared_with=user) |\ - Q(shared_with_team__in=teams) + Q(sharing=Code.USABLE) |\ + Q(usable_by=user) |\ + Q(usable_by_team__in=teams) |\ + Q(shared_with=user) |\ + Q(shared_with_team__in=teams) if add_public: query |= Q(sharing=Code.PUBLIC) @@ -93,12 +93,12 @@ class CodeManager(StoredContributionManager): else: teams = Team.objects.filter(members=user) objects_for_user = self.filter(Q(author__username=author_name) & - (Q(sharing=Code.PUBLIC) | - Q(sharing=Code.USABLE) | - Q(usable_by=user) | - Q(usable_by_team__in=teams) | - Q(shared_with=user) | - Q(shared_with_team__in=teams))).distinct() + (Q(sharing=Code.PUBLIC) | + Q(sharing=Code.USABLE) | + Q(usable_by=user) | + Q(usable_by_team__in=teams) | + Q(shared_with=user) | + Q(shared_with_team__in=teams))).distinct() return objects_for_user.order_by('author__username', 'name', '-version').select_related() @@ -231,7 +231,7 @@ class Code(StoredContribution): blank=True) usable_by_team = models.ManyToManyField(Team, - related_name='usable_%(class)ss', blank=True) + related_name='usable_%(class)ss', blank=True) language = models.CharField(max_length=1, choices=CODE_LANGUAGE, default=PYTHON) diff --git a/beat/web/code/serializers.py b/beat/web/code/serializers.py index 08307391e..4f25aef86 100755 --- a/beat/web/code/serializers.py +++ b/beat/web/code/serializers.py @@ -105,11 +105,11 @@ class CodeSerializer(ContributionSerializer): if user == obj.author: if obj.usable_by.count() > 0: sharing['usable_by'] = map(lambda x: x.username, - obj.usable_by.iterator()) + obj.usable_by.iterator()) if obj.usable_by_team.count() > 0: sharing['usable_by_team'] = map(lambda x: x.name, - obj.usable_by_team.iterator()) + obj.usable_by_team.iterator()) return sharing def get_code(self, obj): diff --git a/beat/web/common/admin.py b/beat/web/common/admin.py index 180265404..939990346 100644 --- a/beat/web/common/admin.py +++ b/beat/web/common/admin.py @@ -71,17 +71,17 @@ def notify_by_email(attribute=None): if not users: modeladmin.message_user(request, "No users to e-mail for " \ - "'%s'" % instance.fullname(), level=messages.WARNING) + "'%s'" % instance.fullname(), level=messages.WARNING) return # filter users using notification preferences users = [u for u in users if getattr(u.accountsettings, \ - attribute)] + attribute)] if not users: modeladmin.message_user(request, - "Affected users for '%s' don't want to be e-mailed" % \ - instance.fullname(), level=messages.WARNING) + "Affected users for '%s' don't want to be e-mailed" % \ + instance.fullname(), level=messages.WARNING) return if instance.sharing == Shareable.PUBLIC: @@ -90,8 +90,8 @@ def notify_by_email(attribute=None): action = 'shared with you (or a team you are in)' else: modeladmin.message_user(request, - "'%s' is private. Not e-mailing anyone." % \ - instance.fullname(), level=messages.ERROR) + "'%s' is private. Not e-mailing anyone." % \ + instance.fullname(), level=messages.ERROR) return objurl = request.build_absolute_uri(instance.get_absolute_url()) @@ -102,7 +102,7 @@ def notify_by_email(attribute=None): 'objurl': objurl, 'beat_version': __version__, 'action': action, - } + } emails = [u.email for u in users] subj = render_to_string('common/sharing_email_subject.txt', ctx) body = render_to_string('common/sharing_email_body.txt', ctx) @@ -113,7 +113,7 @@ def notify_by_email(attribute=None): settings.DEFAULT_FROM_EMAIL, to=[settings.DEFAULT_FROM_EMAIL], bcc=emails, - ) + ) plural = '' if len(emails) == 1 else 's' try: @@ -124,11 +124,11 @@ def notify_by_email(attribute=None): modeladmin.message_user(request, errormsg) import traceback logger.warn(errormsg + ". Exception caught: %s", - traceback.format_exc()) + traceback.format_exc()) modeladmin.message_user(request, "Successfully notified %d " \ - "user%s of '%s'" % \ - (len(emails), plural, instance.fullname())) + "user%s of '%s'" % \ + (len(emails), plural, instance.fullname())) else: # presents the user with an intermediary page asking to confirm @@ -147,12 +147,12 @@ def notify_by_email(attribute=None): request, 'common/email_confirmation.html', { - 'users': users_per_instance, + 'users': users_per_instance, 'title': 'Confirm mass e-mail submission', 'queryset': queryset, 'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME, - }, - ) + }, + ) notify_by_email_inner.short_description = 'Notify affected users' diff --git a/beat/web/common/api.py b/beat/web/common/api.py index bc5cad89a..40e151bcb 100644 --- a/beat/web/common/api.py +++ b/beat/web/common/api.py @@ -184,15 +184,15 @@ class DiffView(generics.RetrieveAPIView): # Retrieve the objects try: object1 = self.model.objects.get(author__username__iexact=author1, - name__iexact=name1, - version=int(version1)) + name__iexact=name1, + version=int(version1)) except: return Response('%s/%s/%s' % (author1, name1, version1), status=404) try: object2 = self.model.objects.get(author__username__iexact=author2, - name__iexact=name2, - version=int(version2)) + name__iexact=name2, + version=int(version2)) except: return Response('%s/%s/%s' % (author2, name2, version2), status=404) @@ -224,7 +224,7 @@ class RetrieveUpdateDestroyContributionView(CommonContextMixin, SerializerFields queryset = self.model.objects.for_user(user, True).filter(author__username__iexact=author_name, name__iexact=object_name, version__gte=version)\ - .order_by('version') + .order_by('version') else: queryset = self.model.objects.for_user(user, True).filter(author__username__iexact=author_name, name__iexact=object_name).order_by('-version') diff --git a/beat/web/common/managers.py b/beat/web/common/managers.py index 2fb6c0717..12044733a 100644 --- a/beat/web/common/managers.py +++ b/beat/web/common/managers.py @@ -54,29 +54,29 @@ class BeatActionManager(ActionManager): check(obj) ctype = ContentType.objects.get_for_model(obj) query = Q( - target_content_type=ctype, - target_object_id=obj.pk, - ) + target_content_type=ctype, + target_object_id=obj.pk, + ) if obj.teams.count() > 0: team_ctype = ContentType.objects.get_for_model(Team) team_ids = [team.id for team in obj.teams.all()] query |= Q( - target_content_type=team_ctype, - target_object_id__in=team_ids, - ) + target_content_type=team_ctype, + target_object_id__in=team_ids, + ) public_query = ~Q( - actor_content_type=ctype, - actor_object_id=obj.pk, - ) & ~Q( - target_content_type=ctype, - target_object_id=obj.pk, - ) & ~Q( - action_object_content_type=ctype, - action_object_object_id=obj.pk, - ) & Q( - public=True - ) + actor_content_type=ctype, + actor_object_id=obj.pk, + ) & ~Q( + target_content_type=ctype, + target_object_id=obj.pk, + ) & ~Q( + action_object_content_type=ctype, + action_object_object_id=obj.pk, + ) & Q( + public=True + ) return self.filter(query | public_query, **kwargs) diff --git a/beat/web/common/models.py b/beat/web/common/models.py index 50b3b68e6..e28a45321 100755 --- a/beat/web/common/models.py +++ b/beat/web/common/models.py @@ -57,8 +57,8 @@ class ShareableManager(models.Manager): return self.public() query = Q(sharing=Shareable.SHARED) &\ - (Q(shared_with=user) |\ - Q(shared_with_team__in=Team.objects.filter(members=user))) + (Q(shared_with=user) |\ + Q(shared_with_team__in=Team.objects.filter(members=user))) if hasattr(self.model, 'author'): query |= Q(author=user) @@ -100,7 +100,7 @@ class Shareable(models.Model): blank=True) shared_with_team = models.ManyToManyField(Team, - related_name='shared_%(class)ss', blank=True) + related_name='shared_%(class)ss', blank=True) objects = ShareableManager() @@ -525,7 +525,7 @@ class ContributionManager(VersionableManager): else: teams = Team.objects.filter(members=user) objects_for_user = self.filter(Q(author__username=author_name) & - (Q(sharing=Contribution.PUBLIC)| + (Q(sharing=Contribution.PUBLIC)| Q(shared_with=user) | Q(shared_with_team__in=teams))).distinct() @@ -543,7 +543,7 @@ class Contribution(Versionable): #_____ Fields __________ author = models.ForeignKey(User, related_name='%(class)ss', - on_delete=models.CASCADE) + on_delete=models.CASCADE) objects = ContributionManager() @@ -700,10 +700,10 @@ class StoredContribution(Contribution): storage""" return os.path.join( - beat.core.hash.toUserPath(self.author.username), - self.name, - str(self.version) + extension, - ) + beat.core.hash.toUserPath(self.author.username), + self.name, + str(self.version) + extension, + ) def declaration_filename(self): diff --git a/beat/web/common/serializers.py b/beat/web/common/serializers.py index e58aca79a..5a1a9ffe0 100644 --- a/beat/web/common/serializers.py +++ b/beat/web/common/serializers.py @@ -157,7 +157,7 @@ class ShareableSerializer(DynamicFieldsSerializer): class Meta(DynamicFieldsSerializer.Meta): model = Shareable default_fields = DynamicFieldsSerializer.Meta.default_fields + \ - ['is_owner', 'modifiable', 'deletable', 'sharing'] + ['is_owner', 'modifiable', 'deletable', 'sharing'] def get_accessibility(self, obj): if obj.sharing == Versionable.PUBLIC: @@ -176,11 +176,11 @@ class ShareableSerializer(DynamicFieldsSerializer): if obj.shared_with.count() > 0: sharing['shared_with'] = map(lambda x: x.username, - obj.shared_with.iterator()) + obj.shared_with.iterator()) if obj.shared_with_team.count() > 0: sharing['shared_with_team'] = map(lambda x: x.fullname(), - obj.shared_with_team.iterator()) + obj.shared_with_team.iterator()) return sharing @@ -330,7 +330,7 @@ class ContributionCreationSerializer(serializers.ModelSerializer): if data.has_key('previous_version'): if self.Meta.beat_core_class is not None: previous_version_id = self.Meta.beat_core_class.Storage(settings.PREFIX, - data['previous_version']) + data['previous_version']) if previous_version_id.username is None: previous_version_id.username = user.username else: @@ -345,7 +345,7 @@ class ContributionCreationSerializer(serializers.ModelSerializer): if data.has_key('fork_of'): if self.Meta.beat_core_class is not None: fork_of_id = self.Meta.beat_core_class.Storage(settings.PREFIX, - data['fork_of']) + data['fork_of']) if fork_of_id.username is None: fork_of_id.username = user.username else: @@ -362,12 +362,12 @@ class ContributionCreationSerializer(serializers.ModelSerializer): if previous_version_id is not None: try: previous_version = self.Meta.model.objects.get( - author__username__iexact=previous_version_id.username, - name=previous_version_id.name, - version=previous_version_id.version) + author__username__iexact=previous_version_id.username, + name=previous_version_id.name, + version=previous_version_id.version) except: raise serializers.ValidationError("Data format '%s' not found" % \ - previous_version_id.fullname) + previous_version_id.fullname) is_accessible = previous_version.accessibility_for(user) if not is_accessible[0]: @@ -378,8 +378,8 @@ class ContributionCreationSerializer(serializers.ModelSerializer): if fork_of_id is not None: try: fork_of = self.Meta.model.objects.get(author__username__iexact=fork_of_id.username, - name=fork_of_id.name, - version=fork_of_id.version) + name=fork_of_id.name, + version=fork_of_id.version) except: raise serializers.ValidationError("{} '{}' not found".format(self.Meta.model.__name__, fork_of_id.fullname)) diff --git a/beat/web/common/texts.py b/beat/web/common/texts.py index 543fdaa59..0c9d80eb3 100755 --- a/beat/web/common/texts.py +++ b/beat/web/common/texts.py @@ -28,7 +28,7 @@ code_suffix = '<br/><i class="fa fa-thumbs-up"></i> The ruler at 80 columns indicate suggested <a href="https://en.wikipedia.org/wiki/POSIX">POSIX line breaks</a> (for readability).<br/><i class="fa fa-thumbs-up"></i> The editor will automatically enlarge to accomodate the entirety of your input<br/><i class="fa fa-thumbs-up"></i> Use <a href="http://codemirror.net/doc/manual.html#commands">keyboard shortcuts</a> for search/replace and faster editing. For example, use Ctrl-F (PC) or Cmd-F (Mac) to search through this box' Messages = { - 'description': 'Describe the object thoroughly using <a href="http://docutils.sourceforge.net/rst.html">reStructuredText mark-up</a>' + code_suffix, + 'description': 'Describe the object thoroughly using <a href="http://docutils.sourceforge.net/rst.html">reStructuredText mark-up</a>' + code_suffix, 'code': 'The code for this algorithm in <a href="https://www.python.org">Python</a>' + code_suffix, 'uses': 'You can use functions and classes implemented in libraries.<br/>Once added, the library will be automatically imported with the name specified.', 'library_code': 'The code for this library in <a href="https://www.python.org">Python</a>' + code_suffix, @@ -41,4 +41,4 @@ Messages = { 'name': 'The name for this object (space-like characters will be automatically replaced by dashes)', 'version': 'The version of this object (an integer starting from 1)', 'shared_library': 'The compiled shared library file implementing your algorithm', - } +} diff --git a/beat/web/common/utils.py b/beat/web/common/utils.py index 8bf426e1b..122c25fab 100644 --- a/beat/web/common/utils.py +++ b/beat/web/common/utils.py @@ -82,8 +82,8 @@ def validate_restructuredtext(value): # Apply transforms (and more collect errors) document.transformer.populate_from_components( - (pub.source, pub.reader, pub.reader.parser, pub.writer, - pub.destination)) + (pub.source, pub.reader, pub.reader.parser, pub.writer, + pub.destination)) transformer = document.transformer while transformer.transforms: if not transformer.sorted: diff --git a/beat/web/databases/admin.py b/beat/web/databases/admin.py index 06d55ad34..233cc12f9 100644 --- a/beat/web/databases/admin.py +++ b/beat/web/databases/admin.py @@ -39,7 +39,7 @@ from .models import DatabaseSetTemplateOutput as DatabaseSetTemplateOutputModel from .models import validate_database from ..ui.forms import CodeMirrorJSONFileField, CodeMirrorRSTFileField, \ - CodeMirrorPythonFileField, NameField + CodeMirrorPythonFileField, NameField from ..common.texts import Messages from ..common.admin import notify_by_email @@ -54,34 +54,34 @@ import simplejson as json class DatabaseModelForm(forms.ModelForm): name = NameField( - widget=forms.TextInput(attrs=dict(size=80)), - help_text=Messages['name'], - ) + widget=forms.TextInput(attrs=dict(size=80)), + help_text=Messages['name'], + ) declaration_file = CodeMirrorJSONFileField( - label='Declaration', - help_text=Messages['json'], - ) + label='Declaration', + help_text=Messages['json'], + ) source_code_file = CodeMirrorPythonFileField( - label='Source code', - help_text=Messages['code'], - ) + label='Source code', + help_text=Messages['code'], + ) description_file = CodeMirrorRSTFileField( - label='Description', - required=False, - allow_empty_file=True, - help_text=Messages['description'], - ) + label='Description', + required=False, + allow_empty_file=True, + help_text=Messages['description'], + ) class Meta: model = DatabaseModel exclude = [] widgets = { - 'short_description': forms.TextInput( - attrs=dict(size=100), - ), + 'short_description': forms.TextInput( + attrs=dict(size=100), + ), } def clean_declaration_file(self): @@ -139,32 +139,32 @@ class DatabaseProtocolInline(admin.TabularInline): class Database(admin.ModelAdmin): list_display = ( - 'id', + 'id', 'name', 'version', 'short_description', 'creation_date', 'previous_version', 'sharing', - ) + ) search_fields = [ - 'name', + 'name', 'short_description', 'previous_version__author__username', 'previous_version__name' - ] + ] list_display_links = ( - 'id', + 'id', 'name', - ) + ) readonly_fields = ('short_description',) form = DatabaseModelForm inlines = [ - DatabaseProtocolInline, - ] + DatabaseProtocolInline, + ] filter_horizontal = [ 'shared_with', @@ -190,44 +190,44 @@ class Database(admin.ModelAdmin): count += 1 self.message_user(request, "Created %s new version(s) of selected " \ - "databases." % count) + "databases." % count) new_version.short_description = 'Create new version' actions = [ notify_by_email('database_notifications_enabled'), 'new_version', - ] + ] fieldsets = ( (None, - dict( - fields=('name',), - ), + dict( + fields=('name',), + ), ), ('Documentation', - dict( - classes=('collapse',), - fields=('short_description', 'description_file'), - ), + dict( + classes=('collapse',), + fields=('short_description', 'description_file'), + ), ), ('Versioning', - dict( - classes=('collapse',), - fields=('version', 'previous_version'), - ), + dict( + classes=('collapse',), + fields=('version', 'previous_version'), + ), ), ('Sharing', - dict( - classes=('collapse',), - fields=('sharing', 'shared_with', 'shared_with_team'), - ), + dict( + classes=('collapse',), + fields=('sharing', 'shared_with', 'shared_with_team'), + ), ), ('Source code', - dict( - fields=('declaration_file', 'source_code_file'), - ), + dict( + fields=('declaration_file', 'source_code_file'), + ), ), - ) + ) admin.site.register(DatabaseModel, Database) @@ -257,8 +257,8 @@ class DatabaseSetTemplate(admin.ModelAdmin): readonly_fields = ('name',) inlines = [ - DatabaseSetTemplateOutputInline, - ] + DatabaseSetTemplateOutputInline, + ] def has_delete_permission(self, request, obj=None): return False @@ -298,8 +298,8 @@ class DatabaseSet(admin.ModelAdmin): readonly_fields = ('name', 'template', 'protocol') inlines = [ - DatabaseSetOutputInline, - ] + DatabaseSetOutputInline, + ] def has_delete_permission(self, request, obj=None): return False diff --git a/beat/web/databases/api.py b/beat/web/databases/api.py index 092bc6abf..b7b9008b3 100755 --- a/beat/web/databases/api.py +++ b/beat/web/databases/api.py @@ -56,7 +56,7 @@ logger = logging.getLogger(__name__) #---------------------------------------------------------- def database_to_json(database, request_user, fields_to_return, - last_version=None): + last_version=None): # Prepare the response result = {} @@ -78,7 +78,7 @@ def database_to_json(database, request_user, fields_to_return, if 'previous_version' in fields_to_return: result['previous_version'] = \ - (database.previous_version.fullname() if \ + (database.previous_version.fullname() if \ database.previous_version is not None else None) if 'creation_date' in fields_to_return: @@ -191,7 +191,7 @@ class RetrieveDatabaseView(views.APIView): version = int(version) databases = Database.objects.for_user(request.user, True).filter(name__iexact=database_name, - version__gte=version).order_by('version') + version__gte=version).order_by('version') database = databases[0] @@ -201,7 +201,7 @@ class RetrieveDatabaseView(views.APIView): last_version = (len(databases) == 1) else: database = Database.objects.for_user(request.user, True).filter( - name__iexact=database_name).order_by('-version')[0] + name__iexact=database_name).order_by('-version')[0] last_version = True except: return HttpResponse(status=status.HTTP_404_NOT_FOUND) @@ -212,16 +212,16 @@ class RetrieveDatabaseView(views.APIView): fields_to_return = request.GET['fields'].split(',') else: fields_to_return = [ 'name', 'version', 'last_version', - 'short_description', 'description', 'fork_of', - 'previous_version', 'is_owner', 'accessibility', 'sharing', - 'opensource', 'hash', 'creation_date', - 'declaration', 'code' ] + 'short_description', 'description', 'fork_of', + 'previous_version', 'is_owner', 'accessibility', 'sharing', + 'opensource', 'hash', 'creation_date', + 'declaration', 'code' ] try: # Prepare the response result = database_to_json(database, request.user, fields_to_return, - last_version=last_version) + last_version=last_version) # Retrieve the code diff --git a/beat/web/databases/migrations/0002_scheduler_addons.py b/beat/web/databases/migrations/0002_scheduler_addons.py index 9c748aa72..e66308e5b 100644 --- a/beat/web/databases/migrations/0002_scheduler_addons.py +++ b/beat/web/databases/migrations/0002_scheduler_addons.py @@ -56,12 +56,12 @@ def refresh_databases(apps, schema_editor): for output in set.template.outputs.all(): try: DatabaseSetOutput(template=output, set=set, - hash=core.hash_output(proto.name, set.name, - output.name)).save() + hash=core.hash_output(proto.name, set.name, + output.name)).save() except KeyError: logger.warn('Database output %s/%d.%s.%s.%s does ' \ - 'not exist' % (db.name, db.version, proto.name, - set.name, output.name)) + 'not exist' % (db.name, db.version, proto.name, + set.name, output.name)) continue diff --git a/beat/web/databases/models.py b/beat/web/databases/models.py index c4cb27213..d70d8f3dc 100755 --- a/beat/web/databases/models.py +++ b/beat/web/databases/models.py @@ -160,28 +160,28 @@ class Database(Versionable): #_____ Fields __________ declaration_file = models.FileField( - storage=DatabaseStorage(), - upload_to=get_contribution_declaration_filename, - blank=True, null=True, - max_length=200, - db_column='declaration' - ) + storage=DatabaseStorage(), + upload_to=get_contribution_declaration_filename, + blank=True, null=True, + max_length=200, + db_column='declaration' + ) description_file = models.FileField( - storage=DatabaseStorage(), - upload_to=get_contribution_description_filename, - blank=True, null=True, - max_length=200, - db_column='description' - ) + storage=DatabaseStorage(), + upload_to=get_contribution_description_filename, + blank=True, null=True, + max_length=200, + db_column='description' + ) source_code_file = models.FileField( - storage=DatabaseStorage(), - upload_to=get_contribution_source_code_filename, - blank=True, null=True, - max_length=200, - db_column='source_code' - ) + storage=DatabaseStorage(), + upload_to=get_contribution_source_code_filename, + blank=True, null=True, + max_length=200, + db_column='source_code' + ) objects = DatabaseManager() @@ -198,9 +198,9 @@ class Database(Versionable): def get_absolute_url(self): return reverse( - 'databases:view', + 'databases:view', args=(self.name, self.version,), - ) + ) def natural_key(self): @@ -277,10 +277,10 @@ class DatabaseProtocolManager(models.Manager): def get_by_natural_key(self, database_name, database_version, name): return self.get( - database__name=database_name, - database__version=database_version, - name=name, - ) + database__name=database_name, + database__version=database_version, + name=name, + ) class DatabaseProtocol(models.Model): @@ -288,7 +288,7 @@ class DatabaseProtocol(models.Model): objects = DatabaseProtocolManager() database = models.ForeignKey(Database, related_name='protocols', - on_delete=models.CASCADE) + on_delete=models.CASCADE) name = models.CharField(max_length=200, blank=True) class Meta: @@ -354,12 +354,12 @@ class DatabaseSetManager(models.Manager): def get_by_natural_key(self, database_name, database_version, protocol_name, name, template_name): return self.get( - protocol__database__name=database_name, - protocol__database__version=database_version, - protocol__name=protocol_name, - name=name, - template__name=template_name, - ) + protocol__database__name=database_name, + protocol__database__version=database_version, + protocol__name=protocol_name, + name=name, + template__name=template_name, + ) class DatabaseSet(models.Model): @@ -367,10 +367,10 @@ class DatabaseSet(models.Model): objects = DatabaseSetManager() protocol = models.ForeignKey(DatabaseProtocol, related_name='sets', - on_delete=models.CASCADE) + on_delete=models.CASCADE) name = models.CharField(max_length=200, blank=True) template = models.ForeignKey(DatabaseSetTemplate, related_name='sets', - on_delete=models.CASCADE) + on_delete=models.CASCADE) class Meta: unique_together = ('protocol', 'name', 'template') @@ -404,10 +404,10 @@ class DatabaseSet(models.Model): class DatabaseSetTemplateOutput(models.Model): template = models.ForeignKey(DatabaseSetTemplate, - related_name='outputs', on_delete=models.CASCADE) + related_name='outputs', on_delete=models.CASCADE) name = models.CharField(max_length=200) dataformat = models.ForeignKey(DataFormat, - related_name='database_outputs', on_delete=models.CASCADE) + related_name='database_outputs', on_delete=models.CASCADE) class Meta: unique_together = ('template', 'name') @@ -430,9 +430,9 @@ class DatabaseSetOutputManager(models.Manager): class DatabaseSetOutput(models.Model): template = models.ForeignKey(DatabaseSetTemplateOutput, - related_name='instances', on_delete=models.CASCADE) + related_name='instances', on_delete=models.CASCADE) set = models.ForeignKey(DatabaseSet, related_name='outputs', - on_delete=models.CASCADE) + on_delete=models.CASCADE) hash = models.CharField(max_length=64, unique=True) objects = DatabaseSetOutputManager() @@ -446,7 +446,7 @@ class DatabaseSetOutput(models.Model): self.set.protocol.name, self.set.name, self.template.name, - ) + ) def all_referenced_dataformats(self): return self.template.all_referenced_dataformats() diff --git a/beat/web/databases/serializers.py b/beat/web/databases/serializers.py index 0d174f69d..cee4d8e45 100644 --- a/beat/web/databases/serializers.py +++ b/beat/web/databases/serializers.py @@ -61,8 +61,8 @@ class DatabaseSerializer(VersionableSerializer): for protocol in obj.protocols.all(): protocol_entry = { - 'name': protocol.name, - } + 'name': protocol.name, + } if include_datasets: protocol_entry['datasets'] = [] @@ -74,9 +74,9 @@ class DatabaseSerializer(VersionableSerializer): if include_outputs: dataset_entry['outputs'] = map(lambda x: { - 'name': x.name, + 'name': x.name, 'dataformat': x.dataformat.fullname(), - }, dataset.template.outputs.order_by('name')) + }, dataset.template.outputs.order_by('name')) protocol_entry['datasets'].append(dataset_entry) @@ -103,7 +103,7 @@ class DatabaseCreationSerializer(serializers.ModelSerializer): if data.has_key('previous_version'): previous_version_id = self.Meta.beat_core_class.Storage(settings.PREFIX, - data['previous_version']) + data['previous_version']) else: previous_version_id = None @@ -111,11 +111,11 @@ class DatabaseCreationSerializer(serializers.ModelSerializer): if previous_version_id is not None: try: previous_version = self.Meta.model.objects.get( - name=previous_version_id.name, - version=previous_version_id.version) + name=previous_version_id.name, + version=previous_version_id.version) except: raise serializers.ValidationError("Database '%s' not found" % \ - previous_version_id.fullname) + previous_version_id.fullname) is_accessible = previous_version.accessibility_for(user) if not is_accessible[0]: diff --git a/beat/web/databases/signals.py b/beat/web/databases/signals.py index 474c719ba..e440eb6e2 100644 --- a/beat/web/databases/signals.py +++ b/beat/web/databases/signals.py @@ -94,9 +94,9 @@ def refresh_protocols(sender, instance, **kwargs): core.name = instance.fullname() protocols = DatabaseProtocol.objects.filter( - database__name=instance.name, - database__version=instance.version, - ) + database__name=instance.name, + database__version=instance.version, + ) existing = set((k.name, k.set_template_basename()) for k in protocols) new_objects = set([(k,v['template']) for k,v in core.protocols.items()]) @@ -130,14 +130,14 @@ def refresh_protocols(sender, instance, **kwargs): name = set_attr['name'], template = dataset_template, protocol = protocol, - ) + ) if not dataset: #create dataset = DatabaseSet( name = set_attr['name'], template = dataset_template, protocol = protocol, - ) + ) dataset.save() # Create the database set template output @@ -147,13 +147,13 @@ def refresh_protocols(sender, instance, **kwargs): "Dataformat should be named following the " \ "style `<username>/<format>/<version>', the " \ "value `%s' is not valid" % (format_name,) - ) + ) (author, name, version) = format_name.split('/') dataformats = DataFormat.objects.filter( author__username=author, name=name, version=version, - ) + ) # TODO: Remove this when validation works (see comments) if len(dataformats) != 1: @@ -161,13 +161,13 @@ def refresh_protocols(sender, instance, **kwargs): "Could not find dataformat named `%s' to set" \ "output `%s' of template `%s' for protocol" \ "`%s' of database `%s'", ( - format_name, + format_name, output_name, dataset_template.name, protocol_name, instance.name, - ) ) + ) return database_template_output = \ @@ -175,7 +175,7 @@ def refresh_protocols(sender, instance, **kwargs): name=output_name, template=dataset_template, dataformat=dataformats[0], - ) + ) if not database_template_output: # create database_template_output = \ @@ -183,7 +183,7 @@ def refresh_protocols(sender, instance, **kwargs): name=output_name, template=dataset_template, dataformat=dataformats[0], - ) + ) database_template_output.save() else: @@ -192,7 +192,7 @@ def refresh_protocols(sender, instance, **kwargs): # Create the database set output hash = core.hash_output(protocol.name, - dataset.name, output_name) + dataset.name, output_name) dataset_output = \ DatabaseSetOutput.objects.filter(hash=hash) @@ -201,7 +201,7 @@ def refresh_protocols(sender, instance, **kwargs): template=database_template_output, set=dataset, hash=hash, - ) + ) dataset_output.save() except Exception: diff --git a/beat/web/databases/templatetags/database_tags.py b/beat/web/databases/templatetags/database_tags.py index e6148e113..c12366b44 100644 --- a/beat/web/databases/templatetags/database_tags.py +++ b/beat/web/databases/templatetags/database_tags.py @@ -47,10 +47,10 @@ def database_table(context, objects, id): ''' return dict( - request=context['request'], - objects=objects, - panel_id=id, - ) + request=context['request'], + objects=objects, + panel_id=id, + ) @register.inclusion_tag('databases/panels/actions.html', takes_context=True) @@ -70,7 +70,7 @@ def database_actions(context, object, display_count): ''' return dict( - request=context['request'], - object=object, - display_count=display_count, - ) + request=context['request'], + object=object, + display_count=display_count, + ) diff --git a/beat/web/databases/tests.py b/beat/web/databases/tests.py index b06aad04f..6b530aac4 100644 --- a/beat/web/databases/tests.py +++ b/beat/web/databases/tests.py @@ -40,7 +40,7 @@ from ..common.testutils import BaseTestCase class DatabaseAPIBase(BaseTestCase): DATABASE = { - "root_folder": "/path/to/root/folder", + "root_folder": "/path/to/root/folder", "protocols": [ { "name": "protocol1", @@ -52,12 +52,12 @@ class DatabaseAPIBase(BaseTestCase): "view": "dummy", "outputs": { "out": settings.SYSTEM_ACCOUNT + "/float/1" - } } - ] - } - ] - } + } + ] + } + ] + } def setUp(self): @@ -95,10 +95,10 @@ class AttestationCreationAPI(DatabaseAPIBase): self.client.login(username=settings.SYSTEM_ACCOUNT, password='1234') db_name = 'test_db' response = self.client.post(self.url, - json.dumps({ - 'name': db_name, - 'declaration': self.DATABASE - }), content_type='application/json') + json.dumps({ + 'name': db_name, + 'declaration': self.DATABASE + }), content_type='application/json') data = self.checkResponse(response, 400) @@ -112,10 +112,10 @@ class AttestationCreationAPI(DatabaseAPIBase): self.client.login(username=settings.SYSTEM_ACCOUNT, password='1234') db_name = 'test_db' response = self.client.post(self.url, - json.dumps({ - 'name': db_name, - 'declaration': self.DATABASE - }), content_type='application/json') + json.dumps({ + 'name': db_name, + 'declaration': self.DATABASE + }), content_type='application/json') data = self.checkResponse(response, 201, content_type='application/json') diff --git a/beat/web/databases/views.py b/beat/web/databases/views.py index b11f38a5e..88d37e553 100644 --- a/beat/web/databases/views.py +++ b/beat/web/databases/views.py @@ -41,7 +41,7 @@ def view(request, name, version=None): version = int(version) database = Database.objects.for_user(request.user, True).get(name__iexact=name, - version=version) + version=version) else: database = Database.objects.for_user(request.user, True).filter(name__iexact=name).order_by('-version')[0] except: @@ -62,10 +62,10 @@ def ls(request): objects = Database.filter_latest_versions(objects) return render_to_response('databases/list.html', - dict( - objects=objects, - author=request.user, - owner=True, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=request.user, + owner=True, + ), + context_instance=RequestContext(request), + ) diff --git a/beat/web/dataformats/admin.py b/beat/web/dataformats/admin.py index fa55018c7..0a4487983 100644 --- a/beat/web/dataformats/admin.py +++ b/beat/web/dataformats/admin.py @@ -34,7 +34,7 @@ from .models import validate_format from .models import DataFormat as DataFormatModel from ..ui.forms import CodeMirrorJSONFileField, CodeMirrorRSTFileField, \ - NameField + NameField from ..common.texts import Messages @@ -47,35 +47,35 @@ import simplejson as json class DataFormatModelForm(forms.ModelForm): name = NameField( - widget=forms.TextInput(attrs=dict(size=80)), - help_text=Messages['name'], - ) + widget=forms.TextInput(attrs=dict(size=80)), + help_text=Messages['name'], + ) declaration_file = CodeMirrorJSONFileField( - label='Declaration', - help_text=Messages['format'], - ) + label='Declaration', + help_text=Messages['format'], + ) description_file = CodeMirrorRSTFileField( - label='Description', - required=False, - allow_empty_file=True, - help_text=Messages['description'], - ) + label='Description', + required=False, + allow_empty_file=True, + help_text=Messages['description'], + ) class Meta: model = DataFormatModel exclude = [] widgets = { - 'short_description': forms.TextInput( - attrs=dict(size=100), - ), + 'short_description': forms.TextInput( + attrs=dict(size=100), + ), 'extend': forms.Select( attrs=dict(disabled=1), - ), + ), 'referenced_formats': forms.SelectMultiple( attrs=dict(disabled=1), - ), + ), } def clean_declaration_file(self): @@ -101,8 +101,8 @@ class DataFormatModelForm(forms.ModelForm): if errors: #it is a list with possibly many entries raise forms.ValidationError( - [forms.ValidationError(k) for k in errors] - ) + [forms.ValidationError(k) for k in errors] + ) if referenced_formats: self.cleaned_data['referenced_formats'] = referenced_formats @@ -164,7 +164,7 @@ class DataFormat(admin.ModelAdmin): actions = [ rehash_dataformat, - ] + ] form = DataFormatModelForm @@ -175,39 +175,39 @@ class DataFormat(admin.ModelAdmin): fieldsets = ( (None, - dict( - fields=('name', 'author'), - ), + dict( + fields=('name', 'author'), + ), ), ('Documentation', - dict( - classes=('collapse',), - fields=('short_description', 'description_file'), - ), + dict( + classes=('collapse',), + fields=('short_description', 'description_file'), + ), ), ('Versioning', - dict( - classes=('collapse',), - fields=('version', 'previous_version', 'fork_of'), - ), + dict( + classes=('collapse',), + fields=('version', 'previous_version', 'fork_of'), + ), ), ('Sharing', - dict( - classes=('collapse',), - fields=('sharing', 'shared_with', 'shared_with_team'), - ), + dict( + classes=('collapse',), + fields=('sharing', 'shared_with', 'shared_with_team'), + ), ), ('Referenced objects (read-only)', - dict( - classes=('collapse',), - fields=('extend', 'referenced_formats',), - ), + dict( + classes=('collapse',), + fields=('extend', 'referenced_formats',), + ), ), ('Source code', - dict( - fields=('hash', 'declaration_file'), - ), + dict( + fields=('hash', 'declaration_file'), + ), ), - ) + ) admin.site.register(DataFormatModel, DataFormat) diff --git a/beat/web/dataformats/forms.py b/beat/web/dataformats/forms.py index 3073c2821..d4f4ff07f 100755 --- a/beat/web/dataformats/forms.py +++ b/beat/web/dataformats/forms.py @@ -44,38 +44,38 @@ from .models import validate_format class CreationForm(forms.Form): version = forms.IntegerField( - required=True, - min_value=1, - widget=forms.HiddenInput(), #make it hidden - ) + required=True, + min_value=1, + widget=forms.HiddenInput(), #make it hidden + ) name = NameField( - label='Name', - max_length=100, - widget=forms.TextInput(attrs=dict(size="100%")), - help_text=Messages['format_name'], - required=True, - ) + label='Name', + max_length=100, + widget=forms.TextInput(attrs=dict(size="100%")), + help_text=Messages['format_name'], + required=True, + ) file = CodeMirrorJSONCharField( - label='Format', - help_text=Messages['format'], - required=True, - ) + label='Format', + help_text=Messages['format'], + required=True, + ) short_description = forms.CharField( - label='Short description', - max_length=100, - widget=forms.TextInput(attrs=dict(size="100%")), - help_text=Messages['short_description'], - required=False, - ) + label='Short description', + max_length=100, + widget=forms.TextInput(attrs=dict(size="100%")), + help_text=Messages['short_description'], + required=False, + ) description = CodeMirrorRSTCharField( - label='Description', - help_text=Messages['description'], - required=False, - ) + label='Description', + help_text=Messages['description'], + required=False, + ) def clean_file(self): """Cleans-up the file data, make sure it is really new""" @@ -95,10 +95,10 @@ class CreationForm(forms.Form): version = self.cleaned_data['version'] obj = DataFormat.objects.filter( - author = self.__user__, - name = name, - version = version, - ) + author = self.__user__, + name = name, + version = version, + ) if obj: raise forms.ValidationError("Choose another name for your data format. The version %d of data format %s already exists" % (version, name)) @@ -118,22 +118,22 @@ class CreationForm(forms.Form): class UpdateForm(forms.Form): file = CodeMirrorJSONCharField( - label='Declaration', - help_text=Messages['format'], - ) + label='Declaration', + help_text=Messages['format'], + ) short_description = forms.CharField( - label='Short description', - widget=forms.TextInput(attrs=dict(size="100%")), - help_text=Messages['short_description'], - required=False, - ) + label='Short description', + widget=forms.TextInput(attrs=dict(size="100%")), + help_text=Messages['short_description'], + required=False, + ) description = CodeMirrorRSTCharField( - label='Description', - help_text=Messages['description'], - required=False, - ) + label='Description', + help_text=Messages['description'], + required=False, + ) def clean_file(self): @@ -154,7 +154,7 @@ class UpdateForm(forms.Form): class DisplayForm(forms.Form): file = CodeMirrorJSONCharField( - label='Source code', - help_text=Messages['format'], - readonly=True, #cannot edit code on display - ) + label='Source code', + help_text=Messages['format'], + readonly=True, #cannot edit code on display + ) diff --git a/beat/web/dataformats/models.py b/beat/web/dataformats/models.py index 491c1442c..fa0ba35dd 100644 --- a/beat/web/dataformats/models.py +++ b/beat/web/dataformats/models.py @@ -64,10 +64,10 @@ def validate_format(declaration): storage = beat.core.dataformat.Storage(settings.PREFIX, name) return DataFormat.objects.get( - author__username=storage.username, - name=storage.name, - version=int(storage.version), - ) + author__username=storage.username, + name=storage.name, + version=int(storage.version), + ) if declaration is None: raise SyntaxError('Data format declaration cannot be empty') @@ -165,20 +165,20 @@ class DataFormat(StoredContribution): #_____ Fields __________ declaration_file = models.FileField( - storage=DataFormatStorage(), - upload_to=get_contribution_declaration_filename, - blank=True, null=True, - max_length=200, - db_column='declaration' - ) + storage=DataFormatStorage(), + upload_to=get_contribution_declaration_filename, + blank=True, null=True, + max_length=200, + db_column='declaration' + ) description_file = models.FileField( - storage=DataFormatStorage(), - upload_to=get_contribution_description_filename, - blank=True, null=True, - max_length=200, - db_column='description' - ) + storage=DataFormatStorage(), + upload_to=get_contribution_description_filename, + blank=True, null=True, + max_length=200, + db_column='description' + ) # Read-only parameters that are updated at every save(), if required extend = models.ForeignKey('self', related_name='extensions', @@ -196,27 +196,27 @@ class DataFormat(StoredContribution): def get_absolute_url(self): return reverse( - 'dataformats:view', + 'dataformats:view', args=(self.author.username, self.name, self.version,), - ) + ) def get_api_update_url(self): '''Returns the endpoint to update this object''' return reverse( - 'api_dataformats:object', + 'api_dataformats:object', args=(self.author.username, self.name, self.version,), - ) + ) def get_api_share_url(self): '''Returns the endpoint to share this object''' return reverse( - 'api_dataformats:share', + 'api_dataformats:share', args=(self.author.username, self.name, self.version,), - ) + ) #_____ Meta parameters __________ @@ -278,22 +278,22 @@ class DataFormat(StoredContribution): def modifiable(self): """Can be modified if no object is pointing at me""" return super(DataFormat, self).modifiable() and \ - ((self.referencing.count() + \ - self.extensions.count() + \ - self.algorithm_endpoints.count() + \ - self.plotters.count() + \ - self.database_outputs.count() + ((self.referencing.count() + \ + self.extensions.count() + \ + self.algorithm_endpoints.count() + \ + self.plotters.count() + \ + self.database_outputs.count() ) == 0) def deletable(self): """Can be deleted if no object is pointing at me""" return super(DataFormat, self).deletable() and \ - ((self.referencing.count() + \ - self.extensions.count() + \ - self.algorithm_endpoints.count() + \ - self.plotters.count() + \ - self.database_outputs.count() + ((self.referencing.count() + \ + self.extensions.count() + \ + self.algorithm_endpoints.count() + \ + self.plotters.count() + \ + self.database_outputs.count() ) == 0) diff --git a/beat/web/dataformats/templatetags/dataformat_tags.py b/beat/web/dataformats/templatetags/dataformat_tags.py index 98b1a9a28..9cc8e4f01 100644 --- a/beat/web/dataformats/templatetags/dataformat_tags.py +++ b/beat/web/dataformats/templatetags/dataformat_tags.py @@ -53,11 +53,11 @@ def dataformat_table(context, objects, owner, id): ''' return dict( - request=context['request'], - objects=objects, - owner=owner, - panel_id=id, - ) + request=context['request'], + objects=objects, + owner=owner, + panel_id=id, + ) @register.inclusion_tag('dataformats/panels/actions.html', takes_context=True) @@ -76,10 +76,10 @@ def dataformat_actions(context, object, display_count): ''' return dict( - request=context['request'], - object=object, - display_count=display_count, - ) + request=context['request'], + object=object, + display_count=display_count, + ) @register.inclusion_tag('dataformats/panels/sharing.html', takes_context=True) @@ -93,20 +93,20 @@ def dataformat_sharing(context, object): ''' return dict( - request=context['request'], - object=object, - users=context['users'], - teams=context['teams'], - ) + request=context['request'], + object=object, + users=context['users'], + teams=context['teams'], + ) @register.inclusion_tag('dataformats/panels/editor.html', takes_context=True) def dataformat_editor(context, obj): return { - 'owner': context['request'].user == obj.author, + 'owner': context['request'].user == obj.author, 'object': obj, 'texts': Texts, - } + } @register.assignment_tag(takes_context=True) @@ -129,7 +129,7 @@ def visible_referrer_algorithms(context, obj): if obj in k.all_referenced_result_dataformats(): analyzers.add(k) return sorted(set(algorithms) | analyzers, - key=lambda x: x.creation_date, reverse=True) + key=lambda x: x.creation_date, reverse=True) @register.assignment_tag(takes_context=True) @@ -144,5 +144,5 @@ def visible_referrers_count(context, obj): '''Calculates the visible usage for a given dataformat and requestor''' return visible_referrer_dataformats(context, obj).count() + \ - len(visible_referrer_algorithms(context, obj)) + \ - visible_referrer_databases(context, obj).count() + len(visible_referrer_algorithms(context, obj)) + \ + visible_referrer_databases(context, obj).count() diff --git a/beat/web/dataformats/tests/core.py b/beat/web/dataformats/tests/core.py index 50e7b99fb..1c7001b81 100644 --- a/beat/web/dataformats/tests/core.py +++ b/beat/web/dataformats/tests/core.py @@ -62,14 +62,14 @@ class DataFormatsAccessibilityFunctionsBase(BaseTestCase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=user1, name='personal', - ) + ) assert dataformat, errors # Accessible to one user (dataformat, errors) = DataFormat.objects.create_dataformat( author=user1, name='public_for_one_user', - ) + ) assert dataformat, errors dataformat.share(users=[user2]) @@ -78,7 +78,7 @@ class DataFormatsAccessibilityFunctionsBase(BaseTestCase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=user1, name='public_for_one_team', - ) + ) assert dataformat, errors dataformat.share(teams=[team1]) @@ -87,7 +87,7 @@ class DataFormatsAccessibilityFunctionsBase(BaseTestCase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=user1, name='public_for_teams', - ) + ) assert dataformat, errors dataformat.share(teams=[team1, team2]) @@ -96,7 +96,7 @@ class DataFormatsAccessibilityFunctionsBase(BaseTestCase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=user1, name='public_for_all', - ) + ) assert dataformat, errors dataformat.share() @@ -129,7 +129,7 @@ class DataFormatsAPIBase(BaseTestCase): name='format_private', short_description='short private description', description='long private description', - ) + ) assert dataformat_private, errors @@ -138,7 +138,7 @@ class DataFormatsAPIBase(BaseTestCase): name='format1', short_description='short description 1', description='long description 1', - ) + ) assert dataformat1, errors dataformat1.share() @@ -148,7 +148,7 @@ class DataFormatsAPIBase(BaseTestCase): name='format2', short_description='short description 2', description='long description 2', - ) + ) assert dataformat2, errors (dataformat3, errors) = DataFormat.objects.create_dataformat( @@ -157,7 +157,7 @@ class DataFormatsAPIBase(BaseTestCase): short_description='short description 3', description='long description 3', declaration='{\n "#extends": "%s"\n}' % dataformat1.fullname(), - ) + ) assert dataformat3, errors dataformat3.share() @@ -166,7 +166,7 @@ class DataFormatsAPIBase(BaseTestCase): name='team_format1', short_description='team short description 1', description='team long description 1', - ) + ) assert dataformat4, errors dataformat4.share(teams=[team1]) @@ -196,14 +196,14 @@ class DataFormatSharingAPIBase(DataFormatsAPIBase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=user1, name='personal', - ) + ) assert dataformat, errors # Accessible to one user (dataformat, errors) = DataFormat.objects.create_dataformat( author=user1, name='public_for_one_user', - ) + ) assert dataformat, errors dataformat.share(users=[user2]) @@ -211,7 +211,7 @@ class DataFormatSharingAPIBase(DataFormatsAPIBase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=user1, name='public_for_one_team', - ) + ) assert dataformat, errors dataformat.share(teams=[team1]) @@ -219,7 +219,7 @@ class DataFormatSharingAPIBase(DataFormatsAPIBase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=user1, name='public_for_teams', - ) + ) assert dataformat, errors dataformat.share(teams=[team1, team2]) @@ -227,7 +227,7 @@ class DataFormatSharingAPIBase(DataFormatsAPIBase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=user1, name='public_for_all', - ) + ) assert dataformat, errors dataformat.share() @@ -236,7 +236,7 @@ class DataFormatSharingAPIBase(DataFormatsAPIBase): author=user1, name='extension_of_personal', declaration='{\n "#extends": "%s/personal/1"\n}' % user1.username, - ) + ) assert dataformat, errors # Personal dataformat not shared with anyone, extension of a public one @@ -244,7 +244,7 @@ class DataFormatSharingAPIBase(DataFormatsAPIBase): author=user1, name='extension_of_public', declaration='{\n "#extends": "%s/public_for_all/1"\n}' % user1.username, - ) + ) assert dataformat, errors # Personal dataformat not shared with anyone, extension of a limited public one @@ -252,7 +252,7 @@ class DataFormatSharingAPIBase(DataFormatsAPIBase): author=user2, name='extension_of_external', declaration='{\n "#extends": "%s/public_for_one_user/1"\n}' % user1.username, - ) + ) assert dataformat, errors diff --git a/beat/web/dataformats/tests/tests.py b/beat/web/dataformats/tests/tests.py index ab4a68e5d..8e9f974fc 100644 --- a/beat/web/dataformats/tests/tests.py +++ b/beat/web/dataformats/tests/tests.py @@ -65,7 +65,7 @@ class DataFormatsCreationFunction(TestCase): author=user, name='format1', short_description='some description', - ) + ) assert dataformat, errors db_dataformat = DataFormat.objects.get(author=user, name='format1') @@ -87,7 +87,7 @@ class DataFormatsCreationFunction(TestCase): declaration={ 'value': 'int32' }, - ) + ) assert dataformat, errors db_dataformat = DataFormat.objects.get(author=user, name='format1') @@ -109,7 +109,7 @@ class DataFormatsCreationFunction(TestCase): declaration={ 'value': 'int32' }, - ) + ) assert dataformat, errors (dataformat, errors) = DataFormat.objects.create_dataformat( @@ -120,7 +120,7 @@ class DataFormatsCreationFunction(TestCase): '#extends': 'johndoe/format1/1', 'value2': 'int32' }, - ) + ) assert dataformat, errors db_dataformat = DataFormat.objects.get(author=user, name='format2') @@ -190,7 +190,7 @@ class DataFormatsCreationFunction(TestCase): declaration={ 'value': 'int32' }, - ) + ) assert dataformat, errors (dataformat, errors) = DataFormat.objects.create_dataformat( @@ -200,7 +200,7 @@ class DataFormatsCreationFunction(TestCase): declaration={ 'value2': 'int32' }, - ) + ) assert dataformat, errors (dataformat, errors) = DataFormat.objects.create_dataformat( @@ -210,7 +210,7 @@ class DataFormatsCreationFunction(TestCase): declaration={ 'value3': 'int32' }, - ) + ) assert dataformat, errors (dataformat, errors) = DataFormat.objects.create_dataformat( @@ -222,7 +222,7 @@ class DataFormatsCreationFunction(TestCase): 'field1': 'johndoe/format1/1', 'field2': 'johndoe/format2/1' }, - ) + ) assert dataformat, errors db_dataformat = DataFormat.objects.get(author=user, name='format4') diff --git a/beat/web/dataformats/tests/tests_api.py b/beat/web/dataformats/tests/tests_api.py index 7f35c3705..9e706abd9 100644 --- a/beat/web/dataformats/tests/tests_api.py +++ b/beat/web/dataformats/tests/tests_api.py @@ -190,7 +190,7 @@ class DataFormatsNameCheck(DataFormatsAPIBase): author=user, name='format-4', short_description='short description 4', - ) + ) assert format4, errors @@ -211,9 +211,9 @@ class DataFormatsNameCheck(DataFormatsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -226,9 +226,9 @@ class DataFormatsNameCheck(DataFormatsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name_1 #due-to{}%&é', - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name_1 #due-to{}%&é', + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -241,9 +241,9 @@ class DataFormatsNameCheck(DataFormatsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'format2', - }), content_type='application/json') + json.dumps({ + 'name': 'format2', + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -256,9 +256,9 @@ class DataFormatsNameCheck(DataFormatsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'format 4', - }), content_type='application/json') + json.dumps({ + 'name': 'format 4', + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -280,7 +280,7 @@ class DataFormatCreation(DataFormatsAPIBase): author=user, name='format-4', short_description='short description 4', - ) + ) assert format4, errors @@ -314,10 +314,10 @@ class DataFormatCreation(DataFormatsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'short_description': 'blah' - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'short_description': 'blah' + }), content_type='application/json') url = reverse('api_dataformats:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, @@ -342,9 +342,9 @@ class DataFormatCreation(DataFormatsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1' - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1' + }), content_type='application/json') url = reverse('api_dataformats:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, @@ -369,10 +369,10 @@ class DataFormatCreation(DataFormatsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name1', - 'short_description': 'blah' - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name1', + 'short_description': 'blah' + }), content_type='application/json') url = reverse('api_dataformats:object', args=['jackdoe', 'invalid-name1', 1]) content = self.checkResponse(response, 201, @@ -397,9 +397,9 @@ class DataFormatCreation(DataFormatsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name1' - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name1' + }), content_type='application/json') url = reverse('api_dataformats:object', args=['jackdoe', 'invalid-name1', 1]) content = self.checkResponse(response, 201, @@ -424,10 +424,10 @@ class DataFormatCreation(DataFormatsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'format2', - 'description': 'blah' - }), content_type='application/json') + json.dumps({ + 'name': 'format2', + 'description': 'blah' + }), content_type='application/json') self.checkResponse(response, 400) @@ -436,9 +436,9 @@ class DataFormatCreation(DataFormatsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'format2', - }), content_type='application/json') + json.dumps({ + 'name': 'format2', + }), content_type='application/json') self.checkResponse(response, 400) @@ -447,10 +447,10 @@ class DataFormatCreation(DataFormatsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'format 4', - 'description': 'blah' - }), content_type='application/json') + json.dumps({ + 'name': 'format 4', + 'description': 'blah' + }), content_type='application/json') self.checkResponse(response, 400) @@ -459,9 +459,9 @@ class DataFormatCreation(DataFormatsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'format 4', - }), content_type='application/json') + json.dumps({ + 'name': 'format 4', + }), content_type='application/json') self.checkResponse(response, 400) @@ -469,11 +469,11 @@ class DataFormatCreation(DataFormatsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'short_description': 'blah', - 'declaration': { 'value': 'int32' } - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'short_description': 'blah', + 'declaration': { 'value': 'int32' } + }), content_type='application/json') url = reverse('api_dataformats:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, @@ -505,10 +505,10 @@ class DataFormatUpdate(DataFormatsAPIBase): def test_no_update_for_anonymous_user(self): response = self.client.put(self.url, - json.dumps({ - 'description': 'blah', - 'declaration': { 'value': 'int32' } - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': { 'value': 'int32' } + }), content_type='application/json') self.checkResponse(response, 403) @@ -518,10 +518,10 @@ class DataFormatUpdate(DataFormatsAPIBase): url = reverse('api_dataformats:object', args=['unknown', 'format_private', 1]) response = self.client.put(url, - json.dumps({ - 'description': 'blah', - 'declaration': { 'value': 'int32' } - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': { 'value': 'int32' } + }), content_type='application/json') self.checkResponse(response, 403) @@ -531,10 +531,10 @@ class DataFormatUpdate(DataFormatsAPIBase): url = reverse('api_dataformats:object', args=['jackdoe', 'unknown', 1]) response = self.client.put(url, - json.dumps({ - 'description': 'blah', - 'declaration': { 'value': 'int32' } - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': { 'value': 'int32' } + }), content_type='application/json') self.checkResponse(response, 404) @@ -552,10 +552,10 @@ class DataFormatUpdate(DataFormatsAPIBase): DataFormat.objects.get(name='format1').share() response = self.client.put(self.format1_url, - json.dumps({ - 'description': 'blah', - 'declaration': { 'value': 'int32' } - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': { 'value': 'int32' } + }), content_type='application/json') self.checkResponse(response, 403) @@ -564,10 +564,10 @@ class DataFormatUpdate(DataFormatsAPIBase): self.client.login(username='johndoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'description': 'blah', - 'declaration': { 'value': 'float64' } - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': { 'value': 'float64' } + }), content_type='application/json') self.checkResponse(response, 204) @@ -575,7 +575,7 @@ class DataFormatUpdate(DataFormatsAPIBase): self.assertEqual(dataformat.description, 'blah') storage = Storage(settings.PREFIX, - dataformat.fullname()) + dataformat.fullname()) assert storage.exists with open(storage.json.path, 'rt') as f: declaration = json.load(f) self.assertEqual(declaration['value'], 'float64') @@ -585,9 +585,9 @@ class DataFormatUpdate(DataFormatsAPIBase): self.client.login(username='johndoe', password='1234') response = self.client.put(self.format1_url, - json.dumps({ - 'description': 'blah', - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + }), content_type='application/json') self.checkResponse(response, 204) @@ -599,16 +599,16 @@ class DataFormatUpdate(DataFormatsAPIBase): self.client.login(username='johndoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': { 'value': 'float64' } - }), content_type='application/json') + json.dumps({ + 'declaration': { 'value': 'float64' } + }), content_type='application/json') self.checkResponse(response, 204) dataformat = DataFormat.objects.get(author__username='johndoe', name='format_private') storage = Storage(settings.PREFIX, - dataformat.fullname()) + dataformat.fullname()) assert storage.exists with open(storage.json.path, 'rt') as f: declaration = json.load(f) self.assertEqual(declaration['value'], 'float64') @@ -624,16 +624,16 @@ class DataFormatUpdate(DataFormatsAPIBase): declaration={ 'value2': 'float64' }, - ) + ) assert dataformat, errors response = self.client.put(self.url, - json.dumps({ - 'declaration': { - '#extends': 'johndoe/format4/1', - 'value': 'float64' - } - }), content_type='application/json') + json.dumps({ + 'declaration': { + '#extends': 'johndoe/format4/1', + 'value': 'float64' + } + }), content_type='application/json') self.checkResponse(response, 204) @@ -644,7 +644,7 @@ class DataFormatUpdate(DataFormatsAPIBase): self.assertEqual(dataformat.referenced_formats.count(), 0) storage = Storage(settings.PREFIX, - dataformat.fullname()) + dataformat.fullname()) assert storage.exists with open(storage.json.path, 'rt') as f: declaration = json.load(f) self.assertEqual(declaration['value'], 'float64') @@ -662,15 +662,15 @@ class DataFormatUpdate(DataFormatsAPIBase): '#extends': 'johndoe/format1/1', 'value2': 'float64' }, - ) + ) assert dataformat, errors response = self.client.put(self.format4_url, - json.dumps({ - 'declaration': { - 'value2': 'float64' - } - }), content_type='application/json') + json.dumps({ + 'declaration': { + 'value2': 'float64' + } + }), content_type='application/json') self.checkResponse(response, 204) @@ -691,16 +691,16 @@ class DataFormatUpdate(DataFormatsAPIBase): '#extends': 'johndoe/format1/1', 'value2': 'float64' }, - ) + ) assert dataformat, errors response = self.client.put(self.format4_url, - json.dumps({ - 'declaration': { - '#extends': 'johndoe/format1/1', - 'value2': 'int32' - } - }), content_type='application/json') + json.dumps({ + 'declaration': { + '#extends': 'johndoe/format1/1', + 'value2': 'int32' + } + }), content_type='application/json') self.checkResponse(response, 204) @@ -721,16 +721,16 @@ class DataFormatUpdate(DataFormatsAPIBase): declaration={ 'value2': 'float64' }, - ) + ) assert dataformat, errors response = self.client.put(self.url, - json.dumps({ - 'declaration': { - 'field1': 'johndoe/format4/1', - 'value': 'float64' - } - }), content_type='application/json') + json.dumps({ + 'declaration': { + 'field1': 'johndoe/format4/1', + 'value': 'float64' + } + }), content_type='application/json') self.checkResponse(response, 204) @@ -741,7 +741,7 @@ class DataFormatUpdate(DataFormatsAPIBase): self.assertEqual(dataformat.referenced_formats.filter(name='format4').count(), 1) storage = Storage(settings.PREFIX, - dataformat.fullname()) + dataformat.fullname()) assert storage.exists with open(storage.json.path, 'rt') as f: declaration = json.load(f) @@ -760,15 +760,15 @@ class DataFormatUpdate(DataFormatsAPIBase): 'value2': 'float64', 'field1': 'johndoe/format1/1', }, - ) + ) assert dataformat, errors response = self.client.put(self.format4_url, - json.dumps({ - 'declaration': { - 'value2': 'float64' - } - }), content_type='application/json') + json.dumps({ + 'declaration': { + 'value2': 'float64' + } + }), content_type='application/json') self.checkResponse(response, 204) @@ -789,16 +789,16 @@ class DataFormatUpdate(DataFormatsAPIBase): 'value2': 'float64', 'field1': 'johndoe/format1/1', }, - ) + ) assert dataformat, errors response = self.client.put(self.format4_url, - json.dumps({ - 'declaration': { - 'value2': 'int32', - 'field1': 'johndoe/format1/1', - } - }), content_type='application/json') + json.dumps({ + 'declaration': { + 'value2': 'int32', + 'field1': 'johndoe/format1/1', + } + }), content_type='application/json') self.checkResponse(response, 204) @@ -821,14 +821,14 @@ class DataFormatRetrieval(DataFormatsAPIBase): author=user, name='format4', short_description='short description 4', - ) + ) assert dataformat, errors (dataformat, errors) = DataFormat.objects.create_dataformat( author=user, name='format5', short_description='short description 5', - ) + ) assert dataformat, errors dataformat.share(users=[User.objects.get(username='johndoe')]) @@ -984,7 +984,7 @@ class DataFormatDeletion(DataFormatsAPIBase): author=user, name='format4', short_description='short description 4', - ) + ) assert dataformat, errors @@ -1057,9 +1057,9 @@ class DataFormatSharingAPI_Failures(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users': ['doejack'], - }), content_type='application/json') + json.dumps({ + 'users': ['doejack'], + }), content_type='application/json') data = self.checkResponse(response, 400, content_type='application/json') self.assertTrue(data is not None) @@ -1070,9 +1070,9 @@ class DataFormatSharingAPI_Failures(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams': ['doejack'], - }), content_type='application/json') + json.dumps({ + 'teams': ['doejack'], + }), content_type='application/json') data = self.checkResponse(response, 400, content_type='application/json') self.assertTrue(data is not None) @@ -1089,9 +1089,9 @@ class NotSharedDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['johndoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['johndoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1108,9 +1108,9 @@ class NotSharedDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams' : ['jackdoe/teamdoe'], - }), content_type='application/json') + json.dumps({ + 'teams' : ['jackdoe/teamdoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1127,9 +1127,9 @@ class NotSharedDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['johndoe', 'janedoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['johndoe', 'janedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1146,9 +1146,9 @@ class NotSharedDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams' : ['jackdoe/teamdoe', 'jackdoe/teamdoe2'], - }), content_type='application/json') + json.dumps({ + 'teams' : ['jackdoe/teamdoe', 'jackdoe/teamdoe2'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1165,8 +1165,8 @@ class NotSharedDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1188,8 +1188,8 @@ class PublicForOneUserDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1205,9 +1205,9 @@ class PublicForOneUserDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['johndoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['johndoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1224,9 +1224,9 @@ class PublicForOneUserDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['janedoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['janedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1243,9 +1243,9 @@ class PublicForOneUserDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams' : ['jackdoe/teamdoe'], - }), content_type='application/json') + json.dumps({ + 'teams' : ['jackdoe/teamdoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1263,9 +1263,9 @@ class PublicForOneUserDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['janedoe', 'jacquelinedoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['janedoe', 'jacquelinedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1282,9 +1282,9 @@ class PublicForOneUserDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams' : ['jackdoe/teamdoe', 'jackdoe/teamdoe2'], - }), content_type='application/json') + json.dumps({ + 'teams' : ['jackdoe/teamdoe', 'jackdoe/teamdoe2'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1309,8 +1309,8 @@ class PublicForOneTeamDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1327,9 +1327,9 @@ class PublicForOneTeamDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['johndoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['johndoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1347,9 +1347,9 @@ class PublicForOneTeamDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['janedoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['janedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1367,9 +1367,9 @@ class PublicForOneTeamDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams' : ['jackdoe/teamdoe2'], - }), content_type='application/json') + json.dumps({ + 'teams' : ['jackdoe/teamdoe2'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1386,9 +1386,9 @@ class PublicForOneTeamDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['janedoe', 'jacquelinedoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['janedoe', 'jacquelinedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1406,9 +1406,9 @@ class PublicForOneTeamDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams' : ['jackdoe/teamdoe2', 'jackdoe/teamdoe3'], - }), content_type='application/json') + json.dumps({ + 'teams' : ['jackdoe/teamdoe2', 'jackdoe/teamdoe3'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1432,8 +1432,8 @@ class PublicForAllDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1449,9 +1449,9 @@ class PublicForAllDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users': ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'users': ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1467,9 +1467,9 @@ class PublicForAllDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams': ['jackdoe/teamdoe'] - }), content_type='application/json') + json.dumps({ + 'teams': ['jackdoe/teamdoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1485,9 +1485,9 @@ class PublicForAllDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users': ['johndoe', 'janedoe'] - }), content_type='application/json') + json.dumps({ + 'users': ['johndoe', 'janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1503,9 +1503,9 @@ class PublicForAllDataFormat_SharingAPI(DataFormatSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams': ['jackdoe/teamdoe', 'jackdoe/teamdoe2'] - }), content_type='application/json') + json.dumps({ + 'teams': ['jackdoe/teamdoe', 'jackdoe/teamdoe2'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1528,8 +1528,8 @@ class NotSharedDataFormat_ExtensionOfNotSharedDataFormat_SharingAPI(DataFormatSh self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1546,9 +1546,9 @@ class NotSharedDataFormat_ExtensionOfNotSharedDataFormat_SharingAPI(DataFormatSh self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['johndoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['johndoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1566,9 +1566,9 @@ class NotSharedDataFormat_ExtensionOfNotSharedDataFormat_SharingAPI(DataFormatSh self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams' : ['jackdoe/teamdoe'], - }), content_type='application/json') + json.dumps({ + 'teams' : ['jackdoe/teamdoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1586,9 +1586,9 @@ class NotSharedDataFormat_ExtensionOfNotSharedDataFormat_SharingAPI(DataFormatSh self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['johndoe', 'janedoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['johndoe', 'janedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1606,9 +1606,9 @@ class NotSharedDataFormat_ExtensionOfNotSharedDataFormat_SharingAPI(DataFormatSh self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams' : ['jackdoe/teamdoe', 'jackdoe/teamdoe2'], - }), content_type='application/json') + json.dumps({ + 'teams' : ['jackdoe/teamdoe', 'jackdoe/teamdoe2'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1633,8 +1633,8 @@ class NotSharedDataFormat_ExtensionOfPublicFormat_SharingAPI(DataFormatSharingAP self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1656,9 +1656,9 @@ class NotSharedDataFormat_ExtensionOfPublicFormat_SharingAPI(DataFormatSharingAP self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['johndoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['johndoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1681,9 +1681,9 @@ class NotSharedDataFormat_ExtensionOfPublicFormat_SharingAPI(DataFormatSharingAP self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams' : ['jackdoe/teamdoe'], - }), content_type='application/json') + json.dumps({ + 'teams' : ['jackdoe/teamdoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1706,9 +1706,9 @@ class NotSharedDataFormat_ExtensionOfPublicFormat_SharingAPI(DataFormatSharingAP self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['johndoe', 'janedoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['johndoe', 'janedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1731,9 +1731,9 @@ class NotSharedDataFormat_ExtensionOfPublicFormat_SharingAPI(DataFormatSharingAP self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams' : ['jackdoe/teamdoe', 'jackdoe/teamdoe2'], - }), content_type='application/json') + json.dumps({ + 'teams' : ['jackdoe/teamdoe', 'jackdoe/teamdoe2'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1763,8 +1763,8 @@ class NotSharedDataFormat_ExtensionOfPublicForOneUserFormat_SharingAPI(DataForma self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') data = self.checkResponse(response, 400, content_type='application/json') @@ -1776,9 +1776,9 @@ class NotSharedDataFormat_ExtensionOfPublicForOneUserFormat_SharingAPI(DataForma self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['jackdoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['jackdoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1802,9 +1802,9 @@ class NotSharedDataFormat_ExtensionOfPublicForOneUserFormat_SharingAPI(DataForma self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['janedoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['janedoe'], + }), content_type='application/json') data = self.checkResponse(response, 400, content_type='application/json') @@ -1816,9 +1816,9 @@ class NotSharedDataFormat_ExtensionOfPublicForOneUserFormat_SharingAPI(DataForma self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams' : ['jackdoe/teamdoe'], - }), content_type='application/json') + json.dumps({ + 'teams' : ['jackdoe/teamdoe'], + }), content_type='application/json') data = self.checkResponse(response, 400, content_type='application/json') @@ -1830,9 +1830,9 @@ class NotSharedDataFormat_ExtensionOfPublicForOneUserFormat_SharingAPI(DataForma self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['janedoe', 'jacquelinedoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['janedoe', 'jacquelinedoe'], + }), content_type='application/json') data = self.checkResponse(response, 400, content_type='application/json') @@ -1844,9 +1844,9 @@ class NotSharedDataFormat_ExtensionOfPublicForOneUserFormat_SharingAPI(DataForma self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'teams' : ['jackdoe/teamdoe', 'jackdoe/teamdoe2'], - }), content_type='application/json') + json.dumps({ + 'teams' : ['jackdoe/teamdoe', 'jackdoe/teamdoe2'], + }), content_type='application/json') data = self.checkResponse(response, 400, content_type='application/json') @@ -1862,9 +1862,9 @@ class NotSharedDataFormat_ExtensionOfPublicForOneUserFormat_SharingAPI(DataForma self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users': ['janedoe'], - }), content_type='application/json') + json.dumps({ + 'users': ['janedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') diff --git a/beat/web/dataformats/views.py b/beat/web/dataformats/views.py index 7f9d8827a..63665106e 100644 --- a/beat/web/dataformats/views.py +++ b/beat/web/dataformats/views.py @@ -62,9 +62,9 @@ def create(request, name=None): # Process the form form = None form_args = dict( - request_user=request.user, - name=name, - ) + request_user=request.user, + name=name, + ) # Retrieves the existing object if possible @@ -73,9 +73,9 @@ def create(request, name=None): if name is not None: try: previous_version = DataFormat.objects.filter( - author=request.user, - name__iexact=name, - ).order_by('-version')[0] + author=request.user, + name__iexact=name, + ).order_by('-version')[0] version = previous_version.version + 1 except: pass @@ -98,14 +98,14 @@ def create(request, name=None): if dataformat is not None: # Redirect to the page of the dataformat just created return HttpResponseRedirect( - reverse('dataformats:view', + reverse('dataformats:view', args=( dataformat.author.username, dataformat.name, dataformat.version, ), ) - ) + ) for error in errors.split('\n'): form.add_error('file', error) @@ -135,7 +135,7 @@ def create(request, name=None): return render_to_response('dataformats/edition.html', { - 'form': form, + 'form': form, 'object': previous_version, 'op': 'new-version' if previous_version else 'new', 'edition': False, @@ -157,8 +157,8 @@ def fork(request, author, name, version): # Process the form form = None form_args = dict( - request_user=request.user, - ) + request_user=request.user, + ) # Retrieves the forked data format @@ -185,14 +185,14 @@ def fork(request, author, name, version): if dataformat is not None: # Redirect to the page of the dataformat just created return HttpResponseRedirect( - reverse('dataformats:view', + reverse('dataformats:view', args=( dataformat.author.username, dataformat.name, dataformat.version, ), ) - ) + ) for error in errors.split('\n'): form.add_error('file', error) @@ -212,7 +212,7 @@ def fork(request, author, name, version): return render_to_response('dataformats/edition.html', { - 'form': form, + 'form': form, 'object': fork_of, 'op': 'fork', }, @@ -266,14 +266,14 @@ def edit(request, author, name, version): else: # Redirect to the page of the dataformat just created return HttpResponseRedirect( - reverse('dataformats:view', + reverse('dataformats:view', args=( dataformat.author.username, dataformat.name, dataformat.version, ), ) - ) + ) # Initialise the form if necessary @@ -304,15 +304,15 @@ def view(request, author, name, version=None): # Retrieves the dataformat if version: dataformat = get_object_or_404( - DataFormat, - author__username__iexact=author, - name__iexact=name, - version=int(version), - ) + DataFormat, + author__username__iexact=author, + name__iexact=name, + version=int(version), + ) else: dataformat = DataFormat.objects.filter( - author__username__iexact=author, - name__iexact=name).order_by('-version') + author__username__iexact=author, + name__iexact=name).order_by('-version') if not dataformat: raise Http404() else: @@ -375,17 +375,17 @@ def ls(request, author_name): # orders dataformats so that the latest information is displayed first objects = DataFormat.objects.from_author_and_public(request.user, - author_name).order_by('-creation_date') + author_name).order_by('-creation_date') objects = DataFormat.filter_latest_versions(objects) return render_to_response('dataformats/list.html', - dict( - objects=objects, - author=author, - owner=(request.user==author), - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=author, + owner=(request.user==author), + ), + context_instance=RequestContext(request), + ) #---------------------------------------------------------- @@ -399,10 +399,10 @@ def public_ls(request): objects = DataFormat.filter_latest_versions(objects) return render_to_response('dataformats/list.html', - dict( - objects=objects, - author=request.user, #anonymous - owner=False, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=request.user, #anonymous + owner=False, + ), + context_instance=RequestContext(request), + ) diff --git a/beat/web/experiments/admin.py b/beat/web/experiments/admin.py index 2e0748df5..e64e65849 100755 --- a/beat/web/experiments/admin.py +++ b/beat/web/experiments/admin.py @@ -44,7 +44,7 @@ from .models import BlockInput as BlockInputModel from .models import validate_experiment from ..ui.forms import CodeMirrorJSONFileField, CodeMirrorRSTFileField, \ - NameField, CodeMirrorJSONCharField + NameField, CodeMirrorJSONCharField from ..common.texts import Messages @@ -54,29 +54,29 @@ from ..common.texts import Messages class ExperimentModelForm(forms.ModelForm): name = NameField( - widget=forms.TextInput(attrs=dict(size=80)), - help_text=Messages['name'], - ) + widget=forms.TextInput(attrs=dict(size=80)), + help_text=Messages['name'], + ) declaration_file = CodeMirrorJSONFileField( - label='Declaration', - help_text=Messages['json'], - ) + label='Declaration', + help_text=Messages['json'], + ) description_file = CodeMirrorRSTFileField( - label='Description', - required=False, - allow_empty_file=True, - help_text=Messages['description'], - ) + label='Description', + required=False, + allow_empty_file=True, + help_text=Messages['description'], + ) class Meta: model = ExperimentModel exclude = [] widgets = { - 'short_description': forms.TextInput( - attrs=dict(size=100), - ), + 'short_description': forms.TextInput( + attrs=dict(size=100), + ), } def clean_declaration_file(self): @@ -95,8 +95,8 @@ class ExperimentModelForm(forms.ModelForm): try: core_experiment, errors = \ - validate_experiment(json.loads(new_declaration), - self.cleaned_data['toolchain'].declaration) + validate_experiment(json.loads(new_declaration), + self.cleaned_data['toolchain'].declaration) except SyntaxError as e: raise forms.ValidationError(str(e)) @@ -121,7 +121,7 @@ class BlockInline(admin.TabularInline): extra = 0 readonly_fields = ['execution_order', 'link', 'algorithm', 'analyzer', - 'status'] + 'status'] ordering = ['execution_order'] fields = readonly_fields @@ -177,14 +177,14 @@ class Experiment(admin.ModelAdmin): 'referenced_datasets', 'referenced_algorithms', 'short_description', - ) + ) list_display_links = ('id', ) actions = [ rehash_experiment, reset_experiment, cancel_experiment, - ] + ] form = ExperimentModelForm @@ -194,45 +194,45 @@ class Experiment(admin.ModelAdmin): ] inlines = [ - BlockInline, - ] + BlockInline, + ] fieldsets = ( (None, - dict( - fields=('name', 'author', 'toolchain'), - ), + dict( + fields=('name', 'author', 'toolchain'), + ), ), ('Status and dates', - dict( - classes=('collapse',), - fields=('start_date', 'end_date', 'status'), - ), + dict( + classes=('collapse',), + fields=('start_date', 'end_date', 'status'), + ), ), ('Documentation', - dict( - classes=('collapse',), - fields=('short_description', 'description_file',), - ), + dict( + classes=('collapse',), + fields=('short_description', 'description_file',), + ), ), ('References (read-only)', - dict( - classes=('collapse',), - fields=('referenced_datasets', 'referenced_algorithms',), - ), + dict( + classes=('collapse',), + fields=('referenced_datasets', 'referenced_algorithms',), + ), ), ('Sharing', - dict( - classes=('collapse',), - fields=('sharing', 'shared_with', 'shared_with_team'), - ), + dict( + classes=('collapse',), + fields=('sharing', 'shared_with', 'shared_with_team'), + ), ), ('Source code', - dict( - fields=('hash', 'declaration_file'), - ), + dict( + fields=('hash', 'declaration_file'), + ), ), - ) + ) admin.site.register(ExperimentModel, Experiment) @@ -252,12 +252,12 @@ class BlockInputInline(admin.TabularInline): def input(self, obj): if obj.database: url = reverse('admin:databases_databaseset_change', - args=(obj.database.set.pk,)) + args=(obj.database.set.pk,)) text = '%s (%s)' % (obj.database, obj.database.hash) what = 'Dataset Output' else: url = reverse('admin:experiments_cachedfile_change', - args=(obj.cache.pk,)) + args=(obj.cache.pk,)) text = obj.cache.hash what = 'Cached File' return mark_safe('%s: <a href="%s">%s</a>' % (what, url, text)) @@ -301,7 +301,7 @@ class BlockDependentsInline(admin.TabularInline): extra = 0 readonly_fields = ['order', 'name', 'algorithm', 'analyzer', - 'status'] + 'status'] ordering = ['id'] fields = readonly_fields @@ -370,7 +370,7 @@ class BlockModelForm(forms.ModelForm): command = CodeMirrorJSONCharField( help_text=Messages['json'], readonly=True, - ) + ) class Meta: model = BlockModel @@ -410,11 +410,11 @@ class Block(admin.ModelAdmin): list_display_links = ('id', 'name') inlines = [ - BlockDependenciesInline, - BlockInputInline, - CachedFileInline, - BlockDependentsInline, - ] + BlockDependenciesInline, + BlockInputInline, + CachedFileInline, + BlockDependentsInline, + ] exclude = ['dependencies'] @@ -458,34 +458,34 @@ class Block(admin.ModelAdmin): fieldsets = ( (None, - dict( - fields=('id', 'name', 'experiment'), - ), + dict( + fields=('id', 'name', 'experiment'), + ), ), ('Status and dates', - dict( - fields=('creation_date', 'start_date', 'end_date', 'status'), - ), + dict( + fields=('creation_date', 'start_date', 'end_date', 'status'), + ), ), ('Code', - dict( - classes=('collapse',), - fields=('algorithm', 'analyzer',), - ), + dict( + classes=('collapse',), + fields=('algorithm', 'analyzer',), + ), ), ('Backend', - dict( - classes=('collapse',), - fields=('environment', 'queue', 'required_slots', 'channel'), - ), + dict( + classes=('collapse',), + fields=('environment', 'queue', 'required_slots', 'channel'), + ), ), ('Command', - dict( - classes=('collapse',), - fields=('command',), - ), + dict( + classes=('collapse',), + fields=('command',), + ), ), - ) + ) admin.site.register(BlockModel, Block) @@ -506,7 +506,7 @@ class Result(admin.ModelAdmin): def get_readonly_fields(self, request, obj=None): return list(self.readonly_fields) + \ - [field.name for field in obj._meta.fields] + [field.name for field in obj._meta.fields] def has_delete_permission(self, request, obj=None): return False @@ -556,11 +556,11 @@ class CachedFile(admin.ModelAdmin): retval = '<ul>' for block in obj.blocks.all(): retval += format_html("<li><a href='{block_url}'>{block_name}</a> @ <a href='{experiment_url}'>{experiment_name}</a> ({block_status})</li>", - experiment_url=reverse('admin:experiments_experiment_change', args=(block.experiment.id,)), - experiment_name=block.experiment.fullname(), - block_url=reverse('admin:experiments_block_change', args=(block.id,)), - block_name=block.name, - block_status=block.get_status_display(), + experiment_url=reverse('admin:experiments_experiment_change', args=(block.experiment.id,)), + experiment_name=block.experiment.fullname(), + block_url=reverse('admin:experiments_block_change', args=(block.id,)), + block_name=block.name, + block_status=block.get_status_display(), ) return retval + '</ul>' @@ -570,41 +570,41 @@ class CachedFile(admin.ModelAdmin): fieldsets = ( (None, - dict( - fields=('hash', 'status', 'blocks',) - ), + dict( + fields=('hash', 'status', 'blocks',) + ), ), ('Logging', - dict( - fields=('error_report', 'stderr', 'stdout'), - ), + dict( + fields=('error_report', 'stderr', 'stdout'), + ), ), ('Performance', - dict( - classes=('collapse',), - fields=( - 'linear_execution_time', - 'speed_up_real', - 'speed_up_maximal', - 'cpu_time', - 'max_memory', - 'queuing_time', - 'data_read_time', - 'data_read_size', - 'data_read_nb_blocks', - 'data_written_time', - 'data_written_size', - 'data_written_nb_blocks', - ), - ), + dict( + classes=('collapse',), + fields=( + 'linear_execution_time', + 'speed_up_real', + 'speed_up_maximal', + 'cpu_time', + 'max_memory', + 'queuing_time', + 'data_read_time', + 'data_read_size', + 'data_read_nb_blocks', + 'data_written_time', + 'data_written_size', + 'data_written_nb_blocks', + ), + ), ), - ) + ) readonly_fields = ['blocks'] def get_readonly_fields(self, request, obj=None): return list(self.readonly_fields) + \ - [field.name for field in obj._meta.fields] + [field.name for field in obj._meta.fields] def has_delete_permission(self, request, obj=None): return False diff --git a/beat/web/experiments/api.py b/beat/web/experiments/api.py index 39a322cc1..4ddefc9df 100755 --- a/beat/web/experiments/api.py +++ b/beat/web/experiments/api.py @@ -219,7 +219,7 @@ class ListCreateExperimentsView(ListCreateContributionView): # Retrieve the toolchain core_toolchain = beat.core.toolchain.Storage(settings.PREFIX, - data['toolchain']) + data['toolchain']) if core_toolchain.version == 'unknown': return BadRequestResponse('Unknown toolchain version') @@ -229,10 +229,10 @@ class ListCreateExperimentsView(ListCreateContributionView): try: db_toolchain = Toolchain.objects.for_user(request.user, True).get( - author__username=core_toolchain.username, - name=core_toolchain.name, - version=core_toolchain.version, - ) + author__username=core_toolchain.username, + name=core_toolchain.name, + version=core_toolchain.version, + ) except Toolchain.DoesNotExist: return Response('Toolchain %s not found' % data['toolchain'], status=404) @@ -254,7 +254,7 @@ class ListCreateExperimentsView(ListCreateContributionView): short_description=short_description, description=description, declaration=declaration, - ) + ) if not experiment: return BadRequestResponse(errors) @@ -434,10 +434,10 @@ class RetrieveUpdateDestroyExperimentView(RetrieveUpdateDestroyContributionView) try: db_toolchain = Toolchain.objects.get( - author__username=core_toolchain.username, - name=core_toolchain.name, - version=core_toolchain.version, - ) + author__username=core_toolchain.username, + name=core_toolchain.name, + version=core_toolchain.version, + ) except Toolchain.DoesNotExist: return Response('Toolchain %s not found' % toolchain_name, status=404) else: @@ -538,11 +538,11 @@ class StartExperimentView(APIView): # Retrieve the experiment experiment = get_object_or_404(Experiment.objects.for_user(request.user, True), - author__username=author_name, - toolchain__author__username=toolchain_author_name, - toolchain__name=toolchain_name, - toolchain__version=version, - name=name + author__username=author_name, + toolchain__author__username=toolchain_author_name, + toolchain__name=toolchain_name, + toolchain__version=version, + name=name ) self.check_object_permissions(request, experiment) @@ -576,11 +576,11 @@ class CancelExperimentView(APIView): # Retrieve the experiment experiment = get_object_or_404(Experiment, - author__username=author_name, - toolchain__author__username=toolchain_author_name, - toolchain__name=toolchain_name, - toolchain__version=version, - name=name + author__username=author_name, + toolchain__author__username=toolchain_author_name, + toolchain__name=toolchain_name, + toolchain__version=version, + name=name ) experiment.cancel() diff --git a/beat/web/experiments/management/commands/cleanup_orphaned_caches.py b/beat/web/experiments/management/commands/cleanup_orphaned_caches.py index b52977cf8..8e02872ca 100644 --- a/beat/web/experiments/management/commands/cleanup_orphaned_caches.py +++ b/beat/web/experiments/management/commands/cleanup_orphaned_caches.py @@ -42,8 +42,8 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--delete', action='store_true', dest='delete', - default=False, help='Really deletes the CachedFiles - ' \ - 'otherwise only displays what would be deleted') + default=False, help='Really deletes the CachedFiles - ' \ + 'otherwise only displays what would be deleted') def handle(self, *ignored, **arguments): diff --git a/beat/web/experiments/migrations/0002_scheduler_addons.py b/beat/web/experiments/migrations/0002_scheduler_addons.py index a1f462385..4de8bcbf5 100644 --- a/beat/web/experiments/migrations/0002_scheduler_addons.py +++ b/beat/web/experiments/migrations/0002_scheduler_addons.py @@ -55,7 +55,7 @@ class Migration(migrations.Migration): model_name='result', name='cache', field=models.ForeignKey(related_name='results', - to='experiments.CachedFile', null=True), + to='experiments.CachedFile', null=True), ), migrations.RunPython(move_result_to_cache), ] diff --git a/beat/web/experiments/migrations/0003_scheduler_addons_2.py b/beat/web/experiments/migrations/0003_scheduler_addons_2.py index 3d72f2965..ac59b9bec 100644 --- a/beat/web/experiments/migrations/0003_scheduler_addons_2.py +++ b/beat/web/experiments/migrations/0003_scheduler_addons_2.py @@ -38,11 +38,11 @@ def dedup_resuls(apps, schema_editor): for i, r in enumerate(Result.objects.order_by('-id')): older = Result.objects.filter(name=r.name, id__lt=r.id, - cache=r.block.hashes.first()) + cache=r.block.hashes.first()) if older: print("Cache %s already contains Result `%s' - keeping " \ - "newest (out of %d)..." % (r.block.hashes.first().hash, r.name, - older.count()+1)) + "newest (out of %d)..." % (r.block.hashes.first().hash, r.name, + older.count()+1)) older.delete() @@ -55,4 +55,4 @@ class Migration(migrations.Migration): operations = [ migrations.RunPython(dedup_resuls), - ] + ] diff --git a/beat/web/experiments/migrations/0004_scheduler_addons_3.py b/beat/web/experiments/migrations/0004_scheduler_addons_3.py index 3b41d1496..ec55934f8 100644 --- a/beat/web/experiments/migrations/0004_scheduler_addons_3.py +++ b/beat/web/experiments/migrations/0004_scheduler_addons_3.py @@ -51,24 +51,24 @@ class Migration(migrations.Migration): name='BlockInput', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, - auto_created=True, primary_key=True)), + auto_created=True, primary_key=True)), ('channel', models.CharField(default=b'', - help_text=b'Synchronization channel within the toolchain', - max_length=200, blank=True)), + help_text=b'Synchronization channel within the toolchain', + max_length=200, blank=True)), ('block', models.ForeignKey(related_name='inputs', - to='experiments.Block', null=True)), + to='experiments.Block', null=True)), ('cache', models.ForeignKey(related_name='inputs', - to='experiments.CachedFile', null=True)), + to='experiments.CachedFile', null=True)), ('database', models.ForeignKey(related_name='blocks', - to='databases.DatabaseSetOutput', null=True)), + to='databases.DatabaseSetOutput', null=True)), ], ), migrations.AddField( model_name='block', name='channel', field=models.CharField(default=b'', - help_text=b'Synchronization channel within the toolchain', - max_length=200, blank=True), + help_text=b'Synchronization channel within the toolchain', + max_length=200, blank=True), ), migrations.AddField( model_name='block', @@ -79,21 +79,21 @@ class Migration(migrations.Migration): model_name='block', name='dependencies', field=models.ManyToManyField(related_name='dependents', - to='experiments.Block', blank=True), + to='experiments.Block', blank=True), ), migrations.AlterField( model_name='block', name='environment', field=models.ForeignKey(related_name='blocks', - on_delete=models.deletion.SET_NULL, to='backend.Environment', - null=True), + on_delete=models.deletion.SET_NULL, to='backend.Environment', + null=True), ), migrations.AddField( model_name='block', name='queue', field=models.ForeignKey(related_name='blocks', - on_delete=models.deletion.SET_NULL, to='backend.Queue', - null=True), + on_delete=models.deletion.SET_NULL, to='backend.Queue', + null=True), ), migrations.AddField( model_name='block', @@ -104,15 +104,15 @@ class Migration(migrations.Migration): model_name='block', name='status', field=models.CharField(default=b'N', max_length=1, - choices=[ - (b'N', b'Not cached'), - (b'P', b'Processing'), - (b'C', b'Cached'), - (b'F', b'Failed'), - (b'S', b'Skipped'), - (b'L', b'Cancelled'), - ] - ), + choices=[ + (b'N', b'Not cached'), + (b'P', b'Processing'), + (b'C', b'Cached'), + (b'F', b'Failed'), + (b'S', b'Skipped'), + (b'L', b'Cancelled'), + ] + ), ), migrations.AlterUniqueTogether( name='block', @@ -122,6 +122,6 @@ class Migration(migrations.Migration): model_name='cachedfile', name='blocks', field=models.ManyToManyField(related_name='outputs', - to='experiments.Block', blank=True), + to='experiments.Block', blank=True), ), ] diff --git a/beat/web/experiments/migrations/0005_scheduler_addons_4.py b/beat/web/experiments/migrations/0005_scheduler_addons_4.py index 5479d104f..37961769a 100644 --- a/beat/web/experiments/migrations/0005_scheduler_addons_4.py +++ b/beat/web/experiments/migrations/0005_scheduler_addons_4.py @@ -58,18 +58,18 @@ def reset_blocks(apps, schema_editor): e.toolchain.name, e.toolchain.version, e.name, - ) + ) print("Updating blocks for experiment %d/%d (%s, id=%d)..." % \ - (i+1, total, fullname, e.id)) + (i+1, total, fullname, e.id)) xp_decl = simplejson.loads(storage.get_file_content(e, - 'declaration_file')) + 'declaration_file')) tc_decl = simplejson.loads(storage.get_file_content(e.toolchain, - 'declaration_file')) + 'declaration_file')) xp = beat.core.experiment.Experiment(settings.PREFIX, (xp_decl, - tc_decl)) + tc_decl)) if xp.errors: message = "The experiment `%s' isn't valid (skipping " \ @@ -87,12 +87,12 @@ def reset_blocks(apps, schema_editor): env = Environment.objects.filter( name=job_description['environment']['name'], version=job_description['environment']['version'], - ) + ) if not env: print("Cannot find environment `%s (%s)' - not setting" % \ - (job_description['environment']['name'], - job_description['environment']['version'])) + (job_description['environment']['name'], + job_description['environment']['version'])) env = None else: env = env[0] @@ -112,20 +112,20 @@ def reset_blocks(apps, schema_editor): author__username=parts[0], name=parts[1], version=parts[2], - ) + ) # Ties the block in slots = job_description.get('nb_slots') try: b, _ = Block.objects.get_or_create(experiment=e, - name=block_name, algorithm=algorithm) + name=block_name, algorithm=algorithm) except utils.IntegrityError as exc: print("Block `%s' for experiment `%s' already exists - " \ - "modifying entry for migration purposes. This " \ - "issue is due a misconnection on the toolchain level " \ - "(known case: tpereira/full_isv/2)" % \ - (block_name, fullname)) + "modifying entry for migration purposes. This " \ + "issue is due a misconnection on the toolchain level " \ + "(known case: tpereira/full_isv/2)" % \ + (block_name, fullname)) b = Block.objects.get(experiment=e, name=block_name) b.command=simplejson.dumps(job_description, indent=4) @@ -140,23 +140,23 @@ def reset_blocks(apps, schema_editor): # from this point: requires block to have an assigned id b.dependencies.add(*[e.blocks.get(name=k) \ - for k in description['dependencies']]) + for k in description['dependencies']]) # reset inputs and outputs - creates if necessary only for v in job_description['inputs'].values(): if 'database' in v: #database input db = DatabaseSetOutput.objects.get(hash=v['hash']) BlockInput.objects.get_or_create(block=b, - channel=v['channel'], database=db) + channel=v['channel'], database=db) else: cache = CachedFile.objects.get(hash=v['hash']) BlockInput.objects.get_or_create(block=b, - channel=v['channel'], cache=cache) + channel=v['channel'], cache=cache) current = list(b.outputs.all()) b.outputs.clear() #dissociates all current outputs outputs = job_description.get('outputs', - {'': job_description.get('result')}) + {'': job_description.get('result')}) for v in outputs.values(): cache, cr = CachedFile.objects.get_or_create(hash=v['hash']) if cr: @@ -184,12 +184,12 @@ def reset_blocks(apps, schema_editor): r.cache = cache r.save() print("CachedFile data `%s' MOVED from `%s'" % \ - (cache.hash, current[0].hash)) + (cache.hash, current[0].hash)) else: print("CachedFile (hash=%s) CREATED for block `%s' " \ - "of experiment `%s' which is in state `%s'" % \ - (cache.hash, block_name, fullname, - b.get_status_display())) + "of experiment `%s' which is in state `%s'" % \ + (cache.hash, block_name, fullname, + b.get_status_display())) cache.blocks.add(b) #asserts all blocks (except analysis blocks have dependents) diff --git a/beat/web/experiments/migrations/0006_block_order.py b/beat/web/experiments/migrations/0006_block_order.py index 4f83b5d17..3e91f10c0 100755 --- a/beat/web/experiments/migrations/0006_block_order.py +++ b/beat/web/experiments/migrations/0006_block_order.py @@ -50,18 +50,18 @@ def set_block_order(apps, schema_editor): e.toolchain.name, e.toolchain.version, e.name, - ) + ) print("Updating blocks for experiment %d/%d (%s, id=%d)..." % \ - (i+1, total, fullname, e.id)) + (i+1, total, fullname, e.id)) xp_decl = simplejson.loads(storage.get_file_content(e, - 'declaration_file')) + 'declaration_file')) tc_decl = simplejson.loads(storage.get_file_content(e.toolchain, - 'declaration_file')) + 'declaration_file')) xp = beat.core.experiment.Experiment(settings.PREFIX, (xp_decl, - tc_decl)) + tc_decl)) if xp.errors: message = "The experiment `%s' isn't valid (skipping " \ diff --git a/beat/web/experiments/migrations/0007_cachedfile_status.py b/beat/web/experiments/migrations/0007_cachedfile_status.py index 00522a805..fc0ccd710 100755 --- a/beat/web/experiments/migrations/0007_cachedfile_status.py +++ b/beat/web/experiments/migrations/0007_cachedfile_status.py @@ -43,15 +43,15 @@ def set_status(apps, schema_editor): for i, c in enumerate(CachedFile.objects.order_by('id')): print("Updating cached file %d/%d (%s, id=%d)..." % \ - (i+1, total, c.hash, c.id)) + (i+1, total, c.hash, c.id)) abs_path = os.path.join(settings.CACHE_ROOT, beat.core.hash.toPath(c.hash, suffix='')) data_files = sorted(glob.glob(abs_path + '*.index')) + \ - sorted(glob.glob(abs_path + '*.data')) + sorted(glob.glob(abs_path + '*.data')) checksum_files = sorted(glob.glob(abs_path + '*.index.checksum')) + \ - sorted(glob.glob(abs_path + '*.data.checksum')) + sorted(glob.glob(abs_path + '*.data.checksum')) if len(data_files) == 0: continue diff --git a/beat/web/experiments/models/block.py b/beat/web/experiments/models/block.py index adb363bbb..f7e4fd3e6 100755 --- a/beat/web/experiments/models/block.py +++ b/beat/web/experiments/models/block.py @@ -52,8 +52,8 @@ from datetime import datetime class BlockManager(models.Manager): def get_by_natural_key(self, name, experiment_author, - toolchain_author, toolchain_name, - toolchain_version, experiment_name): + toolchain_author, toolchain_name, + toolchain_version, experiment_name): return self.get( name=name, experiment__author__username=experiment_author, @@ -61,7 +61,7 @@ class BlockManager(models.Manager): experiment__toolchain__name=toolchain_name, experiment__toolchain__version=toolchain_version, experiment__name=experiment_name, - ) + ) #---------------------------------------------------------- @@ -102,7 +102,7 @@ class Block(models.Model): required_slots = models.PositiveIntegerField(default=1) channel = models.CharField(max_length=200, default='', blank=True, - help_text="Synchronization channel within the toolchain") + help_text="Synchronization channel within the toolchain") # relationship to blocks to which this block depends on dependencies = models.ManyToManyField('self', diff --git a/beat/web/experiments/models/block_input.py b/beat/web/experiments/models/block_input.py index 958512c15..89153f826 100755 --- a/beat/web/experiments/models/block_input.py +++ b/beat/web/experiments/models/block_input.py @@ -42,8 +42,8 @@ class BlockInputManager(models.Manager): toolchain_name, toolchain_version, experiment_name, cache_hash, database_hash): block = Block.objects.get_by_natural_key(name, experiment_author, - toolchain_author, toolchain_name, toolchain_version, - experiment_name) + toolchain_author, toolchain_name, toolchain_version, + experiment_name) if cache_hash: return self.get(cache__hash=cache_hash, block=block) diff --git a/beat/web/experiments/models/cached_file.py b/beat/web/experiments/models/cached_file.py index 6c8e2b5aa..856407bfd 100755 --- a/beat/web/experiments/models/cached_file.py +++ b/beat/web/experiments/models/cached_file.py @@ -100,8 +100,8 @@ class CachedFile(models.Model): def __str__(self): return 'CachedFile(%s, %s, %d blocks)' % ( - self.hash, self.get_status_display(), self.blocks.count() - ) + self.hash, self.get_status_display(), self.blocks.count() + ) def natural_key(self): @@ -154,10 +154,10 @@ class CachedFile(models.Model): abs_path = self.absolute_path(cache) data_files = sorted(glob.glob(abs_path + '*.index')) + \ - sorted(glob.glob(abs_path + '*.data')) + sorted(glob.glob(abs_path + '*.data')) checksum_files = sorted(glob.glob(abs_path + '*.index.checksum')) + \ - sorted(glob.glob(abs_path + '*.data.checksum')) + sorted(glob.glob(abs_path + '*.data.checksum')) if len(data_files) != len(checksum_files): logger.warn("Number of files (%d) is different from checksums (%d) " \ diff --git a/beat/web/experiments/models/experiment.py b/beat/web/experiments/models/experiment.py index 029e3fbaa..85ad7621f 100755 --- a/beat/web/experiments/models/experiment.py +++ b/beat/web/experiments/models/experiment.py @@ -88,8 +88,8 @@ def validate_environments(experiment, user=None): def _valid_combination(queue, environment): return bool(Queue.objects.filter(name=queue, - environments__name=environment['name'], - environments__version=environment['version'] + environments__name=environment['name'], + environments__version=environment['version'] )) errors = [] @@ -127,7 +127,7 @@ def validate_experiment(experiment_info, toolchain_info, user=None): """Makes sure the experiment can be run""" xp = beat.core.experiment.Experiment(settings.PREFIX, - (experiment_info, toolchain_info)) + (experiment_info, toolchain_info)) if not xp.valid: return xp, xp.errors @@ -149,14 +149,14 @@ class DeclarationStorage(OverwriteStorage): class ExperimentManager(ContributionManager): def get_by_natural_key(self, author_username, toolchain_username, - toolchain_name, toolchain_version, name): + toolchain_name, toolchain_version, name): return self.get( - author__username=author_username, - toolchain__author__username=toolchain_username, - toolchain__name=toolchain_name, - toolchain__version=toolchain_version, - name=name - ) + author__username=author_username, + toolchain__author__username=toolchain_username, + toolchain__name=toolchain_name, + toolchain__version=toolchain_version, + name=name + ) def from_author(self, user, author_name, add_public=False): @@ -221,7 +221,7 @@ class Experiment(Shareable): CANCELLING = 'C' STATUS = ( - (PENDING, 'Pending'), + (PENDING, 'Pending'), (SCHEDULED, 'Scheduled'), (RUNNING, 'Running'), (DONE, 'Done'), @@ -244,20 +244,20 @@ class Experiment(Shareable): end_date = models.DateTimeField(null=True, blank=True) declaration_file = models.FileField( - storage=DeclarationStorage(), - upload_to=get_contribution_declaration_filename, - blank=True, null=True, - max_length=300, - db_column='declaration' - ) + storage=DeclarationStorage(), + upload_to=get_contribution_declaration_filename, + blank=True, null=True, + max_length=300, + db_column='declaration' + ) description_file = models.FileField( - storage=DeclarationStorage(), - upload_to=get_contribution_description_filename, - blank=True, null=True, - max_length=300, - db_column='description' - ) + storage=DeclarationStorage(), + upload_to=get_contribution_description_filename, + blank=True, null=True, + max_length=300, + db_column='description' + ) # read-only parameters that are updated at every save(), if required @@ -280,7 +280,7 @@ class Experiment(Shareable): def natural_key(self): return (self.author.username,) + \ - self.toolchain.natural_key() + (self.name,) + self.toolchain.natural_key() + (self.name,) #_____ Methods __________ @@ -294,10 +294,10 @@ class Experiment(Shareable): storage""" return os.path.join( - beat.core.hash.toUserPath(self.author.username), - self.toolchain.fullname(), - self.name + extension, - ) + beat.core.hash.toUserPath(self.author.username), + self.toolchain.fullname(), + self.name + extension, + ) def declaration_filename(self): @@ -404,7 +404,7 @@ class Experiment(Shareable): xp, errors = validate_experiment(declaration, self.toolchain.declaration, self.author) if errors: message = "The experiment isn't valid, due to the " \ - "following errors:\n * %s" + "following errors:\n * %s" raise SyntaxError(message % '\n * '.join(errors)) self.hash = content_hash @@ -441,22 +441,22 @@ class Experiment(Shareable): for dataset_declaration in xp.datasets.values(): try: (db_name, db_version) = \ - dataset_declaration['database'].name.split('/') + dataset_declaration['database'].name.split('/') dataset = DatabaseSet.objects.get( - protocol__database__name=db_name, - protocol__database__version=db_version, - protocol__name=dataset_declaration['protocol'], - name=dataset_declaration['set'], - ) + protocol__database__name=db_name, + protocol__database__version=db_version, + protocol__name=dataset_declaration['protocol'], + name=dataset_declaration['set'], + ) except: if new_experiment: self.delete() raise SyntaxError("The dataset '%s.%s.%s' can't be found" \ - % ( - dataset_declaration['database'].name, - dataset_declaration['protocol'], - dataset_declaration['set'], - ) - ) + % ( + dataset_declaration['database'].name, + dataset_declaration['protocol'], + dataset_declaration['set'], + ) + ) self.referenced_datasets.add(dataset) @@ -475,7 +475,7 @@ class Experiment(Shareable): if new_experiment: self.delete() raise SyntaxError("The algorithm '%s' can't be found" % \ - algorithm.fullname()) + algorithm.fullname()) self.referenced_algorithms.add(algorithm_db) @@ -503,8 +503,8 @@ class Experiment(Shareable): except Exception: import traceback logger.warn("Could not send e-mail to `%s' about " \ - "`%s'. Exception caught: %s", user_email_list, - self, traceback.format_exc()) + "`%s'. Exception caught: %s", user_email_list, + self, traceback.format_exc()) def share(self, users=None, teams=None, algorithms_infos={}): @@ -529,12 +529,12 @@ class Experiment(Shareable): env = Environment.objects.filter( name=job_description['environment']['name'], version=job_description['environment']['version'], - ) + ) if not env: logger.warn("Cannot find environment `%s (%s)' - not setting", - job_description['environment']['name'], - job_description['environment']['version']) + job_description['environment']['name'], + job_description['environment']['version']) env = None else: env = env[0] @@ -542,14 +542,14 @@ class Experiment(Shareable): # Search for queue that contains a specific environment if env: queue = Queue.objects.filter(name=job_description['queue'], - environments__in=[env]) + environments__in=[env]) else: queue = Queue.objects.filter(name=queue) if not queue: env_name = env.fullname() if env else 'NULL' logger.warn("Cannot find queue `%s' which contains " \ - "environment `%s' - not setting", - job_description['queue'], env_name) + "environment `%s' - not setting", + job_description['queue'], env_name) queue = None else: queue = queue[0] @@ -559,7 +559,7 @@ class Experiment(Shareable): author__username=parts[0], name=parts[1], version=parts[2], - ) + ) # Ties the block in b = Block.objects.filter(experiment=self, name=block_name).first() @@ -581,7 +581,7 @@ class Experiment(Shareable): # from this point: requires block to have an assigned id b.dependencies.clear() b.dependencies.add(*[self.blocks.get(name=k) \ - for k in description['dependencies']]) + for k in description['dependencies']]) # reset inputs - creates if necessary only b.inputs.clear() @@ -589,11 +589,11 @@ class Experiment(Shareable): if 'database' in v: #database input db = DatabaseSetOutput.objects.get(hash=v['hash']) BlockInput.objects.get_or_create(block=b, - channel=v['channel'], database=db) + channel=v['channel'], database=db) else: cache = CachedFile.objects.get(hash=v['hash']) BlockInput.objects.get_or_create(block=b, - channel=v['channel'], cache=cache) + channel=v['channel'], cache=cache) # reset outputs - creates if necessary only b.outputs.clear() @@ -640,41 +640,41 @@ class Experiment(Shareable): def get_absolute_url(self): return reverse( - 'experiments:view', + 'experiments:view', args=( self.author.username, self.toolchain.author.username, self.toolchain.name, self.toolchain.version, self.name, - ), - ) + ), + ) def get_api_share_url(self): return reverse( - 'api_experiments:share', + 'api_experiments:share', args=( self.author.username, self.toolchain.author.username, self.toolchain.name, self.toolchain.version, self.name, - ), - ) + ), + ) def get_api_update_url(self): return reverse( - 'api_experiments:object', + 'api_experiments:object', args=( self.author.username, self.toolchain.author.username, self.toolchain.name, self.toolchain.version, self.name, - ), - ) + ), + ) def get_admin_change_url(self): @@ -717,7 +717,7 @@ class Experiment(Shareable): status=Block.PENDING, start_date=None, end_date=None, - ) + ) self.start_date = None self.end_date = None @@ -787,6 +787,6 @@ class Experiment(Shareable): author = username or self.author name = name or self.name xp, _, __ = Experiment.objects.create_experiment(author, - self.toolchain, name, self.get_declaration(), - self.short_description, self.description) + self.toolchain, name, self.get_declaration(), + self.short_description, self.description) return xp diff --git a/beat/web/experiments/models/result.py b/beat/web/experiments/models/result.py index f274ee50c..d85afa67c 100755 --- a/beat/web/experiments/models/result.py +++ b/beat/web/experiments/models/result.py @@ -72,7 +72,7 @@ class Result(models.Model): return ( self.name, self.cache.hash, - ) + ) def value(self): diff --git a/beat/web/experiments/serializers.py b/beat/web/experiments/serializers.py index 8f2b3c950..c9fde18c0 100755 --- a/beat/web/experiments/serializers.py +++ b/beat/web/experiments/serializers.py @@ -60,13 +60,13 @@ class ExperimentSerializer(ShareableSerializer): class Meta: model = Experiment default_fields = ShareableSerializer.Meta.default_fields + ['name', 'toolchain', - 'datasets', 'short_description', - 'creation_date', 'start_date', 'end_date', - 'duration', 'status', - 'accessibility', - 'attestation_number', 'attestation_locked', - 'cpu_time', 'data_read', 'data_written', - 'is_owner'] + 'datasets', 'short_description', + 'creation_date', 'start_date', 'end_date', + 'duration', 'status', + 'accessibility', + 'attestation_number', 'attestation_locked', + 'cpu_time', 'data_read', 'data_written', + 'is_owner'] def __init__(self, *args, **kwargs): diff --git a/beat/web/experiments/templatetags/experiment_tags.py b/beat/web/experiments/templatetags/experiment_tags.py index 23444f352..bbeb6986d 100755 --- a/beat/web/experiments/templatetags/experiment_tags.py +++ b/beat/web/experiments/templatetags/experiment_tags.py @@ -47,11 +47,11 @@ register = template.Library() @register.inclusion_tag('experiments/panels/table.html', takes_context=True) def experiment_table(context, objects, owner, id): return dict( - request=context['request'], - objects=objects, - owner=owner, - panel_id=id, - ) + request=context['request'], + objects=objects, + owner=owner, + panel_id=id, + ) #-------------------------------------------------- @@ -60,9 +60,9 @@ def experiment_table(context, objects, owner, id): @register.inclusion_tag('experiments/panels/breadcrumb.html', takes_context=True) def experiment_breadcrumb(context, obj): return dict( - request=context['request'], - object=obj, - ) + request=context['request'], + object=obj, + ) #-------------------------------------------------- @@ -71,28 +71,28 @@ def experiment_breadcrumb(context, obj): @register.inclusion_tag('experiments/panels/filter_script.html') def filter_script(panel_id, text_filter_id, attestation_filter_id, privacy_filter_id, status_filter_id): return dict( - panel_id=panel_id, - text_filter_id=text_filter_id, - attestation_filter_id=attestation_filter_id, - privacy_filter_id=privacy_filter_id, - status_filter_id=status_filter_id, - ) + panel_id=panel_id, + text_filter_id=text_filter_id, + attestation_filter_id=attestation_filter_id, + privacy_filter_id=privacy_filter_id, + status_filter_id=status_filter_id, + ) #-------------------------------------------------- @register.inclusion_tag('experiments/panels/report_script.html', - takes_context=True) + takes_context=True) def report_script(context, panel_id, master_checkbox_id, checkbox_class, - form_id): + form_id): return dict( - request=context['request'], - panel_id=panel_id, - master_checkbox_id=master_checkbox_id, - checkbox_class=checkbox_class, - form_id=form_id, - ) + request=context['request'], + panel_id=panel_id, + master_checkbox_id=master_checkbox_id, + checkbox_class=checkbox_class, + form_id=form_id, + ) #-------------------------------------------------- @@ -101,9 +101,9 @@ def report_script(context, panel_id, master_checkbox_id, checkbox_class, @register.inclusion_tag('experiments/panels/execution_infos.html') def experiment_execution_infos(id): return dict( - panel_id=id, - URL_PREFIX=settings.URL_PREFIX, - ) + panel_id=id, + URL_PREFIX=settings.URL_PREFIX, + ) #-------------------------------------------------- @@ -112,9 +112,9 @@ def experiment_execution_infos(id): @register.inclusion_tag('experiments/dialogs/algorithm_mapping.html') def algorithm_mapping(id): return dict( - dialog_id=id, - URL_PREFIX=settings.URL_PREFIX, - ) + dialog_id=id, + URL_PREFIX=settings.URL_PREFIX, + ) #-------------------------------------------------- @@ -137,10 +137,10 @@ def experiment_actions(context, object, display_count): ''' return dict( - request=context['request'], - object=object, - display_count=display_count, - ) + request=context['request'], + object=object, + display_count=display_count, + ) @register.inclusion_tag('experiments/panels/sharing.html', takes_context=True) @@ -154,11 +154,11 @@ def experiment_sharing(context, obj): ''' return { - 'request': context['request'], + 'request': context['request'], 'object': obj, 'users': context['users'], 'teams': context['teams'], - } + } #-------------------------------------------------- @@ -222,17 +222,17 @@ def experiment_results(panel_id, experiment): plotter, param = plotting[fmt]['default'] parameters = plotting[fmt]['options'][plotter] json_plotting[fmt] = dict( - plotter=plotter.fullname(), - parameter=param.fullname() if param else '', - parameters=json.dumps([k.fullname() for k in parameters]), - ) + plotter=plotter.fullname(), + parameter=param.fullname() if param else '', + parameters=json.dumps([k.fullname() for k in parameters]), + ) return dict( - analyzers=contents, - plotting=json_plotting, - panel_id=panel_id, - URL_PREFIX=settings.URL_PREFIX, - ) + analyzers=contents, + plotting=json_plotting, + panel_id=panel_id, + URL_PREFIX=settings.URL_PREFIX, + ) #-------------------------------------------------- @@ -264,7 +264,7 @@ def visible_reports(context, xp): return xp.reports.filter(status=Report.PUBLISHED) else: return xp.reports.filter(Q(author=context['request'].user) | - Q(status=Report.PUBLISHED)) + Q(status=Report.PUBLISHED)) #-------------------------------------------------- @@ -282,7 +282,7 @@ def owner_source_algorithms(obj): '''Calculates the user algorithms in source code form for a given experiment''' return [ x for x in obj.referenced_algorithms.filter(author=obj.author) - if not x.is_binary() ] + if not x.is_binary() ] @register.assignment_tag @@ -290,7 +290,7 @@ def owner_binary_algorithms(obj): '''Calculates the user algorithms in binary form for a given experiment''' return [ x for x in obj.referenced_algorithms.filter(author=obj.author) - if x.is_binary() ] + if x.is_binary() ] @register.assignment_tag diff --git a/beat/web/experiments/tests.py b/beat/web/experiments/tests.py index 209ab725f..b00e97fdd 100755 --- a/beat/web/experiments/tests.py +++ b/beat/web/experiments/tests.py @@ -54,10 +54,10 @@ from ..databases.models import Database from ..common.testutils import BaseTestCase, tearDownModule HASHES = { - 'addition1': 'ff59a471cec5c17b45d1dfa5aff3ed897ee2d7ed87de205365b372be1c726c87', + 'addition1': 'ff59a471cec5c17b45d1dfa5aff3ed897ee2d7ed87de205365b372be1c726c87', 'addition2': '41bd0ffd85bef70ea7b1499921797e269471b423c117e261349489d956df41a4', 'analysis' : 'ca9e22ea791bcf1cc63627c4429ae94bf644b1e7b2862e6ee70328f5661af0b6', - } +} class ExperimentTestBase(BaseTestCase): @@ -160,7 +160,7 @@ class ExperimentTestBase(BaseTestCase): } DATABASE = { - "root_folder": "/path/to/root_folder", + "root_folder": "/path/to/root_folder", "protocols": [ { "name": "triple", @@ -174,12 +174,12 @@ class ExperimentTestBase(BaseTestCase): "output1": "johndoe/single_integer/1", "output2": "johndoe/single_integer/1", "output3": "johndoe/single_integer/1" - } } - ] - } - ] - } + } + ] + } + ] + } def setUp(self): for path in [settings.TOOLCHAINS_ROOT, settings.EXPERIMENTS_ROOT, @@ -207,18 +207,18 @@ class ExperimentTestBase(BaseTestCase): DataFormat.objects.create_dataformat( - author=user, - name='single_integer', - short_description='description', - declaration={ - "value": "int32" - }, - ) + author=user, + name='single_integer', + short_description='description', + declaration={ + "value": "int32" + }, + ) database, errors = Database.objects.create_database( 'integers', declaration=self.DATABASE, - ) + ) assert database, errors @@ -226,81 +226,81 @@ class ExperimentTestBase(BaseTestCase): database.save() (self.toolchain1, errors) = Toolchain.objects.create_toolchain(user, - 'toolchain1', 'short description 1', - declaration={ - "blocks": [ { - "name": "addition1", - "inputs": [ - "a", - "b" - ], - "outputs": [ - "sum" - ], - "synchronized_channel": "dataset1" - }, - { - "name": "addition2", - "inputs": [ - "a", - "b" - ], - "outputs": [ - "sum" - ], - "synchronized_channel": "dataset1" - } - ], - "datasets": [ { - "name": "dataset1", - "outputs": [ - "output1", - "output2", - "output3" - ] - } - ], - "connections": [ { - "from": "dataset1.output1", - "to": "addition1.a", - "channel": "dataset1" - }, - { - "from": "dataset1.output2", - "to": "addition1.b", - "channel": "dataset1" - }, - { - "from": "addition1.sum", - "to": "addition2.a", - "channel": "dataset1" - }, - { - "from": "dataset1.output3", - "to": "addition2.b", - "channel": "dataset1" - }, - { - "to": "analysis.input", - "from": "addition2.sum", - "channel": "dataset1" - } - ], - "analyzers": [ - { - "inputs": [ - "input" - ], - "synchronized_channel": "dataset1", - "name": "analysis" - } - ], - "representation": { - "connections": {}, - "blocks": {}, - "channel_colors": {}, - }, - }) + 'toolchain1', 'short description 1', + declaration={ + "blocks": [ { + "name": "addition1", + "inputs": [ + "a", + "b" + ], + "outputs": [ + "sum" + ], + "synchronized_channel": "dataset1" + }, + { + "name": "addition2", + "inputs": [ + "a", + "b" + ], + "outputs": [ + "sum" + ], + "synchronized_channel": "dataset1" + } + ], + "datasets": [ { + "name": "dataset1", + "outputs": [ + "output1", + "output2", + "output3" + ] + } + ], + "connections": [ { + "from": "dataset1.output1", + "to": "addition1.a", + "channel": "dataset1" + }, + { + "from": "dataset1.output2", + "to": "addition1.b", + "channel": "dataset1" + }, + { + "from": "addition1.sum", + "to": "addition2.a", + "channel": "dataset1" + }, + { + "from": "dataset1.output3", + "to": "addition2.b", + "channel": "dataset1" + }, + { + "to": "analysis.input", + "from": "addition2.sum", + "channel": "dataset1" + } + ], + "analyzers": [ + { + "inputs": [ + "input" + ], + "synchronized_channel": "dataset1", + "name": "analysis" + } + ], + "representation": { + "connections": {}, + "blocks": {}, + "channel_colors": {}, + }, + }) assert not errors, 'Toolchain errors: %s' % errors (self.algorithm, errors) = Algorithm.objects.create_algorithm( @@ -339,61 +339,61 @@ class ExperimentTestBase(BaseTestCase): system_user = User.objects.create_user(settings.SYSTEM_ACCOUNT, 'system@test.org', '1234') (self.toolchain2, errors) = Toolchain.objects.create_toolchain(user, - 'toolchain2', 'short description 2', - declaration={ - "blocks": [ { - "name": "addition1", - "inputs": [ - "a", - "b" - ], - "outputs": [ - "sum" - ], - "synchronized_channel": "dataset1" - } - ], - "datasets": [ { - "name": "dataset1", - "outputs": [ - "output1", - "output2", - "output3" - ] - } - ], - "connections": [ - { - "from": "dataset1.output1", - "to": "addition1.a", - "channel": "dataset1" - }, - { - "from": "dataset1.output2", - "to": "addition1.b", - "channel": "dataset1" - }, - { - "to": "analysis.input", - "from": "addition1.sum", - "channel": "dataset1" - } - ], - "analyzers": [ - { - "inputs": [ - "input" - ], - "synchronized_channel": "dataset1", - "name": "analysis" - } - ], - "representation": { - "connections": {}, - "blocks": {}, - "channel_colors": {}, - }, - }) + 'toolchain2', 'short description 2', + declaration={ + "blocks": [ { + "name": "addition1", + "inputs": [ + "a", + "b" + ], + "outputs": [ + "sum" + ], + "synchronized_channel": "dataset1" + } + ], + "datasets": [ { + "name": "dataset1", + "outputs": [ + "output1", + "output2", + "output3" + ] + } + ], + "connections": [ + { + "from": "dataset1.output1", + "to": "addition1.a", + "channel": "dataset1" + }, + { + "from": "dataset1.output2", + "to": "addition1.b", + "channel": "dataset1" + }, + { + "to": "analysis.input", + "from": "addition1.sum", + "channel": "dataset1" + } + ], + "analyzers": [ + { + "inputs": [ + "input" + ], + "synchronized_channel": "dataset1", + "name": "analysis" + } + ], + "representation": { + "connections": {}, + "blocks": {}, + "channel_colors": {}, + }, + }) assert not errors, 'Toolchain errors: %s' % errors (dataformat, errors) = DataFormat.objects.create_dataformat( @@ -401,9 +401,9 @@ class ExperimentTestBase(BaseTestCase): name='float', short_description='description', declaration={ - "value": "float64" - }, - ) + "value": "float64" + }, + ) assert dataformat, errors @@ -412,9 +412,9 @@ class ExperimentTestBase(BaseTestCase): name='text', short_description='description', declaration={ - "text": "string" - }, - ) + "text": "string" + }, + ) assert dataformat, errors @@ -484,10 +484,10 @@ class ExperimentCreationAPI(ExperimentTestBase): self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/private/unknown', - 'declaration': ExperimentTestBase.DECLARATION1, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/private/unknown', + 'declaration': ExperimentTestBase.DECLARATION1, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -496,9 +496,9 @@ class ExperimentCreationAPI(ExperimentTestBase): self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -507,10 +507,10 @@ class ExperimentCreationAPI(ExperimentTestBase): self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': {}, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': {}, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -523,10 +523,10 @@ class ExperimentCreationAPI(ExperimentTestBase): declaration['globals']['environment']['name'] = 'unknown' response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -539,10 +539,10 @@ class ExperimentCreationAPI(ExperimentTestBase): declaration['globals']['environment']['version'] = 'unknown' response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -558,10 +558,10 @@ class ExperimentCreationAPI(ExperimentTestBase): ) response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -577,10 +577,10 @@ class ExperimentCreationAPI(ExperimentTestBase): ) response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -596,10 +596,10 @@ class ExperimentCreationAPI(ExperimentTestBase): ) response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -615,10 +615,10 @@ class ExperimentCreationAPI(ExperimentTestBase): ) response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -634,10 +634,10 @@ class ExperimentCreationAPI(ExperimentTestBase): ) response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -653,10 +653,10 @@ class ExperimentCreationAPI(ExperimentTestBase): ) response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -672,10 +672,10 @@ class ExperimentCreationAPI(ExperimentTestBase): ) response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': declaration, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': declaration, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -684,10 +684,10 @@ class ExperimentCreationAPI(ExperimentTestBase): self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': ExperimentTestBase.DECLARATION1, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': ExperimentTestBase.DECLARATION1, + }), content_type='application/json') data = self.checkResponse(response, 201, content_type='application/json') @@ -730,10 +730,10 @@ class ExperimentDeletionAPI(ExperimentTestBase): self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': ExperimentTestBase.DECLARATION1, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': ExperimentTestBase.DECLARATION1, + }), content_type='application/json') data = self.checkResponse(response, 201, content_type='application/json') @@ -750,7 +750,7 @@ class ExperimentDeletionAPI(ExperimentTestBase): url = reverse('api_experiments:share', args=['johndoe', 'johndoe', 'toolchain1', 1, experiment.name]) response = self.client.post(url, json.dumps({ 'teams': [team.name] - }), content_type='application/json') + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -770,10 +770,10 @@ class ExperimentDeletionAPI(ExperimentTestBase): self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': ExperimentTestBase.DECLARATION1, - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': ExperimentTestBase.DECLARATION1, + }), content_type='application/json') self.checkResponse(response, 201, content_type='application/json') @@ -788,9 +788,9 @@ class ExperimentDeletionAPI(ExperimentTestBase): url = reverse('api_attestations:create') response = self.client.post(url, - json.dumps({ - 'experiment': experiment.fullname(), - }), content_type='application/json') + json.dumps({ + 'experiment': experiment.fullname(), + }), content_type='application/json') self.checkResponse(response, 201, content_type='application/json') @@ -817,11 +817,11 @@ class ExperimentModificationAPI(ExperimentTestBase): url = reverse('api_experiments:list_create', args=['johndoe']) response = self.client.post(url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': ExperimentTestBase.DECLARATION1, - 'name': 'pending', - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': ExperimentTestBase.DECLARATION1, + 'name': 'pending', + }), content_type='application/json') self.checkResponse(response, 201, content_type='application/json') @@ -851,9 +851,9 @@ class ExperimentModificationAPI(ExperimentTestBase): self.client.login(username='johndoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'toolchain': 'johndoe/private/unknown', - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/private/unknown', + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -862,9 +862,9 @@ class ExperimentModificationAPI(ExperimentTestBase): self.client.login(username='johndoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': {}, - }), content_type='application/json') + json.dumps({ + 'declaration': {}, + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -873,9 +873,9 @@ class ExperimentModificationAPI(ExperimentTestBase): self.client.login(username='johndoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'name': 'changed', - }), content_type='application/json') + json.dumps({ + 'name': 'changed', + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -894,10 +894,10 @@ class ExperimentModificationAPI(ExperimentTestBase): self.client.login(username='johndoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'short_description': 'short description', - 'description': 'long description', - }), content_type='application/json') + json.dumps({ + 'short_description': 'short description', + 'description': 'long description', + }), content_type='application/json') self.checkResponse(response, 200, content_type='application/json') @@ -921,11 +921,11 @@ class ExperimentStartingAPI(ExperimentTestBase): url = reverse('api_experiments:list_create', args=['johndoe']) response = self.client.post(url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': ExperimentTestBase.DECLARATION1, - 'name': 'pending', - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': ExperimentTestBase.DECLARATION1, + 'name': 'pending', + }), content_type='application/json') self.checkResponse(response, 201, content_type='application/json') @@ -1023,7 +1023,7 @@ class ExperimentStartingAPI(ExperimentTestBase): url = reverse('api_experiments:share', args=['johndoe', 'johndoe', 'toolchain1', 1, experiment.name]) response = self.client.post(url, json.dumps({ 'teams': [team.name] - }), content_type='application/json') + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1052,7 +1052,7 @@ class ExperimentStartingAPI(ExperimentTestBase): url = reverse('api_experiments:share', args=['johndoe', 'johndoe', 'toolchain1', 1, experiment.name]) response = self.client.post(url, json.dumps({ 'users': [janedoe.username] - }), content_type='application/json') + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1091,11 +1091,11 @@ class ResultsAPI(ExperimentTestBase): url = reverse('api_experiments:list_create', args=['johndoe']) response = self.client.post(url, - json.dumps({ - 'toolchain': 'johndoe/toolchain1/1', - 'declaration': ExperimentTestBase.DECLARATION1, - 'name': 'experiment1', - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain1/1', + 'declaration': ExperimentTestBase.DECLARATION1, + 'name': 'experiment1', + }), content_type='application/json') self.checkResponse(response, 201, content_type='application/json') @@ -1106,11 +1106,11 @@ class ResultsAPI(ExperimentTestBase): url = reverse('api_experiments:list_create', args=['johndoe']) response = self.client.post(url, - json.dumps({ - 'toolchain': 'johndoe/toolchain2/1', - 'declaration': ExperimentTestBase.DECLARATION2, - 'name': 'experiment2', - }), content_type='application/json') + json.dumps({ + 'toolchain': 'johndoe/toolchain2/1', + 'declaration': ExperimentTestBase.DECLARATION2, + 'name': 'experiment2', + }), content_type='application/json') self.checkResponse(response, 201, content_type='application/json') @@ -1127,8 +1127,8 @@ class ResultsAPI(ExperimentTestBase): ) self.experiment2 = Experiment.objects.get(author__username='johndoe', - toolchain__name='toolchain2', - name='experiment2', + toolchain__name='toolchain2', + name='experiment2', ) self.url = reverse('api_experiments:object', args=['johndoe', 'johndoe', 'toolchain1', 1, 'experiment1']) diff --git a/beat/web/experiments/views.py b/beat/web/experiments/views.py index 43a0c24d1..576af7f57 100644 --- a/beat/web/experiments/views.py +++ b/beat/web/experiments/views.py @@ -44,29 +44,29 @@ from ..team.models import Team @login_required def new_from_toolchain(request, toolchain_author_name, toolchain_name, - toolchain_version): + toolchain_version): '''Sets up a new experiment from a toolchain name''' # Retrieve the toolchain toolchain = get_object_or_404( - Toolchain, - author__username=toolchain_author_name, - name=toolchain_name, - version=toolchain_version, - ) + Toolchain, + author__username=toolchain_author_name, + name=toolchain_name, + version=toolchain_version, + ) # Check that the user can access it has_access = toolchain.accessibility_for(request.user)[0] if not(has_access): raise Http404() return render_to_response( - 'experiments/setup.html', + 'experiments/setup.html', { 'toolchain': toolchain, 'action': 'new', - }, + }, context_instance=RequestContext(request), - ) + ) #---------------------------------------------------------- @@ -74,50 +74,50 @@ def new_from_toolchain(request, toolchain_author_name, toolchain_name, @login_required def fork(request, author_name, toolchain_author_name, - toolchain_name, toolchain_version, name): + toolchain_name, toolchain_version, name): '''Sets up a new experiment from an experiment fork''' # Retrieve the experiment experiment = get_object_or_404( - Experiment, - author__username=author_name, - toolchain__author__username=toolchain_author_name, - toolchain__name=toolchain_name, - toolchain__version=toolchain_version, - name=name - ) + Experiment, + author__username=author_name, + toolchain__author__username=toolchain_author_name, + toolchain__name=toolchain_name, + toolchain__version=toolchain_version, + name=name + ) # Check that the user can access it (has_access, accessibility) = experiment.accessibility_for(request.user) if not(has_access): raise Http404() return render_to_response( - 'experiments/setup.html', + 'experiments/setup.html', { 'toolchain': experiment.toolchain, 'experiment': experiment, 'action': 'fork', - }, + }, context_instance=RequestContext(request), - ) + ) #---------------------------------------------------------- @login_required def reset(request, toolchain_author_name, - toolchain_name, toolchain_version, name): + toolchain_name, toolchain_version, name): '''Resets the current experiment so it can run again''' # Retrieve the experiment experiment = get_object_or_404( - Experiment, - author=request.user, - toolchain__author__username=toolchain_author_name, - toolchain__name=toolchain_name, - toolchain__version=toolchain_version, - name=name - ) + Experiment, + author=request.user, + toolchain__author__username=toolchain_author_name, + toolchain__name=toolchain_name, + toolchain__version=toolchain_version, + name=name + ) if not experiment.deletable(): raise Http404() @@ -127,18 +127,18 @@ def reset(request, toolchain_author_name, def view(request, author_name, toolchain_author_name, toolchain_name, - toolchain_version, name): + toolchain_version, name): '''Views an experiment no matter its present state''' # Retrieve the experiment experiment = get_object_or_404( - Experiment, - author__username=author_name, - toolchain__author__username=toolchain_author_name, - toolchain__name=toolchain_name, - toolchain__version=toolchain_version, - name=name - ) + Experiment, + author__username=author_name, + toolchain__author__username=toolchain_author_name, + toolchain__name=toolchain_name, + toolchain__version=toolchain_version, + name=name + ) # Check that the user can access it (has_access, accessibility) = experiment.accessibility_for(request.user) @@ -147,29 +147,29 @@ def view(request, author_name, toolchain_author_name, toolchain_name, if experiment.status == Experiment.PENDING: if request.user.is_anonymous(): raise Http404() return render_to_response( - 'experiments/setup.html', + 'experiments/setup.html', { 'toolchain': experiment.toolchain, 'experiment': experiment, 'action': 'pending', - }, + }, context_instance=RequestContext(request), - ) + ) # Users the object can be shared with users = User.objects.exclude(username__in=settings.ACCOUNTS_TO_EXCLUDE_FROM_TEAMS).order_by('username') # The experiment was already done, show results return render_to_response( - 'experiments/view.html', + 'experiments/view.html', { 'experiment': experiment, 'owner': experiment.author == request.user, 'users': users, 'teams': Team.objects.for_user(request.user, True) - }, + }, context_instance=RequestContext(request), - ) + ) #---------------------------------------------------------- @@ -185,8 +185,8 @@ def ls(request, author_name): # orders so that experiments that the latest information is displayed first objects = Experiment.objects.from_author_and_public(request.user, - author_name).annotate(updated=Coalesce('end_date', 'start_date', - 'creation_date')).order_by('-updated') + author_name).annotate(updated=Coalesce('end_date', 'start_date', + 'creation_date')).order_by('-updated') if request.user.is_anonymous(): objects = objects.exclude(status=Experiment.PENDING) @@ -194,13 +194,13 @@ def ls(request, author_name): owner = (request.user == author) return render_to_response('experiments/list.html', - dict( - objects=objects, - author=author, - owner=owner, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=author, + owner=owner, + ), + context_instance=RequestContext(request), + ) #---------------------------------------------------------- @@ -213,10 +213,10 @@ def public_ls(request): objects = Experiment.objects.public().exclude(status=Experiment.PENDING).annotate(updated=Coalesce('end_date', 'start_date', 'creation_date')).order_by('-updated') return render_to_response('experiments/list.html', - dict( - objects=objects, - author=request.user, #anonymous - owner=False, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=request.user, #anonymous + owner=False, + ), + context_instance=RequestContext(request), + ) diff --git a/beat/web/libraries/admin.py b/beat/web/libraries/admin.py index 7d9407ae8..53a0af7b7 100644 --- a/beat/web/libraries/admin.py +++ b/beat/web/libraries/admin.py @@ -31,7 +31,7 @@ from django.core.files.base import ContentFile from django.utils import six from ..ui.forms import CodeMirrorPythonFileField, CodeMirrorRSTFileField, \ - CodeMirrorJSONFileField + CodeMirrorJSONFileField from ..common.texts import Messages @@ -49,35 +49,35 @@ import simplejson as json class LibraryModelForm(forms.ModelForm): name = NameField( - widget=forms.TextInput(attrs=dict(size=80)), - help_text=Messages['algo_name'], - ) + widget=forms.TextInput(attrs=dict(size=80)), + help_text=Messages['algo_name'], + ) declaration_file = CodeMirrorJSONFileField( - label='Declaration', - help_text=Messages['json'], - ) + label='Declaration', + help_text=Messages['json'], + ) source_code_file = CodeMirrorPythonFileField( - label='Source code', - help_text=Messages['code'], - ) + label='Source code', + help_text=Messages['code'], + ) description_file = CodeMirrorRSTFileField( - label='Description', - required=False, - allow_empty_file=True, - help_text=Messages['description'], - ) + label='Description', + required=False, + allow_empty_file=True, + help_text=Messages['description'], + ) class Meta: model = LibraryModel exclude = [] widgets = { - 'short_description': forms.TextInput( - attrs=dict(size=100), - ), - } + 'short_description': forms.TextInput( + attrs=dict(size=100), + ), + } def clean_declaration_file(self): """Cleans-up the declaration_file data, make sure it is really new""" @@ -127,7 +127,7 @@ rehash_library.short_description = 'Rehash selected library' class Library(admin.ModelAdmin): list_display = ( - 'id', + 'id', 'author', 'name', 'version', @@ -137,24 +137,24 @@ class Library(admin.ModelAdmin): 'fork_of', 'sharing', 'hash', - ) + ) search_fields = [ - 'author__username', + 'author__username', 'name', 'short_description', 'previous_version__author__username', 'previous_version__name', 'fork_of__author__username', 'fork_of__name' - ] + ] list_filter = ['sharing'] list_display_links = ['id', 'name'] readonly_fields = ['hash', 'short_description'] actions = [ rehash_library, - ] + ] form = LibraryModelForm @@ -168,39 +168,39 @@ class Library(admin.ModelAdmin): fieldsets = ( (None, - dict( - fields=('name', 'author',), - ), + dict( + fields=('name', 'author',), + ), ), ('Documentation', - dict( - classes=('collapse',), - fields=('short_description', 'description_file',), - ), + dict( + classes=('collapse',), + fields=('short_description', 'description_file',), + ), ), ('Versioning', - dict( - classes=('collapse',), - fields=('version', 'previous_version', 'fork_of'), - ), + dict( + classes=('collapse',), + fields=('version', 'previous_version', 'fork_of'), + ), ), ('Sharing', - dict( - classes=('collapse',), - fields=('sharing', 'shared_with', 'shared_with_team', 'usable_by', 'usable_by_team'), - ), + dict( + classes=('collapse',), + fields=('sharing', 'shared_with', 'shared_with_team', 'usable_by', 'usable_by_team'), + ), ), ('Cached Information (read-only)', - dict( - classes=('collapse',), - fields=('referenced_libraries',), - ), + dict( + classes=('collapse',), + fields=('referenced_libraries',), + ), ), ('Definition', - dict( - fields=('hash', 'declaration_file', 'language', 'source_code_file'), - ), + dict( + fields=('hash', 'declaration_file', 'language', 'source_code_file'), + ), ), - ) + ) admin.site.register(LibraryModel, Library) diff --git a/beat/web/libraries/api.py b/beat/web/libraries/api.py index 2473d1c9a..a46b212d5 100644 --- a/beat/web/libraries/api.py +++ b/beat/web/libraries/api.py @@ -34,7 +34,7 @@ from ..code.api import ShareCodeView, RetrieveUpdateDestroyCodeView from ..code.serializers import CodeDiffSerializer from ..common.api import (CheckContributionNameView, ListContributionView, - ListCreateContributionView) + ListCreateContributionView) from ..code.api import DiffView @@ -105,7 +105,7 @@ class RetrieveUpdateDestroyLibrariesView(RetrieveUpdateDestroyCodeView): for item in library.referencing.all(): for algorithm in item.used_by_algorithms.all(): experiments.append(list(set(map(lambda x: x.experiment, - algorithm.blocks.iterator())))) + algorithm.blocks.iterator())))) for experiment in set(experiments): experiment.delete() return modified, library diff --git a/beat/web/libraries/models.py b/beat/web/libraries/models.py index ffc0d27f3..6e85a6cc0 100644 --- a/beat/web/libraries/models.py +++ b/beat/web/libraries/models.py @@ -102,28 +102,28 @@ class Library(Code): #_____ Fields __________ declaration_file = models.FileField( - storage=LibraryStorage(), - upload_to=get_contribution_declaration_filename, - blank=True, null=True, - max_length=200, - db_column='declaration' - ) + storage=LibraryStorage(), + upload_to=get_contribution_declaration_filename, + blank=True, null=True, + max_length=200, + db_column='declaration' + ) description_file = models.FileField( - storage=LibraryStorage(), - upload_to=get_contribution_description_filename, - blank=True, null=True, - max_length=200, - db_column='description' - ) + storage=LibraryStorage(), + upload_to=get_contribution_description_filename, + blank=True, null=True, + max_length=200, + db_column='description' + ) source_code_file = models.FileField( - storage=LibraryStorage(), - upload_to=get_contribution_source_code_filename, - blank=True, null=True, - max_length=200, - db_column='source_code' - ) + storage=LibraryStorage(), + upload_to=get_contribution_source_code_filename, + blank=True, null=True, + max_length=200, + db_column='source_code' + ) # Read-only parameters that are updated at every save(), if required referenced_libraries = models.ManyToManyField('self', @@ -144,27 +144,27 @@ class Library(Code): def get_absolute_url(self): return reverse( - 'libraries:view', + 'libraries:view', args=(self.author.username, self.name, self.version,), - ) + ) def get_api_update_url(self): '''Returns the endpoint to update this object''' return reverse( - 'api_libraries:object', + 'api_libraries:object', args=(self.author.username, self.name, self.version,), - ) + ) def get_api_share_url(self): '''Returns the endpoint to share this object''' return reverse( - 'api_libraries:share', + 'api_libraries:share', args=(self.author.username, self.name, self.version,), - ) + ) #_____ Overrides __________ @@ -241,7 +241,7 @@ class Library(Code): algorithm__in=self.used_by_algorithms.all()).filter( \ Q(experiment__status=Experiment.DONE) | \ ((~Q(experiment__status=Experiment.DONE)) & Q(status=Block.DONE)) - )).annotate(itemcount=Count('id')).order_by('-creation_date' \ + )).annotate(itemcount=Count('id')).order_by('-creation_date' \ ).distinct() return [(k, k.itemcount) for k in envs] diff --git a/beat/web/libraries/templatetags/library_tags.py b/beat/web/libraries/templatetags/library_tags.py index 5b7916d5c..9943b4ed2 100644 --- a/beat/web/libraries/templatetags/library_tags.py +++ b/beat/web/libraries/templatetags/library_tags.py @@ -49,11 +49,11 @@ def library_table(context, objects, owner, id): ''' return { - 'request': context['request'], + 'request': context['request'], 'objects': objects, 'owner': owner, 'panel_id': id, - } + } @register.inclusion_tag('libraries/panels/actions.html', takes_context=True) @@ -73,11 +73,11 @@ def library_actions(context, obj, display_count): ''' request = context['request'] return { - 'request': request, + 'request': request, 'object': obj, 'display_count': display_count, 'open_source': obj.open_source(request.user), - } + } @register.inclusion_tag('libraries/panels/sharing.html', takes_context=True) @@ -91,23 +91,23 @@ def library_sharing(context, obj): ''' return { - 'request': context['request'], + 'request': context['request'], 'object': obj, 'owner': context['request'].user == obj.author, 'users': context['users'], 'teams': context['teams'], - } + } @register.inclusion_tag('libraries/panels/editor.html', takes_context=True) def library_editor(context, obj): request = context['request'] return { - 'owner': request.user == obj.author, + 'owner': request.user == obj.author, 'object': obj, 'texts': Texts, 'open_source': obj.open_source(request.user), - } + } @register.assignment_tag(takes_context=True) @@ -129,4 +129,4 @@ def visible_referrers_count(context, obj): '''Calculates the visible usage for a given library and requestor''' return visible_referrer_libraries(context, obj).count() + \ - visible_referrer_algorithms(context, obj).count() + visible_referrer_algorithms(context, obj).count() diff --git a/beat/web/libraries/tests/core.py b/beat/web/libraries/tests/core.py index 31567388c..775a13985 100644 --- a/beat/web/libraries/tests/core.py +++ b/beat/web/libraries/tests/core.py @@ -65,12 +65,12 @@ class LibrariesCreationFunction(LibrariesBaseTestCase): author=user, name='library1', short_description='some description', - ) + ) assert library, errors storage = Storage(settings.PREFIX, - library.fullname()) + library.fullname()) storage.language = 'python' assert storage.exists() @@ -107,12 +107,12 @@ class LibrariesCreationFunction(LibrariesBaseTestCase): name='library1', declaration=declaration, code=code, - ) + ) assert library, errors storage = Storage(settings.PREFIX, - library.fullname()) + library.fullname()) storage.language = 'python' assert storage.exists() @@ -129,8 +129,8 @@ class LibrariesCreationFunction(LibrariesBaseTestCase): expected = json.loads(declaration) assert in_storage == expected, "There are differences on the " \ - "declaration (beyond white spaces): %r != %r" % \ - (in_storage, expected) + "declaration (beyond white spaces): %r != %r" % \ + (in_storage, expected) # set storage language so it can find the code storage.language = in_storage['language'] @@ -139,7 +139,7 @@ class LibrariesCreationFunction(LibrariesBaseTestCase): expected = code assert in_storage == expected, "There are differences on the " \ - "code code: %r != %r" % (in_storage, expected) + "code code: %r != %r" % (in_storage, expected) class LibrariesTestCase(LibrariesBaseTestCase): @@ -157,7 +157,7 @@ class LibrariesTestCase(LibrariesBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert library, errors # Usable by one user @@ -167,7 +167,7 @@ class LibrariesTestCase(LibrariesBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert library, errors library.share(public=False, users=[user2]) @@ -179,7 +179,7 @@ class LibrariesTestCase(LibrariesBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert library, errors library.share(public=False, teams=[team1]) @@ -191,7 +191,7 @@ class LibrariesTestCase(LibrariesBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert library, errors library.share(public=False, teams=[team1, team2]) @@ -203,7 +203,7 @@ class LibrariesTestCase(LibrariesBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert library, errors library.share(public=False) @@ -215,7 +215,7 @@ class LibrariesTestCase(LibrariesBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert library, errors # library.shared_with.add(user2) @@ -228,7 +228,7 @@ class LibrariesTestCase(LibrariesBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert library, errors # library.shared_with_team.add(team1) @@ -241,7 +241,7 @@ class LibrariesTestCase(LibrariesBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert library, errors library.share(public=True, teams=[team1, team2]) @@ -253,7 +253,7 @@ class LibrariesTestCase(LibrariesBaseTestCase): short_description='', declaration=declaration, code=code, - ) + ) assert library, errors library.share(public=True) @@ -291,7 +291,7 @@ class LibrariesAccessibilityFunctionsBase(LibrariesTestCase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=user1, name='public_for_all', - ) + ) assert dataformat, errors dataformat.share() @@ -339,7 +339,7 @@ class LibrariesAPIBase(LibrariesTestCase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=user2, name='single_integer', - ) + ) assert dataformat, errors dataformat.share() @@ -352,7 +352,7 @@ class LibrariesAPIBase(LibrariesTestCase): short_description='', declaration=LibrariesAPIBase.DECLARATION, code=LibrariesAPIBase.CODE, - ) + ) assert library, errors library.previous_version = None diff --git a/beat/web/libraries/tests/tests_api.py b/beat/web/libraries/tests/tests_api.py index f673ddb0e..3d1a817c5 100644 --- a/beat/web/libraries/tests/tests_api.py +++ b/beat/web/libraries/tests/tests_api.py @@ -265,7 +265,7 @@ class LibrariesNameCheck(LibrariesAPIBase): author=user, name='library-4', short_description='short description 4' - ) + ) assert version4, errors self.url = reverse('api_libraries:check_name') @@ -287,10 +287,10 @@ class LibrariesNameCheck(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'private': True - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'private': True + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -303,10 +303,10 @@ class LibrariesNameCheck(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name_1 #due-to{}%&é', - 'private': True - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name_1 #due-to{}%&é', + 'private': True + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -319,10 +319,10 @@ class LibrariesNameCheck(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'usable_by_one_user', - 'private': True - }), content_type='application/json') + json.dumps({ + 'name': 'usable_by_one_user', + 'private': True + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -335,10 +335,10 @@ class LibrariesNameCheck(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'library 4', - 'private': True - }), content_type='application/json') + json.dumps({ + 'name': 'library 4', + 'private': True + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -358,7 +358,7 @@ class LibraryCreation(LibrariesAPIBase): author=user, name='library-4', short_description='short description 4' - ) + ) assert version4, errors self.url = reverse('api_libraries:list_create', args=['jackdoe']) @@ -370,15 +370,15 @@ class LibraryCreation(LibrariesAPIBase): code = code or default.code storage = beat.core.library.Storage(settings.PREFIX, - library.fullname()) + library.fullname()) assert storage.exists in_storage = json.loads(storage.json.load()) expected = json.loads(declaration) assert in_storage == expected, "There are differences on the " \ - "declaration (beyond white spaces): %r != %r" % \ - (in_storage, expected) + "declaration (beyond white spaces): %r != %r" % \ + (in_storage, expected) # set storage language so it can find the code storage.language = in_storage['language'] @@ -387,7 +387,7 @@ class LibraryCreation(LibrariesAPIBase): expected = code assert in_storage == expected, "There are differences on the " \ - "code: %r != %r" % (in_storage, expected) + "code: %r != %r" % (in_storage, expected) def test_no_creation_for_anonymous_user(self): @@ -414,10 +414,10 @@ class LibraryCreation(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'description': 'blah' - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'description': 'blah' + }), content_type='application/json') url = reverse('api_libraries:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, @@ -442,14 +442,14 @@ class LibraryCreation(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1' - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1' + }), content_type='application/json') url = reverse('api_libraries:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, - content_type='application/json', - location=url, + content_type='application/json', + location=url, ) self.assertTrue(isinstance(content, dict)) @@ -469,10 +469,10 @@ class LibraryCreation(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name1', - 'description': 'blah' - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name1', + 'description': 'blah' + }), content_type='application/json') url = reverse('api_libraries:object', args=['jackdoe', 'invalid-name1', 1]) content = self.checkResponse(response, 201, @@ -497,9 +497,9 @@ class LibraryCreation(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name1' - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name1' + }), content_type='application/json') url = reverse('api_libraries:object', args=['jackdoe', 'invalid-name1', 1]) content = self.checkResponse(response, 201, @@ -523,12 +523,12 @@ class LibraryCreation(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'description': 'blah', - 'declaration':LibrariesAPIBase.DECLARATION, - 'code': LibrariesAPIBase.CODE - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'description': 'blah', + 'declaration':LibrariesAPIBase.DECLARATION, + 'code': LibrariesAPIBase.CODE + }), content_type='application/json') url = reverse('api_libraries:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, @@ -547,18 +547,18 @@ class LibraryCreation(LibrariesAPIBase): self.assertEqual(library.short_description, '') self.assertEqual(library.description, 'blah') self.checkLibrary(library, LibrariesAPIBase.DECLARATION, - LibrariesAPIBase.CODE) + LibrariesAPIBase.CODE) def test_not_used_valid_name__no_description(self): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'declaration': LibrariesAPIBase.DECLARATION, - 'code': LibrariesAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'declaration': LibrariesAPIBase.DECLARATION, + 'code': LibrariesAPIBase.CODE, + }), content_type='application/json') url = reverse('api_libraries:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, @@ -576,19 +576,19 @@ class LibraryCreation(LibrariesAPIBase): self.assertEqual(library.short_description, '') self.checkLibrary(library, LibrariesAPIBase.DECLARATION, - LibrariesAPIBase.CODE) + LibrariesAPIBase.CODE) def test_not_used_invalid_name(self): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name1', - 'description': 'blah', - 'declaration': LibrariesAPIBase.DECLARATION, - 'code': LibrariesAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name1', + 'description': 'blah', + 'declaration': LibrariesAPIBase.DECLARATION, + 'code': LibrariesAPIBase.CODE, + }), content_type='application/json') url = reverse('api_libraries:object', args=['jackdoe', 'invalid-name1', 1]) content = self.checkResponse(response, 201, @@ -608,18 +608,18 @@ class LibraryCreation(LibrariesAPIBase): self.assertEqual(library.description, 'blah') self.checkLibrary(library, LibrariesAPIBase.DECLARATION, - LibrariesAPIBase.CODE) + LibrariesAPIBase.CODE) def test_not_used_invalid_name__no_description(self): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name1', - 'declaration': LibrariesAPIBase.DECLARATION, - 'code': LibrariesAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name1', + 'declaration': LibrariesAPIBase.DECLARATION, + 'code': LibrariesAPIBase.CODE, + }), content_type='application/json') url = reverse('api_libraries:object', args=['jackdoe', 'invalid-name1', 1]) content = self.checkResponse(response, 201, @@ -637,20 +637,20 @@ class LibraryCreation(LibrariesAPIBase): self.assertEqual(library.short_description, '') self.checkLibrary(library, LibrariesAPIBase.DECLARATION, - LibrariesAPIBase.CODE) + LibrariesAPIBase.CODE) def test_used_valid_name_no_code(self): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'usable_by_one_user', - 'description': 'blah' - }), content_type='application/json') + json.dumps({ + 'name': 'usable_by_one_user', + 'description': 'blah' + }), content_type='application/json') self.checkResponse(response, 400, - content_type='application/json' + content_type='application/json' ) @@ -658,12 +658,12 @@ class LibraryCreation(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'usable_by_one_user' - }), content_type='application/json') + json.dumps({ + 'name': 'usable_by_one_user' + }), content_type='application/json') self.checkResponse(response, 400, - content_type='application/json' + content_type='application/json' ) @@ -671,13 +671,13 @@ class LibraryCreation(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'library 4', - 'description': 'blah' - }), content_type='application/json') + json.dumps({ + 'name': 'library 4', + 'description': 'blah' + }), content_type='application/json') self.checkResponse(response, 400, - content_type='application/json' + content_type='application/json' ) @@ -685,12 +685,12 @@ class LibraryCreation(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'library 4' - }), content_type='application/json') + json.dumps({ + 'name': 'library 4' + }), content_type='application/json') self.checkResponse(response, 400, - content_type='application/json' + content_type='application/json' ) @@ -698,15 +698,15 @@ class LibraryCreation(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'usable_by_one_user', - 'description': 'blah', - 'declaration': LibrariesAPIBase.DECLARATION, - 'code': LibrariesAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'name': 'usable_by_one_user', + 'description': 'blah', + 'declaration': LibrariesAPIBase.DECLARATION, + 'code': LibrariesAPIBase.CODE, + }), content_type='application/json') self.checkResponse(response, 400, - content_type='application/json' + content_type='application/json' ) @@ -714,14 +714,14 @@ class LibraryCreation(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'usable_by_one_user', - 'declaration': LibrariesAPIBase.DECLARATION, - 'code': LibrariesAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'name': 'usable_by_one_user', + 'declaration': LibrariesAPIBase.DECLARATION, + 'code': LibrariesAPIBase.CODE, + }), content_type='application/json') self.checkResponse(response, 400, - content_type='application/json' + content_type='application/json' ) @@ -729,15 +729,15 @@ class LibraryCreation(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'library 4', - 'description': 'blah', - 'declaration': LibrariesAPIBase.DECLARATION, - 'code': LibrariesAPIBase.CODE - }), content_type='application/json') + json.dumps({ + 'name': 'library 4', + 'description': 'blah', + 'declaration': LibrariesAPIBase.DECLARATION, + 'code': LibrariesAPIBase.CODE + }), content_type='application/json') self.checkResponse(response, 400, - content_type='application/json' + content_type='application/json' ) @@ -745,12 +745,12 @@ class LibraryCreation(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': '', - 'description': 'blah', - 'declaration': LibrariesAPIBase.DECLARATION, - 'code': LibrariesAPIBase.CODE - }), content_type='application/json') + json.dumps({ + 'name': '', + 'description': 'blah', + 'declaration': LibrariesAPIBase.DECLARATION, + 'code': LibrariesAPIBase.CODE + }), content_type='application/json') content = self.checkResponse(response, 400, content_type='application/json' @@ -761,14 +761,14 @@ class LibraryCreation(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'library 4', - 'declaration': LibrariesAPIBase.DECLARATION, - 'code': LibrariesAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'name': 'library 4', + 'declaration': LibrariesAPIBase.DECLARATION, + 'code': LibrariesAPIBase.CODE, + }), content_type='application/json') self.checkResponse(response, 400, - content_type='application/json' + content_type='application/json' ) @@ -779,11 +779,11 @@ class LibraryUpdate(LibrariesAPIBase): def test_no_update_for_anonymous_user(self): response = self.client.put(self.url, - json.dumps({ - 'description': 'blah', - 'declaration': LibrariesAPIBase.DECLARATION, - 'code': LibrariesAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': LibrariesAPIBase.DECLARATION, + 'code': LibrariesAPIBase.CODE, + }), content_type='application/json') self.checkResponse(response, 403) @@ -792,11 +792,11 @@ class LibraryUpdate(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') url = reverse('api_libraries:object', args=['unknown', 'personal', 1]) response = self.client.put(url, - json.dumps({ - 'description': 'blah', - 'declaration': LibrariesAPIBase.DECLARATION, - 'code': LibrariesAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': LibrariesAPIBase.DECLARATION, + 'code': LibrariesAPIBase.CODE, + }), content_type='application/json') self.checkResponse(response, 403) @@ -805,11 +805,11 @@ class LibraryUpdate(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') url = reverse('api_libraries:object', args=['jackdoe', 'unknown', 1]) response = self.client.put(url, - json.dumps({ - 'description': 'blah', - 'declaration': LibrariesAPIBase.DECLARATION, - 'code': LibrariesAPIBase.CODE, - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': LibrariesAPIBase.DECLARATION, + 'code': LibrariesAPIBase.CODE, + }), content_type='application/json') self.checkResponse(response, 404) @@ -824,10 +824,10 @@ class LibraryUpdate(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'description': 'blah', - 'declaration': LibrariesAPIBase.UPDATE - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': LibrariesAPIBase.UPDATE + }), content_type='application/json') self.checkResponse(response, 204) @@ -835,7 +835,7 @@ class LibraryUpdate(LibrariesAPIBase): self.assertEqual(library.description, 'blah') storage = beat.core.library.Storage(settings.PREFIX, - library.fullname()) + library.fullname()) storage.language = 'python' assert storage.exists() self.assertEqual(storage.json.load(), LibrariesAPIBase.UPDATE) @@ -845,9 +845,9 @@ class LibraryUpdate(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'description': 'blah', - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + }), content_type='application/json') self.checkResponse(response, 204) @@ -859,16 +859,16 @@ class LibraryUpdate(LibrariesAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': LibrariesAPIBase.UPDATE - }), content_type='application/json') + json.dumps({ + 'declaration': LibrariesAPIBase.UPDATE + }), content_type='application/json') self.checkResponse(response, 204) library = Library.objects.get(author__username='jackdoe', name='personal', version=1) storage = beat.core.library.Storage(settings.PREFIX, - library.fullname()) + library.fullname()) storage.language = 'python' assert storage.exists() self.assertEqual(storage.json.load(), LibrariesAPIBase.UPDATE) @@ -1140,9 +1140,9 @@ class LibrarySharingAPI_Failures(LibrarySharingAPIBase): def test_fail_sharing_for_anonymous_user(self): response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + }), content_type='application/json') self.checkResponse(response, 403) @@ -1150,9 +1150,9 @@ class LibrarySharingAPI_Failures(LibrarySharingAPIBase): def test_fail_sharing_for_unauthorized_user(self): self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + }), content_type='application/json') self.checkResponse(response, 403) @@ -1161,10 +1161,10 @@ class LibrarySharingAPI_Failures(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['doejack'], - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['doejack'], + }), content_type='application/json') data = self.checkResponse(response, 400, content_type='application/json') self.assertTrue(data is not None) @@ -1175,10 +1175,10 @@ class LibrarySharingAPI_Failures(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['doejack'], - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['doejack'], + }), content_type='application/json') data = self.checkResponse(response, 400, content_type='application/json') self.assertTrue(data is not None) @@ -1189,9 +1189,9 @@ class LibrarySharingAPI_Failures(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'notknownstatus', - }), content_type='application/json') + json.dumps({ + 'status': 'notknownstatus', + }), content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -1207,9 +1207,9 @@ class NotSharedLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1225,10 +1225,10 @@ class NotSharedLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['johndoe'], - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['johndoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1246,10 +1246,10 @@ class NotSharedLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['johndoe', 'janedoe'], - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['johndoe', 'janedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1267,9 +1267,9 @@ class NotSharedLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - }), content_type='application/json') + json.dumps({ + 'status': 'public', + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1285,10 +1285,10 @@ class NotSharedLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['johndoe'], - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['johndoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1306,10 +1306,10 @@ class NotSharedLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['johndoe', 'janedoe'], - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['johndoe', 'janedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1335,9 +1335,9 @@ class UsableByOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1353,10 +1353,10 @@ class UsableByOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['johndoe'], - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['johndoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1374,10 +1374,10 @@ class UsableByOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1394,10 +1394,10 @@ class UsableByOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['janedoe', 'jacquelinedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['janedoe', 'jacquelinedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1415,9 +1415,9 @@ class UsableByOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - }), content_type='application/json') + json.dumps({ + 'status': 'public', + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1433,10 +1433,10 @@ class UsableByOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1453,10 +1453,10 @@ class UsableByOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1474,10 +1474,10 @@ class UsableByOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['janedoe', 'jacquelinedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['janedoe', 'jacquelinedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1503,9 +1503,9 @@ class UsableByAllLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable' - }), content_type='application/json') + json.dumps({ + 'status': 'usable' + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1521,10 +1521,10 @@ class UsableByAllLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users': ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users': ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1540,10 +1540,10 @@ class UsableByAllLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users': ['johndoe', 'janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users': ['johndoe', 'janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1559,9 +1559,9 @@ class UsableByAllLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public' - }), content_type='application/json') + json.dumps({ + 'status': 'public' + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1577,10 +1577,10 @@ class UsableByAllLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1597,10 +1597,10 @@ class UsableByAllLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['johndoe', 'janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['johndoe', 'janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1625,9 +1625,9 @@ class PublicForOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1644,10 +1644,10 @@ class PublicForOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1664,10 +1664,10 @@ class PublicForOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1685,10 +1685,10 @@ class PublicForOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users' : ['janedoe', 'jacquelinedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users' : ['janedoe', 'jacquelinedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1706,9 +1706,9 @@ class PublicForOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public' - }), content_type='application/json') + json.dumps({ + 'status': 'public' + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1724,10 +1724,10 @@ class PublicForOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1744,10 +1744,10 @@ class PublicForOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1764,10 +1764,10 @@ class PublicForOneUserLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users' : ['janedoe', 'jacquelinedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users' : ['janedoe', 'jacquelinedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1792,9 +1792,9 @@ class PublicForAllLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable' - }), content_type='application/json') + json.dumps({ + 'status': 'usable' + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1810,10 +1810,10 @@ class PublicForAllLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users': ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users': ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1829,10 +1829,10 @@ class PublicForAllLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'usable', - 'users': ['johndoe', 'janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'usable', + 'users': ['johndoe', 'janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1848,9 +1848,9 @@ class PublicForAllLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public' - }), content_type='application/json') + json.dumps({ + 'status': 'public' + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1866,10 +1866,10 @@ class PublicForAllLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users': ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users': ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1885,10 +1885,10 @@ class PublicForAllLibrary_SharingAPI(LibrarySharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'status': 'public', - 'users': ['johndoe', 'janedoe'] - }), content_type='application/json') + json.dumps({ + 'status': 'public', + 'users': ['johndoe', 'janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') diff --git a/beat/web/libraries/tests/tests_team.py b/beat/web/libraries/tests/tests_team.py index ac3d89a0b..879eb575e 100644 --- a/beat/web/libraries/tests/tests_team.py +++ b/beat/web/libraries/tests/tests_team.py @@ -504,7 +504,7 @@ class TeamDeletionPropagation(LibrariesAccessibilityFunctionsBase): name='library1', short_description='some description', declaration=DECLARATION, - ) + ) assert library, errors library.share(True, teams=[team_to_delete]) diff --git a/beat/web/libraries/views.py b/beat/web/libraries/views.py index d1f6a707a..38ce49142 100644 --- a/beat/web/libraries/views.py +++ b/beat/web/libraries/views.py @@ -53,16 +53,16 @@ def create(request): """ visible_libraries = Library.objects.from_author_and_public(request.user, - request.user.username).order_by('-creation_date') + request.user.username).order_by('-creation_date') return render_to_response('libraries/edition.html', - dict( - op="new", - texts=Messages, - visible_libraries=visible_libraries, - ), - context_instance=RequestContext(request) - ) + dict( + op="new", + texts=Messages, + visible_libraries=visible_libraries, + ), + context_instance=RequestContext(request) + ) @csrf_protect @@ -74,22 +74,22 @@ def new_version(request, name): """ previous_version = Library.objects.filter(author=request.user, - name__iexact=name).order_by('-version') + name__iexact=name).order_by('-version') if not previous_version: raise Http404() visible_libraries = Library.objects.from_author_and_public(request.user, - request.user.username).order_by('-creation_date') + request.user.username).order_by('-creation_date') return render_to_response('libraries/edition.html', - dict( - op="new-version", - texts=Messages, - library=previous_version[0], - visible_libraries=visible_libraries, - ), - context_instance=RequestContext(request) - ) + dict( + op="new-version", + texts=Messages, + library=previous_version[0], + visible_libraries=visible_libraries, + ), + context_instance=RequestContext(request) + ) @csrf_protect @@ -117,16 +117,16 @@ def fork(request, author_name, name, version): raise Http404() visible_libraries = Library.objects.from_author_and_public(request.user, - request.user.username).order_by('-creation_date') + request.user.username).order_by('-creation_date') return render_to_response('libraries/edition.html', - dict( - op="fork", - texts=Messages, - library=fork_of, - visible_libraries=visible_libraries, - ), - context_instance=RequestContext(request)) + dict( + op="fork", + texts=Messages, + library=fork_of, + visible_libraries=visible_libraries, + ), + context_instance=RequestContext(request)) #---------------------------------------------------------- @@ -141,26 +141,26 @@ def edit(request, author_name, name, version): # Retrieves the library library = get_object_or_404(Library, author__username=author_name, - name__iexact=name, version=int(version)) + name__iexact=name, version=int(version)) # only author can edit it if library.author != request.user: raise Http404() if not library.modifiable(): return HttpResponseForbidden('Library %s is not modifiable' % \ - library.fullname()) + library.fullname()) visible_libraries = Library.objects.from_author_and_public(request.user, - request.user.username).exclude(id=library.id).order_by('-creation_date') + request.user.username).exclude(id=library.id).order_by('-creation_date') return render_to_response('libraries/edition.html', - dict( - op="edit", - texts=Messages, - library=library, - visible_libraries=visible_libraries, - ), - context_instance=RequestContext(request)) + dict( + op="edit", + texts=Messages, + library=library, + visible_libraries=visible_libraries, + ), + context_instance=RequestContext(request)) #---------------------------------------------------------- @@ -172,14 +172,14 @@ def view(request, author_name, name, version=None): # Retrieves the library if version: library = get_object_or_404( - Library, - author__username__iexact=author_name, - name__iexact=name, - version=int(version), - ) + Library, + author__username__iexact=author_name, + name__iexact=name, + version=int(version), + ) else: library = Library.objects.filter(author__username__iexact=author_name, - name__iexact=name).order_by('-version') + name__iexact=name).order_by('-version') if not library: raise Http404() else: @@ -242,17 +242,17 @@ def ls(request, author_name): # orders libraries so that the latest information is displayed first objects = Library.objects.from_author_and_public(request.user, - author_name).order_by('-creation_date') + author_name).order_by('-creation_date') objects = Library.filter_latest_versions(objects) return render_to_response('libraries/list.html', - dict( - objects=objects, - author=author, - owner=(request.user==author), - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=author, + owner=(request.user==author), + ), + context_instance=RequestContext(request), + ) #---------------------------------------------------------- @@ -266,10 +266,10 @@ def public_ls(request): objects = Library.filter_latest_versions(objects) return render_to_response('libraries/list.html', - dict( - objects=objects, - author=request.user, #anonymous - owner=False, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=request.user, #anonymous + owner=False, + ), + context_instance=RequestContext(request), + ) diff --git a/beat/web/navigation/admin.py b/beat/web/navigation/admin.py index 85d82d7ca..b947ca27e 100644 --- a/beat/web/navigation/admin.py +++ b/beat/web/navigation/admin.py @@ -92,7 +92,7 @@ class UserAdmin(UserAdmin): return "Supervisor account" else: supervisiontrack = SupervisionTrack.objects.get(supervisee=obj, - is_valid=True) + is_valid=True) godfather = supervisiontrack.godfather return godfather @@ -121,7 +121,7 @@ class UserAdmin(UserAdmin): '-is_staff', '-last_login', 'username', - ) + ) inlines = ( AgreementInline, @@ -152,7 +152,7 @@ class SupervisionTrackAdmin(admin.ModelAdmin): ordering = ( 'godfather', - ) + ) admin.site.register(SupervisionTrack, SupervisionTrackAdmin) @@ -174,6 +174,6 @@ class ProfileAdmin(admin.ModelAdmin): ordering = ( 'user', - ) + ) admin.site.register(Profile, ProfileAdmin) diff --git a/beat/web/navigation/context_processors.py b/beat/web/navigation/context_processors.py index 3163423fa..e7aa23902 100644 --- a/beat/web/navigation/context_processors.py +++ b/beat/web/navigation/context_processors.py @@ -32,14 +32,14 @@ def exported_settings(request): return { 'URL_PREFIX': settings.URL_PREFIX, 'PREREGISTRATION_ONLY': settings.PREREGISTRATION_ONLY - } + } def beat_version(request): return { 'beat_version': __version__, - } + } def google_analytics(request): return { 'google_analytics': getattr(settings, 'GOOGLE_ANALYTICS_KEY'), - } + } diff --git a/beat/web/navigation/models.py b/beat/web/navigation/models.py index 81696b9ee..a8136f1c7 100644 --- a/beat/web/navigation/models.py +++ b/beat/web/navigation/models.py @@ -38,10 +38,10 @@ class Agreement(models.Model): version = models.PositiveIntegerField( default=1, help_text='Last version of the ToS the user has agreed with', - ) + ) def __unicode__(self): return u"%s agrees with ToS version %d" % ( - self.user.username, - self.version - ) + self.user.username, + self.version + ) diff --git a/beat/web/navigation/signals.py b/beat/web/navigation/signals.py index f06baa1da..9dcdd4b07 100644 --- a/beat/web/navigation/signals.py +++ b/beat/web/navigation/signals.py @@ -37,5 +37,5 @@ def create_agreement(sender, instance, created, **kwargs): """If the user was just created, make sure to instantiate an agreement""" if created and not instance.pk == settings.ANONYMOUS_USER_ID: agreement = Agreement(user=instance, - version=settings.TERMS_OF_SERVICE_VERSION) + version=settings.TERMS_OF_SERVICE_VERSION) agreement.save() diff --git a/beat/web/navigation/urls.py b/beat/web/navigation/urls.py index 24ea8fb89..0e8bf96bf 100644 --- a/beat/web/navigation/urls.py +++ b/beat/web/navigation/urls.py @@ -34,18 +34,18 @@ urlpatterns = [ r'^tos/$', views.terms_of_service, name='terms-of-service', - ), + ), url( r'^disclaimer/$', views.legal_disclaimer, name='legal-disclaimer', - ), + ), url( r'^contact/$', views.contact, name='contact', - ), + ), ] diff --git a/beat/web/navigation/views.py b/beat/web/navigation/views.py index 9e5cd514b..d291dbc21 100644 --- a/beat/web/navigation/views.py +++ b/beat/web/navigation/views.py @@ -47,14 +47,14 @@ def terms_of_service(request): else: # equivalent behavior for non-logged in users request.session['beat_disclaimer_version'] = \ - settings.LEGAL_DISCLAIMER_VERSION + settings.LEGAL_DISCLAIMER_VERSION remove_banner_message(request) return render_to_response( - 'navigation/terms_of_service.html', + 'navigation/terms_of_service.html', dict(contents=contents), context_instance=RequestContext(request), - ) + ) #------------------------------------------------ @@ -73,15 +73,15 @@ def legal_disclaimer(request): else: # equivalent behavior for non-logged in users request.session['beat_disclaimer_version'] = \ - settings.LEGAL_DISCLAIMER_VERSION + settings.LEGAL_DISCLAIMER_VERSION remove_banner_message(request) return render_to_response( - 'navigation/legal_disclaimer.html', + 'navigation/legal_disclaimer.html', dict(contents=contents), context_instance=RequestContext(request), - ) + ) @@ -92,7 +92,7 @@ def contact(request): '''Returns an HTML page with the contact information''' return render_to_response( - 'navigation/contact.html', + 'navigation/contact.html', dict(), context_instance=RequestContext(request), - ) + ) diff --git a/beat/web/plotters/admin.py b/beat/web/plotters/admin.py index 8ec74eab6..83d0dd6a3 100644 --- a/beat/web/plotters/admin.py +++ b/beat/web/plotters/admin.py @@ -41,7 +41,7 @@ from .models import DefaultPlotter from .models import validate_plotter from ..ui.forms import CodeMirrorRSTFileField, CodeMirrorJSONFileField, \ - CodeMirrorPythonFileField, CodeMirrorJSONCharField + CodeMirrorPythonFileField, CodeMirrorJSONCharField from ..ui.forms import NameField import simplejson as json @@ -64,45 +64,45 @@ rehash_plotter.short_description = 'Rehash selected plotters' class PlotterModelForm(forms.ModelForm): name = NameField( - widget=forms.TextInput(attrs=dict(size=80)), - help_text=Messages['algo_name'], - ) + widget=forms.TextInput(attrs=dict(size=80)), + help_text=Messages['algo_name'], + ) declaration_file = CodeMirrorJSONFileField( - label='Declaration', - help_text=Messages['json'], - ) + label='Declaration', + help_text=Messages['json'], + ) source_code_file = CodeMirrorPythonFileField( - label='Source code', - help_text=Messages['code'], - ) + label='Source code', + help_text=Messages['code'], + ) description_file = CodeMirrorRSTFileField( - label='Description', - required=False, - allow_empty_file=True, - help_text=Messages['description'], - ) + label='Description', + required=False, + allow_empty_file=True, + help_text=Messages['description'], + ) parameters = CodeMirrorJSONCharField( - readonly=True, - required=False, - ) + readonly=True, + required=False, + ) sample_data = CodeMirrorJSONCharField( - readonly=True, - required=False, - ) + readonly=True, + required=False, + ) class Meta: model = Plotter exclude = [] widgets = { - 'short_description': forms.TextInput( - attrs=dict(size=100), - ), - } + 'short_description': forms.TextInput( + attrs=dict(size=100), + ), + } def clean_declaration_file(self): """Cleans-up the clean_declaration_file data, make sure it is really new""" @@ -144,7 +144,7 @@ class PlotterAdmin(admin.ModelAdmin): list_display = ('id', 'author', 'name', 'version', 'language', 'dataformat', 'short_description') search_fields = [ - 'name', + 'name', 'dataformat__name', 'author__username', 'name', @@ -154,16 +154,16 @@ class PlotterAdmin(admin.ModelAdmin): 'previous_version__name', 'fork_of__author__username', 'fork_of__name', - ] + ] list_display_links = ('id', 'name') list_filter = ('author',) readonly_fields = ('hash', 'short_description', 'dataformat', - 'referenced_libraries') + 'referenced_libraries') actions = [ rehash_plotter, - ] + ] form = PlotterModelForm @@ -175,41 +175,41 @@ class PlotterAdmin(admin.ModelAdmin): fieldsets = ( (None, - dict( - fields=('name', 'author'), - ), + dict( + fields=('name', 'author'), + ), ), ('Documentation', - dict( - classes=('collapse',), - fields=('short_description', 'description_file',), - ), + dict( + classes=('collapse',), + fields=('short_description', 'description_file',), + ), ), ('Versioning', - dict( - classes=('collapse',), - fields=('version', 'previous_version', 'fork_of'), - ), + dict( + classes=('collapse',), + fields=('version', 'previous_version', 'fork_of'), + ), ), ('Sharing', - dict( - classes=('collapse',), - fields=('sharing', 'shared_with', 'shared_with_team', 'usable_by'), - ), + dict( + classes=('collapse',), + fields=('sharing', 'shared_with', 'shared_with_team', 'usable_by'), + ), ), ('Cached Information (read-only)', - dict( - classes=('collapse',), - fields=('dataformat', 'parameters', 'referenced_libraries', - 'sample_data'), - ), + dict( + classes=('collapse',), + fields=('dataformat', 'parameters', 'referenced_libraries', + 'sample_data'), + ), ), ('Definition', - dict( - fields=('hash', 'declaration_file', 'language', 'source_code_file'), - ), + dict( + fields=('hash', 'declaration_file', 'language', 'source_code_file'), + ), ), - ) + ) admin.site.register(Plotter, PlotterAdmin) @@ -217,26 +217,26 @@ admin.site.register(Plotter, PlotterAdmin) class PlotterParameterModelForm(forms.ModelForm): name = NameField( - widget=forms.TextInput(attrs=dict(size=80)), - help_text=Messages['name'], - ) + widget=forms.TextInput(attrs=dict(size=80)), + help_text=Messages['name'], + ) data = CodeMirrorJSONCharField( - help_text=Messages['json'], - ) + help_text=Messages['json'], + ) description = CodeMirrorRSTFileField( required=False, help_text=Messages['description'], - ) + ) class Meta: model = PlotterParameter exclude = [] widgets = { - 'short_description': forms.TextInput( - attrs=dict(size=100), - ), + 'short_description': forms.TextInput( + attrs=dict(size=100), + ), } @@ -274,34 +274,34 @@ class PlotterParameterAdmin(admin.ModelAdmin): fieldsets = ( (None, - dict( - fields=('name', 'author'), - ), + dict( + fields=('name', 'author'), + ), ), ('Documentation', - dict( - classes=('collapse',), - fields=('short_description', 'description'), - ), + dict( + classes=('collapse',), + fields=('short_description', 'description'), + ), ), ('Versioning', - dict( - classes=('collapse',), - fields=('version', 'previous_version', 'fork_of'), - ), + dict( + classes=('collapse',), + fields=('version', 'previous_version', 'fork_of'), + ), ), ('Sharing', - dict( - classes=('collapse',), - fields=('sharing', 'shared_with', 'shared_with_team'), - ), + dict( + classes=('collapse',), + fields=('sharing', 'shared_with', 'shared_with_team'), + ), ), ('Plotter Parameters', - dict( - fields=('plotter', 'data',), - ), + dict( + fields=('plotter', 'data',), + ), ), - ) + ) admin.site.register(PlotterParameter, PlotterParameterAdmin) diff --git a/beat/web/plotters/api.py b/beat/web/plotters/api.py index 782cb1326..ba9cbd2f0 100644 --- a/beat/web/plotters/api.py +++ b/beat/web/plotters/api.py @@ -332,9 +332,9 @@ class RetrieveUpdateDestroyPlotterParametersView(RetrieveUpdateDestroyContributi # Retrieve the plotterparameter dbplotterparameter = get_object_or_404(PlotterParameter, - author__username__iexact=author_name, - name__iexact=object_name, - version=version) + author__username__iexact=author_name, + name__iexact=object_name, + version=version) # Check that the object can still be modified (if applicable, the # documentation can always be modified) diff --git a/beat/web/plotters/migrations/0002_plotter_sample_data.py b/beat/web/plotters/migrations/0002_plotter_sample_data.py index 8b82f7c4d..a2b310f12 100644 --- a/beat/web/plotters/migrations/0002_plotter_sample_data.py +++ b/beat/web/plotters/migrations/0002_plotter_sample_data.py @@ -45,5 +45,5 @@ class Migration(migrations.Migration): field=models.TextField(default=b'{}', blank=True), ), migrations.RunPython(add_plotter_sample_data, - backward_dummy) + backward_dummy) ] diff --git a/beat/web/plotters/models.py b/beat/web/plotters/models.py index 2e5a9f8a9..edf0ff073 100755 --- a/beat/web/plotters/models.py +++ b/beat/web/plotters/models.py @@ -112,21 +112,21 @@ class PlotterManager(CodeManager): parts = s.split('/') query = self.filter( - dataformat__author__username=parts[0], - dataformat__name=parts[1], - dataformat__version=int(parts[2]), - ).order_by('-creation_date') + dataformat__author__username=parts[0], + dataformat__name=parts[1], + dataformat__version=int(parts[2]), + ).order_by('-creation_date') default = DefaultPlotter.objects.get( - plotter__dataformat__author__username=parts[0], - plotter__dataformat__name=parts[1], - plotter__dataformat__version=int(parts[2]), - ) + plotter__dataformat__author__username=parts[0], + plotter__dataformat__name=parts[1], + plotter__dataformat__version=int(parts[2]), + ) return { - 'options': collections.OrderedDict([(k, PlotterParameter.objects.filter(plotter=k).order_by('-creation_date')) for k in query]), + 'options': collections.OrderedDict([(k, PlotterParameter.objects.filter(plotter=k).order_by('-creation_date')) for k in query]), 'default': (default.plotter, default.parameter), - } + } @@ -139,34 +139,34 @@ class Plotter(Code): #_____ Fields __________ dataformat = models.ForeignKey(DataFormat, - null=True, - help_text=u'Applicable data format to use this code with', - related_name='plotters', + null=True, + help_text=u'Applicable data format to use this code with', + related_name='plotters', ) declaration_file = models.FileField( - storage=PlotterStorage(), - upload_to=get_contribution_declaration_filename, - blank=True, null=True, - max_length=200, - db_column='declaration' - ) + storage=PlotterStorage(), + upload_to=get_contribution_declaration_filename, + blank=True, null=True, + max_length=200, + db_column='declaration' + ) description_file = models.FileField( - storage=PlotterStorage(), - upload_to=get_contribution_description_filename, - blank=True, null=True, - max_length=200, - db_column='description' - ) + storage=PlotterStorage(), + upload_to=get_contribution_description_filename, + blank=True, null=True, + max_length=200, + db_column='description' + ) source_code_file = models.FileField( - storage=PlotterStorage(), - upload_to=get_contribution_source_code_filename, - blank=True, null=True, - max_length=200, - db_column='source_code' - ) + storage=PlotterStorage(), + upload_to=get_contribution_source_code_filename, + blank=True, null=True, + max_length=200, + db_column='source_code' + ) sample_data = models.TextField(default='{}', blank=True) # Read-only parameters that are updated at every save(), if required @@ -192,12 +192,12 @@ class Plotter(Code): "default_value": details.get('default'), "comment": details.get('description', ''), "type": details['type'], - } + } ) if 'choice' in details: parameters[-1]['choices'] = '[' + \ - ','.join([str(k) for k in details['choice']]) + ']' + ','.join([str(k) for k in details['choice']]) + ']' if 'range' in details: parameters[-1]['minimum'] = details['range'][0] @@ -210,10 +210,10 @@ class Plotter(Code): # Set dataformat self.dataformat = DataFormat.objects.get( - author__username=wrapper.dataformat.storage.username, - name=wrapper.dataformat.storage.name, - version=int(wrapper.dataformat.storage.version), - ) + author__username=wrapper.dataformat.storage.username, + name=wrapper.dataformat.storage.name, + version=int(wrapper.dataformat.storage.version), + ) # Invoke the base implementation super(Plotter, self).save(*args, **kwargs) @@ -258,9 +258,9 @@ class Plotter(Code): def get_absolute_url(self): return reverse( - 'plotters:view', + 'plotters:view', args=(self.author.username, self.name, self.version,), - ) + ) @@ -291,27 +291,27 @@ class PlotterParameter(Contribution): def get_absolute_url(self): return reverse( - 'plotters:plotterparameter-author-view', + 'plotters:plotterparameter-author-view', args=(self.author.username, self.name, self.version,), - ) + ) def get_api_update_url(self): '''Returns the endpoint to update this object''' return reverse( - 'api_plotters:view', + 'api_plotters:view', args=(self.author.username, self.name, self.version,), - ) + ) def get_api_share_url(self): '''Returns the endpoint to share this object''' return reverse( - 'api_plotters:share', + 'api_plotters:share', args=(self.author.username, self.name, self.version,), - ) + ) diff --git a/beat/web/plotters/serializers.py b/beat/web/plotters/serializers.py index 13df01f3c..e6a6ce109 100644 --- a/beat/web/plotters/serializers.py +++ b/beat/web/plotters/serializers.py @@ -45,9 +45,9 @@ class PlotterSerializer(ContributionSerializer): class Meta(ContributionSerializer.Meta): model = Plotter default_fields = [ - #'name', 'dataformat', + #'name', 'dataformat', 'id', 'accessibility', 'modifiable', 'deletable', 'is_owner', 'name', 'dataformat', 'fork_of', 'last_version', 'previous_version', 'short_description', 'description', 'version', 'creation_date', 'data', 'sample_data', 'declaration', - ] + ] class PlotterParameterSerializer(ContributionSerializer): @@ -55,8 +55,8 @@ class PlotterParameterSerializer(ContributionSerializer): model = PlotterParameter exclude = [] default_fields = [ - 'name', 'plotter', - ] + 'name', 'plotter', + ] class DefaultPlotterSerializer(DynamicFieldsSerializer): @@ -67,8 +67,8 @@ class DefaultPlotterSerializer(DynamicFieldsSerializer): class Meta(DynamicFieldsSerializer.Meta): model = DefaultPlotter default_fields = [ - 'dataformat', 'plotter', 'parameter', - ] + 'dataformat', 'plotter', 'parameter', + ] #---------------------------------------------------------- diff --git a/beat/web/plotters/templatetags/plotter_tags.py b/beat/web/plotters/templatetags/plotter_tags.py index 5612146e9..0a076e666 100644 --- a/beat/web/plotters/templatetags/plotter_tags.py +++ b/beat/web/plotters/templatetags/plotter_tags.py @@ -54,11 +54,11 @@ def plotter_table(context, objects, owner, id): ''' return dict( - request=context['request'], - objects=objects, - owner=owner, - panel_id=id, - ) + request=context['request'], + objects=objects, + owner=owner, + panel_id=id, + ) @register.inclusion_tag('plotterparameters/panels/table.html', takes_context=True) def plotterparameter_table(context, objects, owner, id): @@ -77,11 +77,11 @@ def plotterparameter_table(context, objects, owner, id): ''' return dict( - request=context['request'], - objects=objects, - owner=owner, - panel_id=id, - ) + request=context['request'], + objects=objects, + owner=owner, + panel_id=id, + ) @register.inclusion_tag('plotterparameters/panels/sample_plot.html', takes_context=True) @@ -104,12 +104,12 @@ def plotterparameter_sampleplot(context, plotterparameter): plotter_sample_data = plotterparameter.plotter.sample_data return dict( - request=context['request'], - plotterparameter=plotterparameter, - plotter=plotter, - plotter_sample_data=plotter_sample_data.replace("\n",""), - panel_id=id, - ) + request=context['request'], + plotterparameter=plotterparameter, + plotter=plotter, + plotter_sample_data=plotter_sample_data.replace("\n",""), + panel_id=id, + ) @register.inclusion_tag('plotterparameters/panels/sample_plot.html', takes_context=True) def plotterparameter_sampleplot_display(context, plotter): @@ -128,12 +128,12 @@ def plotterparameter_sampleplot_display(context, plotter): ''' return dict( - request=context['request'], - plotterparameter=plotterparameter, - plotter=plotter, - plotter_sample_data=plotter_sample_data.replace("\n",""), - panel_id=id, - ) + request=context['request'], + plotterparameter=plotterparameter, + plotter=plotter, + plotter_sample_data=plotter_sample_data.replace("\n",""), + panel_id=id, + ) @register.inclusion_tag('plotterparameters/panels/viewer_editor_fork.html', takes_context=True) def plotterparameter_viewer_editor_fork(context, plotterparameter): @@ -156,14 +156,14 @@ def plotterparameter_viewer_editor_fork(context, plotterparameter): parameters = context['parameters'] return dict( - request=context['request'], - parameters=parameters, - plotterparameter=plotterparameter, - plotter=plotter, - plotter_sample_data=plotter_sample_data, - panel_id=id, - URL_PREFIX=context['URL_PREFIX'], - ) + request=context['request'], + parameters=parameters, + plotterparameter=plotterparameter, + plotter=plotter, + plotter_sample_data=plotter_sample_data, + panel_id=id, + URL_PREFIX=context['URL_PREFIX'], + ) @@ -188,14 +188,14 @@ def plotterparameter_viewer_editor_new_version(context, plotterparameter): parameters = context['parameters'] return dict( - request=context['request'], - parameters=parameters, - plotterparameter=plotterparameter, - plotter=plotter, - plotter_sample_data=plotter_sample_data, - panel_id=id, - URL_PREFIX=context['URL_PREFIX'], - ) + request=context['request'], + parameters=parameters, + plotterparameter=plotterparameter, + plotter=plotter, + plotter_sample_data=plotter_sample_data, + panel_id=id, + URL_PREFIX=context['URL_PREFIX'], + ) @register.inclusion_tag('plotterparameters/panels/viewer_editor.html', takes_context=True) @@ -220,13 +220,13 @@ def plotterparameter_viewer_editor(context, plotterparameter): plotter_sample_data = None return dict( - request=context['request'], - plotterparameter=plotterparameter, - plotter=plotter, - plotter_sample_data=plotter_sample_data, - panel_id=id, - URL_PREFIX=context['URL_PREFIX'], - ) + request=context['request'], + plotterparameter=plotterparameter, + plotter=plotter, + plotter_sample_data=plotter_sample_data, + panel_id=id, + URL_PREFIX=context['URL_PREFIX'], + ) else: plotter = plotterparameter.plotter @@ -235,13 +235,13 @@ def plotterparameter_viewer_editor(context, plotterparameter): plotter_sample_data = plotterparameter.plotter.sample_data return dict( - request=context['request'], - plotterparameter=plotterparameter, - plotter=plotter, - plotter_sample_data=plotter_sample_data, - panel_id=id, - URL_PREFIX=context['URL_PREFIX'], - ) + request=context['request'], + plotterparameter=plotterparameter, + plotter=plotter, + plotter_sample_data=plotter_sample_data, + panel_id=id, + URL_PREFIX=context['URL_PREFIX'], + ) @register.inclusion_tag('plotterparameters/panels/viewer_editor_tuner.html', takes_context=True) @@ -266,13 +266,13 @@ def plotterparameter_viewer_editor_tuner(context, plotterparameter): plotter_sample_data = plotterparameter.plotter.sample_data return dict( - request=context['request'], - plotterparameter=plotterparameter, - plotter=plotter, - plotter_sample_data=plotter_sample_data, - panel_id=id, - URL_PREFIX=context['URL_PREFIX'], - ) + request=context['request'], + plotterparameter=plotterparameter, + plotter=plotter, + plotter_sample_data=plotter_sample_data, + panel_id=id, + URL_PREFIX=context['URL_PREFIX'], + ) @register.inclusion_tag('plotters/panels/actions.html', takes_context=True) @@ -291,10 +291,10 @@ def plotter_actions(context, object, display_count): ''' return dict( - request=context['request'], - object=object, - display_count=display_count, - ) + request=context['request'], + object=object, + display_count=display_count, + ) @register.inclusion_tag('plotterparameters/panels/actions.html', takes_context=True) @@ -313,10 +313,10 @@ def plotterparameter_actions(context, object, display_count): ''' return dict( - request=context['request'], - object=object, - display_count=display_count, - ) + request=context['request'], + object=object, + display_count=display_count, + ) @register.inclusion_tag('plotterparameters/panels/sharing.html', takes_context=True) @@ -330,12 +330,12 @@ def plotterparameter_sharing(context, obj): ''' return { - 'request': context['request'], + 'request': context['request'], 'object': obj, 'owner': context['request'].user == obj.author, 'users': context['users'], 'teams': context['teams'], - } + } @register.inclusion_tag('plotters/panels/sharing.html', takes_context=True) @@ -349,12 +349,12 @@ def plotter_sharing(context, obj): ''' return { - 'request': context['request'], + 'request': context['request'], 'object': obj, 'owner': context['request'].user == obj.author, 'users': context['users'], 'teams': context['teams'], - } + } @register.inclusion_tag('plotters/panels/viewer.html', takes_context=True) @@ -372,12 +372,12 @@ def plotter_viewer(context, obj, xp, id): ''' return { - 'request': context['request'], + 'request': context['request'], 'object': obj, 'xp': xp, 'panel_id': id, 'URL_PREFIX': settings.URL_PREFIX, - } + } @register.assignment_tag(takes_context=True) @@ -406,7 +406,7 @@ def visible_reports(context, object): return object.reports.filter(Q(status=Report.PUBLISHED)) else: return object.reports.filter(Q(author=context['request'].user) | - Q(status=Report.PUBLISHED)) + Q(status=Report.PUBLISHED)) #---------------------------------------------------------------- @@ -416,10 +416,10 @@ def visible_reports(context, object): def plotter_editor(context, obj): request = context['request'] return { - 'owner': request.user == obj.author, + 'owner': request.user == obj.author, 'object': obj, 'open_source': obj.open_source(request.user), - } + } @@ -459,8 +459,8 @@ register.inclusion_tag('plotterparameters/dialogs/plotterparameter_created.html' def plotterparameter_merged_parameters(context, plotter, plotterparameter): request = context['request'] return { - 'owner': request.user == plotter.author, + 'owner': request.user == plotter.author, 'object': plotter, 'plotterparameter': plotterparameter, 'open_source': plotter.open_source(request.user), - } + } diff --git a/beat/web/plotters/tests.py b/beat/web/plotters/tests.py index 454169914..31adff841 100644 --- a/beat/web/plotters/tests.py +++ b/beat/web/plotters/tests.py @@ -66,9 +66,9 @@ class PlotterParameterTestCase(APITestCase): name='text', short_description='description', declaration={ - "text": "string" - }, - ) + "text": "string" + }, + ) assert dataformat, errors @@ -83,7 +83,7 @@ class PlotterParameterTestCase(APITestCase): 'description':'some longer description plotter',\ 'declaration':{"language": "python","parameters":{},"dataformat":"plot/text/1"},\ 'code':'#test'\ - } + } response = self.client.post(self.url_plotter, self.data_plotter, format='json') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.plotter = Plotter.objects.get(name='plotter_test') @@ -112,7 +112,7 @@ class PlotterParameterCreationTestCase(PlotterParameterTestCase): 'short_description':'some description',\ 'description':'some longer description',\ 'plotter':self.plotter.id\ - } + } def test_anonymous_user(self): response = self.client.post(self.url, self.data, format='json') @@ -155,7 +155,7 @@ class PlotterParameterListTestCase(PlotterParameterTestCase): 'short_description':'some description',\ 'description':'some longer description',\ 'plotter':self.plotter.id\ - } + } self.data2 = {\ #'author':self.johndoe,\ @@ -163,7 +163,7 @@ class PlotterParameterListTestCase(PlotterParameterTestCase): 'short_description':'some description2',\ 'description':'some longer description2',\ 'plotter':self.plotter.id\ - } + } def test_anonymous_user(self): response = self.client.get(self.url, format='json') @@ -217,13 +217,13 @@ class PlotterParameterRetrievalTestCase(PlotterParameterTestCase): 'author_name': self.johndoe.username, 'object_name': 'plotterparameter1', 'version': 1, - }) + }) self.url_single_plotterparameter2 = reverse('api_plotters:view', kwargs={ 'author_name': self.johndoe.username, 'object_name': 'plotterparameter2', 'version': 1, - }) + }) self.data = {\ #'author':self.johndoe,\ @@ -231,7 +231,7 @@ class PlotterParameterRetrievalTestCase(PlotterParameterTestCase): 'short_description':'some description',\ 'description':'some longer description',\ 'plotter':self.plotter.id\ - } + } self.data2 = {\ #'author':self.johndoe,\ @@ -239,7 +239,7 @@ class PlotterParameterRetrievalTestCase(PlotterParameterTestCase): 'short_description':'some description2',\ 'description':'some longer description2',\ 'plotter':self.plotter.id\ - } + } def test_anonymous_user(self): response = self.client.get(self.url_single_plotterparameter, format='json') @@ -296,13 +296,13 @@ class PlotterParameterUpdateTestCase(PlotterParameterTestCase): 'author_name': self.johndoe.username, 'object_name': 'plotterparameter1', 'version': 1, - }) + }) self.url_single_plotterparameter2 = reverse('api_plotters:view', kwargs={ 'author_name': self.johndoe.username, 'object_name': 'plotterparameter2', 'version': 1, - }) + }) self.data = {\ #'author':self.johndoe,\ @@ -310,7 +310,7 @@ class PlotterParameterUpdateTestCase(PlotterParameterTestCase): 'short_description':'some description',\ 'description':'some longer description',\ 'plotter':self.plotter.id\ - } + } self.data2 = {\ #'author':self.johndoe,\ @@ -318,7 +318,7 @@ class PlotterParameterUpdateTestCase(PlotterParameterTestCase): 'short_description':'some description2',\ 'description':'some longer description2',\ 'plotter':self.plotter.id\ - } + } def test_anonymous_user(self): response = self.client.get(self.url_single_plotterparameter, format='json') @@ -375,13 +375,13 @@ class PlotterParameterDeletionTestCase(PlotterParameterTestCase): 'author_name': self.johndoe.username, 'object_name': 'plotterparameter1', 'version': 1, - }) + }) self.url_single_plotterparameter2 = reverse('api_plotters:view', kwargs={ 'author_name': self.johndoe.username, 'object_name': 'plotterparameter2', 'version': 1, - }) + }) self.data = {\ #'author':self.johndoe,\ @@ -389,7 +389,7 @@ class PlotterParameterDeletionTestCase(PlotterParameterTestCase): 'short_description':'some description',\ 'description':'some longer description',\ 'plotter':self.plotter.id\ - } + } self.data2 = {\ #'author':self.johndoe,\ @@ -397,7 +397,7 @@ class PlotterParameterDeletionTestCase(PlotterParameterTestCase): 'short_description':'some description2',\ 'description':'some longer description2',\ 'plotter':self.plotter.id\ - } + } def test_anonymous_user(self): response = self.client.get(self.url_single_plotterparameter, format='json') diff --git a/beat/web/plotters/urls.py b/beat/web/plotters/urls.py index 44b2f2a23..f7fd9cad4 100644 --- a/beat/web/plotters/urls.py +++ b/beat/web/plotters/urls.py @@ -33,14 +33,14 @@ partial_patterns = [ url(r'^plotinfo/$', views.PartialGroupView.as_view( template_name='plotterparameters/partials/plotgraphicinfo.html', - ), + ), name='plotinfo', ), url(r'^plotparamsinfo/$', views.PartialGroupView.as_view( template_name='plotterparameters/partials/plotparamsinfo.html', - ), + ), name='plotinfo', ), @@ -121,7 +121,7 @@ urlpatterns = [ r'^plotterparameter/(?P<author_name>\w+)/(?P<plotterparameter_name>[-\w]+)/(?P<version>\d+)/$', views.plotterparameter_for_author, name='plotterparameter-author-view', - ), + ), url( r'^(?P<author>\w+)/(?P<name>[-\w]+)/(?P<version>\d+)/$', diff --git a/beat/web/plotters/views.py b/beat/web/plotters/views.py index b7af439ef..71a9b2704 100644 --- a/beat/web/plotters/views.py +++ b/beat/web/plotters/views.py @@ -115,14 +115,14 @@ def plot(request): report_experiments or use.getlist('experiment') or use.getlist('experiment[]'), itertools.cycle(use.getlist('analyzer') or use.getlist('analyzer[]')), itertools.cycle(use.getlist('output') or use.getlist('output[]')), - ): + ): experiments[xpid] = { - 'analyzer': analyzer, + 'analyzer': analyzer, 'output': output, - } + } keywords = [ - 'experiment', + 'experiment', 'experiment[]', 'analyzer', 'analyzer[]', @@ -131,7 +131,7 @@ def plot(request): 'plotter', 'parameter', 'report_number', - ] + ] extra_parameters = {} for key in [k for k in use.keys() if k not in keywords]: @@ -154,11 +154,11 @@ def plot(request): toolchain__name=ts.name, toolchain__version=ts.version, name=es.name, - ) + ) except Experiment.DoesNotExist as e: message = "Experiment `%s' is not accessible" \ - % '/'.join((es.username, ts.username, ts.name, ts.version, - es.name)) + % '/'.join((es.username, ts.username, ts.name, ts.version, + es.name)) logger.warn(message) return HttpResponseBadRequest(message) @@ -183,10 +183,10 @@ def plot(request): username, name, version = use['plotter'].split('/') try: final_plotter = Plotter.objects.get(author__username=username, - name=name, version=version) + name=name, version=version) except Plotter.DoesNotExist as e: message = "Plotter `%s' is not accessible" % \ - '/'.join((username, name, version)) + '/'.join((username, name, version)) logger.warn(message) return HttpResponseBadRequest(message) @@ -194,13 +194,13 @@ def plot(request): username, name, version = use['parameter'].split('/') try: user_parameter = PlotterParameter.objects.get( - author__username=username, - name=name, - version=version, - ) + author__username=username, + name=name, + version=version, + ) except PlotterParameter.DoesNotExist as e: message = "Parameter `%s' is not accessible" % \ - '/'.join((username, name, version)) + '/'.join((username, name, version)) logger.warn(message) return HttpResponseBadRequest(message) @@ -212,30 +212,30 @@ def plot(request): (analyzer_author, analyzer_name, analyzer_version) = v['analyzer'].split('/') xp = v['obj'] block = get_object_or_404(Block, - experiment=v['obj'], - algorithm__author__username=analyzer_author, - algorithm__name=analyzer_name, - algorithm__version=analyzer_version, - ) + experiment=v['obj'], + algorithm__author__username=analyzer_author, + algorithm__name=analyzer_name, + algorithm__version=analyzer_version, + ) else: block = get_object_or_404(Block, - experiment=v['obj'], - name=v['analyzer'], - ) + experiment=v['obj'], + name=v['analyzer'], + ) result = get_object_or_404(Result, - cache=block.outputs.get(), - name=v['output'], - ) + cache=block.outputs.get(), + name=v['output'], + ) # now decide if the chart is compatible username, name, version = result.type.split('/') try: dfobj = DataFormat.objects.get(author__username=username, - name=name, version=int(version)) + name=name, version=int(version)) except DataFormat.DoesNotExist as e: message = "Data format `%s' is not accessible" % \ - '/'.join((username, name, version)) + '/'.join((username, name, version)) logger.warn(message) return HttpResponseBadRequest(message) @@ -344,7 +344,7 @@ def plot_sample(request): return HttpResponseBadRequest('This view must be called with either a GET or POST request') keywords = [ - 'experiment', + 'experiment', 'experiment[]', 'analyzer', 'analyzer[]', @@ -353,7 +353,7 @@ def plot_sample(request): 'plotter', 'parameter', 'report_number', - ] + ] extra_parameters = {} for key in [k for k in use.keys() if k not in keywords]: @@ -368,10 +368,10 @@ def plot_sample(request): username, name, version = use['plotter'].split('/') try: final_plotter = Plotter.objects.get(author__username=username, - name=name, version=version) + name=name, version=version) except Plotter.DoesNotExist as e: message = "Plotter `%s' is not accessible" % \ - '/'.join((username, name, version)) + '/'.join((username, name, version)) logger.warn(message) return HttpResponseBadRequest(message) @@ -379,13 +379,13 @@ def plot_sample(request): username, name, version = use['parameter'].split('/') try: user_parameter = PlotterParameter.objects.get( - author__username=username, - name=name, - version=version, - ) + author__username=username, + name=name, + version=version, + ) except PlotterParameter.DoesNotExist as e: message = "Parameter `%s' is not accessible" % \ - '/'.join((username, name, version)) + '/'.join((username, name, version)) logger.warn(message) return HttpResponseBadRequest(message) @@ -492,7 +492,7 @@ def plot_sample_with_params(request): return HttpResponseBadRequest('This view must be called with either a GET or POST request') keywords = [ - 'experiment', + 'experiment', 'experiment[]', 'analyzer', 'analyzer[]', @@ -501,7 +501,7 @@ def plot_sample_with_params(request): 'plotter', #'parameter', 'report_number', - ] + ] extra_parameters = {} for key in [k for k in use.keys() if k not in keywords]: @@ -516,10 +516,10 @@ def plot_sample_with_params(request): username, name, version = use['plotter'].split('/') try: final_plotter = Plotter.objects.get(author__username=username, - name=name, version=version) + name=name, version=version) except Plotter.DoesNotExist as e: message = "Plotter `%s' is not accessible" % \ - '/'.join((username, name, version)) + '/'.join((username, name, version)) logger.warn(message) return HttpResponseBadRequest(message) @@ -591,14 +591,14 @@ def view(request, author, name, version=None): # Retrieves the algorithm if version: plotter = get_object_or_404( - Plotter, - author__username__iexact=author, - name__iexact=name, - version=int(version), - ) + Plotter, + author__username__iexact=author, + name__iexact=name, + version=int(version), + ) else: plotter = Plotter.objects.filter(author__username__iexact=author, - name__iexact=name).order_by('-version') + name__iexact=name).order_by('-version') if not plotter: raise Http404() else: @@ -640,13 +640,13 @@ def list_plotters(request): owner=(request.user==author) return render_to_response('plotters/list.html', - dict( - objects=objects, - author=author, - owner=owner, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=author, + owner=owner, + ), + context_instance=RequestContext(request), + ) #---------------------------------------------------------- @@ -658,13 +658,13 @@ def list_plotters_public(request): objects=Plotter.objects.public().order_by('-creation_date') return render_to_response('plotters/list.html', - dict( - objects=objects, - author=request.user, #anonymous - owner=False, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=request.user, #anonymous + owner=False, + ), + context_instance=RequestContext(request), + ) #---------------------------------------------------------- @@ -682,13 +682,13 @@ def list_plotterparameters(request, author_name): owner=(request.user==author) return render_to_response('plotterparameters/list.html', - dict( - objects=objects, - author=author, - owner=owner, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=author, + owner=owner, + ), + context_instance=RequestContext(request), + ) #---------------------------------------------------------- @@ -702,13 +702,13 @@ def list_plotterparameters_public(request): objects = PlotterParameter.filter_latest_versions(objects) return render_to_response('plotterparameters/list.html', - dict( - objects=objects, - author=request.user, #anonymous - owner=False, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=request.user, #anonymous + owner=False, + ), + context_instance=RequestContext(request), + ) #---------------------------------------------------------- @@ -719,20 +719,20 @@ def plotterparameter_latest(request, author, name): # check that the user exists on the system objects = PlotterParameter.objects.filter( - author__username__iexact=author, - name__iexact=name, -).order_by('-creation_date') + author__username__iexact=author, + name__iexact=name, + ).order_by('-creation_date') objects = PlotterParameter.filter_latest_versions(objects) return render_to_response('plotterparameters/list.html', - dict( - objects=objects, - author=request.user, #anonymous - owner=False, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=request.user, #anonymous + owner=False, + ), + context_instance=RequestContext(request), + ) @@ -743,9 +743,9 @@ def plotterparameter_for_author(request, author_name, plotterparameter_name, ver # get the query from the DB obj = get_object_or_404(PlotterParameter, - author__username = author_name, - name = plotterparameter_name, - version = version) + author__username = author_name, + name = plotterparameter_name, + version = version) plotter_origin = Plotter.objects.get(id=obj.plotter.id) @@ -759,17 +759,17 @@ def plotterparameter_for_author(request, author_name, plotterparameter_name, ver users = User.objects.exclude(username__in=settings.ACCOUNTS_TO_EXCLUDE_FROM_TEAMS).order_by('username') return render_to_response('plotterparameters/plotterparameter.html', - { - 'author' : author_name, - 'plotterparameter_name' : plotterparameter_name, - 'owner' : (request.user == obj.author), - 'users': users, - 'teams': Team.objects.for_user(request.user, True), - 'plotterparameter' : obj, - 'plotter_origin' : plotter_origin, - 'USE_HTTPS_GRAVATAR': settings.USE_HTTPS_GRAVATAR, - }, - context_instance=RequestContext(request)) + { + 'author' : author_name, + 'plotterparameter_name' : plotterparameter_name, + 'owner' : (request.user == obj.author), + 'users': users, + 'teams': Team.objects.for_user(request.user, True), + 'plotterparameter' : obj, + 'plotter_origin' : plotter_origin, + 'USE_HTTPS_GRAVATAR': settings.USE_HTTPS_GRAVATAR, + }, + context_instance=RequestContext(request)) #---------------------------------------------------------- @@ -781,20 +781,20 @@ def diff(request, author1, name1, version1, author2, name2, version2): """ plotterparameter1 = get_object_or_404( - PlotterParameter, - author__username__iexact=author1, - name__iexact=name1, - version=int(version1), - ) + PlotterParameter, + author__username__iexact=author1, + name__iexact=name1, + version=int(version1), + ) has_access, _ = plotterparameter1.accessibility_for(request.user) if not has_access: raise Http404() plotterparameter2 = get_object_or_404( - PlotterParameter, - author__username__iexact=author2, - name__iexact=name2, - version=int(version2), - ) + PlotterParameter, + author__username__iexact=author2, + name__iexact=name2, + version=int(version2), + ) has_access, _ = plotterparameter2.accessibility_for(request.user) if not has_access: raise Http404() @@ -823,16 +823,16 @@ def create_plotterparameter(request, author_name): owner=(request.user==author) return render_to_response('plotterparameters/plotterparameter.html', - dict( - objects=objects, - author=author, - owner=owner, - plotterparameter_name="CREATION_MODE", - plotterparameter="CREATION_MODE", - USE_HTTPS_GRAVATAR=settings.USE_HTTPS_GRAVATAR, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=author, + owner=owner, + plotterparameter_name="CREATION_MODE", + plotterparameter="CREATION_MODE", + USE_HTTPS_GRAVATAR=settings.USE_HTTPS_GRAVATAR, + ), + context_instance=RequestContext(request), + ) #------------------------------------------------ @@ -856,10 +856,10 @@ def create_new_version(request, author_name=None, plotterparameter_name=None, ve plotterparameter = None if plotterparameter_name is not None: previous_versions = PlotterParameter.objects.filter( - author=request.user, - name__iexact=plotterparameter_name, - version=version, - ).order_by('-version') + author=request.user, + name__iexact=plotterparameter_name, + version=version, + ).order_by('-version') if len(previous_versions) == 0: raise Http404() @@ -878,16 +878,16 @@ def create_new_version(request, author_name=None, plotterparameter_name=None, ve parameters['declaration'] = simplejson.dumps(declaration) return render_to_response('plotterparameters/plotterparameter.html', - dict( - author=request.user.username, - parameters=parameters, - plotterparameter_name=plotterparameter_name, - plotterparameter=plotterparameter, - owner=(request.user == plotterparameter.author), - plotterparameter_mode="NEW_VERSION_MODE", - ), - context_instance=RequestContext(request), - ) + dict( + author=request.user.username, + parameters=parameters, + plotterparameter_name=plotterparameter_name, + plotterparameter=plotterparameter, + owner=(request.user == plotterparameter.author), + plotterparameter_mode="NEW_VERSION_MODE", + ), + context_instance=RequestContext(request), + ) @login_required @@ -907,7 +907,7 @@ def fork(request, author_name, plotterparameter_name, version): description = fork_of.description parameters = { - 'plotterparameter_author': author_name, + 'plotterparameter_author': author_name, 'plotterparameter_name': plotterparameter_name, 'plotterparameter_version': version, 'fork_of': fork_of, @@ -916,19 +916,19 @@ def fork(request, author_name, plotterparameter_name, version): 'errors': '', 'edition': False, 'request_user': request.user.username, - } + } return render_to_response('plotterparameters/plotterparameter.html', - dict( - author=request.user.username, - parameters=parameters, - plotterparameter_name=plotterparameter_name, - plotterparameter=fork_of, - owner=(request.user == fork_of.author), - plotterparameter_mode="FORK_MODE", - ), - context_instance=RequestContext(request), - ) + dict( + author=request.user.username, + parameters=parameters, + plotterparameter_name=plotterparameter_name, + plotterparameter=fork_of, + owner=(request.user == fork_of.author), + plotterparameter_mode="FORK_MODE", + ), + context_instance=RequestContext(request), + ) diff --git a/beat/web/reports/admin.py b/beat/web/reports/admin.py index 705f488cf..c70113a71 100644 --- a/beat/web/reports/admin.py +++ b/beat/web/reports/admin.py @@ -44,15 +44,15 @@ import simplejson as json class ReportModelForm(forms.ModelForm): description = CodeMirrorRSTCharField( - label='Description', - required=False, - help_text=Messages['description'], - ) + label='Description', + required=False, + help_text=Messages['description'], + ) content = CodeMirrorJSONCharField( - label='Content', - help_text=Messages['json'], - ) + label='Content', + help_text=Messages['json'], + ) def clean_content(self): """Cleans-up the content data, make sure it is really new""" @@ -77,37 +77,37 @@ class ReportAdmin(admin.ModelAdmin): fieldsets = ( (None, - dict( - fields=('status', 'name', 'number', 'author',), - ), + dict( + fields=('status', 'name', 'number', 'author',), + ), ), ('Dates', - dict( - classes=('collapse',), - fields=('creation_date', 'expiration_date', 'publication_date',), - ), + dict( + classes=('collapse',), + fields=('creation_date', 'expiration_date', 'publication_date',), + ), ), ('Documentation', - dict( - classes=('collapse',), - fields=('short_description', 'description',), - ), + dict( + classes=('collapse',), + fields=('short_description', 'description',), + ), ), (None, - dict( - fields=('analyzer', 'experiments', 'referenced_plotters', 'referenced_plotterparameters', 'content',), - ), + dict( + fields=('analyzer', 'experiments', 'referenced_plotters', 'referenced_plotterparameters', 'content',), + ), ), - ) + ) list_display = ('id', 'name', 'number', 'author', 'creation_date', 'expiration_date', 'publication_date') search_fields = [ - 'author__username', + 'author__username', 'name', 'short_description', 'description', 'number', - ] + ] list_display_links = ('id', 'name') list_filter = ('author', 'name') diff --git a/beat/web/reports/management/commands/clean_report.py b/beat/web/reports/management/commands/clean_report.py index 7be69d626..852614491 100644 --- a/beat/web/reports/management/commands/clean_report.py +++ b/beat/web/reports/management/commands/clean_report.py @@ -42,7 +42,7 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--noinput', action='store_false', dest='interactive', default=True, - help=('Tells Django to NOT prompt the user for input of any kind.')) + help=('Tells Django to NOT prompt the user for input of any kind.')) def handle(self, *args, **options): diff --git a/beat/web/reports/management/commands/send_report_cleanup_warning_and_cleanup.py b/beat/web/reports/management/commands/send_report_cleanup_warning_and_cleanup.py index 03a0b863a..8395bee42 100644 --- a/beat/web/reports/management/commands/send_report_cleanup_warning_and_cleanup.py +++ b/beat/web/reports/management/commands/send_report_cleanup_warning_and_cleanup.py @@ -50,7 +50,7 @@ class Command(BaseCommand): expiration_date = date.today() + timedelta(days=expiration_reminder) reports_about_to_expire = Report.objects.filter(status=Report.LOCKED, expiration_date__range=(datetime.combine(expiration_date, time.min), - datetime.combine(expiration_date, time.max))) + datetime.combine(expiration_date, time.max))) if reports_about_to_expire: current_site = Site.objects.get_current() template_path = 'reports/report_about_to_expire_email.txt' @@ -61,10 +61,10 @@ class Command(BaseCommand): send_mail(subject, render_to_string(template_path, { - 'report': report, + 'report': report, 'beat_version': __version__, 'site': current_site, - } + } ), settings.DEFAULT_FROM_EMAIL, [report.author.email]) diff --git a/beat/web/reports/migrations/0004_auto_20170410_1121.py b/beat/web/reports/migrations/0004_auto_20170410_1121.py index c2206e36f..7e6755f71 100644 --- a/beat/web/reports/migrations/0004_auto_20170410_1121.py +++ b/beat/web/reports/migrations/0004_auto_20170410_1121.py @@ -10,10 +10,10 @@ import re # and returns a table in the new representation def parse_table(table, precision): conv_table = { - 'itemName': 'Table', + 'itemName': 'Table', 'fields': ['Experiment'], 'precision': precision - } + } for row in table: if not row['selected']: @@ -47,7 +47,7 @@ def parse_plot(plot): 'itemName': plot['required_plotter'][0], 'name': plot['data']['output'][0], 'type': plot['required_plotter'][0] - } + } return conv_plot # helper func to build the experiment's full name @@ -87,14 +87,14 @@ def move_content_to_groups_format(apps, schema_editor): groups = {} # default to just one group that contains all experiments/items group1 = { - # list of experiments in the group + # list of experiments in the group 'experiments': [ experiment_fullname(e) for e in exps ], 'reportItems': [], # analyzer of the report 'analyzer': analyzer_fullname(report) if report.analyzer else '', 'aliases': {}, 'idx': 1 - } + } old_aliases = report_content['alias_experiments'] if 'alias_experiments' in report_content else {} # assign aliases @@ -124,9 +124,9 @@ def move_content_to_groups_format(apps, schema_editor): count_plots += 1 converted_item = { - 'id': converted_id, + 'id': converted_id, 'content': converted_content - } + } group1['reportItems'].append(converted_item) @@ -143,5 +143,5 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RunPython(move_content_to_groups_format) + migrations.RunPython(move_content_to_groups_format) ] diff --git a/beat/web/reports/models.py b/beat/web/reports/models.py index 442effbd0..e7235b3dc 100644 --- a/beat/web/reports/models.py +++ b/beat/web/reports/models.py @@ -139,51 +139,51 @@ class Report(models.Model): def get_absolute_url(self): return reverse( - 'reports:view', + 'reports:view', args=( self.number, - ), - ) + ), + ) def get_author_absolute_url(self): return reverse( - 'reports:author-view', + 'reports:author-view', args=( self.author.username, self.name - ), - ) + ), + ) def get_api_update_url(self): return reverse( - 'api_reports:object', + 'api_reports:object', args=( self.author.username, self.name - ), - ) + ), + ) def get_api_add_url(self): return reverse( - 'api_reports:add_experiments', + 'api_reports:add_experiments', args=( self.author.username, self.name - ), - ) + ), + ) def get_api_remove_url(self): return reverse( - 'api_reports:remove_experiments', + 'api_reports:remove_experiments', args=( self.author.username, self.name - ), - ) + ), + ) def save(self, *args, **kwargs): diff --git a/beat/web/reports/templatetags/report_tags.py b/beat/web/reports/templatetags/report_tags.py index 427402f92..7827dc5d7 100644 --- a/beat/web/reports/templatetags/report_tags.py +++ b/beat/web/reports/templatetags/report_tags.py @@ -57,11 +57,11 @@ def report_table(context, objects, owner, id): objects = objects.annotate(updated=Coalesce('publication_date', 'creation_date',)).order_by('-updated') return dict( - request=context['request'], - objects=objects, - owner=owner, - panel_id=id, - ) + request=context['request'], + objects=objects, + owner=owner, + panel_id=id, + ) #-------------------------------------------------- @@ -70,10 +70,10 @@ def report_table(context, objects, owner, id): @register.inclusion_tag('reports/panels/breadcrumb.html', takes_context=True) def report_breadcrumb(context, obj): return { - 'request': context['request'], + 'request': context['request'], 'owner': context['owner'], 'object': obj, - } + } #-------------------------------------------------- @@ -95,10 +95,10 @@ def report_actions(context, object, display_count): ''' return dict( - request=context['request'], - object=object, - display_count=display_count, - ) + request=context['request'], + object=object, + display_count=display_count, + ) #-------------------------------------------------- @@ -122,13 +122,13 @@ def report_viewer(context, object, owner, report_number): ''' return dict( - request=context['request'], - object=object, - owner=owner, - exps=object.experiments.all(), - report_number=report_number, - URL_PREFIX=context['URL_PREFIX'], - ) + request=context['request'], + object=object, + owner=owner, + exps=object.experiments.all(), + report_number=report_number, + URL_PREFIX=context['URL_PREFIX'], + ) #-------------------------------------------------- diff --git a/beat/web/reports/tests.py b/beat/web/reports/tests.py index 2da6c2f42..ff9b6185a 100755 --- a/beat/web/reports/tests.py +++ b/beat/web/reports/tests.py @@ -78,12 +78,12 @@ class ReportTestCase(APITestCase): "output1": "johndoe/single_integer/1", "output2": "johndoe/single_integer/1", "output3": "johndoe/single_integer/1" - } } - ] - } - ] - } + } + ] + } + ] + } TOOLCHAIN_ONE_ANALYZER = { @@ -92,74 +92,74 @@ class ReportTestCase(APITestCase): "inputs": [ "a", "b" - ], + ], "outputs": [ "sum" - ], + ], "synchronized_channel": "dataset1" - }, + }, { "name": "addition2", "inputs": [ "a", "b" - ], + ], "outputs": [ "sum" - ], + ], "synchronized_channel": "dataset1" - } - ], + } + ], "datasets": [ { "name": "dataset1", "outputs": [ "output1", "output2", "output3" - ] - } - ], + ] + } + ], "connections": [ { - "from": "dataset1.output1", + "from": "dataset1.output1", "to": "addition1.a", "channel": "dataset1" - }, + }, { "from": "dataset1.output2", "to": "addition1.b", "channel": "dataset1" - }, + }, { "from": "addition1.sum", "to": "addition2.a", "channel": "dataset1" - }, + }, { "from": "dataset1.output3", "to": "addition2.b", "channel": "dataset1" - }, + }, { "to": "analysis.input", "from": "addition2.sum", "channel": "dataset1" - } - ], + } + ], "analyzers": [ - { - "inputs": [ - "input" - ], - "synchronized_channel": "dataset1", - "name": "analysis" - } + { + "inputs": [ + "input" ], + "synchronized_channel": "dataset1", + "name": "analysis" + } + ], "representation": { - "connections": {}, + "connections": {}, "blocks": {}, "channel_colors": {}, - }, - } + }, + } TOOLCHAIN_TWO_ANALYZERS = { @@ -168,88 +168,88 @@ class ReportTestCase(APITestCase): "inputs": [ "a", "b" - ], + ], "outputs": [ "sum" - ], + ], "synchronized_channel": "dataset1" - }, + }, { "name": "addition2", "inputs": [ "a", "b" - ], + ], "outputs": [ "sum" - ], + ], "synchronized_channel": "dataset1" - } - ], + } + ], "datasets": [ { "name": "dataset1", "outputs": [ "output1", "output2", "output3" - ] - } - ], + ] + } + ], "connections": [ { "from": "dataset1.output1", "to": "addition1.a", "channel": "dataset1" - }, + }, { "from": "dataset1.output2", "to": "addition1.b", "channel": "dataset1" - }, + }, { "from": "addition1.sum", "to": "addition2.a", "channel": "dataset1" - }, + }, { "from": "dataset1.output3", "to": "addition2.b", "channel": "dataset1" - }, + }, { "to": "analysis.input", "from": "addition2.sum", "channel": "dataset1" - }, + }, { "to": "analysis2.input", "from": "addition2.sum", "channel": "dataset1" - } + } - ], + ], "analyzers": [ - { - "inputs": [ - "input" - ], - "synchronized_channel": "dataset1", + { + "inputs": [ + "input" + ], + "synchronized_channel": "dataset1", "name": "analysis" - }, - { - "inputs": [ - "input" - ], - "synchronized_channel": "dataset1", + }, + { + "inputs": [ + "input" + ], + "synchronized_channel": "dataset1", "name": "analysis2" - } + } - ], + ], "representation": { - "connections": {}, + "connections": {}, "blocks": {}, "channel_colors": {}, - }, - } + }, + } ALGORITHM_DECLARATION = """{ @@ -507,24 +507,24 @@ class ReportTestCase(APITestCase): # Create a data format for user plot (dataformat_plot, errors) = DataFormat.objects.create_dataformat( - author=self.plot, - name='single_integer', - short_description='description', - declaration={ - "value": "int32" - }, - ) + author=self.plot, + name='single_integer', + short_description='description', + declaration={ + "value": "int32" + }, + ) dataformat_plot.share() # Create a data format (dataformat, errors) = DataFormat.objects.create_dataformat( - author=self.johndoe, - name='single_integer', - short_description='description', - declaration={ - "value": "int32" - }, - ) + author=self.johndoe, + name='single_integer', + short_description='description', + declaration={ + "value": "int32" + }, + ) dataformat.share() @@ -533,7 +533,7 @@ class ReportTestCase(APITestCase): database, errors = Database.objects.create_database( 'integers', declaration=ReportTestCase.DATABASE, - ) + ) database.share() assert database, errors @@ -577,8 +577,8 @@ class ReportTestCase(APITestCase): # Create the toolchains (self.toolchain_one_analyzer, errors) = Toolchain.objects.create_toolchain(self.johndoe, - 'toolchain_one_analyzer', 'short description 1', - declaration=ReportTestCase.TOOLCHAIN_ONE_ANALYZER) + 'toolchain_one_analyzer', 'short description 1', + declaration=ReportTestCase.TOOLCHAIN_ONE_ANALYZER) assert not errors, 'Toolchain errors: %s' % errors @@ -586,8 +586,8 @@ class ReportTestCase(APITestCase): (self.toolchain_two_analyzers, errors) = Toolchain.objects.create_toolchain(self.johndoe, - 'toolctoolchain_two_analyzershain2', 'short description 1', - declaration=ReportTestCase.TOOLCHAIN_TWO_ANALYZERS) + 'toolctoolchain_two_analyzershain2', 'short description 1', + declaration=ReportTestCase.TOOLCHAIN_TWO_ANALYZERS) assert not errors, 'Toolchain errors: %s' % errors @@ -602,25 +602,25 @@ class ReportTestCase(APITestCase): ReportTestCase.CONFIGURATION_ANALYZER2) self.experiment_two_analyzers = self.create_experiment(self.johndoe, self.toolchain_two_analyzers, - 'experiment_two_analyzers', - ReportTestCase.CONFIGURATION_TWO_ANALYZERS) + 'experiment_two_analyzers', + ReportTestCase.CONFIGURATION_TWO_ANALYZERS) self.inaccessible_experiment = self.create_experiment(self.jackdoe, self.toolchain_one_analyzer, 'inaccessible_experiment', ReportTestCase.CONFIGURATION_ANALYZER1) self.no_attestation_other_user_accessible_experiment = self.create_experiment(self.jackdoe, self.toolchain_one_analyzer, - 'no_attestation_other_user_accessible_experiment', - ReportTestCase.CONFIGURATION_ANALYZER1) + 'no_attestation_other_user_accessible_experiment', + ReportTestCase.CONFIGURATION_ANALYZER1) self.no_attestation_other_user_accessible_experiment.share(users=[self.johndoe]) self.attestation_other_user_accessible_experiment = self.create_experiment(self.jackdoe, self.toolchain_one_analyzer, - 'attestation_other_user_accessible_experiment', - ReportTestCase.CONFIGURATION_ANALYZER1) + 'attestation_other_user_accessible_experiment', + ReportTestCase.CONFIGURATION_ANALYZER1) self.attestation_other_user_accessible_experiment.share(users=[self.johndoe]) self.no_attestation_other_user_public_experiment = self.create_experiment(self.jackdoe, self.toolchain_one_analyzer, - 'no_attestation_other_user_public_experiment', - ReportTestCase.CONFIGURATION_ANALYZER1) + 'no_attestation_other_user_public_experiment', + ReportTestCase.CONFIGURATION_ANALYZER1) self.no_attestation_other_user_public_experiment.share() Attestation.objects.create_attestation(self.attestation_other_user_accessible_experiment) @@ -631,7 +631,7 @@ class ReportTestCase(APITestCase): "description": "descr", "language":"python", "parameters":{} - }, + }, ) plotter_1.share(True) # Create some plotterparameters @@ -829,7 +829,7 @@ class ReportCreationTestCase(ReportTestCase): expected_answer = { 'name': '%s/report_new' % self.johndoe.username, 'url': reverse('api_reports:object', kwargs={'owner_name' : self.johndoe.username, - 'report_name': 'report_new' + 'report_name': 'report_new' }), } @@ -849,7 +849,7 @@ class ReportCreationTestCase(ReportTestCase): expected_answer = { 'name': '%s/report_new' % self.johndoe.username, 'url': reverse('api_reports:object', kwargs={'owner_name' : self.johndoe.username, - 'report_name': 'report_new' + 'report_name': 'report_new' }), } @@ -876,7 +876,7 @@ class ReportCreationTestCase(ReportTestCase): expected_answer = { 'name': '%s/report_new' % self.johndoe.username, 'url': reverse('api_reports:object', kwargs={'owner_name' : self.johndoe.username, - 'report_name': 'report_new' + 'report_name': 'report_new' }), } @@ -954,7 +954,7 @@ class EditableReportRetrievalTestCase(ReportTestCase): self.report = self.reportdoe_editable self.url = reverse('api_reports:object', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) def test_anonymous_user(self): @@ -1002,7 +1002,7 @@ class LockedReportRetrievalTestCase(ReportTestCase): self.report = self.reportdoe_locked self.url = reverse('api_reports:object', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) def test_anonymous_user(self): @@ -1052,7 +1052,7 @@ class PublishedReportRetrievalTestCase(ReportTestCase): self.report = self.reportdoe_published self.url = reverse('api_reports:object', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) def test_anonymous_user(self): @@ -1140,7 +1140,7 @@ class EditableReportUpdateTestCase(ReportTestCase): self.report = self.reportdoe_editable self.url = reverse('api_reports:object', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) self.data = { @@ -1185,7 +1185,7 @@ class LockedReportUpdateTestCase(ReportTestCase): self.report = self.reportdoe_locked self.url = reverse('api_reports:object', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) self.data = { @@ -1223,7 +1223,7 @@ class PublishedReportUpdateTestCase(ReportTestCase): self.report = self.reportdoe_published self.url = reverse('api_reports:object', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) self.data = { @@ -1261,7 +1261,7 @@ class EditableReportDeletionTestCase(ReportTestCase): self.report = self.reportdoe_editable self.url = reverse('api_reports:object', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) def test_anonymous_user(self): @@ -1292,7 +1292,7 @@ class LockedReportDeletionTestCase(ReportTestCase): self.report = self.reportdoe_locked self.url = reverse('api_reports:object', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) def test_anonymous_user(self): @@ -1323,7 +1323,7 @@ class PublishedReportDeletionTestCase(ReportTestCase): self.report = self.reportdoe_published self.url = reverse('api_reports:object', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) def test_anonymous_user(self): @@ -1354,11 +1354,11 @@ class EditableReportLockingTestCase(ReportTestCase): self.report = self.reportdoe_editable self.url = reverse('api_reports:lock', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) self.url_add_experiment = reverse('api_reports:add_experiments', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) self.data_experiment = { @@ -1389,7 +1389,7 @@ class EditableReportLockingTestCase(ReportTestCase): } self.url_update_content = reverse('api_reports:object', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) self.data_update_content = { @@ -1397,12 +1397,12 @@ class EditableReportLockingTestCase(ReportTestCase): "description": "lengthy", "experiments": [], "content": { - "chart1":{ - "data":{ - "plotter": "plot/isoroc/1" - }, - "selected_template":"plot/plotterparameter/1" - } + "chart1":{ + "data":{ + "plotter": "plot/isoroc/1" + }, + "selected_template":"plot/plotterparameter/1" + } } } @@ -1543,7 +1543,7 @@ class LockedReportLockingTestCase(ReportTestCase): self.report = self.reportdoe_locked self.url = reverse('api_reports:lock', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) def test_anonymous_user(self): @@ -1574,7 +1574,7 @@ class PublishedReportLockingTestCase(ReportTestCase): self.report = self.reportdoe_published self.url = reverse('api_reports:lock', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) def test_anonymous_user(self): @@ -1605,7 +1605,7 @@ class EditableReportPublishTestCase(ReportTestCase): self.report = self.reportdoe_editable self.url = reverse('api_reports:publish', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) def test_anonymous_user(self): @@ -1636,7 +1636,7 @@ class LockedReportPublishTestCase(ReportTestCase): self.report = self.reportdoe_locked self.url = reverse('api_reports:publish', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) def test_anonymous_user(self): @@ -1669,7 +1669,7 @@ class PublishedReportPublishTestCase(ReportTestCase): self.report = self.reportdoe_published self.url = reverse('api_reports:publish', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) def test_anonymous_user(self): @@ -1700,7 +1700,7 @@ class EditableReportAddExperimentsTestCase(ReportTestCase): self.report = self.reportdoe_editable self.url = reverse('api_reports:add_experiments', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) self.data = { @@ -1875,7 +1875,7 @@ class LockedReportAddExperimentsTestCase(ReportTestCase): self.report = self.reportdoe_locked self.url = reverse('api_reports:add_experiments', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) self.data = { @@ -1912,7 +1912,7 @@ class PublishedReportAddExperimentsTestCase(ReportTestCase): self.report = self.reportdoe_published self.url = reverse('api_reports:add_experiments', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) self.data = { @@ -1949,7 +1949,7 @@ class EditableReportRemoveExperimentsTestCase(ReportTestCase): self.report = self.reportdoe_editable self.url = reverse('api_reports:remove_experiments', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) self.data = { @@ -1996,7 +1996,7 @@ class LockedReportRemoveExperimentsTestCase(ReportTestCase): self.report = self.reportdoe_locked self.url = reverse('api_reports:remove_experiments', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) self.data = { @@ -2033,7 +2033,7 @@ class PublishedReportRemoveExperimentsTestCase(ReportTestCase): self.report = self.reportdoe_published self.url = reverse('api_reports:remove_experiments', kwargs={'owner_name' : self.johndoe.username, - 'report_name': self.report.name + 'report_name': self.report.name }) self.data = { diff --git a/beat/web/reports/urls.py b/beat/web/reports/urls.py index c172273e0..611e5ef7d 100644 --- a/beat/web/reports/urls.py +++ b/beat/web/reports/urls.py @@ -34,21 +34,21 @@ partial_patterns = [ url(r'^reportInfo/$', views.PartialGroupView.as_view( template_name='reports/partials/reportGeneralInfo.html', - ), + ), name='info', ), url(r'^reportTable/$', views.PartialGroupView.as_view( template_name='reports/partials/reportSingleTable.html', - ), + ), name='table', ), url(r'^reportChartDropDown/$', views.PartialGroupView.as_view( template_name='reports/partials/reportChartDropDown.html', - ), + ), name='dropdown', ), @@ -75,18 +75,18 @@ urlpatterns = [ r'^(?P<number>\d+)/$', views.by_number, name='view', - ), + ), url( r'^(?P<author_name>\w+)/$', views.ls, name='list', - ), + ), url( r'^(?P<author_name>\w+)/(?P<report_name>[-\w]+)/$', views.for_author, name='author-view', - ), + ), ] diff --git a/beat/web/reports/views.py b/beat/web/reports/views.py index 0a778fea7..59aa872b8 100644 --- a/beat/web/reports/views.py +++ b/beat/web/reports/views.py @@ -74,14 +74,14 @@ def by_number(request, number): raise Http404('No %s matches the given query.' % Report._meta.object_name) return render_to_response('reports/report.html', - { - 'report_number' : number, - 'owner': False, - 'report': obj, - 'USE_HTTPS_GRAVATAR': settings.USE_HTTPS_GRAVATAR, - 'show_actionbar': show_actionbar(request, obj) - }, - context_instance=RequestContext(request)) + { + 'report_number' : number, + 'owner': False, + 'report': obj, + 'USE_HTTPS_GRAVATAR': settings.USE_HTTPS_GRAVATAR, + 'show_actionbar': show_actionbar(request, obj) + }, + context_instance=RequestContext(request)) #------------------------------------------------ @@ -90,8 +90,8 @@ def by_number(request, number): def for_author(request, author_name, report_name): # get the query from the DB obj = get_object_or_404(Report, - author__username = author_name, - name = report_name) + author__username = author_name, + name = report_name) isAuthor = request.user.username == obj.author.username isEditable = obj.status == 'E' @@ -107,15 +107,15 @@ def for_author(request, author_name, report_name): # only valid when the author is accessing it and its editable if isEditable and isAuthor: return render_to_response('reports/report.html', - { - 'author' : author_name, - 'report_name' : report_name, - 'owner' : (request.user == obj.author), - 'report' : obj, - 'USE_HTTPS_GRAVATAR': settings.USE_HTTPS_GRAVATAR, - 'show_actionbar': show_actionbar(request, obj) - }, - context_instance=RequestContext(request)) + { + 'author' : author_name, + 'report_name' : report_name, + 'owner' : (request.user == obj.author), + 'report' : obj, + 'USE_HTTPS_GRAVATAR': settings.USE_HTTPS_GRAVATAR, + 'show_actionbar': show_actionbar(request, obj) + }, + context_instance=RequestContext(request)) # return 404 raise Http404('No %s matches the given query.' % Report._meta.object_name) @@ -143,13 +143,13 @@ def ls(request, author_name): objects = objects.annotate(updated=Coalesce('publication_date', 'creation_date',)).order_by('-updated') return render_to_response('reports/list.html', - dict( - objects=objects, - author=author, - owner=owner, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=author, + owner=owner, + ), + context_instance=RequestContext(request), + ) #------------------------------------------------ @@ -163,13 +163,13 @@ def public_ls(request): objects = objects.annotate(updated=Coalesce('publication_date', 'creation_date',)).order_by('-updated') return render_to_response('reports/list.html', - dict( - objects=objects, - author=request.user, - owner=False, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=request.user, + owner=False, + ), + context_instance=RequestContext(request), + ) #------------------------------------------------ diff --git a/beat/web/scripts/localhost.py b/beat/web/scripts/localhost.py index 096237031..c1da8a100 100644 --- a/beat/web/scripts/localhost.py +++ b/beat/web/scripts/localhost.py @@ -177,17 +177,17 @@ def start_app(identity, arguments, terminal, exclude, delay=0): return None logger.info("Starting `%s' (%s) with output redirected to `%s'", identity, - ' '.join(arguments), terminal) + ' '.join(arguments), terminal) retval = SubprocessProtocol(identity, arguments, terminal) if delay: twisted.internet.reactor.callLater(delay, - twisted.internet.reactor.spawnProcess, - retval, arguments[0], arguments, - usePTY=True) + twisted.internet.reactor.spawnProcess, + retval, arguments[0], arguments, + usePTY=True) else: twisted.internet.reactor.spawnProcess(retval, arguments[0], arguments, - usePTY=True) + usePTY=True) return retval bindir = os.path.dirname(os.path.realpath(sys.argv[0])) @@ -206,11 +206,11 @@ def get_scheduler_token(account): def main(user_input=None): arguments = docopt.docopt( - __doc__ % dict( - prog=os.path.basename(sys.argv[0]), - nb_cores=__import__('multiprocessing').cpu_count(), + __doc__ % dict( + prog=os.path.basename(sys.argv[0]), + nb_cores=__import__('multiprocessing').cpu_count(), ), - ) + ) # Sets-up logging if arguments['--verbose'] == 1: logging.getLogger().setLevel(logging.INFO) @@ -229,60 +229,60 @@ def main(user_input=None): # Web server, via django web_arguments = [ - DJANGO_BIN, + DJANGO_BIN, 'runserver', '--settings=%s' % arguments['--settings'], '-v%d' % arguments['--verbose'], '--insecure', '--nothreading', - ] + ] web_app = start_app('web', web_arguments, arguments['--web-log'], - arguments['--exclude']) + arguments['--exclude']) # Scheduler, based on Twisted scheduler_arguments = [ - SCHEDULER_BIN, + SCHEDULER_BIN, '--prefix=%s' % arguments['--prefix'], '--period=%s' % arguments['--period'], #seconds '--port=10001', #worker -> scheduler port '--sport=10000', #web -> scheduler port '--web-api=http://127.0.0.1:8000/api/v1', #web API URL '--secret-key=%s' % get_scheduler_token(settings.SCHEDULER_ACCOUNT), - ] + ] if arguments['--verbose']: scheduler_arguments.append('-' + arguments['--verbose']*'v') scheduler_app = start_app('scheduler', scheduler_arguments, - arguments['--scheduler-log'], arguments['--exclude']) + arguments['--scheduler-log'], arguments['--exclude']) # Queue configuration commander - bound to the scheduler qconf_arguments = [ - DJANGO_BIN, + DJANGO_BIN, 'qconf', '--settings=%s' % arguments['--settings'], '-v%d' % arguments['--verbose'], - ] + ] if arguments['--exclude'] == 'scheduler': qconf_exclude = 'qconf' else: qconf_exclude = 'run' qconf_app = start_app('qconf', qconf_arguments, - arguments['--scheduler-log'], qconf_exclude, delay=5) + arguments['--scheduler-log'], qconf_exclude, delay=5) # Worker, also based on Twisted from ..backend.models import Worker worker_arguments = [ - WORKER_BIN, + WORKER_BIN, '--prefix=%s' % arguments['--prefix'], '--port=10001', #scheduler port '--name=%s' % Worker.objects.order_by('id').first().name, '--period=%s' % arguments['--period'], #seconds '--cores=%s' % arguments['--cores'], '--keep-erred-configuration', - ] + ] if arguments['--verbose']: worker_arguments.append('-' + arguments['--verbose']*'v') worker_app = start_app('worker', worker_arguments, - arguments['--worker-log'], arguments['--exclude']) + arguments['--worker-log'], arguments['--exclude']) sys.exit(twisted.internet.reactor.run()) diff --git a/beat/web/scripts/process.py b/beat/web/scripts/process.py index 326a12b16..94fa76352 100755 --- a/beat/web/scripts/process.py +++ b/beat/web/scripts/process.py @@ -71,10 +71,10 @@ import logging def main(user_input=None): arguments = docopt.docopt( - __doc__ % dict( - prog=os.path.basename(sys.argv[0]), + __doc__ % dict( + prog=os.path.basename(sys.argv[0]), ), - ) + ) # Initializes the Django framework os.environ.setdefault('DJANGO_SETTINGS_MODULE', arguments['--settings']) @@ -92,15 +92,15 @@ def main(user_input=None): split = JobSplit.objects.get(pk=int(arguments['<split>'])) except JobSplit.DoesNotExist: logger.info("Job split `%s' does not exist. Likely cancelled, " \ - "so, ignoring.", arguments['<split>']) + "so, ignoring.", arguments['<split>']) sys.exit(0) def stop(): split.executor.kill() message = "Force-stopped user processes for split `%s' for block " \ - "`%s' of experiment `%s'" % \ - (split, split.job.block.name, - split.job.block.experiment.fullname()) + "`%s' of experiment `%s'" % \ + (split, split.job.block.name, + split.job.block.experiment.fullname()) logger.info(message) # installs SIGTERM handler diff --git a/beat/web/search/admin.py b/beat/web/search/admin.py index 442f05254..2442dc424 100644 --- a/beat/web/search/admin.py +++ b/beat/web/search/admin.py @@ -53,35 +53,35 @@ rehash_search.short_description = 'Rehash selected search' class SearchModelForm(forms.ModelForm): name = NameField( - widget=forms.TextInput(attrs=dict(size=80)), - help_text=Messages['algo_name'], - ) + widget=forms.TextInput(attrs=dict(size=80)), + help_text=Messages['algo_name'], + ) description = CodeMirrorRSTCharField( - required=False, - help_text=Messages['description'], - ) + required=False, + help_text=Messages['description'], + ) filters = CodeMirrorJSONCharField( - readonly=False, - required=False, - help_text=Messages['json'], - ) + readonly=False, + required=False, + help_text=Messages['json'], + ) settings = CodeMirrorJSONCharField( - readonly=False, - required=False, - help_text=Messages['json'], - ) + readonly=False, + required=False, + help_text=Messages['json'], + ) class Meta: model = Search exclude = [] widgets = { - 'short_description': forms.TextInput( - attrs=dict(size=100), - ), - } + 'short_description': forms.TextInput( + attrs=dict(size=100), + ), + } #---------------------------------------------------------- @@ -91,13 +91,13 @@ class SearchAdmin(admin.ModelAdmin): list_display = ('id', 'author', 'name') search_fields = [ - 'author__username', + 'author__username', 'name', 'short_description', 'description', 'filters', 'settings', - ] + ] list_display_links = ('id', 'name') list_filter = ('author', 'name', 'version') @@ -116,34 +116,34 @@ class SearchAdmin(admin.ModelAdmin): fieldsets = ( (None, - dict( - fields=('name', 'author',), - ), + dict( + fields=('name', 'author',), + ), ), ('Documentation', - dict( - classes=('collapse',), - fields=('short_description', 'description',), - ), + dict( + classes=('collapse',), + fields=('short_description', 'description',), + ), ), ('Versioning', - dict( - classes=('collapse',), - fields=('version', 'previous_version', 'fork_of'), - ), + dict( + classes=('collapse',), + fields=('version', 'previous_version', 'fork_of'), + ), ), ('Sharing', - dict( - classes=('collapse',), - fields=('sharing', 'shared_with', 'shared_with_team'), - ), + dict( + classes=('collapse',), + fields=('sharing', 'shared_with', 'shared_with_team'), + ), ), ('Definition', - dict( - fields=('hash', 'filters', 'settings'), - ), + dict( + fields=('hash', 'filters', 'settings'), + ), ), - ) + ) admin.site.register(Search, SearchAdmin) @@ -176,20 +176,20 @@ class LeaderboardAdmin(admin.ModelAdmin): list_display = ('id', 'search', 'created', 'updated', users_to_notify, number_of_experiments, search_sharing) search_fiels = [ - 'search__author__username', + 'search__author__username', 'search__name', 'search_short_description', 'search_description', 'filters', 'settings', - ] + ] list_display_links = ('id', 'search',) inlines = [ RankInline, - ] + ] filter_horizontal = [ 'notify', - ] + ] admin.site.register(Leaderboard, LeaderboardAdmin) diff --git a/beat/web/search/api.py b/beat/web/search/api.py index 9e1d3e6fc..79e669dc3 100644 --- a/beat/web/search/api.py +++ b/beat/web/search/api.py @@ -93,7 +93,7 @@ class SearchView(APIView): @staticmethod def build_name_and_description_query(keywords): return reduce(lambda a, b: a & b, map(lambda keyword: Q(name__icontains=keyword) | - Q(short_description__icontains=keyword), keywords)) + Q(short_description__icontains=keyword), keywords)) def post(self, request): data = request.data @@ -264,25 +264,25 @@ class SearchView(APIView): if (scope_database is None) and (scope_algorithm is None) and \ (scope_analyzer is None) and ((scope_type is None) or (scope_type == 'toolchains')): result['toolchains'] = self._retrieve_contributions( - Toolchain.objects.for_user(request.user, True), - scope_toolchain, query - ) + Toolchain.objects.for_user(request.user, True), + scope_toolchain, query + ) # Search for algorithms matching the query if (scope_database is None) and (scope_toolchain is None) and \ (scope_analyzer is None) and ((scope_type is None) or (scope_type == 'algorithms')): result['algorithms'] = self._retrieve_contributions( - Algorithm.objects.for_user(request.user, True).filter(result_dataformat__isnull=True), - scope_algorithm, query - ) + Algorithm.objects.for_user(request.user, True).filter(result_dataformat__isnull=True), + scope_algorithm, query + ) # Search for analyzers matching the query if (scope_database is None) and (scope_toolchain is None) and \ (scope_algorithm is None) and ((scope_type is None) or (scope_type == 'analyzers')): result['analyzers'] = self._retrieve_contributions( - Algorithm.objects.for_user(request.user, True).filter(result_dataformat__isnull=False), - scope_analyzer, query - ) + Algorithm.objects.for_user(request.user, True).filter(result_dataformat__isnull=False), + scope_analyzer, query + ) # Search for data formats matching the query if (scope_database is None) and (scope_toolchain is None) and \ diff --git a/beat/web/search/management/commands/update_leaderboards.py b/beat/web/search/management/commands/update_leaderboards.py index 94c7678b1..6cded0732 100644 --- a/beat/web/search/management/commands/update_leaderboards.py +++ b/beat/web/search/management/commands/update_leaderboards.py @@ -77,21 +77,21 @@ class Command(BaseCommand): mesg = EmailMessage( subject.strip(), render_to_string(template_path, - { - 'leaderboard': obj, - 'prev_date': prev_date, - 'beat_version': __version__, - 'site': current_site, - } - ), + { + 'leaderboard': obj, + 'prev_date': prev_date, + 'beat_version': __version__, + 'site': current_site, + } + ), settings.DEFAULT_FROM_EMAIL, to=[], bcc=emails, - ) + ) mesg.send() else: logger.debug('Leaderboard %s did not change or notification is off' % obj.search) logger.info('Leaderboard updates: %d / Notifications: %d' % \ - (objects_updated, objects_changed)) + (objects_updated, objects_changed)) diff --git a/beat/web/search/migrations/0002_scheduler_addons.py b/beat/web/search/migrations/0002_scheduler_addons.py index f269a5f4a..e435eb523 100644 --- a/beat/web/search/migrations/0002_scheduler_addons.py +++ b/beat/web/search/migrations/0002_scheduler_addons.py @@ -41,14 +41,14 @@ def reset_ranks(apps, schema_editor): if total: print('') for i, r in enumerate(Result.objects.order_by('-id')): older = Result.objects.filter(name=r.name, id__lt=r.id, - cache=r.block.hashes.first()) + cache=r.block.hashes.first()) for old in older: # check if any leaderboard ranks require updates for rank in Rank.objects.filter(result__in=(old,)): print("Rank %d for search `%s/%s' uses old Result `%d' - " \ - "resetting to newer Result `%d'..." % \ - (rank.id, rank.leaderboard.search.author.username, - rank.leaderboard.search.name, old.id, r.id)) + "resetting to newer Result `%d'..." % \ + (rank.id, rank.leaderboard.search.author.username, + rank.leaderboard.search.name, old.id, r.id)) rank.result.remove(old) rank.result.add(r) @@ -62,4 +62,4 @@ class Migration(migrations.Migration): operations = [ migrations.RunPython(reset_ranks), - ] + ] diff --git a/beat/web/search/models.py b/beat/web/search/models.py index 54c95ed76..826097b4c 100644 --- a/beat/web/search/models.py +++ b/beat/web/search/models.py @@ -75,40 +75,40 @@ class Search(Contribution): def get_absolute_url(self): return reverse( - 'search:view', + 'search:view', args=( self.author.username, self.name, - ), - ) + ), + ) def get_notify_url(self): return reverse( - 'search:notify', + 'search:notify', args=( self.author.username, self.name, - ), - ) + ), + ) def get_api_update_url(self): '''Returns the endpoint to update this object''' return reverse( - 'api_search:save', + 'api_search:save', args=(self.author.username, self.name,), - ) + ) def get_api_share_url(self): '''Returns the endpoint to share this object''' return reverse( - 'api_search:share', + 'api_search:share', args=(self.author.username, self.name,), - ) + ) def has_leaderboard(self): @@ -132,12 +132,12 @@ class Leaderboard(models.Model): notify = models.ManyToManyField(User, limit_choices_to={'is_active': True}, blank=True, help_text='If set, and the leader board changes, an e-mail notification will be sent to people on this list, every time it changes.') experiments = models.ManyToManyField(Experiment, - limit_choices_to={'status': Experiment.DONE}, - through='Rank', - related_name='leaderboards', - blank=True, - help_text='Experiments currently set on the leaderboard', - ) + limit_choices_to={'status': Experiment.DONE}, + through='Rank', + related_name='leaderboards', + blank=True, + help_text='Experiments currently set on the leaderboard', + ) objects = LeaderboardManager() @@ -149,12 +149,12 @@ class Leaderboard(models.Model): def get_absolute_url(self): return reverse( - 'search:view', + 'search:view', args=( self.search.author.username, self.search.name, - ), - ) + ), + ) def current_experiments(self, time_delta=None): @@ -278,7 +278,7 @@ class Leaderboard(models.Model): for algorithm, header, table in self.current_experiments(): for k, row in enumerate(table): r = Rank(leaderboard=self, experiment=row[0], - algorithm=algorithm, order=k) + algorithm=algorithm, order=k) r.save() for j in row[1:]: r.result.add(j) @@ -308,4 +308,4 @@ class Rank(models.Model): def __str__(self): return '%s: [%d] %s' % (self.leaderboard.search.fullname(), - self.order, self.experiment.fullname()) + self.order, self.experiment.fullname()) diff --git a/beat/web/search/signals.py b/beat/web/search/signals.py index 0f497b27a..73e15b10f 100644 --- a/beat/web/search/signals.py +++ b/beat/web/search/signals.py @@ -45,15 +45,15 @@ def notify_users(sender, instance, **kwargs): mesg = EmailMessage( subject.strip(), render_to_string(template_path, - { - 'leaderboard': instance, - 'prev_date': prev_date, - 'beat_version': __version__, - 'site': current_site, - } - ), + { + 'leaderboard': instance, + 'prev_date': prev_date, + 'beat_version': __version__, + 'site': current_site, + } + ), settings.DEFAULT_FROM_EMAIL, to=[settings.DEFAULT_FROM_EMAIL], bcc=emails, - ) + ) mesg.send() diff --git a/beat/web/search/templatetags/search_tags.py b/beat/web/search/templatetags/search_tags.py index 5b03d7e2b..bcc5454d5 100644 --- a/beat/web/search/templatetags/search_tags.py +++ b/beat/web/search/templatetags/search_tags.py @@ -55,19 +55,19 @@ def search_table(context, objects, owner, id): ''' return dict( - request=context['request'], - objects=objects, - owner=owner, - panel_id=id, - ) + request=context['request'], + objects=objects, + owner=owner, + panel_id=id, + ) @register.inclusion_tag('search/panels/breadcrumb.html', takes_context=True) def search_breadcrumb(context, obj): return { - 'request': context['request'], + 'request': context['request'], 'object': obj, - } + } @register.inclusion_tag('search/panels/actions.html', takes_context=True) @@ -86,10 +86,10 @@ def search_actions(context, object, display_count): ''' return dict( - request=context['request'], - object=object, - display_count=display_count, - ) + request=context['request'], + object=object, + display_count=display_count, + ) @register.inclusion_tag('search/panels/sharing.html', takes_context=True) @@ -103,10 +103,10 @@ def search_sharing(context, object): ''' return dict( - object=object, - users=context['users'], - teams=context['teams'], - ) + object=object, + users=context['users'], + teams=context['teams'], + ) @register.inclusion_tag('search/panels/viewer.html', takes_context=True) @@ -127,14 +127,14 @@ def search_viewer(context, object, results, filters, display_settings, owner): ''' return dict( - request=context['request'], - filters=filters, - settings=display_settings, - object=object, - results=results, - owner=owner, - URL_PREFIX=context['URL_PREFIX'], - ) + request=context['request'], + filters=filters, + settings=display_settings, + object=object, + results=results, + owner=owner, + URL_PREFIX=context['URL_PREFIX'], + ) @register.inclusion_tag('search/panels/results.html', takes_context=True) @@ -159,12 +159,12 @@ def results_table(context, object, results, id): ''' return dict( - request=context['request'], - object=object, - results=results, - id=id, - URL_PREFIX=context['URL_PREFIX'], - ) + request=context['request'], + object=object, + results=results, + id=id, + URL_PREFIX=context['URL_PREFIX'], + ) @register.assignment_tag @@ -209,10 +209,10 @@ def plot_details_for_result(r): plotting = Plotter.objects.for_strformat(r.type) return dict( - plotter=plotting['default'][0].fullname(), - parameter=None if plotting['default'][1] == None else plotting['default'][1].fullname(), - parameters=json.dumps([k.fullname() for k in plotting['options'][plotting['default'][0]]]), - ) + plotter=plotting['default'][0].fullname(), + parameter=None if plotting['default'][1] == None else plotting['default'][1].fullname(), + parameters=json.dumps([k.fullname() for k in plotting['options'][plotting['default'][0]]]), + ) @register.assignment_tag diff --git a/beat/web/search/urls.py b/beat/web/search/urls.py index ea7cab7f8..4349a7854 100644 --- a/beat/web/search/urls.py +++ b/beat/web/search/urls.py @@ -41,7 +41,7 @@ urlpatterns = [ r'^run/$', views.search, name='search', - ), + ), url( r'^(?P<author_name>\w+)/$', @@ -53,12 +53,12 @@ urlpatterns = [ r'^(?P<author_name>\w+)/(?P<query_name>[\w\-]+)/$', views.view, name='view', - ), + ), url( r'^(?P<author_name>\w+)/(?P<query_name>[\w\-]+)/notify/$', views.notify, name='notify', - ), + ), ] diff --git a/beat/web/search/utils.py b/beat/web/search/utils.py index bc688812e..c5019c019 100644 --- a/beat/web/search/utils.py +++ b/beat/web/search/utils.py @@ -746,12 +746,12 @@ def generate_experiment_filter(experiment, django_operator): return Q(name__iexact=UNLIKELY_STRING) if django_operator == 'contains': return Q(author__username__icontains=experiment_authorname) & Q(toolchain__author__username__icontains=toolchain_authorname) & \ - Q(toolchain__name__icontains=toolchain_name) & Q(toolchain__version=toolchain_version) & \ - Q(name__icontains=experiment_name) + Q(toolchain__name__icontains=toolchain_name) & Q(toolchain__version=toolchain_version) & \ + Q(name__icontains=experiment_name) elif django_operator == 'exact': return Q(author__username__iexact=experiment_authorname) & Q(toolchain__author__username__iexact=toolchain_authorname) & \ - Q(toolchain__name__iexact=toolchain_name) & Q(toolchain__version=toolchain_version) & \ - Q(name__iexact=experiment_name) + Q(toolchain__name__iexact=toolchain_name) & Q(toolchain__version=toolchain_version) & \ + Q(name__iexact=experiment_name) elif len(experiment_elems) == 4: toolchain_authorname, toolchain_name, toolchain_version, experiment_name = experiment_elems experiment_authorname = toolchain_authorname @@ -761,12 +761,12 @@ def generate_experiment_filter(experiment, django_operator): return Q(name__iexact=UNLIKELY_STRING) if django_operator == 'contains': return Q(toolchain__author__username__icontains=toolchain_authorname) & \ - Q(toolchain__name__icontains=toolchain_name) & Q(toolchain__version=toolchain_version) & \ - Q(name__icontains=experiment_name) + Q(toolchain__name__icontains=toolchain_name) & Q(toolchain__version=toolchain_version) & \ + Q(name__icontains=experiment_name) elif django_operator == 'exact': return Q(toolchain__author__username__iexact=toolchain_authorname) & \ - Q(toolchain__name__iexact=toolchain_name) & Q(toolchain__version=toolchain_version) & \ - Q(name__iexact=experiment_name) + Q(toolchain__name__iexact=toolchain_name) & Q(toolchain__version=toolchain_version) & \ + Q(name__iexact=experiment_name) elif len(experiment_elems) == 3: toolchain_name, toolchain_version, experiment_name = experiment_elems try: @@ -775,10 +775,10 @@ def generate_experiment_filter(experiment, django_operator): return Q(name__iexact=UNLIKELY_STRING) if django_operator == 'contains': return Q(toolchain__name__icontains=toolchain_name) & Q(toolchain__version=toolchain_version) & \ - Q(name__icontains=experiment_name) + Q(name__icontains=experiment_name) elif django_operator == 'exact': return Q(toolchain__name__iexact=toolchain_name) & Q(toolchain__version=toolchain_version) & \ - Q(name__iexact=experiment_name) + Q(name__iexact=experiment_name) elif len(experiment_elems) == 2: toolchain_version, experiment_name = experiment_elems try: diff --git a/beat/web/search/views.py b/beat/web/search/views.py index 5099c5f23..2e139be5b 100644 --- a/beat/web/search/views.py +++ b/beat/web/search/views.py @@ -220,11 +220,11 @@ def filters_from_query(query): def _make_context(name, entries): return { - 'context': name, + 'context': name, 'operator': _operator_chooser(entries), 'value': _value_chooser(entries), 'name': None, - } + } keywords = [x.strip() for x in query.split() if x.strip()] @@ -256,7 +256,7 @@ def filters_from_query(query): 'operator': 'contains-any-of', 'value': any_fields, 'name': None, - }) + }) return filters @@ -286,15 +286,15 @@ def search(request): display_settings = request.POST['settings'].strip() return render_to_response('search/view.html', - dict( - search=None, - owner=False, - filters=filters, - settings=display_settings, - results=search_experiments(request.user, json.loads(filters)), - URL_PREFIX=settings.URL_PREFIX, - ), - context_instance=RequestContext(request)) + dict( + search=None, + owner=False, + filters=filters, + settings=display_settings, + results=search_experiments(request.user, json.loads(filters)), + URL_PREFIX=settings.URL_PREFIX, + ), + context_instance=RequestContext(request)) #------------------------------------------------ @@ -305,8 +305,8 @@ def view(request, author_name, query_name): # get the query from the DB obj = get_object_or_404(Search, - author__username = author_name, - name = query_name) + author__username = author_name, + name = query_name) # makes sure that the current user has access to it has_access, _ = obj.accessibility_for(request.user) @@ -328,18 +328,18 @@ def view(request, author_name, query_name): users = User.objects.exclude(username__in=settings.ACCOUNTS_TO_EXCLUDE_FROM_TEAMS).order_by('username') return render_to_response('search/view.html', - { - 'search': obj, - 'owner': (request.user == obj.author), - 'filters': filters, - 'settings': display_settings, - 'results': search_experiments(request.user, json.loads(filters)), - 'URL_PREFIX': settings.URL_PREFIX, - 'users': users, - 'teams': Team.objects.for_user(request.user, True) - }, - context_instance=RequestContext(request), - ) + { + 'search': obj, + 'owner': (request.user == obj.author), + 'filters': filters, + 'settings': display_settings, + 'results': search_experiments(request.user, json.loads(filters)), + 'URL_PREFIX': settings.URL_PREFIX, + 'users': users, + 'teams': Team.objects.for_user(request.user, True) + }, + context_instance=RequestContext(request), + ) #---------------------------------------------------------- @@ -355,16 +355,16 @@ def ls(request, author_name): # orders searchs so that the latest information is displayed first objects = Search.objects.from_author_and_public(request.user, - author_name).order_by('-creation_date') + author_name).order_by('-creation_date') return render_to_response('search/list.html', - dict( - objects=objects, - author=author, - owner=(request.user==author), - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=author, + owner=(request.user==author), + ), + context_instance=RequestContext(request), + ) #---------------------------------------------------------- @@ -377,13 +377,13 @@ def public_ls(request): objects = Search.objects.public().order_by('-creation_date') return render_to_response('search/list.html', - dict( - objects=objects, - author=request.user, - owner=False, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=request.user, + owner=False, + ), + context_instance=RequestContext(request), + ) #---------------------------------------------------------- @@ -395,8 +395,8 @@ def notify(request, author_name, query_name): # get the query from the DB obj = get_object_or_404(Search, - author__username = author_name, - name = query_name) + author__username = author_name, + name = query_name) # makes sure that the current user has access to it has_access, _ = obj.accessibility_for(request.user) diff --git a/beat/web/settings/settings.py b/beat/web/settings/settings.py index 23311a217..76da80970 100755 --- a/beat/web/settings/settings.py +++ b/beat/web/settings/settings.py @@ -75,66 +75,66 @@ LOGGING = { 'simple': { 'format': '[%(asctime)s - %(name)s] %(levelname)s: %(message)s', 'datefmt': "%d/%b/%Y %H:%M:%S", - }, }, + }, 'handlers': { 'discard': { 'level': 'DEBUG', 'class': 'logging.NullHandler', - }, + }, 'console': { 'level': 'INFO', 'class': 'logging.StreamHandler', 'formatter': 'simple', - }, + }, 'mail_admins': { 'level': 'ERROR', 'class': 'django.utils.log.AdminEmailHandler', - } - }, + } + }, 'loggers': { '': { 'handlers': ['discard'], 'level': 'INFO', - }, + }, 'beat.core': { 'handlers': ['console'], - }, + }, 'beat.core.scripts.worker': { 'handlers': ['discard'], 'propagate': False, - }, + }, 'beat.web': { 'handlers': ['console', 'mail_admins'], - }, + }, 'beat.web.scripts.scheduler': { 'handlers': ['discard'], 'propagate': False, - }, + }, 'beat.web.attestations.management.commands': { 'handlers': ['console'], 'propagate': False, #don't e-mail those! - }, + }, 'beat.web.search.management.commands': { 'handlers': ['console'], 'propagate': False, #don't e-mail those! - }, + }, 'beat.web.experiments.management.commands': { 'handlers': ['console'], 'propagate': False, #don't e-mail those! - }, + }, 'beat.web.reports.management.commands': { 'handlers': ['console'], 'propagate': False, #don't e-mail those! - }, + }, 'beat.web.backend.management.commands': { 'handlers': ['console'], 'propagate': False, #don't e-mail those! - }, + }, 'beat.web.utils.management.commands': { 'handlers': ['console'], 'propagate': False, #don't e-mail those! - }, + }, } } @@ -167,12 +167,12 @@ warn_logger.addFilter(SuppressDeprecated()) DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', + 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'django.sql3', 'OPTIONS': { - 'timeout': 10, #seconds - }, + 'timeout': 10, #seconds }, + }, } @@ -184,9 +184,9 @@ DATABASES = { STATIC_URL = '/static/' STATICFILES_DIRS = ( - # Bower sources + # Bower sources pkg_resources.resource_filename('beat.web', 'static'), - ) +) STATIC_ROOT = 'static' @@ -365,7 +365,7 @@ INSTALLED_APPS = ( RESTRUCTUREDTEXT_FILTER_SETTINGS = { 'file_insertion_enabled': 0, 'raw_enabled': 0, - } +} # Where CodeMirror is installed and some other settings CODEMIRROR_PATH = 'codemirror' #w.r.t to STATIC_URL diff --git a/beat/web/settings/test.py b/beat/web/settings/test.py index 8d3219cb8..e47f76e14 100755 --- a/beat/web/settings/test.py +++ b/beat/web/settings/test.py @@ -67,5 +67,5 @@ LOCAL_SCHEDULER_USE_DOCKER = False # To speed-up tests, don't put this in production PASSWORD_HASHERS = [ - 'django.contrib.auth.hashers.MD5PasswordHasher', + 'django.contrib.auth.hashers.MD5PasswordHasher', ] diff --git a/beat/web/statistics/admin.py b/beat/web/statistics/admin.py index 1ed2e4900..56bab00a6 100644 --- a/beat/web/statistics/admin.py +++ b/beat/web/statistics/admin.py @@ -35,7 +35,7 @@ from django.contrib import admin class HourlyStatistics(admin.ModelAdmin): list_display = ( - 'id', + 'id', 'date', 'hour', 'cpu_time', @@ -46,7 +46,7 @@ class HourlyStatistics(admin.ModelAdmin): 'data_written_size', 'data_written_nb_blocks', 'data_written_time', - ) + ) list_display_links = ('id', ) admin.site.register(HourlyStatisticsModel, HourlyStatistics) diff --git a/beat/web/statistics/templatetags/statistics_tags.py b/beat/web/statistics/templatetags/statistics_tags.py index 11a9d7a11..afa62cd12 100644 --- a/beat/web/statistics/templatetags/statistics_tags.py +++ b/beat/web/statistics/templatetags/statistics_tags.py @@ -38,7 +38,7 @@ register = template.Library() @register.inclusion_tag('statistics/panels/status.html', takes_context=True) def status(context, id): return { - 'request': context['request'], + 'request': context['request'], 'panel_id': id, 'totals': calculate_totals(), - } + } diff --git a/beat/web/statistics/tests.py b/beat/web/statistics/tests.py index e9ecc7825..0b5e516bd 100644 --- a/beat/web/statistics/tests.py +++ b/beat/web/statistics/tests.py @@ -45,27 +45,27 @@ import beat.core.stats import nose.tools STATS_1 = { - 'cpu': { 'user': 1, 'system': 1.5, }, + 'cpu': { 'user': 1, 'system': 1.5, }, 'memory': { 'rss': 100, }, 'data': { 'volume': { 'read': 1000, 'write': 2000, }, 'blocks': { 'read': 100, 'write': 200, }, 'time': { 'read': 10000, 'write': 20000, }, 'generated_files': [], - } - } + } +} STATS_2 = { - 'cpu': { 'user': 2, 'system': 3, }, + 'cpu': { 'user': 2, 'system': 3, }, 'memory': { 'rss': 200, }, 'data': { 'volume': { 'read': 500, 'write': 600, }, 'blocks': { 'read': 50, 'write': 60, }, 'time': { 'read': 5000, 'write': 6000, }, 'generated_files': [], - } - } + } +} class UpdateStatisticsFunction(TestCase): diff --git a/beat/web/statistics/urls.py b/beat/web/statistics/urls.py index 2faf8c734..32532cff6 100644 --- a/beat/web/statistics/urls.py +++ b/beat/web/statistics/urls.py @@ -30,10 +30,10 @@ from . import views urlpatterns = [ - url( - r'^$', + url( + r'^$', views.statistics, name='summary', - ), + ), ] diff --git a/beat/web/statistics/views.py b/beat/web/statistics/views.py index 2b1664ffc..616fdcb5e 100644 --- a/beat/web/statistics/views.py +++ b/beat/web/statistics/views.py @@ -64,13 +64,13 @@ def calculate_totals(): counter = objects.count() details = objects.aggregate( - cpu_time=Sum('cpu_time'), - max_memory=Sum('max_memory'), - data_read_size=Sum('data_read_size'), - data_read_time=Sum('data_read_time'), - data_written_size=Sum('data_written_size'), - data_written_time=Sum('data_written_time'), - ) + cpu_time=Sum('cpu_time'), + max_memory=Sum('max_memory'), + data_read_size=Sum('data_read_size'), + data_read_time=Sum('data_read_time'), + data_written_size=Sum('data_written_size'), + data_written_time=Sum('data_written_time'), + ) cpu_time = details['cpu_time'] memory = details['max_memory'] @@ -88,40 +88,40 @@ def calculate_totals(): return dict( - counter=counter, - cpu_time_hours=int(cpu_time/float(60**2)) if cpu_time else 0, - memory_gb=int(memory/float(2**30)) if memory else 0, - input_gb = int(input_size/float(2**30)) if input_size else 0, - input_bw_mb_s = int((input_size/float(2**20))/input_time) if input_size else 0, - output_gb = int(output_size/float(2**30)) if output_size else 0, - output_bw_mb_s = int((output_size/float(2**20))/output_time) if output_size else 0, - - users=User.objects.count(), - newusers=new_users.count(), - waitingvalidationusers=waiting_validation_users.count(), - acceptedusers=accepted_users.count(), - rejectedusers=rejected_users.count(), - yearrevalidationusers=yearrevalidation_users.count(), - blockedusers=blocked_users.count(), - databases=Database.objects.count(), - environments=Environment.objects.count(), - queues=Queue.objects.count(), - workers=Worker.objects.count(), - - experiments=Experiment.objects.count(), - toolchains=Toolchain.objects.count(), - algorithms=Algorithm.objects.count(), - libraries=Library.objects.count(), - dataformats=DataFormat.objects.count(), - teams=Team.objects.count(), - - attestations=Attestation.objects.count(), - searches=Search.objects.count(), - reports=Report.objects.count(), - plotters=Plotter.objects.count(), - plotterparameters=PlotterParameter.objects.count(), - - ) + counter=counter, + cpu_time_hours=int(cpu_time/float(60**2)) if cpu_time else 0, + memory_gb=int(memory/float(2**30)) if memory else 0, + input_gb = int(input_size/float(2**30)) if input_size else 0, + input_bw_mb_s = int((input_size/float(2**20))/input_time) if input_size else 0, + output_gb = int(output_size/float(2**30)) if output_size else 0, + output_bw_mb_s = int((output_size/float(2**20))/output_time) if output_size else 0, + + users=User.objects.count(), + newusers=new_users.count(), + waitingvalidationusers=waiting_validation_users.count(), + acceptedusers=accepted_users.count(), + rejectedusers=rejected_users.count(), + yearrevalidationusers=yearrevalidation_users.count(), + blockedusers=blocked_users.count(), + databases=Database.objects.count(), + environments=Environment.objects.count(), + queues=Queue.objects.count(), + workers=Worker.objects.count(), + + experiments=Experiment.objects.count(), + toolchains=Toolchain.objects.count(), + algorithms=Algorithm.objects.count(), + libraries=Library.objects.count(), + dataformats=DataFormat.objects.count(), + teams=Team.objects.count(), + + attestations=Attestation.objects.count(), + searches=Search.objects.count(), + reports=Report.objects.count(), + plotters=Plotter.objects.count(), + plotterparameters=PlotterParameter.objects.count(), + + ) def convert_values(stats): @@ -142,11 +142,11 @@ def convert_values(stats): return (s[num]/float(2**20))/s[den] #mb per sec return dict( - cpu_time=[_seconds_to_hours(k, 'cpu_time') for k in stats], - memory=[_bytes_to_gb(k, 'max_memory') for k in stats], - input_bw=[_bw_in_mbs(k, 'data_read_size', 'data_read_time') for k in stats], - output_bw=[_bw_in_mbs(k, 'data_written_size', 'data_written_time') for k in stats], - ) + cpu_time=[_seconds_to_hours(k, 'cpu_time') for k in stats], + memory=[_bytes_to_gb(k, 'max_memory') for k in stats], + input_bw=[_bw_in_mbs(k, 'data_read_size', 'data_read_time') for k in stats], + output_bw=[_bw_in_mbs(k, 'data_written_size', 'data_written_time') for k in stats], + ) def grouper(n, iterable, fillvalue=None): @@ -162,7 +162,7 @@ def get_statistics(hours_to_go_back, cluster_by): now = datetime.datetime.now() back = now - datetime.timedelta(hours=hours_to_go_back) available = HourlyStatistics.objects.filter(date__gt=back).order_by('date', - 'hour') + 'hour') # this must be true! assert available.count() <= hours_to_go_back @@ -192,7 +192,7 @@ def get_statistics(hours_to_go_back, cluster_by): return retval fields = ('cpu_time', 'max_memory', 'data_read_size', 'data_read_time', - 'data_written_size', 'data_written_time') + 'data_written_size', 'data_written_time') summaries = [_totals(g, fields) for g in groups] # setup data so information is shown for every field accros groups @@ -244,7 +244,7 @@ def weekly_charts(): retval = dict(labels=labels) retval.update(get_statistics(hours_to_go_back=24*7*24, - cluster_by=24*7)) + cluster_by=24*7)) return simplejson.dumps(retval) @@ -270,10 +270,10 @@ def statistics(request): if not(request.user.is_superuser): return HttpResponseForbidden() return render_to_response('statistics/statistics.html', - dict( - totals=calculate_totals(), - hourly_chart_data=hourly_charts(), - daily_chart_data=daily_charts(), - weekly_chart_data=weekly_charts(), - ), - context_instance=RequestContext(request)) + dict( + totals=calculate_totals(), + hourly_chart_data=hourly_charts(), + daily_chart_data=daily_charts(), + weekly_chart_data=weekly_charts(), + ), + context_instance=RequestContext(request)) diff --git a/beat/web/team/models.py b/beat/web/team/models.py index e8e4e8ff2..5814b7870 100644 --- a/beat/web/team/models.py +++ b/beat/web/team/models.py @@ -43,7 +43,7 @@ class TeamManager(models.Manager): return self.public() query = Q(owner=user) |\ - (Q(privacy_level__in=[Team.MEMBERS, Team.PRIVATE]) & Q(members=user)) + (Q(privacy_level__in=[Team.MEMBERS, Team.PRIVATE]) & Q(members=user)) if add_public: query |= Q(privacy_level=Team.PUBLIC) diff --git a/beat/web/team/templatetags/team_tags.py b/beat/web/team/templatetags/team_tags.py index bc8acad19..a4a6474d4 100644 --- a/beat/web/team/templatetags/team_tags.py +++ b/beat/web/team/templatetags/team_tags.py @@ -53,11 +53,11 @@ def team_table(context, objects, owner, id): ''' return { - 'request': context['request'], + 'request': context['request'], 'objects': objects, 'owner': owner, 'panel_id': id, - } + } #-------------------------------------------------- @@ -80,10 +80,10 @@ def team_actions(context, obj, display_count): ''' return { - 'request': context['request'], + 'request': context['request'], 'display_count': display_count, 'object': obj, - } + } #-------------------------------------------------- diff --git a/beat/web/team/tests.py b/beat/web/team/tests.py index 1d12285ea..782a71e19 100644 --- a/beat/web/team/tests.py +++ b/beat/web/team/tests.py @@ -68,7 +68,7 @@ class TeamTestCase(APITestCase): (dataformat, errors) = DataFormat.objects.create_dataformat( author=self.johndoe, name='data_format_shared_with_private_team', - ) + ) assert dataformat, errors dataformat.share(teams=[self.teamdoe_private]) diff --git a/beat/web/team/views.py b/beat/web/team/views.py index d067d3dcb..902eb1b68 100644 --- a/beat/web/team/views.py +++ b/beat/web/team/views.py @@ -48,10 +48,10 @@ def create(request): """ return render_to_response('team/edition.html', - { - 'users': User.objects.exclude(username__in=settings.ACCOUNTS_TO_EXCLUDE_FROM_TEAMS).order_by('username'), - }, - context_instance=RequestContext(request)) + { + 'users': User.objects.exclude(username__in=settings.ACCOUNTS_TO_EXCLUDE_FROM_TEAMS).order_by('username'), + }, + context_instance=RequestContext(request)) #---------------------------------------------------------- @@ -68,16 +68,16 @@ def edit(request, author_name, name): # Retrieves the team team = get_object_or_404(Team, - owner__username__iexact=author_name, - name__iexact=name + owner__username__iexact=author_name, + name__iexact=name ) return render_to_response('team/edition.html', - { - 'team': team, - 'users': User.objects.exclude(username__in=settings.ACCOUNTS_TO_EXCLUDE_FROM_TEAMS).order_by('username'), - }, - context_instance=RequestContext(request)) + { + 'team': team, + 'users': User.objects.exclude(username__in=settings.ACCOUNTS_TO_EXCLUDE_FROM_TEAMS).order_by('username'), + }, + context_instance=RequestContext(request)) #---------------------------------------------------------- @@ -111,13 +111,13 @@ def ls(request, author_name): objects = Team.objects.for_user(request.user, True).filter(owner=author) return render_to_response('team/list.html', - dict( - objects=objects, - author=author, - owner=(request.user == author), - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=author, + owner=(request.user == author), + ), + context_instance=RequestContext(request), + ) #---------------------------------------------------------- @@ -127,10 +127,10 @@ def public_ls(request): '''List all accessible teams to the request user''' return render_to_response('team/list.html', - dict( - objects=Team.objects.public(), - author=request.user, #anonymous - owner=False, - ), - context_instance=RequestContext(request), - ) + dict( + objects=Team.objects.public(), + author=request.user, #anonymous + owner=False, + ), + context_instance=RequestContext(request), + ) diff --git a/beat/web/toolchains/admin.py b/beat/web/toolchains/admin.py index 89abc22fe..95822f754 100644 --- a/beat/web/toolchains/admin.py +++ b/beat/web/toolchains/admin.py @@ -33,7 +33,7 @@ from django.utils import six from .models import Toolchain as ToolchainModel from ..ui.forms import CodeMirrorJSONFileField, CodeMirrorRSTFileField, \ - NameField + NameField from ..common.texts import Messages @@ -44,32 +44,32 @@ from ..common.texts import Messages class ToolchainModelForm(forms.ModelForm): name = NameField( - widget=forms.TextInput(attrs=dict(size=80)), - help_text=Messages['name'], - ) + widget=forms.TextInput(attrs=dict(size=80)), + help_text=Messages['name'], + ) declaration_file = CodeMirrorJSONFileField( - label='Declaration', - help_text=Messages['json'], - ) + label='Declaration', + help_text=Messages['json'], + ) description_file = CodeMirrorRSTFileField( - label='Description', - required=False, - allow_empty_file=True, - help_text=Messages['description'], - ) + label='Description', + required=False, + allow_empty_file=True, + help_text=Messages['description'], + ) class Meta: model = ToolchainModel exclude = [] widgets = { - 'short_description': forms.TextInput( - attrs=dict(size=100), - ), + 'short_description': forms.TextInput( + attrs=dict(size=100), + ), 'errors': forms.Textarea( attrs=dict(readonly=1,cols=150,), - ), + ), } @@ -140,7 +140,7 @@ class Toolchain(admin.ModelAdmin): actions = [ rehash_toolchain, - ] + ] form = ToolchainModelForm @@ -151,33 +151,33 @@ class Toolchain(admin.ModelAdmin): fieldsets = ( (None, - dict( - fields=('name', 'author'), - ), + dict( + fields=('name', 'author'), + ), ), ('Documentation', - dict( - classes=('collapse',), - fields=('short_description', 'description_file'), - ), + dict( + classes=('collapse',), + fields=('short_description', 'description_file'), + ), ), ('Versioning', - dict( - classes=('collapse',), - fields=('version', 'previous_version', 'fork_of'), - ), + dict( + classes=('collapse',), + fields=('version', 'previous_version', 'fork_of'), + ), ), ('Sharing', - dict( - classes=('collapse',), - fields=('sharing', 'shared_with', 'shared_with_team'), - ), + dict( + classes=('collapse',), + fields=('sharing', 'shared_with', 'shared_with_team'), + ), ), ('Source code', - dict( - fields=('hash', 'declaration_file', 'errors'), - ), + dict( + fields=('hash', 'declaration_file', 'errors'), + ), ), - ) + ) admin.site.register(ToolchainModel, Toolchain) diff --git a/beat/web/toolchains/api.py b/beat/web/toolchains/api.py index 2b0c5fa51..da6efb409 100644 --- a/beat/web/toolchains/api.py +++ b/beat/web/toolchains/api.py @@ -169,7 +169,7 @@ class RetrieveUpdateDestroyToolchainsView(RetrieveUpdateDestroyContributionView) declaration = json.dumps(json_declaration, indent=4) toolchain_declaration = beat.core.toolchain.Toolchain( - settings.PREFIX, json_declaration) + settings.PREFIX, json_declaration) if not toolchain_declaration.valid: if strict: diff --git a/beat/web/toolchains/models.py b/beat/web/toolchains/models.py index bd6d2e90d..df926b8c8 100644 --- a/beat/web/toolchains/models.py +++ b/beat/web/toolchains/models.py @@ -166,36 +166,36 @@ class Toolchain(StoredContribution): def get_absolute_url(self): return reverse( - 'toolchains:view', + 'toolchains:view', args=(self.author.username, self.name, self.version,), - ) + ) def get_api_update_url(self): '''Returns the endpoint to update this object''' return reverse( - 'api_toolchains:object', + 'api_toolchains:object', args=(self.author.username, self.name, self.version,), - ) + ) def get_api_share_url(self): '''Returns the endpoint to share this object''' return reverse( - 'api_toolchains:share', + 'api_toolchains:share', args=(self.author.username, self.name, self.version,), - ) + ) def get_new_experiment_url(self): '''Returns the view to create a new experiment from self''' return reverse( - 'experiments:new-from-toolchain', + 'experiments:new-from-toolchain', args=(self.author.username, self.name, self.version,), - ) + ) #_____ Overrides __________ diff --git a/beat/web/toolchains/templatetags/toolchain_tags.py b/beat/web/toolchains/templatetags/toolchain_tags.py index 8f4d30abd..d07f32c00 100644 --- a/beat/web/toolchains/templatetags/toolchain_tags.py +++ b/beat/web/toolchains/templatetags/toolchain_tags.py @@ -53,11 +53,11 @@ def toolchain_table(context, objects, owner, id): ''' return dict( - request=context['request'], - objects=objects, - owner=owner, - panel_id=id, - ) + request=context['request'], + objects=objects, + owner=owner, + panel_id=id, + ) @register.inclusion_tag('toolchains/panels/actions.html', takes_context=True) @@ -76,10 +76,10 @@ def toolchain_actions(context, object, display_count): ''' return dict( - request=context['request'], - object=object, - display_count=display_count, - ) + request=context['request'], + object=object, + display_count=display_count, + ) @register.inclusion_tag('toolchains/panels/sharing.html', takes_context=True) @@ -93,12 +93,12 @@ def toolchain_sharing(context, obj): ''' return { - 'request': context['request'], + 'request': context['request'], 'object': obj, 'owner': context['request'].user == obj.author, 'users': context['users'], 'teams': context['teams'], - } + } @register.inclusion_tag('toolchains/panels/viewer.html', takes_context=True) @@ -116,12 +116,12 @@ def toolchain_viewer(context, obj, xp, id): ''' return { - 'request': context['request'], + 'request': context['request'], 'object': obj, 'xp': xp, 'panel_id': id, 'URL_PREFIX': settings.URL_PREFIX, - } + } @register.assignment_tag(takes_context=True) diff --git a/beat/web/toolchains/tests.py b/beat/web/toolchains/tests.py index b78bd7a36..3efd575ec 100644 --- a/beat/web/toolchains/tests.py +++ b/beat/web/toolchains/tests.py @@ -48,47 +48,47 @@ class ToolchainsCreationFunction(TestCase): DECLARATION = { "blocks": [ { - "name": "block1", + "name": "block1", "inputs": [ "in" ], - "outputs": [ + "outputs": [ "out" ], - "synchronized_channel": "dataset1" - } + "synchronized_channel": "dataset1" + } ], "analyzers": [ { - "name": "analysis", + "name": "analysis", "inputs": [ "in" ], - "synchronized_channel": "dataset1" - } + "synchronized_channel": "dataset1" + } ], "datasets": [ { - "name": "dataset1", + "name": "dataset1", "outputs": [ "output1" ], - } + } ], "connections": [ { - "from": "dataset1.output1", + "from": "dataset1.output1", "to": "block1.in", "channel": "dataset1" - }, + }, { "from": "block1.out", "to": "analysis.in", "channel": "dataset1" - } + } ], "representation": { "connections": {}, "blocks": {}, "channel_colors": {} - } + } } @@ -110,7 +110,7 @@ class ToolchainsCreationFunction(TestCase): name='toolchain1', short_description='some description', description='some longer description', - ) + ) assert toolchain, errors @@ -123,11 +123,11 @@ class ToolchainsCreationFunction(TestCase): self.assertTrue(toolchain.fork_of is None) storage = beat.core.toolchain.Storage(settings.PREFIX, - toolchain.fullname()) + toolchain.fullname()) assert storage.exists serializer = beat.core.toolchain.Toolchain(settings.PREFIX, - storage.fullname) + storage.fullname) assert serializer.valid def test_with_valid_declaration(self): @@ -139,7 +139,7 @@ class ToolchainsCreationFunction(TestCase): short_description='some description', description='some longer description', declaration=ToolchainsCreationFunction.DECLARATION, - ) + ) assert toolchain, errors @@ -180,7 +180,7 @@ class ToolchainsCreationFunction(TestCase): } ] }, - ) + ) assert errors @@ -201,7 +201,7 @@ class ToolchainAccessibilityFunctionsBase(BaseTestCase): (toolchain1, errors) = Toolchain.objects.create_toolchain( author=user1, name='personal', - ) + ) assert toolchain1, errors @@ -209,7 +209,7 @@ class ToolchainAccessibilityFunctionsBase(BaseTestCase): (toolchain2, errors) = Toolchain.objects.create_toolchain( author=user1, name='public_for_one_user', - ) + ) assert toolchain2, errors @@ -222,7 +222,7 @@ class ToolchainAccessibilityFunctionsBase(BaseTestCase): (toolchain3, errors) = Toolchain.objects.create_toolchain( author=user1, name='public_for_all', - ) + ) assert toolchain3, errors @@ -444,47 +444,47 @@ class ToolchainsAPIBase(BaseTestCase): DECLARATION = { "blocks": [ { - "name": "block1", + "name": "block1", "inputs": [ "in" ], - "outputs": [ + "outputs": [ "out" ], - "synchronized_channel": "dataset1" - } + "synchronized_channel": "dataset1" + } ], "analyzers": [ { - "name": "analysis", + "name": "analysis", "inputs": [ "in" ], - "synchronized_channel": "dataset1" - } + "synchronized_channel": "dataset1" + } ], "datasets": [ { - "name": "dataset1", + "name": "dataset1", "outputs": [ "output1" ] - } + } ], "connections": [ { - "from": "dataset1.output1", + "from": "dataset1.output1", "to": "block1.in", "channel": "dataset1" - }, + }, { "from": "block1.out", "to": "analysis.in", "channel": "dataset1" - } + } ], "representation": { "connections": {}, "blocks": {}, "channel_colors": {} - } + } } @@ -503,7 +503,7 @@ class ToolchainsAPIBase(BaseTestCase): author=user1, name='personal', declaration=ToolchainsAPIBase.DECLARATION, - ) + ) assert toolchain, errors @@ -512,7 +512,7 @@ class ToolchainsAPIBase(BaseTestCase): author=user1, name='public_for_one_user', declaration=ToolchainsAPIBase.DECLARATION, - ) + ) toolchain.share(users=[user2]) assert toolchain, errors @@ -522,7 +522,7 @@ class ToolchainsAPIBase(BaseTestCase): author=user1, name='public_for_all', declaration=ToolchainsAPIBase.DECLARATION, - ) + ) toolchain.share() assert toolchain, errors @@ -645,7 +645,7 @@ class ToolchainsNameCheck(ToolchainsAPIBase): author=user, name='toolchain-4', short_description='short description 4', - ) + ) assert toolchain4, errors @@ -654,10 +654,10 @@ class ToolchainsNameCheck(ToolchainsAPIBase): def test_no_check_for_anonymous_user(self): response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'private': True, - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'private': True, + }), content_type='application/json') self.checkResponse(response, 403) def test_bad_request_for_post_method_without_needed_data(self): @@ -672,10 +672,10 @@ class ToolchainsNameCheck(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1', - 'private': True, - }), content_type='application/json') + json.dumps({ + 'name': 'valid-name1', + 'private': True, + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -688,10 +688,10 @@ class ToolchainsNameCheck(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name_1 #due-to{}%&é', - 'private': True, - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name_1 #due-to{}%&é', + 'private': True, + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -704,10 +704,10 @@ class ToolchainsNameCheck(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'personal', - 'private': True, - }), content_type='application/json') + json.dumps({ + 'name': 'personal', + 'private': True, + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -720,10 +720,10 @@ class ToolchainsNameCheck(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'toolchain 4', - 'private': True, - }), content_type='application/json') + json.dumps({ + 'name': 'toolchain 4', + 'private': True, + }), content_type='application/json') content = self.checkResponse(response, 200, content_type='application/json') @@ -737,47 +737,47 @@ class ToolchainCreation(ToolchainsAPIBase): DECLARATION_INVALID = { "blocks": [ { - "name": "block1", + "name": "block1", "inputs": [ "in" ], - "outputs": [ + "outputs": [ "out" ], - "synchronized_channel": "dataset1" - } + "synchronized_channel": "dataset1" + } ], "analyzers": [ { - "name": "analysis", + "name": "analysis", "inputs": [ "in" ], - "synchronized_channel": "dataset1" - } + "synchronized_channel": "dataset1" + } ], "datasets": [ { - "name": "dataset1", + "name": "dataset1", "outputs": [ "output1" ] - } + } ], "connections": [ { - "from": "dataset1.output1", + "from": "dataset1.output1", "to": "block1.in", "channel": "dataset1" - }, + }, { "from": "block2.out", "to": "analysis.in", "channel": "dataset1" - } + } ], "representation": { "connections": {}, "blocks": {}, "channel_colors": {} - } + } } @@ -790,7 +790,7 @@ class ToolchainCreation(ToolchainsAPIBase): author=user, name='toolchain-4', short_description='short description 4', - ) + ) assert toolchain4, errors @@ -808,12 +808,12 @@ class ToolchainCreation(ToolchainsAPIBase): if jsondata is None: #checks only toolchain tc = beat.core.toolchain.Toolchain(settings.PREFIX, - storage.fullname) + storage.fullname) else: #checks experiment (and toolchain indirectly) tc = beat.core.toolchain.Toolchain(settings.PREFIX, jsondata) assert tc.valid, \ - '\n * %s' % '\n * '.join(tc.errors) + '\n * %s' % '\n * '.join(tc.errors) def test_no_creation_for_anonymous_user(self): response = self.client.post(self.url) @@ -839,8 +839,8 @@ class ToolchainCreation(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'valid-name1'}), content_type='application/json') + json.dumps({ + 'name': 'valid-name1'}), content_type='application/json') url = reverse('api_toolchains:object', args=['jackdoe', 'valid-name1', 1]) content = self.checkResponse(response, 201, @@ -866,9 +866,9 @@ class ToolchainCreation(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'invalid name1' - }), content_type='application/json') + json.dumps({ + 'name': 'invalid name1' + }), content_type='application/json') url = reverse('api_toolchains:object', args=['jackdoe', 'invalid-name1', 1]) content = self.checkResponse(response, 201, @@ -894,9 +894,9 @@ class ToolchainCreation(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'personal' - }), content_type='application/json') + json.dumps({ + 'name': 'personal' + }), content_type='application/json') self.checkResponse(response, 400) @@ -905,9 +905,9 @@ class ToolchainCreation(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'toolchain 4' - }), content_type='application/json') + json.dumps({ + 'name': 'toolchain 4' + }), content_type='application/json') self.checkResponse(response, 400) @@ -916,15 +916,15 @@ class ToolchainCreation(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'new_toolchain', - 'description': 'blah' - }), content_type='application/json') + json.dumps({ + 'name': 'new_toolchain', + 'description': 'blah' + }), content_type='application/json') url = reverse('api_toolchains:object', args=['jackdoe', 'new_toolchain', 1]) content = self.checkResponse(response, 201, - content_type='application/json', - location=url) + content_type='application/json', + location=url) url = reverse('api_toolchains:object', args=['jackdoe', 'new_toolchain', 1]) self.assertTrue(isinstance(content, dict)) @@ -946,10 +946,10 @@ class ToolchainCreation(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'new_toolchain', - 'declaration': ToolchainsAPIBase.DECLARATION, - }), content_type='application/json') + json.dumps({ + 'name': 'new_toolchain', + 'declaration': ToolchainsAPIBase.DECLARATION, + }), content_type='application/json') url = reverse('api_toolchains:object', args=['jackdoe', 'new_toolchain', 1]) content = self.checkResponse(response, 201, @@ -972,10 +972,10 @@ class ToolchainCreation(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'new_toolchain', - 'declaration': ToolchainCreation.DECLARATION_INVALID, - }), content_type='application/json') + json.dumps({ + 'name': 'new_toolchain', + 'declaration': ToolchainCreation.DECLARATION_INVALID, + }), content_type='application/json') content = self.checkResponse(response, 400, content_type='application/json') assert content.find("The toolchain declaration is **invalid**") != -1 @@ -983,11 +983,11 @@ class ToolchainCreation(ToolchainsAPIBase): def test_no_forking_for_anonymous_user(self): response = self.client.post(self.url, - json.dumps({ - 'name': 'name1', - 'description': 'blah', - 'fork_of': 'johndoe/toolchain1/1' - }), content_type='application/json') + json.dumps({ + 'name': 'name1', + 'description': 'blah', + 'fork_of': 'johndoe/toolchain1/1' + }), content_type='application/json') self.checkResponse(response, 403) @@ -997,11 +997,11 @@ class ToolchainCreation(ToolchainsAPIBase): url = reverse('api_toolchains:list_create', args=['johndoe']) response = self.client.post(url, - json.dumps({ - 'name': 'name1', - 'description': 'blah', - 'fork_of': 'johndoe/toolchain1/1' - }), content_type='application/json') + json.dumps({ + 'name': 'name1', + 'description': 'blah', + 'fork_of': 'johndoe/toolchain1/1' + }), content_type='application/json') self.checkResponse(response, 403) @@ -1011,10 +1011,10 @@ class ToolchainCreation(ToolchainsAPIBase): url = reverse('api_toolchains:list_create', args=['johndoe']) response = self.client.post(url, - json.dumps({ - 'description': 'blah', - 'fork_of': 'jackdoe/public_for_one_user/1' - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'fork_of': 'jackdoe/public_for_one_user/1' + }), content_type='application/json') content = self.checkResponse(response, 400, content_type='application/json') self.assertEqual(content, {'name': ['This field is required.']}) @@ -1025,11 +1025,11 @@ class ToolchainCreation(ToolchainsAPIBase): url = reverse('api_toolchains:list_create', args=['janedoe']) response = self.client.post(url, - json.dumps({ - 'name': 'name1', - 'description': 'blah', - 'fork_of': 'jackdoe/public_for_one_user/1' - }), content_type='application/json') + json.dumps({ + 'name': 'name1', + 'description': 'blah', + 'fork_of': 'jackdoe/public_for_one_user/1' + }), content_type='application/json') content = self.checkResponse(response, 400, content_type='application/json') self.assertEqual(content, {'non_field_errors': ['No access allowed']}) @@ -1040,11 +1040,11 @@ class ToolchainCreation(ToolchainsAPIBase): url = reverse('api_toolchains:list_create', args=['janedoe']) response = self.client.post(url, - json.dumps({ - 'name': 'name1', - 'description': 'blah', - 'fork_of': 'jackdoe/personal/1' - }), content_type='application/json') + json.dumps({ + 'name': 'name1', + 'description': 'blah', + 'fork_of': 'jackdoe/personal/1' + }), content_type='application/json') content = self.checkResponse(response, 400, content_type='application/json') self.assertEqual(content, {'non_field_errors': ['No access allowed']}) @@ -1055,11 +1055,11 @@ class ToolchainCreation(ToolchainsAPIBase): url = reverse('api_toolchains:list_create', args=['janedoe']) response = self.client.post(url, - json.dumps({ - 'name': 'name1', - 'description': 'blah', - 'fork_of': 'jackdoe/public_for_all/1' - }), content_type='application/json') + json.dumps({ + 'name': 'name1', + 'description': 'blah', + 'fork_of': 'jackdoe/public_for_all/1' + }), content_type='application/json') url = reverse('api_toolchains:object', args=['janedoe', 'name1', 1]) content = self.checkResponse(response, 201, @@ -1084,16 +1084,16 @@ class ToolchainCreation(ToolchainsAPIBase): self.assertEqual(toolchain_forked.fork_of, toolchain) orginal_storage = beat.core.toolchain.Storage(settings.PREFIX, - toolchain.fullname()) + toolchain.fullname()) assert orginal_storage.exists destination_storage = beat.core.toolchain.Storage(settings.PREFIX, - toolchain_forked.fullname()) + toolchain_forked.fullname()) assert destination_storage.exists self.checkToolchainFile(toolchain.fullname(), - ToolchainsAPIBase.DECLARATION) + ToolchainsAPIBase.DECLARATION) self.checkToolchainFile(toolchain_forked.fullname(), - ToolchainsAPIBase.DECLARATION) + ToolchainsAPIBase.DECLARATION) def test_successful_forking_public_for_one_user(self): @@ -1101,11 +1101,11 @@ class ToolchainCreation(ToolchainsAPIBase): url = reverse('api_toolchains:list_create', args=['johndoe']) response = self.client.post(url, - json.dumps({ - 'name': 'name1', - 'description': 'blah', - 'fork_of': 'jackdoe/public_for_one_user/1' - }), content_type='application/json') + json.dumps({ + 'name': 'name1', + 'description': 'blah', + 'fork_of': 'jackdoe/public_for_one_user/1' + }), content_type='application/json') url = reverse('api_toolchains:object', args=['johndoe', 'name1', 1]) content = self.checkResponse(response, 201, @@ -1127,28 +1127,28 @@ class ToolchainCreation(ToolchainsAPIBase): self.assertEqual(toolchain_forked.fork_of, toolchain) orginal_storage = beat.core.toolchain.Storage(settings.PREFIX, - toolchain.fullname()) + toolchain.fullname()) assert orginal_storage.exists destination_storage = beat.core.toolchain.Storage(settings.PREFIX, - toolchain_forked.fullname()) + toolchain_forked.fullname()) assert destination_storage.exists self.checkToolchainFile(toolchain.fullname(), - ToolchainsAPIBase.DECLARATION) + ToolchainsAPIBase.DECLARATION) self.checkToolchainFile(toolchain_forked.fullname(), - ToolchainsAPIBase.DECLARATION) + ToolchainsAPIBase.DECLARATION) def test_successful_forking_with_declaration(self): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'name': 'name1', - 'description': 'blah', - 'declaration': ToolchainsAPIBase.DECLARATION, - 'fork_of': 'jackdoe/public_for_one_user/1' - }), content_type='application/json') + json.dumps({ + 'name': 'name1', + 'description': 'blah', + 'declaration': ToolchainsAPIBase.DECLARATION, + 'fork_of': 'jackdoe/public_for_one_user/1' + }), content_type='application/json') url = reverse('api_toolchains:object', args=['jackdoe', 'name1', 1]) self.checkResponse(response, 201, @@ -1165,93 +1165,93 @@ class ToolchainUpdate(ToolchainsAPIBase): DECLARATION_UPDATE = { "blocks": [ { - "name": "block2", + "name": "block2", "inputs": [ "in" ], - "outputs": [ + "outputs": [ "out" ], - "synchronized_channel": "dataset1" - } + "synchronized_channel": "dataset1" + } ], "analyzers": [ { - "name": "analysis", + "name": "analysis", "inputs": [ "in" ], - "synchronized_channel": "dataset1" - } + "synchronized_channel": "dataset1" + } ], "datasets": [ { - "name": "dataset1", + "name": "dataset1", "outputs": [ "output1" ] - } + } ], "connections": [ { - "from": "dataset1.output1", + "from": "dataset1.output1", "to": "block2.in", "channel": "dataset1" - }, + }, { "from": "block2.out", "to": "analysis.in", "channel": "dataset1" - } + } ], "representation": { "connections": {}, "blocks": {}, "channel_colors": {} - } + } } DECLARATION_INVALID = { "blocks": [ { - "name": "block1", + "name": "block1", "inputs": [ "in" ], - "outputs": [ + "outputs": [ "out" ], - "synchronized_channel": "dataset1" - } + "synchronized_channel": "dataset1" + } ], "analyzers": [ { - "name": "analysis", + "name": "analysis", "inputs": [ "in" ], - "synchronized_channel": "dataset1" - } + "synchronized_channel": "dataset1" + } ], "datasets": [ { - "name": "dataset1", + "name": "dataset1", "outputs": [ "output1" ], - } + } ], "connections": [ { - "from": "dataset1.output1", + "from": "dataset1.output1", "to": "block1.in", "channel": "dataset1" - }, + }, { "from": "block2.out", "to": "analysis.in", "channel": "dataset1" - } + } ], "representation": { "connections": {}, "blocks": {}, "channel_colors": {} - } + } } def setUp(self): @@ -1265,12 +1265,12 @@ class ToolchainUpdate(ToolchainsAPIBase): if jsondata is None: #checks only toolchain tc = beat.core.toolchain.Toolchain(settings.PREFIX, - storage.fullname) + storage.fullname) else: #checks experiment (and toolchain indirectly) tc = beat.core.toolchain.Toolchain(settings.PREFIX, jsondata) assert tc.valid, \ - '\n * %s' % '\n * '.join(tc.errors) + '\n * %s' % '\n * '.join(tc.errors) self.assertTrue(isinstance(data, dict)) self.assertTrue(data.has_key('declaration')) @@ -1278,9 +1278,9 @@ class ToolchainUpdate(ToolchainsAPIBase): def test_no_update_for_anonymous_user(self): response = self.client.put(self.url, - json.dumps({ - 'description': 'blah', - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + }), content_type='application/json') self.checkResponse(response, 403) @@ -1288,9 +1288,9 @@ class ToolchainUpdate(ToolchainsAPIBase): def test_no_update_for_other_user(self): self.client.login(username='johndoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'description': 'blah', - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + }), content_type='application/json') self.checkResponse(response, 403) @@ -1300,9 +1300,9 @@ class ToolchainUpdate(ToolchainsAPIBase): url = reverse('api_toolchains:object', args=['unknown', 'personal', 1]) response = self.client.put(url, - json.dumps({ - 'description': 'blah', - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + }), content_type='application/json') self.checkResponse(response, 403) @@ -1312,9 +1312,9 @@ class ToolchainUpdate(ToolchainsAPIBase): url = reverse('api_toolchains:object', args=['jackdoe', 'unknown', 1]) response = self.client.put(url, - json.dumps({ - 'description': 'blah', - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + }), content_type='application/json') self.checkResponse(response, 404) @@ -1324,9 +1324,9 @@ class ToolchainUpdate(ToolchainsAPIBase): url = reverse('api_toolchains:object', args=['jackdoe', 'personal', 2]) response = self.client.put(url, - json.dumps({ - 'description': 'blah', - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + }), content_type='application/json') self.checkResponse(response, 404) @@ -1336,9 +1336,9 @@ class ToolchainUpdate(ToolchainsAPIBase): url = reverse('api_toolchains:object', args=['jackdoe', 'personal']) response = self.client.put(url, - json.dumps({ - 'description': 'blah', - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + }), content_type='application/json') self.checkResponse(response, 400) @@ -1352,7 +1352,7 @@ class ToolchainUpdate(ToolchainsAPIBase): def test_fail_to_update_without_content(self): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, '{}', - content_type='application/json') + content_type='application/json') self.checkResponse(response, 400, content_type='application/json') @@ -1360,9 +1360,9 @@ class ToolchainUpdate(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'description': 'blah', - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + }), content_type='application/json') self.checkResponse(response, 200, content_type='application/json') @@ -1374,9 +1374,9 @@ class ToolchainUpdate(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': ToolchainUpdate.DECLARATION_UPDATE, - }), content_type='application/json') + json.dumps({ + 'declaration': ToolchainUpdate.DECLARATION_UPDATE, + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1391,9 +1391,9 @@ class ToolchainUpdate(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'declaration': ToolchainUpdate.DECLARATION_INVALID, - }), content_type='application/json') + json.dumps({ + 'declaration': ToolchainUpdate.DECLARATION_INVALID, + }), content_type='application/json') content = self.checkResponse(response, 400, content_type='application/json' @@ -1405,10 +1405,10 @@ class ToolchainUpdate(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'description': 'blah', - 'declaration': self.DECLARATION_INVALID, - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': self.DECLARATION_INVALID, + }), content_type='application/json') content = self.checkResponse(response, 400, content_type='application/json' @@ -1420,10 +1420,10 @@ class ToolchainUpdate(ToolchainsAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.put(self.url, - json.dumps({ - 'description': 'blah', - 'declaration': ToolchainUpdate.DECLARATION_UPDATE, - }), content_type='application/json') + json.dumps({ + 'description': 'blah', + 'declaration': ToolchainUpdate.DECLARATION_UPDATE, + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1622,8 +1622,8 @@ class ToolchainSharingAPI_Failures(ToolchainSharingAPIBase): def test_fail_sharing_for_anonymous_user(self): response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') self.checkResponse(response, 403) @@ -1631,8 +1631,8 @@ class ToolchainSharingAPI_Failures(ToolchainSharingAPIBase): def test_fail_sharing_for_unauthorized_user(self): self.client.login(username='johndoe', password='1234') response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') self.checkResponse(response, 403) @@ -1641,9 +1641,9 @@ class ToolchainSharingAPI_Failures(ToolchainSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['doejack'], - }), content_type='application/json') + json.dumps({ + 'users' : ['doejack'], + }), content_type='application/json') data = self.checkResponse(response, 400, content_type='application/json') self.assertTrue(data is not None) @@ -1661,8 +1661,8 @@ class NotSharedToolchain_SharingAPI(ToolchainSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1678,9 +1678,9 @@ class NotSharedToolchain_SharingAPI(ToolchainSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['johndoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['johndoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1697,9 +1697,9 @@ class NotSharedToolchain_SharingAPI(ToolchainSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['johndoe', 'janedoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['johndoe', 'janedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1723,8 +1723,8 @@ class PublicForOneUserToolchain_SharingAPI(ToolchainSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1740,9 +1740,9 @@ class PublicForOneUserToolchain_SharingAPI(ToolchainSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['johndoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['johndoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1759,9 +1759,9 @@ class PublicForOneUserToolchain_SharingAPI(ToolchainSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['janedoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['janedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1778,9 +1778,9 @@ class PublicForOneUserToolchain_SharingAPI(ToolchainSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users' : ['janedoe', 'jacquelinedoe'], - }), content_type='application/json') + json.dumps({ + 'users' : ['janedoe', 'jacquelinedoe'], + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1805,8 +1805,8 @@ class PublicForAllToolchain_SharingAPI(ToolchainSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - }), content_type='application/json') + json.dumps({ + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1822,9 +1822,9 @@ class PublicForAllToolchain_SharingAPI(ToolchainSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users': ['johndoe'] - }), content_type='application/json') + json.dumps({ + 'users': ['johndoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') @@ -1840,9 +1840,9 @@ class PublicForAllToolchain_SharingAPI(ToolchainSharingAPIBase): self.client.login(username='jackdoe', password='1234') response = self.client.post(self.url, - json.dumps({ - 'users': ['johndoe', 'janedoe'] - }), content_type='application/json') + json.dumps({ + 'users': ['johndoe', 'janedoe'] + }), content_type='application/json') data = self.checkResponse(response, 200, content_type='application/json') diff --git a/beat/web/toolchains/views.py b/beat/web/toolchains/views.py index aafc5805d..51c7458cd 100644 --- a/beat/web/toolchains/views.py +++ b/beat/web/toolchains/views.py @@ -65,9 +65,9 @@ def create(request, name=None): # Retrieves the existing toolchain (if necessary) if name is not None: previous_versions = Toolchain.objects.filter( - author=request.user, - name__iexact=name, - ).order_by('-version') + author=request.user, + name__iexact=name, + ).order_by('-version') if len(previous_versions) == 0: raise Http404() @@ -166,14 +166,14 @@ def view(request, author, name, version=None): # Retrieves the forked toolchain if version: toolchain = get_object_or_404( - Toolchain, - author__username__iexact=author, - name__iexact=name, - version=int(version), - ) + Toolchain, + author__username__iexact=author, + name__iexact=name, + version=int(version), + ) else: toolchain = Toolchain.objects.filter(author__username__iexact=author, - name__iexact=name).order_by('-version') + name__iexact=name).order_by('-version') if not toolchain: raise Http404() else: @@ -211,20 +211,20 @@ def diff(request, author1, name1, version1, author2, name2, version2): """ toolchain1 = get_object_or_404( - Toolchain, - author__username__iexact=author1, - name__iexact=name1, - version=int(version1), - ) + Toolchain, + author__username__iexact=author1, + name__iexact=name1, + version=int(version1), + ) has_access, _ = toolchain1.accessibility_for(request.user) if not has_access: raise Http404() toolchain2 = get_object_or_404( - Toolchain, - author__username__iexact=author2, - name__iexact=name2, - version=int(version2), - ) + Toolchain, + author__username__iexact=author2, + name__iexact=name2, + version=int(version2), + ) has_access, _ = toolchain2.accessibility_for(request.user) if not has_access: raise Http404() @@ -246,17 +246,17 @@ def ls(request, author_name): # orders toolchains so that the latest information is displayed first objects = Toolchain.objects.from_author_and_public(request.user, - author_name).order_by('-creation_date') + author_name).order_by('-creation_date') objects = Toolchain.filter_latest_versions(objects) return render_to_response('toolchains/list.html', - dict( - objects=objects, - author=author, - owner=(request.user==author), - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=author, + owner=(request.user==author), + ), + context_instance=RequestContext(request), + ) def public_ls(request): @@ -267,10 +267,10 @@ def public_ls(request): objects = Toolchain.filter_latest_versions(objects) return render_to_response('toolchains/list.html', - dict( - objects=objects, - author=request.user, #anonymous - owner=False, - ), - context_instance=RequestContext(request), - ) + dict( + objects=objects, + author=request.user, #anonymous + owner=False, + ), + context_instance=RequestContext(request), + ) diff --git a/beat/web/ui/forms.py b/beat/web/ui/forms.py index 84cc0f151..21e9a098b 100644 --- a/beat/web/ui/forms.py +++ b/beat/web/ui/forms.py @@ -82,8 +82,8 @@ class CodeMirrorRSTCharField(CodeMirrorCharField): codemirror_kwargs = dict(codemirror_kwargs) addon_js = list(codemirror_kwargs.get('addon_js', [])) addon_js += [ - "display/rulers", - ] + "display/rulers", + ] codemirror_kwargs['addon_js'] = addon_js codemirror_kwargs['mode'] = 'rst' @@ -105,9 +105,9 @@ class CodeMirrorPythonCharField(CodeMirrorCharField): codemirror_kwargs = dict(codemirror_kwargs) addon_js = list(codemirror_kwargs.get('addon_js', [])) addon_js += [ - "fold/indent-fold", + "fold/indent-fold", "display/rulers", - ] + ] codemirror_kwargs['addon_js'] = addon_js codemirror_kwargs['mode'] = 'python' @@ -121,9 +121,9 @@ class CodeMirrorJSONCharField(CodeMirrorCharField): codemirror_kwargs = dict(codemirror_kwargs) addon_js = list(codemirror_kwargs.get('addon_js', [])) addon_js += [ - "fold/brace-fold", + "fold/brace-fold", "display/rulers", - ] + ] codemirror_kwargs['addon_js'] = addon_js codemirror_kwargs['mode'] = {'name': 'javascript', 'json': True} @@ -164,8 +164,8 @@ class CodeMirrorRSTFileField(CodeMirrorFileField): codemirror_kwargs = dict(codemirror_kwargs) addon_js = list(codemirror_kwargs.get('addon_js', [])) addon_js += [ - "display/rulers", - ] + "display/rulers", + ] codemirror_kwargs['addon_js'] = addon_js codemirror_kwargs['mode'] = 'rst' @@ -187,9 +187,9 @@ class CodeMirrorPythonFileField(CodeMirrorFileField): codemirror_kwargs = dict(codemirror_kwargs) addon_js = list(codemirror_kwargs.get('addon_js', [])) addon_js += [ - "fold/indent-fold", + "fold/indent-fold", "display/rulers", - ] + ] codemirror_kwargs['addon_js'] = addon_js codemirror_kwargs['mode'] = 'python' @@ -203,9 +203,9 @@ class CodeMirrorJSONFileField(CodeMirrorFileField): codemirror_kwargs = dict(codemirror_kwargs) addon_js = list(codemirror_kwargs.get('addon_js', [])) addon_js += [ - "fold/brace-fold", + "fold/brace-fold", "display/rulers", - ] + ] codemirror_kwargs['addon_js'] = addon_js codemirror_kwargs['mode'] = {'name': 'javascript', 'json': True} diff --git a/beat/web/ui/registration/forms.py b/beat/web/ui/registration/forms.py index 355dcc2d0..255698717 100644 --- a/beat/web/ui/registration/forms.py +++ b/beat/web/ui/registration/forms.py @@ -83,9 +83,9 @@ class RegistrationForm(forms.Form): password2 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, render_value=False), label=_(u'Password (again)')) godfather = forms.RegexField(regex=r'^\w+$', - max_length=30, - widget=forms.TextInput(attrs=attrs_dict), - label=_(u'Supervisor Username')) + max_length=30, + widget=forms.TextInput(attrs=attrs_dict), + label=_(u'Supervisor Username')) def clean_username(self): @@ -143,12 +143,12 @@ class RegistrationForm(forms.Form): """ new_user = RegistrationProfile.objects.create_inactive_user( - username=self.cleaned_data['username'], - first_name=self.cleaned_data['first_name'], - last_name=self.cleaned_data['last_name'], - password=self.cleaned_data['password1'], - email=self.cleaned_data['email'], - ) + username=self.cleaned_data['username'], + first_name=self.cleaned_data['first_name'], + last_name=self.cleaned_data['last_name'], + password=self.cleaned_data['password1'], + email=self.cleaned_data['email'], + ) #Create and assign key new_user.profile.supervision_key = new_user.profile._generate_current_supervision_key() @@ -157,7 +157,7 @@ class RegistrationForm(forms.Form): supervisee = new_user, godfather = godfather, is_valid = False, - ) + ) #Assign key to supervision track supervisiontrack.supervision_key = new_user.profile.supervision_key @@ -205,10 +205,10 @@ class RegistrationFormTermsOfService(RegistrationForm): """ tos = forms.BooleanField( - widget=forms.CheckboxInput(attrs=attrs_dict), - label=u'I have carefully read the <a href="">Terms of Service</a>, which include the Privacy and Data Protection Terms of Use, and fully agree and undertake to comply with all provisions therein by checking this box.', - error_messages=dict(required=u"You must agree to the Terms of Service in order to register"), - ) + widget=forms.CheckboxInput(attrs=attrs_dict), + label=u'I have carefully read the <a href="">Terms of Service</a>, which include the Privacy and Data Protection Terms of Use, and fully agree and undertake to comply with all provisions therein by checking this box.', + error_messages=dict(required=u"You must agree to the Terms of Service in order to register"), + ) class RegistrationFormUniqueEmail(RegistrationForm): @@ -272,11 +272,11 @@ class BlockedUserRevalidationForm(forms.Form): widget=forms.TextInput(attrs=attrs_dict), label=_(u'Username')) password = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, render_value=False), - label=_(u'Password')) + label=_(u'Password')) godfather = forms.RegexField(regex=r'^\w+$', - max_length=30, - widget=forms.TextInput(attrs=attrs_dict), - label=_(u'Supervisor Username (Your account needs to be re-validated by a recognized person)')) + max_length=30, + widget=forms.TextInput(attrs=attrs_dict), + label=_(u'Supervisor Username (Your account needs to be re-validated by a recognized person)')) def clean_username(self): diff --git a/beat/web/ui/registration/models.py b/beat/web/ui/registration/models.py index 405c31daf..5f747cf47 100644 --- a/beat/web/ui/registration/models.py +++ b/beat/web/ui/registration/models.py @@ -331,7 +331,7 @@ class RegistrationProfile(models.Model): """ expiration_date = datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS) return self.activation_key == self.ACTIVATED or \ - (self.user.date_joined + expiration_date <= datetime.datetime.now()) + (self.user.date_joined + expiration_date <= datetime.datetime.now()) activation_key_expired.boolean = True diff --git a/beat/web/ui/registration/views.py b/beat/web/ui/registration/views.py index 3518d3f90..42a1e683e 100644 --- a/beat/web/ui/registration/views.py +++ b/beat/web/ui/registration/views.py @@ -183,8 +183,8 @@ def register(request, success_url=None, context[key] = callable(value) and value() or value return render_to_response( - template_name, - { - 'form': form, - }, - context_instance=context) + template_name, + { + 'form': form, + }, + context_instance=context) diff --git a/beat/web/ui/templatetags/markup.py b/beat/web/ui/templatetags/markup.py index de62becf2..c37ea1e30 100644 --- a/beat/web/ui/templatetags/markup.py +++ b/beat/web/ui/templatetags/markup.py @@ -86,13 +86,13 @@ def markdown(value, arg=''): extensions, safe_mode=True, enable_attributes=False, - )) + )) else: return mark_safe(markdown.markdown( force_text(value), extensions, safe_mode=False, - )) + )) @register.filter(is_safe=True) diff --git a/beat/web/ui/templatetags/ui_tags.py b/beat/web/ui/templatetags/ui_tags.py index adefe9f1d..b7de33aff 100644 --- a/beat/web/ui/templatetags/ui_tags.py +++ b/beat/web/ui/templatetags/ui_tags.py @@ -45,7 +45,7 @@ def navbar(context): return { 'request': context['request'], 'public_urls': [ - ('experiments', 'experiments:public-list'), + ('experiments', 'experiments:public-list'), (False, ''), ('toolchains', 'toolchains:public-list'), ('algorithms', 'algorithms:public-list'), @@ -62,9 +62,9 @@ def navbar(context): ('environments', 'backend:list-environments'), ('plotters', 'plotters:list'), #('plotterparameters', 'plotters:plotterparameter-public-list'), - ], + ], 'user_urls': [ - ('experiments', 'experiments:list', True), + ('experiments', 'experiments:list', True), (False, '', False), ('toolchains', 'toolchains:list', True), ('algorithms', 'algorithms:list', True), @@ -81,8 +81,8 @@ def navbar(context): ('environments', 'backend:list-environments', False), ('plotters', 'plotters:list', False), #('plotterparameters', 'plotters:plotterparameter-list', True), - ], - } + ], + } #-------------------------------------------------- @@ -92,13 +92,13 @@ def navbar(context): def contribution_breadcrumb(context, obj): name_plural = obj.get_verbose_name_plural() return { - 'request': context['request'], + 'request': context['request'], 'object': obj, 'name_plural': name_plural, 'listurl': name_plural + ':list', 'public_listurl': name_plural + ':public-list', 'viewurl': name_plural + ':view-latest', - } + } #-------------------------------------------------- @@ -108,13 +108,13 @@ def contribution_breadcrumb(context, obj): def contribution_breadcrumb_plotter(context, obj): name_plural = obj.get_verbose_name_plural() return { - 'request': context['request'], + 'request': context['request'], 'object': obj, 'name_plural': name_plural, 'listurl': name_plural + ':list', 'public_listurl': name_plural + ':list', 'viewurl': name_plural + ':plotter-view-latest', - } + } #-------------------------------------------------- @@ -125,13 +125,13 @@ def contribution_breadcrumb_plotterparameter(context, obj): name_plural = 'plotterparameters' name_url = 'plotters' return { - 'request': context['request'], + 'request': context['request'], 'object': obj, 'name_plural': name_plural, 'listurl': name_url + ':plotterparameter-list', 'public_listurl': name_url + ':plotterparameter-public-list', 'viewurl': name_url + ':plotterparameter-view-latest', - } + } #-------------------------------------------------- @@ -140,10 +140,10 @@ def contribution_breadcrumb_plotterparameter(context, obj): @register.inclusion_tag('ui/filter_script.html') def filter_script(panel_id, text_filter_id, privacy_filter_id): return dict( - panel_id=panel_id, - text_filter_id=text_filter_id, - privacy_filter_id=privacy_filter_id, - ) + panel_id=panel_id, + text_filter_id=text_filter_id, + privacy_filter_id=privacy_filter_id, + ) #-------------------------------------------------- @@ -162,13 +162,13 @@ def smart_selector(id): def list_tabs(context, user, tab): name = 'list' if not user.is_anonymous() else 'public-list' return dict( - request=context['request'], - user=user, - tab=tab, + request=context['request'], + user=user, + tab=tab, - #tab name -> list url mappings + #tab name -> list url mappings user_tabs=OrderedDict([ - ('experiments', 'experiments:' + name), + ('experiments', 'experiments:' + name), (False, ''), ('toolchains', 'toolchains:' + name), ('algorithms', 'algorithms:' + name), @@ -180,13 +180,13 @@ def list_tabs(context, user, tab): ('searches', 'search:' + name), ('teams', 'teams:' + name), ('plotterparameters', 'plotters:plotterparameter-' + name), - ]), + ]), system_tabs=OrderedDict([ - ('databases', 'databases:list'), + ('databases', 'databases:list'), ('environments', 'backend:list-environments'), ('plotters', 'plotters:list'), - ]), - ) + ]), + ) #-------------------------------------------------- @@ -213,13 +213,13 @@ def multiple_selector(id): @register.inclusion_tag('ui/doc_editor.html', takes_context=True) def doc_editor(context, obj, url_name, editable=True): return { - 'request': context['request'], + 'request': context['request'], 'owner': obj.author == context['request'].user, 'object': obj, 'url_name': url_name, 'texts': Texts, 'editable': editable, - } + } #-------------------------------------------------- @@ -228,13 +228,13 @@ def doc_editor(context, obj, url_name, editable=True): @register.inclusion_tag('ui/history.html', takes_context=True) def history(context, plural, obj, panel_id, height): return { - 'plural': plural, + 'plural': plural, 'object': obj, 'history': obj.json_history(context['request'].user), 'panel_id': panel_id, 'height': height, 'URL_PREFIX': context['URL_PREFIX'], - } + } #-------------------------------------------------- @@ -253,7 +253,7 @@ def code_editor_scripts(modes): 'addon/search/searchcursor.js', 'addon/dialog/dialog.js', 'addon/display/rulers.js', - ] + ] # adds mode-related CodeMirror plugins js += ['mode/%s/%s.js' % (k,k) for k in modes.split(',')] @@ -304,9 +304,9 @@ def messages(request): """Sets-up the HTML for message display""" from django.contrib import messages as django_messages return dict( - messages=django_messages.get_messages(request), - DEFAULT_MESSAGE_LEVELS=django_messages.DEFAULT_LEVELS, - ) + messages=django_messages.get_messages(request), + DEFAULT_MESSAGE_LEVELS=django_messages.DEFAULT_LEVELS, + ) #-------------------------------------------------- diff --git a/beat/web/ui/urls.py b/beat/web/ui/urls.py index 960b0c3ad..7212a310e 100644 --- a/beat/web/ui/urls.py +++ b/beat/web/ui/urls.py @@ -80,10 +80,10 @@ urlpatterns = [ url(r'^signup/complete/$', TemplateView.as_view( - template_name=('registration/registration_pending.html' if \ - settings.PREREGISTRATION_ONLY else \ - 'registration/registration_complete.html') - ), + template_name=('registration/registration_pending.html' if \ + settings.PREREGISTRATION_ONLY else \ + 'registration/registration_complete.html') + ), name='registration-complete', ), @@ -95,17 +95,17 @@ urlpatterns = [ url(r'^preregister/$', register, dict( - success_url='pre-registration-complete', + success_url='pre-registration-complete', form_class= PreregistrationForm, template_name='registration/preregistration_form.html', - ), + ), name='pre-registration' ), url(r'^preregistration/complete/$', TemplateView.as_view( - template_name='registration/preregistration_complete.html', - ), + template_name='registration/preregistration_complete.html', + ), name='pre-registration-complete', ), diff --git a/beat/web/ui/views.py b/beat/web/ui/views.py index 3c26932f4..e56abdd89 100755 --- a/beat/web/ui/views.py +++ b/beat/web/ui/views.py @@ -64,7 +64,7 @@ def index(request): '''Our main index page''' return render_to_response('ui/index.html', - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) #---------------------------------------------------------- @@ -110,7 +110,7 @@ def blocked_user_reactivation(request): supervisee = supervisee, godfather = godfather, is_valid = False, - ) + ) # Assign key to supervision track supervisiontrack.supervision_key = supervisee.profile.supervision_key @@ -191,7 +191,7 @@ def blocked_user_reactivation(request): form = BlockedUserRevalidationForm() return render_to_response('registration/blocked_user_reactivate.html', {'form': form}, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) #---------------------------------------------------------- @@ -230,19 +230,19 @@ def gather_contributions(requestor, author): return dict( - experiments=experiments, - toolchains=toolchains, - algorithms=algorithms, - libraries=libraries, - dataformats=dataformats, - teams=teams, + experiments=experiments, + toolchains=toolchains, + algorithms=algorithms, + libraries=libraries, + dataformats=dataformats, + teams=teams, - attestations=attestations, - searches=searches, - reports=reports, - plotters=plotters, + attestations=attestations, + searches=searches, + reports=reports, + plotters=plotters, - ) + ) #---------------------------------------------------------- @@ -264,14 +264,14 @@ def activity_stream(request, author_name): leaderboards = Leaderboard.objects.filter(search__in=Search.objects.for_user(request.user).filter(author=author)).order_by('-changed') return render_to_response('ui/activity_stream.html', - dict( - owner = (request.user == author), - author= author, - statistics= gather_contributions(request.user, author), - leaderboards= leaderboards, - ), - context_instance=RequestContext(request), - ) + dict( + owner = (request.user == author), + author= author, + statistics= gather_contributions(request.user, author), + leaderboards= leaderboards, + ), + context_instance=RequestContext(request), + ) #---------------------------------------------------------- @@ -289,32 +289,32 @@ def docreq(request, author_name): to = '%s %s <%s>' % (author.first_name, author.last_name, author.email) cc = '%s %s <%s>' % (request.user.first_name, request.user.last_name, - request.user.email) + request.user.email) try: subject_template = 'ui/docreq_email_subject.txt' subject = render_to_string(subject_template, - { - 'user': request.user, - 'url': url, - }, - ).strip() + { + 'user': request.user, + 'url': url, + }, + ).strip() body_template = 'ui/docreq_email_body.txt' body = render_to_string(body_template, - { - 'user': request.user, - 'url': url, - 'beat_version': __version__, - }, - ) + { + 'user': request.user, + 'url': url, + 'beat_version': __version__, + }, + ) message = EmailMessage(subject=subject, body=body, - from_email=settings.DEFAULT_FROM_EMAIL, to=[to], reply_to=[cc]) + from_email=settings.DEFAULT_FROM_EMAIL, to=[to], reply_to=[cc]) message.send() except Exception: import traceback logger.warn("Could not send e-mail to `%s' (cc: `%s') about " \ - "documentation request for `%s'. Exception caught: %s", to, cc, - url, traceback.format_exc()) + "documentation request for `%s'. Exception caught: %s", to, cc, + url, traceback.format_exc()) return HttpResponse() @@ -336,7 +336,7 @@ def user_settings(request): if password_change_form.is_valid(): password_change_form.save() messages.add_message(request, messages.SUCCESS, - 'Password changed successfully') + 'Password changed successfully') elif 'token' in request.POST: @@ -344,31 +344,31 @@ def user_settings(request): Token.objects.create(user=user) password_change_form = PasswordChangeForm(user=user) messages.add_message(request, messages.SUCCESS, - 'Token changed successfully') + 'Token changed successfully') else: password_change_form = PasswordChangeForm(user=user) return render_to_response('ui/user_settings.html', - { - 'password_change_form': password_change_form, - 'token' : user.auth_token, - 'statistics' : { - 'nb_experiments': user.experiments.count(), - 'nb_public_experiments': user.experiments.filter(sharing=Shareable.PUBLIC).count(), - 'nb_attested_experiments': user.experiments.filter(~Q(attestation=None)).count(), - 'nb_toolchains': user.toolchains.count(), - 'nb_public_toolchains': user.toolchains.filter(sharing=Shareable.PUBLIC).count(), - 'nb_algorithms': user.algorithms.count(), - 'nb_public_algorithms': user.algorithms.filter(sharing=Shareable.PUBLIC).count(), - 'nb_libraries': user.algorithms.count(), - 'nb_public_libraries': user.librarys.filter(sharing=Shareable.PUBLIC).count(), - 'nb_dataformats': user.dataformats.count(), - 'nb_public_dataformats': user.dataformats.filter(sharing=Shareable.PUBLIC).count(), - }, - }, - context_instance=RequestContext(request)) + { + 'password_change_form': password_change_form, + 'token' : user.auth_token, + 'statistics' : { + 'nb_experiments': user.experiments.count(), + 'nb_public_experiments': user.experiments.filter(sharing=Shareable.PUBLIC).count(), + 'nb_attested_experiments': user.experiments.filter(~Q(attestation=None)).count(), + 'nb_toolchains': user.toolchains.count(), + 'nb_public_toolchains': user.toolchains.filter(sharing=Shareable.PUBLIC).count(), + 'nb_algorithms': user.algorithms.count(), + 'nb_public_algorithms': user.algorithms.filter(sharing=Shareable.PUBLIC).count(), + 'nb_libraries': user.algorithms.count(), + 'nb_public_libraries': user.librarys.filter(sharing=Shareable.PUBLIC).count(), + 'nb_dataformats': user.dataformats.count(), + 'nb_public_dataformats': user.dataformats.filter(sharing=Shareable.PUBLIC).count(), + }, + }, + context_instance=RequestContext(request)) #---------------------------------------------------------- diff --git a/beat/web/ui/widgets.py b/beat/web/ui/widgets.py index 9a79c6a15..ad67fedac 100644 --- a/beat/web/ui/widgets.py +++ b/beat/web/ui/widgets.py @@ -135,10 +135,10 @@ class CodeMirrorTextarea(forms.Textarea): def media(self): mode_name = self.mode_name js = [ - "%s/lib/codemirror.js" % (CODEMIRROR_PATH,), + "%s/lib/codemirror.js" % (CODEMIRROR_PATH,), "%s/addon/fold/foldcode.js" % (CODEMIRROR_PATH,), "%s/addon/fold/foldgutter.js" % (CODEMIRROR_PATH,), - ] + ] if not self.custom_mode: js.append("%s/mode/%s/%s.js" % (CODEMIRROR_PATH, mode_name, mode_name)) @@ -156,23 +156,23 @@ class CodeMirrorTextarea(forms.Textarea): js += ["ui/js/codemirror-defaults.js"] css = ( - "%s/lib/codemirror.css" % CODEMIRROR_PATH, - ) + \ - tuple("%s/theme/%s.css" % (CODEMIRROR_PATH, theme_css_filename) - for theme_css_filename in self.theme_css) + \ - tuple("%s/addon/%s.css" % (CODEMIRROR_PATH, css_file) - for css_file in self.addon_css) + \ - ( - "ui/css/codemirror-overrides.css", + "%s/lib/codemirror.css" % CODEMIRROR_PATH, + ) + \ + tuple("%s/theme/%s.css" % (CODEMIRROR_PATH, theme_css_filename) + for theme_css_filename in self.theme_css) + \ + tuple("%s/addon/%s.css" % (CODEMIRROR_PATH, css_file) + for css_file in self.addon_css) + \ + ( + "ui/css/codemirror-overrides.css", "%s/addon/fold/foldgutter.css" % CODEMIRROR_PATH, - ) + ) # adds version fingerprinting to javascript/css files js = ['%s?v=%s' % (k, __version__) for k in js] css = ['%s?v=%s' % (k, __version__) for k in css] return forms.Media(css={'all': css}, - js=js + js=js ) def __init__( @@ -266,11 +266,11 @@ class CodeMirrorTextarea(forms.Textarea): self.keymap = keymap self.addon_js = uniq(list(addon_js) + [ - "mode/overlay", + "mode/overlay", "search/search", "search/searchcursor", "dialog/dialog", - ]) + ]) self.addon_css = uniq(list(addon_css) + ["dialog/dialog"]) @@ -300,11 +300,11 @@ class CodeMirrorTextarea(forms.Textarea): super(CodeMirrorTextarea, self).render(name, value, attrs), '<script type="text/javascript">var %(name)s_editor = CodeMirror.fromTextArea(document.getElementById("id_%(name)s"), %(options)s);%(suffix)s</script>' % \ dict( - name=name, - options=option_json, - suffix=suffix, - ), - ] + name=name, + options=option_json, + suffix=suffix, + ), + ] return mark_safe('\n'.join(output)) class CodeMirrorFileWidget(CodeMirrorTextarea): diff --git a/beat/web/urls.py b/beat/web/urls.py index 25b019f61..d7d626b32 100755 --- a/beat/web/urls.py +++ b/beat/web/urls.py @@ -45,55 +45,55 @@ unprefixed_patterns += navigation_urls.urlpatterns unprefixed_patterns += [ url(r'^algorithms/', - include('beat.web.algorithms.urls', namespace='algorithms'), + include('beat.web.algorithms.urls', namespace='algorithms'), ), url(r'^libraries/', - include('beat.web.libraries.urls', namespace='libraries'), + include('beat.web.libraries.urls', namespace='libraries'), ), url(r'^attestations/', - include('beat.web.attestations.urls', namespace='attestations'), + include('beat.web.attestations.urls', namespace='attestations'), ), url(r'^backend/', - include('beat.web.backend.urls', namespace='backend'), + include('beat.web.backend.urls', namespace='backend'), ), url(r'^dataformats/', - include('beat.web.dataformats.urls', namespace='dataformats'), + include('beat.web.dataformats.urls', namespace='dataformats'), ), url(r'^databases/', - include('beat.web.databases.urls', namespace='databases'), + include('beat.web.databases.urls', namespace='databases'), ), url(r'^experiments/', - include('beat.web.experiments.urls', namespace='experiments'), + include('beat.web.experiments.urls', namespace='experiments'), ), url(r'^search/', - include('beat.web.search.urls', namespace='search'), + include('beat.web.search.urls', namespace='search'), ), url(r'^statistics/', - include('beat.web.statistics.urls', namespace='statistics'), + include('beat.web.statistics.urls', namespace='statistics'), ), url(r'^toolchains/', - include('beat.web.toolchains.urls', namespace='toolchains'), + include('beat.web.toolchains.urls', namespace='toolchains'), ), url(r'^teams/', - include('beat.web.team.urls', namespace='teams'), + include('beat.web.team.urls', namespace='teams'), ), url(r'^plotters/', - include('beat.web.plotters.urls', namespace='plotters'), + include('beat.web.plotters.urls', namespace='plotters'), ), url(r'^reports/', - include('beat.web.reports.urls', namespace='reports'), + include('beat.web.reports.urls', namespace='reports'), ), url(r'^accounts/', @@ -103,61 +103,61 @@ unprefixed_patterns += [ url(r'^admin/', include(admin.site.urls)), url(r'^docs/', - include('rest_framework_swagger.urls', namespace='docs'), + include('rest_framework_swagger.urls', namespace='docs'), ), url(r'^activity/', include('actstream.urls'), ), - ] +] # API unprefixed_patterns += [ url(r'^api/v1/teams/', - include('beat.web.team.api_urls', namespace='api_teams'), + include('beat.web.team.api_urls', namespace='api_teams'), ), url(r'^api/v1/algorithms/', - include('beat.web.algorithms.api_urls', namespace='api_algorithms'), + include('beat.web.algorithms.api_urls', namespace='api_algorithms'), ), url(r'^api/v1/attestations/', - include('beat.web.attestations.api_urls', namespace='api_attestations'), + include('beat.web.attestations.api_urls', namespace='api_attestations'), ), url(r'^api/v1/backend/', - include('beat.web.backend.api_urls', namespace='api_backend'), + include('beat.web.backend.api_urls', namespace='api_backend'), ), url(r'^api/v1/databases/', - include('beat.web.databases.api_urls', namespace='api_databases'), + include('beat.web.databases.api_urls', namespace='api_databases'), ), url(r'^api/v1/dataformats/', - include('beat.web.dataformats.api_urls', namespace='api_dataformats'), + include('beat.web.dataformats.api_urls', namespace='api_dataformats'), ), url(r'^api/v1/experiments/', - include('beat.web.experiments.api_urls', namespace='api_experiments'), + include('beat.web.experiments.api_urls', namespace='api_experiments'), ), url(r'^api/v1/libraries/', - include('beat.web.libraries.api_urls', namespace='api_libraries'), + include('beat.web.libraries.api_urls', namespace='api_libraries'), ), url(r'^api/v1/search/', - include('beat.web.search.api_urls', namespace='api_search'), + include('beat.web.search.api_urls', namespace='api_search'), ), url(r'^api/v1/toolchains/', - include('beat.web.toolchains.api_urls', namespace='api_toolchains'), + include('beat.web.toolchains.api_urls', namespace='api_toolchains'), ), url(r'^api/v1/plotters/', - include('beat.web.plotters.api_urls', namespace='api_plotters'), + include('beat.web.plotters.api_urls', namespace='api_plotters'), ), url(r'^api/v1/reports/', @@ -168,7 +168,7 @@ unprefixed_patterns += [ include('beat.web.accounts.api_urls', namespace='api_accounts'), ), - ] +] # Process an eventual prefix in the URLs diff --git a/beat/web/utils/management/commands/backup.py b/beat/web/utils/management/commands/backup.py index c93586954..2875e8f19 100644 --- a/beat/web/utils/management/commands/backup.py +++ b/beat/web/utils/management/commands/backup.py @@ -45,7 +45,7 @@ from django.apps import apps, registry from ....import __version__ APPS = [ #dump and load order are respected - 'authtoken', + 'authtoken', 'backend', 'statistics', 'dataformats', @@ -60,7 +60,7 @@ APPS = [ #dump and load order are respected 'reports', 'actstream', 'post_office', - ] +] def _check(app, queryset): @@ -111,29 +111,29 @@ class Command(BaseCommand): # for these apps, only backs-up these particular object types only = dict( - dataformats = 'dataformats.DataFormat', - libraries = 'libraries.Library', - algorithms = 'algorithms.Algorithm', - databases = 'databases.Database', - toolchains = 'toolchains.Toolchain', - ) + dataformats = 'dataformats.DataFormat', + libraries = 'libraries.Library', + algorithms = 'algorithms.Algorithm', + databases = 'databases.Database', + toolchains = 'toolchains.Toolchain', + ) dump_arguments = dict( - indent = 2, - verbosity=arguments.get('verbosity'), - interactive=False, - use_natural_primary_keys = True, - use_natural_foreign_keys = True, - format = 'json', - exclude = [ - 'sessions', + indent = 2, + verbosity=arguments.get('verbosity'), + interactive=False, + use_natural_primary_keys = True, + use_natural_foreign_keys = True, + format = 'json', + exclude = [ + 'sessions', 'admin', 'contenttypes', 'auth.Permission', 'backend.Job', 'backend.JobSplit', - ], - ) + ], + ) # remove uninstalled apps global APPS @@ -182,7 +182,7 @@ class Command(BaseCommand): if os.path.exists(path): destdir = os.path.join(tmpdir, 'prefix', app) logger.info("Backing up core objects for `%s' -> `%s'", - app, destdir) + app, destdir) shutil.copytree(path, destdir) else: logger.info("No disk presence found for `%s'", app) diff --git a/beat/web/utils/management/commands/install.py b/beat/web/utils/management/commands/install.py index a735c8b5f..2a5e6db6f 100755 --- a/beat/web/utils/management/commands/install.py +++ b/beat/web/utils/management/commands/install.py @@ -140,7 +140,7 @@ def setup_environment(queue_config_filename, verbosity): from django.core.management import call_command call_command('qsetup', verbosity=verbosity, reset=True, - config=queue_config_filename) + config=queue_config_filename) def create_sites(): @@ -239,10 +239,10 @@ def upload_dataformat(prefix, name, data): author = data[name.split(os.sep)[0].replace('name', '')] dataformat = DataFormat.objects.filter( - author=author, - name=storage.name, - version=int(storage.version), - ) + author=author, + name=storage.name, + version=int(storage.version), + ) if not dataformat: # creates it @@ -253,7 +253,7 @@ def upload_dataformat(prefix, name, data): short_description=obj.get('description', ''), description=description, declaration=declaration, - ) + ) if dataformat is None: raise SyntaxError(errors) @@ -325,7 +325,7 @@ def upload_database(prefix, name, data): from ....common.models import Shareable database = Database.objects.filter(name=storage.name, - version=int(storage.version)) + version=int(storage.version)) if not database: @@ -336,7 +336,7 @@ def upload_database(prefix, name, data): short_description = obj.get('description', ''), description = description, version=int(storage.version), - ) + ) if database is None: logger.warn("Did not add database `%s', because: %s", name, errors) @@ -396,7 +396,7 @@ def upload_toolchain(prefix, name, data): author=author, name=storage.name, version=int(storage.version), - ) + ) if not toolchain: @@ -407,7 +407,7 @@ def upload_toolchain(prefix, name, data): short_description=obj.get('description', ''), description=description, declaration=declaration, - ) + ) if toolchain is None: logger.warn("Did not add toolchain `%s', because: %s", name, errors) return False @@ -467,7 +467,7 @@ def upload_library(prefix, name, data): author=author, name=storage.name, version=int(storage.version), - ) + ) if not library: (library, errors) = Library.objects.create_library( @@ -478,7 +478,7 @@ def upload_library(prefix, name, data): description=description, declaration=declaration, code=code, - ) + ) if library is None: logger.warn("Did not add library `%s', because: %s", name, errors) return False @@ -537,7 +537,7 @@ def upload_algorithm(prefix, name, data): author=author, name=storage.name, version=int(storage.version), - ) + ) if not algorithm: (algorithm, errors) = Algorithm.objects.create_algorithm( @@ -548,7 +548,7 @@ def upload_algorithm(prefix, name, data): description=description, declaration=declaration, code=code, - ) + ) if algorithm is None: logger.warn("Did not add algorithm `%s', because: %s", name, errors) return False @@ -603,10 +603,10 @@ def upload_experiment(prefix, name, data): toolchain_storage = beat.core.toolchain.Storage(name, storage.toolchain) toolchain = Toolchain.objects.get( - author=author, - name=toolchain_storage.name, - version=int(toolchain_storage.version), - ) + author=author, + name=toolchain_storage.name, + version=int(toolchain_storage.version), + ) from ....experiments.models import Experiment @@ -614,7 +614,7 @@ def upload_experiment(prefix, name, data): author=author, toolchain=toolchain, name=storage.name, - ) + ) if not experiment: (experiment, _toolchain_obj, errors) = Experiment.objects.create_experiment( @@ -624,7 +624,7 @@ def upload_experiment(prefix, name, data): declaration=declaration, short_description=obj.get('description', ''), description=description, - ) + ) if experiment is None: logger.warn("Did not add experiment `%s', because: %s", name, errors) return False @@ -683,10 +683,10 @@ def upload_plotter(prefix, name, data): author=author, name=storage.name, version=int(storage.version), - ) + ) sample_data_file_location = prefix + "/plotters/" + name.split("/")[0] + "/" + \ - name.split("/")[1] + "/sample_data.txt" + name.split("/")[1] + "/sample_data.txt" with open(sample_data_file_location) as sample_data_file: sample_data = simplejson.load(sample_data_file) @@ -700,7 +700,7 @@ def upload_plotter(prefix, name, data): description=description, declaration=declaration, code=code, - ) + ) if plotter is None: logger.warn("Did not add plotter `%s', because: %s", name, errors) return False @@ -743,8 +743,8 @@ def upload_plotter(prefix, name, data): short_desc = short_desc_data_file.readline().split("\n")[0] plotterparameter = PlotterParameter.objects.create(name=plotter.dataformat.name, - author=author, plotter=plotter, data=simplejson.dumps(plotterparameter_data, - indent=4), short_description=short_desc, sharing = Shareable.PUBLIC) + author=author, plotter=plotter, data=simplejson.dumps(plotterparameter_data, + indent=4), short_description=short_desc, sharing = Shareable.PUBLIC) plotterparameter.save() logger.info("Add plotterparameter `%s' ", plotterparameter) @@ -756,7 +756,7 @@ def upload_plotter(prefix, name, data): default.plotter = plotter else: default = DefaultPlotter(dataformat=plotter.dataformat, - plotter=plotter, parameter=plotterparameter) + plotter=plotter, parameter=plotterparameter) default.save() logger.info("Set plotter `%s' and plotterparameter `%s' as default for `%s'", plotter, plotterparameter, plotter.dataformat) @@ -764,11 +764,11 @@ def upload_plotter(prefix, name, data): if plotter.dataformat.name == "isoroc": # Adding extra plotterparameter if not already present for plotter isoroc other_plotterparameter_location = prefix + "/plotters/" + name.split("/")[0] + "/" + \ - "other_plotterparameters" + "other_plotterparameters" the_folders = filter(lambda x:\ - os.path.isdir(os.path.join(other_plotterparameter_location, x)),\ - os.listdir(other_plotterparameter_location)) + os.path.isdir(os.path.join(other_plotterparameter_location, x)),\ + os.listdir(other_plotterparameter_location)) for folder_name in the_folders: @@ -776,7 +776,7 @@ def upload_plotter(prefix, name, data): author=author, name=folder_name, version=int(storage.version), - ) + ) if others_plotterparameter is not None: param_folder = other_plotterparameter_location + "/" + folder_name @@ -790,8 +790,8 @@ def upload_plotter(prefix, name, data): short_desc = short_desc_data_file.readline().split("\n")[0] plotterparameter = PlotterParameter.objects.create(name=folder_name, - author=author, plotter=plotter, data=simplejson.dumps(plotterparameter_data, - indent=4), short_description=short_desc, sharing = Shareable.PUBLIC) + author=author, plotter=plotter, data=simplejson.dumps(plotterparameter_data, + indent=4), short_description=short_desc, sharing = Shareable.PUBLIC) logger.info("Add plotterparameter `%s' ", folder_name) @@ -826,14 +826,14 @@ def upload_dispatcher(prefix, project, type, name, data): base_subdir = os.path.join(prefix, project) valid_types = { - 'dataformats': upload_dataformat, + 'dataformats': upload_dataformat, 'databases': upload_database, 'libraries': upload_library, 'algorithms': upload_algorithm, 'toolchains': upload_toolchain, 'experiments': upload_experiment, 'plotters': upload_plotter, - } + } if type not in valid_types: raise KeyError("Type must be one of `%s'" % ', '.join(valid_types.keys())) @@ -866,9 +866,9 @@ def link_database_versions(): #search for similar try: existing = Database.objects.get(name=obj.name, - version=obj.version-1) + version=obj.version-1) logger.info("Liking database `%s' -> `%s' (version)", - obj, existing) + obj, existing) obj.previous_version = existing obj.save() except Database.DoesNotExist: @@ -884,9 +884,9 @@ def link_contribution_versions(klass): #search for similar try: existing = klass.objects.get(author=obj.author, name=obj.name, - version=obj.version-1) + version=obj.version-1) logger.info("Liking %s `%s' -> `%s' (version)", - klass.__name__.lower(), obj, existing) + klass.__name__.lower(), obj, existing) obj.previous_version = existing obj.save() except klass.DoesNotExist: @@ -894,7 +894,7 @@ def link_contribution_versions(klass): def install_contributions(source_prefix, project, template_data, - db_root_file=None): + db_root_file=None): '''Installs all contributions for a given project @@ -920,7 +920,7 @@ def install_contributions(source_prefix, project, template_data, # one after the other. If one fails, we retry on the next loop, until all # formats have been uploaded. dataformat_filenames_next = list_objects(source_prefix, project, - 'dataformats', '*.json') + 'dataformats', '*.json') dataformat_filenames_cur = [] while True: @@ -931,7 +931,7 @@ def install_contributions(source_prefix, project, template_data, dataformat_filenames_next = [] for k in dataformat_filenames_cur: if not upload_dispatcher(source_prefix, project, 'dataformats', k, - template_data): + template_data): dataformat_filenames_next.append(k) from ....dataformats.models import DataFormat link_contribution_versions(DataFormat) @@ -943,13 +943,13 @@ def install_contributions(source_prefix, project, template_data, for k in list_objects(source_prefix, project, 'databases', '*.json'): if k in db_root: template_data['root_folder'] = db_root[k] upload_dispatcher(source_prefix, project, 'databases', k, - template_data) + template_data) link_database_versions() for k in list_objects(source_prefix, project, 'toolchains', - '*.json'): + '*.json'): upload_dispatcher(source_prefix, project, 'toolchains', k, - template_data) + template_data) from ....toolchains.models import Toolchain link_contribution_versions(Toolchain) @@ -957,7 +957,7 @@ def install_contributions(source_prefix, project, template_data, # dependencies between different libraries and algorithms. Our # recipe: we use the same technique as for dataformats. library_filenames_next = list_objects(source_prefix, project, - 'libraries', '*.json') + 'libraries', '*.json') library_filenames_cur = [] while True: @@ -968,28 +968,28 @@ def install_contributions(source_prefix, project, template_data, library_filenames_next = [] for k in library_filenames_cur: if not upload_dispatcher(source_prefix, project, - 'libraries', k, template_data): + 'libraries', k, template_data): library_filenames_next.append(k) from ....libraries.models import Library link_contribution_versions(Library) for k in list_objects(source_prefix, project, 'algorithms', - '*.json'): + '*.json'): upload_dispatcher(source_prefix, project, 'algorithms', k, - template_data) + template_data) from ....algorithms.models import Algorithm link_contribution_versions(Algorithm) for k in list_objects(source_prefix, project, 'plotters', '*.json'): upload_dispatcher(source_prefix, project, 'plotters', k, - template_data) + template_data) from ....plotters.models import Plotter link_contribution_versions(Plotter) for k in list_objects(source_prefix, project, 'experiments', - '*.json'): + '*.json'): upload_dispatcher(source_prefix, project, 'experiments', k, - template_data) + template_data) class Command(BaseCommand): @@ -1002,10 +1002,10 @@ class Command(BaseCommand): super(Command, self).__init__() self.prefix = os.path.join( - os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0]))), - 'src', + os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0]))), + 'src', 'beat.examples', - ) + ) # gets a list of all available projects, excluding directories ignore = ['system', 'LICENSE', '.git', '.gitignore', 'README.rst'] @@ -1023,42 +1023,42 @@ class Command(BaseCommand): parser.formatter_class = RawDescriptionHelpFormatter parser.add_argument('--username', '-u', dest='username', type=str, - default='user', help='Username to create, associated with ' \ - 'user contributions [default: %(default)s]') + default='user', help='Username to create, associated with ' \ + 'user contributions [default: %(default)s]') parser.add_argument('--password', '-P', dest='password', type=str, - default='user', help='The password to set for such an user ' \ - '[default: %(default)s]') + default='user', help='The password to set for such an user ' \ + '[default: %(default)s]') parser.add_argument('--private', '-p', action='store_true', - dest='private', default=False, help='Set this flag if all ' \ - 'objects should be private to the user rather than public') + dest='private', default=False, help='Set this flag if all ' \ + 'objects should be private to the user rather than public') parser.add_argument('--database-root-file', '-R', type=str, - dest='database_root_file', help='The JSON file containing ' \ - 'the root directories of the databases installed ' \ - 'on the platform. If not set or if there is no ' \ - 'entry in this file for a given database, the root ' \ - 'directory defined on the JSON database file is used.') + dest='database_root_file', help='The JSON file containing ' \ + 'the root directories of the databases installed ' \ + 'on the platform. If not set or if there is no ' \ + 'entry in this file for a given database, the root ' \ + 'directory defined on the JSON database file is used.') parser.add_argument('--source-prefix', '-X', type=str, - dest='source_prefix', default=self.prefix, - help='Set this to the root of the directory containing ' \ - 'the project prefixes you wish to install ' \ - '[default: %(default)s]') + dest='source_prefix', default=self.prefix, + help='Set this to the root of the directory containing ' \ + 'the project prefixes you wish to install ' \ + '[default: %(default)s]') parser.add_argument('--queue-configuration', '-Q', type=str, - dest='queue_configuration', help='The configuration for ' \ - 'queues and environments to be inserted into the ' \ - 'web server. If not passed, use the default ' \ - 'queue-worker-environment configuration for a ' \ - 'local development server.') + dest='queue_configuration', help='The configuration for ' \ + 'queues and environments to be inserted into the ' \ + 'web server. If not passed, use the default ' \ + 'queue-worker-environment configuration for a ' \ + 'local development server.') parser.add_argument('project', nargs='*', type=str, - default=self.projects, help='The project data you wish to ' \ - 'install. Currently, the default is to install ' \ - 'data for all available projects. [default: ' \ - '%s]' % ', '.join(self.projects)) + default=self.projects, help='The project data you wish to ' \ + 'install. Currently, the default is to install ' \ + 'data for all available projects. [default: ' \ + '%s]' % ', '.join(self.projects)) def handle(self, *ignored, **arguments): @@ -1076,13 +1076,13 @@ class Command(BaseCommand): while 'system' in arguments['project']: logger.warn("Removing `system' from the list of projects to " \ - "install (this is them minimal default anyway)") + "install (this is them minimal default anyway)") arguments['project'].remove('system') for k in arguments['project']: if k not in self.projects: logger.error("Project `%s' is not available, choose from: %s", - ', '.join("`%s'" % k for k in self.projects)) + ', '.join("`%s'" % k for k in self.projects)) sys.exit(1) # Creates the prefix directory @@ -1093,7 +1093,7 @@ class Command(BaseCommand): # Creates the cache directory if not os.path.exists(settings.CACHE_ROOT): logger.info("Creating cache directory `%s'...", - settings.CACHE_ROOT) + settings.CACHE_ROOT) os.makedirs(settings.CACHE_ROOT) # Sync database @@ -1104,7 +1104,7 @@ class Command(BaseCommand): create_sites() system_user, plot_user, user = create_users(arguments['username'], - arguments['password']) + arguments['password']) # Sets up initial groups @@ -1112,7 +1112,7 @@ class Command(BaseCommand): # Sets up the queue and environments setup_environment(arguments['queue_configuration'], - arguments['verbosity']) + arguments['verbosity']) from ....backend.models import Environment, EnvironmentLanguage, Queue from ....code.models import Code environment = EnvironmentLanguage.objects.filter(language=Code.PYTHON).first().environment @@ -1128,10 +1128,10 @@ class Command(BaseCommand): private = arguments['private'], queue = queue.name, environment = dict(name=environment.name, - version=environment.version), - ) + version=environment.version), + ) logger.info("Adding objects for project `%s'...", project) install_contributions(self.prefix, project, template_data, - arguments['database_root_file']) + arguments['database_root_file']) diff --git a/beat/web/utils/management/commands/restore.py b/beat/web/utils/management/commands/restore.py index 6276b5a66..c784f8523 100644 --- a/beat/web/utils/management/commands/restore.py +++ b/beat/web/utils/management/commands/restore.py @@ -76,11 +76,11 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('-e', '--exclude', dest='exclude', action='append', - default=[], help='An app_label to exclude (use multiple ' \ - '--exclude to exclude multiple apps).') + default=[], help='An app_label to exclude (use multiple ' \ + '--exclude to exclude multiple apps).') parser.add_argument('backup', type=str, - help='The backup you wish to restore from') + help='The backup you wish to restore from') def handle(self, *ignored, **arguments): @@ -108,9 +108,9 @@ class Command(BaseCommand): exclude += [app for app in APPS if app not in installed_apps] arguments = dict( - verbosity=arguments.get('verbosity'), - interactive=False, - ) + verbosity=arguments.get('verbosity'), + interactive=False, + ) # reset database contents logger.info("Loading initial data...") @@ -119,7 +119,7 @@ class Command(BaseCommand): # loads the initial data srcfile = os.path.join(tmpdir, 'initial.json') logger.info("Loading unspecified initial data <- `%s'" % \ - srcfile) + srcfile) call_command('loaddata', srcfile, **arguments) # reset all user tokens (so they can be re-inserted) @@ -133,7 +133,7 @@ class Command(BaseCommand): srcdir = os.path.join(tmpdir, 'prefix', app) if os.path.exists(srcdir): logger.info("Restoring core objects for `%s' <- " \ - "`%s'" % (app, srcdir)) + "`%s'" % (app, srcdir)) if os.path.exists(path): logger.info("Removing `%s'..." % path) shutil.rmtree(path) @@ -143,7 +143,7 @@ class Command(BaseCommand): srcfile = os.path.join(tmpdir, '%s.json' % app) logger.info("Loading data for `%s' <- `%s'" % \ - (app, srcfile)) + (app, srcfile)) call_command('loaddata', srcfile, **arguments) # creates the cache directory diff --git a/beat/web/utils/management/commands/xdumpdata.py b/beat/web/utils/management/commands/xdumpdata.py index b6b4404f5..0dd4ef3e2 100644 --- a/beat/web/utils/management/commands/xdumpdata.py +++ b/beat/web/utils/management/commands/xdumpdata.py @@ -22,31 +22,31 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('args', metavar='app_label[.ModelName]', nargs='*', - help='Restricts dumped data to the specified app_label or app_label.ModelName.') + help='Restricts dumped data to the specified app_label or app_label.ModelName.') parser.add_argument('--format', default='json', dest='format', - help='Specifies the output serialization format for fixtures.') + help='Specifies the output serialization format for fixtures.') parser.add_argument('--indent', default=None, dest='indent', type=int, - help='Specifies the indent level to use when pretty-printing output.') + help='Specifies the indent level to use when pretty-printing output.') parser.add_argument('--database', action='store', dest='database', - default=DEFAULT_DB_ALIAS, - help='Nominates a specific database to dump fixtures from. ' - 'Defaults to the "default" database.') + default=DEFAULT_DB_ALIAS, + help='Nominates a specific database to dump fixtures from. ' + 'Defaults to the "default" database.') parser.add_argument('-e', '--exclude', dest='exclude', action='append', default=[], - help='An app_label or app_label.ModelName to exclude ' - '(use multiple --exclude to exclude multiple apps/models).') + help='An app_label or app_label.ModelName to exclude ' + '(use multiple --exclude to exclude multiple apps/models).') parser.add_argument('--natural-foreign', action='store_true', dest='use_natural_foreign_keys', default=False, - help='Use natural foreign keys if they are available.') + help='Use natural foreign keys if they are available.') parser.add_argument('--natural-primary', action='store_true', dest='use_natural_primary_keys', default=False, - help='Use natural primary keys if they are available.') + help='Use natural primary keys if they are available.') parser.add_argument('-a', '--all', action='store_true', dest='use_base_manager', default=False, - help="Use Django's base manager to dump all models stored in the database, " - "including those that would otherwise be filtered or modified by a custom manager.") + help="Use Django's base manager to dump all models stored in the database, " + "including those that would otherwise be filtered or modified by a custom manager.") parser.add_argument('--pks', dest='primary_keys', - help="Only dump objects with given primary keys. " - "Accepts a comma separated list of keys. " - "This option will only work when you specify one model.") + help="Only dump objects with given primary keys. " + "Accepts a comma separated list of keys. " + "This option will only work when you specify one model.") parser.add_argument('-o', '--output', default=None, dest='output', - help='Specifies file to which the output is written.') + help='Specifies file to which the output is written.') def handle(self, *app_labels, **options): format = options.get('format') @@ -85,8 +85,8 @@ class Command(BaseCommand): if primary_keys: raise CommandError("You can only use --pks option with one model") app_list = OrderedDict((app_config, None) - for app_config in apps.get_app_configs() - if app_config.models_module is not None and app_config not in excluded_apps) + for app_config in apps.get_app_configs() + if app_config.models_module is not None and app_config not in excluded_apps) else: if len(app_labels) > 1 and primary_keys: raise CommandError("You can only use --pks option with one model") @@ -178,10 +178,10 @@ class Command(BaseCommand): stream = open(output, 'w') if output else None try: serializers.serialize(format, get_objects(), indent=indent, - use_natural_foreign_keys=use_natural_foreign_keys, - use_natural_primary_keys=use_natural_primary_keys, - stream=stream or self.stdout, progress_output=progress_output, - object_count=object_count) + use_natural_foreign_keys=use_natural_foreign_keys, + use_natural_primary_keys=use_natural_primary_keys, + stream=stream or self.stdout, progress_output=progress_output, + object_count=object_count) finally: if stream: stream.close() diff --git a/buildout.cfg b/buildout.cfg index 682232fd6..56c5ef190 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -10,6 +10,7 @@ eggs = beat.core ipdb coverage pip + autopep8 newest = false develop = . versions = versions -- GitLab