From c790b5f4899fbb6f17567e6ed9053b741f227300 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 1 Dec 2020 12:45:23 +0200 Subject: [PATCH] Reformat some files using black. --- django_etebase/exceptions.py | 5 +++- django_etebase/migrations/0001_initial.py | 20 ++++++++++++---- .../migrations/0003_collectioninvitation.py | 4 +++- .../0004_collectioninvitation_version.py | 4 +++- .../migrations/0005_auto_20200526_1021.py | 6 ++++- .../0013_collectionmemberremoved.py | 4 +++- .../migrations/0014_auto_20200602_1558.py | 6 ++++- .../0015_collectionitemrevision_salt.py | 4 +++- .../migrations/0016_auto_20200623_0820.py | 15 +++++++++--- ...0020_remove_collectionitemrevision_salt.py | 5 +++- .../migrations/0022_auto_20200804_1059.py | 5 +++- .../migrations/0025_auto_20200804_1216.py | 10 ++++++-- .../migrations/0026_auto_20200907_0752.py | 12 ++++++++-- .../migrations/0029_auto_20200907_0801.py | 10 ++++++-- django_etebase/models.py | 16 ++++++++++--- django_etebase/serializers.py | 24 +++++++++++++++---- django_etebase/views.py | 7 ++++-- 17 files changed, 125 insertions(+), 32 deletions(-) diff --git a/django_etebase/exceptions.py b/django_etebase/exceptions.py index f3aa08a..437a71c 100644 --- a/django_etebase/exceptions.py +++ b/django_etebase/exceptions.py @@ -4,6 +4,9 @@ from rest_framework import serializers, status class EtebaseValidationError(serializers.ValidationError): def __init__(self, code, detail, status_code=status.HTTP_400_BAD_REQUEST): super().__init__( - {"code": code, "detail": detail,} + { + "code": code, + "detail": detail, + } ) self.status_code = status_code diff --git a/django_etebase/migrations/0001_initial.py b/django_etebase/migrations/0001_initial.py index 86f0fa6..42ee022 100644 --- a/django_etebase/migrations/0001_initial.py +++ b/django_etebase/migrations/0001_initial.py @@ -33,7 +33,9 @@ class Migration(migrations.Migration): ("version", models.PositiveSmallIntegerField()), ("owner", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], - options={"unique_together": {("uid", "owner")},}, + options={ + "unique_together": {("uid", "owner")}, + }, ), migrations.CreateModel( name="CollectionItem", @@ -61,7 +63,9 @@ class Migration(migrations.Migration): ), ), ], - options={"unique_together": {("uid", "collection")},}, + options={ + "unique_together": {("uid", "collection")}, + }, ), migrations.CreateModel( name="CollectionItemChunk", @@ -122,7 +126,9 @@ class Migration(migrations.Migration): ), ), ], - options={"unique_together": {("item", "current")},}, + options={ + "unique_together": {("item", "current")}, + }, ), migrations.CreateModel( name="RevisionChunkRelation", @@ -145,7 +151,9 @@ class Migration(migrations.Migration): ), ), ], - options={"ordering": ("id",),}, + options={ + "ordering": ("id",), + }, ), migrations.CreateModel( name="CollectionMember", @@ -170,6 +178,8 @@ class Migration(migrations.Migration): ), ("user", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], - options={"unique_together": {("user", "collection")},}, + options={ + "unique_together": {("user", "collection")}, + }, ), ] diff --git a/django_etebase/migrations/0003_collectioninvitation.py b/django_etebase/migrations/0003_collectioninvitation.py index 1b416ab..4aa05c9 100644 --- a/django_etebase/migrations/0003_collectioninvitation.py +++ b/django_etebase/migrations/0003_collectioninvitation.py @@ -54,6 +54,8 @@ class Migration(migrations.Migration): ), ), ], - options={"unique_together": {("user", "fromMember")},}, + options={ + "unique_together": {("user", "fromMember")}, + }, ), ] diff --git a/django_etebase/migrations/0004_collectioninvitation_version.py b/django_etebase/migrations/0004_collectioninvitation_version.py index 29ae3f1..40a290e 100644 --- a/django_etebase/migrations/0004_collectioninvitation_version.py +++ b/django_etebase/migrations/0004_collectioninvitation_version.py @@ -11,6 +11,8 @@ class Migration(migrations.Migration): operations = [ migrations.AddField( - model_name="collectioninvitation", name="version", field=models.PositiveSmallIntegerField(default=1), + model_name="collectioninvitation", + name="version", + field=models.PositiveSmallIntegerField(default=1), ), ] diff --git a/django_etebase/migrations/0005_auto_20200526_1021.py b/django_etebase/migrations/0005_auto_20200526_1021.py index 3775277..9855ff1 100644 --- a/django_etebase/migrations/0005_auto_20200526_1021.py +++ b/django_etebase/migrations/0005_auto_20200526_1021.py @@ -10,5 +10,9 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RenameField(model_name="userinfo", old_name="pubkey", new_name="loginPubkey",), + migrations.RenameField( + model_name="userinfo", + old_name="pubkey", + new_name="loginPubkey", + ), ] diff --git a/django_etebase/migrations/0013_collectionmemberremoved.py b/django_etebase/migrations/0013_collectionmemberremoved.py index 4481e80..d8c57ea 100644 --- a/django_etebase/migrations/0013_collectionmemberremoved.py +++ b/django_etebase/migrations/0013_collectionmemberremoved.py @@ -33,6 +33,8 @@ class Migration(migrations.Migration): ), ("user", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], - options={"unique_together": {("user", "collection")},}, + options={ + "unique_together": {("user", "collection")}, + }, ), ] diff --git a/django_etebase/migrations/0014_auto_20200602_1558.py b/django_etebase/migrations/0014_auto_20200602_1558.py index 42bed52..ec0de46 100644 --- a/django_etebase/migrations/0014_auto_20200602_1558.py +++ b/django_etebase/migrations/0014_auto_20200602_1558.py @@ -10,5 +10,9 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RenameField(model_name="userinfo", old_name="encryptedSeckey", new_name="encryptedContent",), + migrations.RenameField( + model_name="userinfo", + old_name="encryptedSeckey", + new_name="encryptedContent", + ), ] diff --git a/django_etebase/migrations/0015_collectionitemrevision_salt.py b/django_etebase/migrations/0015_collectionitemrevision_salt.py index c4dc3e9..3a13baa 100644 --- a/django_etebase/migrations/0015_collectionitemrevision_salt.py +++ b/django_etebase/migrations/0015_collectionitemrevision_salt.py @@ -11,6 +11,8 @@ class Migration(migrations.Migration): operations = [ migrations.AddField( - model_name="collectionitemrevision", name="salt", field=models.BinaryField(default=b"", editable=True), + model_name="collectionitemrevision", + name="salt", + field=models.BinaryField(default=b"", editable=True), ), ] diff --git a/django_etebase/migrations/0016_auto_20200623_0820.py b/django_etebase/migrations/0016_auto_20200623_0820.py index a273b0d..14871a2 100644 --- a/django_etebase/migrations/0016_auto_20200623_0820.py +++ b/django_etebase/migrations/0016_auto_20200623_0820.py @@ -21,7 +21,16 @@ class Migration(migrations.Migration): to="django_etebase.CollectionItem", ), ), - migrations.AlterUniqueTogether(name="collection", unique_together=set(),), - migrations.RemoveField(model_name="collection", name="uid",), - migrations.RemoveField(model_name="collection", name="version",), + migrations.AlterUniqueTogether( + name="collection", + unique_together=set(), + ), + migrations.RemoveField( + model_name="collection", + name="uid", + ), + migrations.RemoveField( + model_name="collection", + name="version", + ), ] diff --git a/django_etebase/migrations/0020_remove_collectionitemrevision_salt.py b/django_etebase/migrations/0020_remove_collectionitemrevision_salt.py index 21d0337..1b69a5c 100644 --- a/django_etebase/migrations/0020_remove_collectionitemrevision_salt.py +++ b/django_etebase/migrations/0020_remove_collectionitemrevision_salt.py @@ -10,5 +10,8 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RemoveField(model_name="collectionitemrevision", name="salt",), + migrations.RemoveField( + model_name="collectionitemrevision", + name="salt", + ), ] diff --git a/django_etebase/migrations/0022_auto_20200804_1059.py b/django_etebase/migrations/0022_auto_20200804_1059.py index 60af33f..bc4bad9 100644 --- a/django_etebase/migrations/0022_auto_20200804_1059.py +++ b/django_etebase/migrations/0022_auto_20200804_1059.py @@ -10,5 +10,8 @@ class Migration(migrations.Migration): ] operations = [ - migrations.AlterUniqueTogether(name="collectionitemchunk", unique_together={("item", "uid")},), + migrations.AlterUniqueTogether( + name="collectionitemchunk", + unique_together={("item", "uid")}, + ), ] diff --git a/django_etebase/migrations/0025_auto_20200804_1216.py b/django_etebase/migrations/0025_auto_20200804_1216.py index 91bf4c8..995d275 100644 --- a/django_etebase/migrations/0025_auto_20200804_1216.py +++ b/django_etebase/migrations/0025_auto_20200804_1216.py @@ -18,6 +18,12 @@ class Migration(migrations.Migration): on_delete=django.db.models.deletion.CASCADE, related_name="chunks", to="django_etebase.Collection" ), ), - migrations.AlterUniqueTogether(name="collectionitemchunk", unique_together={("collection", "uid")},), - migrations.RemoveField(model_name="collectionitemchunk", name="item",), + migrations.AlterUniqueTogether( + name="collectionitemchunk", + unique_together={("collection", "uid")}, + ), + migrations.RemoveField( + model_name="collectionitemchunk", + name="item", + ), ] diff --git a/django_etebase/migrations/0026_auto_20200907_0752.py b/django_etebase/migrations/0026_auto_20200907_0752.py index 3283654..1c90610 100644 --- a/django_etebase/migrations/0026_auto_20200907_0752.py +++ b/django_etebase/migrations/0026_auto_20200907_0752.py @@ -10,6 +10,14 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RenameField(model_name="collectioninvitation", old_name="accessLevel", new_name="accessLevelOld",), - migrations.RenameField(model_name="collectionmember", old_name="accessLevel", new_name="accessLevelOld",), + migrations.RenameField( + model_name="collectioninvitation", + old_name="accessLevel", + new_name="accessLevelOld", + ), + migrations.RenameField( + model_name="collectionmember", + old_name="accessLevel", + new_name="accessLevelOld", + ), ] diff --git a/django_etebase/migrations/0029_auto_20200907_0801.py b/django_etebase/migrations/0029_auto_20200907_0801.py index f3bfe61..1e00ffe 100644 --- a/django_etebase/migrations/0029_auto_20200907_0801.py +++ b/django_etebase/migrations/0029_auto_20200907_0801.py @@ -10,6 +10,12 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RemoveField(model_name="collectioninvitation", name="accessLevelOld",), - migrations.RemoveField(model_name="collectionmember", name="accessLevelOld",), + migrations.RemoveField( + model_name="collectioninvitation", + name="accessLevelOld", + ), + migrations.RemoveField( + model_name="collectionmember", + name="accessLevelOld", + ), ] diff --git a/django_etebase/models.py b/django_etebase/models.py index 691947d..00bbf71 100644 --- a/django_etebase/models.py +++ b/django_etebase/models.py @@ -182,7 +182,10 @@ class CollectionMember(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) encryptionKey = models.BinaryField(editable=True, blank=False, null=False) collectionType = models.ForeignKey(CollectionType, on_delete=models.PROTECT, null=True) - accessLevel = models.IntegerField(choices=AccessLevels.choices, default=AccessLevels.READ_ONLY,) + accessLevel = models.IntegerField( + choices=AccessLevels.choices, + default=AccessLevels.READ_ONLY, + ) class Meta: unique_together = ("user", "collection") @@ -193,7 +196,11 @@ class CollectionMember(models.Model): def revoke(self): with transaction.atomic(): CollectionMemberRemoved.objects.update_or_create( - collection=self.collection, user=self.user, defaults={"stoken": Stoken.objects.create(),}, + collection=self.collection, + user=self.user, + defaults={ + "stoken": Stoken.objects.create(), + }, ) self.delete() @@ -220,7 +227,10 @@ class CollectionInvitation(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="incoming_invitations", on_delete=models.CASCADE) signedEncryptionKey = models.BinaryField(editable=False, blank=False, null=False) - accessLevel = models.IntegerField(choices=AccessLevels.choices, default=AccessLevels.READ_ONLY,) + accessLevel = models.IntegerField( + choices=AccessLevels.choices, + default=AccessLevels.READ_ONLY, + ) class Meta: unique_together = ("user", "fromMember") diff --git a/django_etebase/serializers.py b/django_etebase/serializers.py index ef3b296..b0769ef 100644 --- a/django_etebase/serializers.py +++ b/django_etebase/serializers.py @@ -156,7 +156,11 @@ class BetterErrorsMixin: else: message = str(error) ret.append( - {"field": field_name, "code": error.code, "detail": message,} + { + "field": field_name, + "code": error.code, + "detail": message, + } ) return ret @@ -169,7 +173,11 @@ class BetterErrorsMixin: raise EtebaseValidationError(err.code, err.message) raise serializers.ValidationError( - {"code": "field_errors", "detail": "Field validations failed.", "errors": errors,} + { + "code": "field_errors", + "detail": "Field validations failed.", + "errors": errors, + } ) @@ -343,7 +351,11 @@ class CollectionSerializer(BetterErrorsMixin, serializers.ModelSerializer): class CollectionMemberSerializer(BetterErrorsMixin, serializers.ModelSerializer): - username = UserSlugRelatedField(source="user", read_only=True, style={"base_template": "input.html"},) + username = UserSlugRelatedField( + source="user", + read_only=True, + style={"base_template": "input.html"}, + ) class Meta: model = models.CollectionMember @@ -365,7 +377,11 @@ class CollectionMemberSerializer(BetterErrorsMixin, serializers.ModelSerializer) class CollectionInvitationSerializer(BetterErrorsMixin, serializers.ModelSerializer): - username = UserSlugRelatedField(source="user", queryset=User.objects, style={"base_template": "input.html"},) + username = UserSlugRelatedField( + source="user", + queryset=User.objects, + style={"base_template": "input.html"}, + ) collection = serializers.CharField(source="collection.uid") fromUsername = BinaryBase64Field(source="fromMember.user.username", read_only=True) fromPubkey = BinaryBase64Field(source="fromMember.user.userinfo.pubkey", read_only=True) diff --git a/django_etebase/views.py b/django_etebase/views.py index f3abcbc..8c05948 100644 --- a/django_etebase/views.py +++ b/django_etebase/views.py @@ -413,7 +413,10 @@ class CollectionItemViewSet(BaseViewSet): return Response(ret, status=status.HTTP_200_OK) return Response( - {"items": serializer.errors, "deps": deps_serializer.errors if deps is not None else [],}, + { + "items": serializer.errors, + "deps": deps_serializer.errors if deps is not None else [], + }, status=status.HTTP_409_CONFLICT, ) @@ -708,7 +711,7 @@ class AuthenticationViewSet(viewsets.ViewSet): elif challenge_data["userId"] != user.id: content = {"code": "wrong_user", "detail": "This challenge is for the wrong user"} return Response(content, status=status.HTTP_400_BAD_REQUEST) - elif not settings.DEBUG and host.split(':', 1)[0] != request.get_host().split(':', 1)[0]: + elif not settings.DEBUG and host.split(":", 1)[0] != request.get_host().split(":", 1)[0]: detail = 'Found wrong host name. Got: "{}" expected: "{}"'.format(host, request.get_host()) content = {"code": "wrong_host", "detail": detail} return Response(content, status=status.HTTP_400_BAD_REQUEST)