Skip to content

Commit

Permalink
chore: formatting all python files using black formatter (#3366)
Browse files Browse the repository at this point in the history
  • Loading branch information
sriramveeraghanta committed Jan 22, 2024
1 parent b4a31df commit e0e2518
Show file tree
Hide file tree
Showing 235 changed files with 12,966 additions and 4,167 deletions.
28 changes: 21 additions & 7 deletions apiserver/back_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def update_description():
updated_issues.append(issue)

Issue.objects.bulk_update(
updated_issues, ["description_html", "description_stripped"], batch_size=100
updated_issues,
["description_html", "description_stripped"],
batch_size=100,
)
print("Success")
except Exception as e:
Expand All @@ -40,7 +42,9 @@ def update_comments():
updated_issue_comments = []

for issue_comment in issue_comments:
issue_comment.comment_html = f"<p>{issue_comment.comment_stripped}</p>"
issue_comment.comment_html = (
f"<p>{issue_comment.comment_stripped}</p>"
)
updated_issue_comments.append(issue_comment)

IssueComment.objects.bulk_update(
Expand Down Expand Up @@ -99,7 +103,9 @@ def updated_issue_sort_order():
issue.sort_order = issue.sequence_id * random.randint(100, 500)
updated_issues.append(issue)

Issue.objects.bulk_update(updated_issues, ["sort_order"], batch_size=100)
Issue.objects.bulk_update(
updated_issues, ["sort_order"], batch_size=100
)
print("Success")
except Exception as e:
print(e)
Expand Down Expand Up @@ -137,7 +143,9 @@ def update_project_cover_images():
project.cover_image = project_cover_images[random.randint(0, 19)]
updated_projects.append(project)

Project.objects.bulk_update(updated_projects, ["cover_image"], batch_size=100)
Project.objects.bulk_update(
updated_projects, ["cover_image"], batch_size=100
)
print("Success")
except Exception as e:
print(e)
Expand Down Expand Up @@ -186,7 +194,9 @@ def update_label_color():

def create_slack_integration():
try:
_ = Integration.objects.create(provider="slack", network=2, title="Slack")
_ = Integration.objects.create(
provider="slack", network=2, title="Slack"
)
print("Success")
except Exception as e:
print(e)
Expand All @@ -212,12 +222,16 @@ def update_integration_verified():

def update_start_date():
try:
issues = Issue.objects.filter(state__group__in=["started", "completed"])
issues = Issue.objects.filter(
state__group__in=["started", "completed"]
)
updated_issues = []
for issue in issues:
issue.start_date = issue.created_at.date()
updated_issues.append(issue)
Issue.objects.bulk_update(updated_issues, ["start_date"], batch_size=500)
Issue.objects.bulk_update(
updated_issues, ["start_date"], batch_size=500
)
print("Success")
except Exception as e:
print(e)
Expand Down
6 changes: 3 additions & 3 deletions apiserver/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import os
import sys

if __name__ == '__main__':
if __name__ == "__main__":
os.environ.setdefault(
'DJANGO_SETTINGS_MODULE',
'plane.settings.production')
"DJANGO_SETTINGS_MODULE", "plane.settings.production"
)
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
2 changes: 1 addition & 1 deletion apiserver/plane/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .celery import app as celery_app

__all__ = ('celery_app',)
__all__ = ("celery_app",)
2 changes: 1 addition & 1 deletion apiserver/plane/analytics/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class AnalyticsConfig(AppConfig):
name = 'plane.analytics'
name = "plane.analytics"
2 changes: 1 addition & 1 deletion apiserver/plane/api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class ApiConfig(AppConfig):
name = "plane.api"
name = "plane.api"
7 changes: 5 additions & 2 deletions apiserver/plane/api/middleware/api_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def get_api_token(self, request):
def validate_api_token(self, token):
try:
api_token = APIToken.objects.get(
Q(Q(expired_at__gt=timezone.now()) | Q(expired_at__isnull=True)),
Q(
Q(expired_at__gt=timezone.now())
| Q(expired_at__isnull=True)
),
token=token,
is_active=True,
)
Expand All @@ -44,4 +47,4 @@ def authenticate(self, request):

# Validate the API token
user, token = self.validate_api_token(token)
return user, token
return user, token
17 changes: 9 additions & 8 deletions apiserver/plane/api/rate_limit.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from rest_framework.throttling import SimpleRateThrottle


class ApiKeyRateThrottle(SimpleRateThrottle):
scope = 'api_key'
rate = '60/minute'
scope = "api_key"
rate = "60/minute"

def get_cache_key(self, request, view):
# Retrieve the API key from the request header
api_key = request.headers.get('X-Api-Key')
api_key = request.headers.get("X-Api-Key")
if not api_key:
return None # Allow the request if there's no API key

# Use the API key as part of the cache key
return f'{self.scope}:{api_key}'
return f"{self.scope}:{api_key}"

def allow_request(self, request, view):
allowed = super().allow_request(request, view)
Expand All @@ -24,7 +25,7 @@ def allow_request(self, request, view):
# Remove old histories
while history and history[-1] <= now - self.duration:
history.pop()

# Calculate the requests
num_requests = len(history)

Expand All @@ -35,7 +36,7 @@ def allow_request(self, request, view):
reset_time = int(now + self.duration)

# Add headers
request.META['X-RateLimit-Remaining'] = max(0, available)
request.META['X-RateLimit-Reset'] = reset_time
request.META["X-RateLimit-Remaining"] = max(0, available)
request.META["X-RateLimit-Reset"] = reset_time

return allowed
return allowed
8 changes: 6 additions & 2 deletions apiserver/plane/api/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
)
from .state import StateLiteSerializer, StateSerializer
from .cycle import CycleSerializer, CycleIssueSerializer, CycleLiteSerializer
from .module import ModuleSerializer, ModuleIssueSerializer, ModuleLiteSerializer
from .inbox import InboxIssueSerializer
from .module import (
ModuleSerializer,
ModuleIssueSerializer,
ModuleLiteSerializer,
)
from .inbox import InboxIssueSerializer
6 changes: 4 additions & 2 deletions apiserver/plane/api/serializers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def to_representation(self, instance):
response[expand] = exp_serializer.data
else:
# You might need to handle this case differently
response[expand] = getattr(instance, f"{expand}_id", None)
response[expand] = getattr(
instance, f"{expand}_id", None
)

return response
return response
7 changes: 4 additions & 3 deletions apiserver/plane/api/serializers/cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def validate(self, data):
and data.get("end_date", None) is not None
and data.get("start_date", None) > data.get("end_date", None)
):
raise serializers.ValidationError("Start date cannot exceed end date")
raise serializers.ValidationError(
"Start date cannot exceed end date"
)
return data

class Meta:
Expand Down Expand Up @@ -55,7 +57,6 @@ class Meta:


class CycleLiteSerializer(BaseSerializer):

class Meta:
model = Cycle
fields = "__all__"
fields = "__all__"
4 changes: 2 additions & 2 deletions apiserver/plane/api/serializers/inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from .base import BaseSerializer
from plane.db.models import InboxIssue

class InboxIssueSerializer(BaseSerializer):

class InboxIssueSerializer(BaseSerializer):
class Meta:
model = InboxIssue
fields = "__all__"
Expand All @@ -16,4 +16,4 @@ class Meta:
"updated_by",
"created_at",
"updated_at",
]
]
37 changes: 23 additions & 14 deletions apiserver/plane/api/serializers/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .user import UserLiteSerializer
from .state import StateLiteSerializer


class IssueSerializer(BaseSerializer):
assignees = serializers.ListField(
child=serializers.PrimaryKeyRelatedField(
Expand Down Expand Up @@ -66,14 +67,16 @@ def validate(self, data):
and data.get("target_date", None) is not None
and data.get("start_date", None) > data.get("target_date", None)
):
raise serializers.ValidationError("Start date cannot exceed target date")

raise serializers.ValidationError(
"Start date cannot exceed target date"
)

try:
if(data.get("description_html", None) is not None):
if data.get("description_html", None) is not None:
parsed = html.fromstring(data["description_html"])
parsed_str = html.tostring(parsed, encoding='unicode')
parsed_str = html.tostring(parsed, encoding="unicode")
data["description_html"] = parsed_str

except Exception as e:
raise serializers.ValidationError(f"Invalid HTML: {str(e)}")

Expand All @@ -96,7 +99,8 @@ def validate(self, data):
if (
data.get("state")
and not State.objects.filter(
project_id=self.context.get("project_id"), pk=data.get("state").id
project_id=self.context.get("project_id"),
pk=data.get("state").id,
).exists()
):
raise serializers.ValidationError(
Expand All @@ -107,7 +111,8 @@ def validate(self, data):
if (
data.get("parent")
and not Issue.objects.filter(
workspace_id=self.context.get("workspace_id"), pk=data.get("parent").id
workspace_id=self.context.get("workspace_id"),
pk=data.get("parent").id,
).exists()
):
raise serializers.ValidationError(
Expand Down Expand Up @@ -238,9 +243,13 @@ def to_representation(self, instance):
]
if "labels" in self.fields:
if "labels" in self.expand:
data["labels"] = LabelSerializer(instance.labels.all(), many=True).data
data["labels"] = LabelSerializer(
instance.labels.all(), many=True
).data
else:
data["labels"] = [str(label.id) for label in instance.labels.all()]
data["labels"] = [
str(label.id) for label in instance.labels.all()
]

return data

Expand Down Expand Up @@ -278,7 +287,8 @@ class Meta:
# Validation if url already exists
def create(self, validated_data):
if IssueLink.objects.filter(
url=validated_data.get("url"), issue_id=validated_data.get("issue_id")
url=validated_data.get("url"),
issue_id=validated_data.get("issue_id"),
).exists():
raise serializers.ValidationError(
{"error": "URL already exists for this Issue"}
Expand Down Expand Up @@ -324,11 +334,11 @@ class Meta:

def validate(self, data):
try:
if(data.get("comment_html", None) is not None):
if data.get("comment_html", None) is not None:
parsed = html.fromstring(data["comment_html"])
parsed_str = html.tostring(parsed, encoding='unicode')
parsed_str = html.tostring(parsed, encoding="unicode")
data["comment_html"] = parsed_str

except Exception as e:
raise serializers.ValidationError(f"Invalid HTML: {str(e)}")
return data
Expand Down Expand Up @@ -362,7 +372,6 @@ class Meta:


class LabelLiteSerializer(BaseSerializer):

class Meta:
model = Label
fields = [
Expand Down
12 changes: 7 additions & 5 deletions apiserver/plane/api/serializers/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def validate(self, data):
and data.get("target_date", None) is not None
and data.get("start_date", None) > data.get("target_date", None)
):
raise serializers.ValidationError("Start date cannot exceed target date")
raise serializers.ValidationError(
"Start date cannot exceed target date"
)

if data.get("members", []):
data["members"] = ProjectMember.objects.filter(
Expand Down Expand Up @@ -146,16 +148,16 @@ class Meta:
# Validation if url already exists
def create(self, validated_data):
if ModuleLink.objects.filter(
url=validated_data.get("url"), module_id=validated_data.get("module_id")
url=validated_data.get("url"),
module_id=validated_data.get("module_id"),
).exists():
raise serializers.ValidationError(
{"error": "URL already exists for this Issue"}
)
return ModuleLink.objects.create(**validated_data)


class ModuleLiteSerializer(BaseSerializer):

class ModuleLiteSerializer(BaseSerializer):
class Meta:
model = Module
fields = "__all__"
fields = "__all__"
Loading

0 comments on commit e0e2518

Please sign in to comment.