From 122e7011fb810ea9f0cc9dfc57c66ee20a538de0 Mon Sep 17 00:00:00 2001 From: Krrish Sehgal <133865424+krrish-sehgal@users.noreply.github.com> Date: Tue, 5 Nov 2024 21:10:26 +0530 Subject: [PATCH] Fix formatting issues with ruff --- blt/urls.py | 14 +- website/class_views.py | 86 ++++---- website/forms.py | 7 +- website/migrations/0142_ipreport.py | 5 +- website/models.py | 14 +- website/templates/malicious_ips_list.html | 38 ++-- website/templates/report_ip.html | 196 ++++++++---------- website/templates/sizzle/sizzle.html | 3 +- .../templates/sizzle/user_sizzle_report.html | 12 +- website/views.py | 4 +- 10 files changed, 188 insertions(+), 191 deletions(-) diff --git a/blt/urls.py b/blt/urls.py index 6c24d4c97..f9ee95b5e 100644 --- a/blt/urls.py +++ b/blt/urls.py @@ -62,11 +62,13 @@ IssueView, JoinCompany, ListHunts, + MaliciousIpListView, OngoingHunts, PreviousHunts, ProjectBadgeView, ProjectDetailView, ProjectListView, + ReportIpView, ScoreboardView, SpecificIssuesView, SpecificMonthLeaderboardView, @@ -76,9 +78,6 @@ UserDeleteView, UserProfileDetailsView, UserProfileDetailView, - ReportIpView, - MaliciousIpListView, - ) from website.views import ( # TODO AutoLabel, SaveBiddingData, @@ -460,8 +459,7 @@ path("project//", ProjectDetailView.as_view(), name="project_view"), path("projects//badge/", ProjectBadgeView.as_view(), name="project-badge"), path("report-ip/", ReportIpView.as_view(), name="report_ip"), - path("malicious-ips/", MaliciousIpListView.as_view(), name='malicious_ips_list'), - + path("malicious-ips/", MaliciousIpListView.as_view(), name="malicious_ips_list"), re_path( r"^api/v1/createissues/$", csrf_exempt(IssueCreate.as_view()), @@ -573,7 +571,11 @@ path("api/timelogsreport/", website.views.TimeLogListAPIView, name="timelogsreport"), path("time-logs/", website.views.TimeLogListView, name="time_logs"), path("sizzle-daily-log/", website.views.sizzle_daily_log, name="sizzle_daily_log"), - path("user-sizzle-report//", website.views.user_sizzle_report, name="user_sizzle_report"), + path( + "user-sizzle-report//", + website.views.user_sizzle_report, + name="user_sizzle_report", + ), ] if settings.DEBUG: diff --git a/website/class_views.py b/website/class_views.py index 22b3b9034..ef22e6054 100644 --- a/website/class_views.py +++ b/website/class_views.py @@ -6,10 +6,6 @@ from decimal import Decimal from urllib.parse import urlparse - -from django.urls import reverse_lazy -from django.views.generic import FormView - import requests import six import stripe @@ -47,7 +43,7 @@ from django.utils.decorators import method_decorator from django.utils.timezone import now from django.views.decorators.csrf import csrf_exempt -from django.views.generic import DetailView, ListView, TemplateView, View +from django.views.generic import DetailView, FormView, ListView, TemplateView, View from django.views.generic.edit import CreateView from PIL import Image, ImageDraw, ImageFont from rest_framework.authtoken.models import Token @@ -57,7 +53,14 @@ from user_agents import parse from blt import settings -from website.forms import CaptchaForm, GitHubURLForm, HuntForm, UserDeleteForm, UserProfileForm , IpReportForm +from website.forms import ( + CaptchaForm, + GitHubURLForm, + HuntForm, + IpReportForm, + UserDeleteForm, + UserProfileForm, +) from website.models import ( IP, BaconToken, @@ -72,6 +75,7 @@ Hunt, HuntPrize, InviteFriend, + IpReport, Issue, IssueScreenshot, Monitor, @@ -87,7 +91,6 @@ UserProfile, Wallet, Winner, - IpReport, ) from website.utils import ( get_client_ip, @@ -1201,6 +1204,7 @@ def get_context_data(self, **kwargs): return context + class UploadCreate(View): template_name = "index.html" @@ -2214,7 +2218,7 @@ def get_context_data(self, **kwargs): class ReportIpView(FormView): - template_name = 'report_ip.html' + template_name = "report_ip.html" form_class = IpReportForm captcha = CaptchaForm() @@ -2223,11 +2227,15 @@ def post(self, request, *args, **kwargs): captcha_form = CaptchaForm(request.POST) if not captcha_form.is_valid(): messages.error(request, "Invalid CAPTCHA. Please try again.") - return render(request, self.template_name, { - "form": self.get_form(), - "captcha_form": captcha_form, - }) - + return render( + request, + self.template_name, + { + "form": self.get_form(), + "captcha_form": captcha_form, + }, + ) + # Process form and duplicate IP check form = self.get_form() if form.is_valid(): @@ -2235,15 +2243,19 @@ def post(self, request, *args, **kwargs): ip_type = form.cleaned_data.get("ip_type") if IpReport.objects.filter(ip_address=ip_address, ip_type=ip_type).exists(): messages.error(request, "This IP address has already been reported.") - return render(request, self.template_name, { - "form": form, - "captcha_form": captcha_form, - }) - + return render( + request, + self.template_name, + { + "form": form, + "captcha_form": captcha_form, + }, + ) + return self.form_valid(form) else: return self.form_invalid(form) - + @atomic def form_valid(self, form): # Check daily report limit per IP @@ -2251,36 +2263,38 @@ def form_valid(self, form): limit = 50 if self.request.user.is_authenticated else 30 today = now().date() recent_reports_count = IpReport.objects.filter( - reporter_ip_address=reporter_ip, - created=today + reporter_ip_address=reporter_ip, created=today ).count() - + if recent_reports_count >= limit: messages.error(self.request, "You have reached the daily limit for IP reports.") - return render(self.request, self.template_name, { - "form": self.get_form(), - "captcha_form": CaptchaForm(), - }) - + return render( + self.request, + self.template_name, + { + "form": self.get_form(), + "captcha_form": CaptchaForm(), + }, + ) form.instance.reporter_ip_address = reporter_ip form.instance.user = self.request.user if self.request.user.is_authenticated else None form.save() messages.success(self.request, "IP report successfully submitted.") - - return redirect("malicious_ips_list") - + return redirect("malicious_ips_list") + def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context['captcha_form'] = CaptchaForm() + context = super().get_context_data(**kwargs) + context["captcha_form"] = CaptchaForm() return context + class MaliciousIpListView(ListView): model = IpReport - template_name = 'malicious_ips_list.html' - context_object_name = 'malicious_ips' - paginate_by = 10 + template_name = "malicious_ips_list.html" + context_object_name = "malicious_ips" + paginate_by = 10 def get_queryset(self): - return IpReport.objects.all() \ No newline at end of file + return IpReport.objects.all() diff --git a/website/forms.py b/website/forms.py index f4a878715..f047b5647 100644 --- a/website/forms.py +++ b/website/forms.py @@ -2,7 +2,7 @@ from django import forms from mdeditor.fields import MDTextFormField -from .models import Bid, Monitor, UserProfile ,IpReport +from .models import Bid, IpReport, Monitor, UserProfile class UserProfileForm(forms.ModelForm): @@ -66,8 +66,9 @@ class Meta: class IpReportForm(forms.ModelForm): class Meta: model = IpReport - fields = ['ip_address', 'ip_type', 'description', 'malicious_activity_title'] - + fields = ["ip_address", "ip_type", "description", "malicious_activity_title"] + + class BidForm(forms.ModelForm): class Meta: model = Bid diff --git a/website/migrations/0142_ipreport.py b/website/migrations/0142_ipreport.py index 9d86ff2f3..c7717d807 100644 --- a/website/migrations/0142_ipreport.py +++ b/website/migrations/0142_ipreport.py @@ -6,7 +6,6 @@ class Migration(migrations.Migration): - dependencies = [ ("website", "0141_project_project_visit_count_project_repo_visit_count"), migrations.swappable_dependency(settings.AUTH_USER_MODEL), @@ -29,9 +28,7 @@ class Migration(migrations.Migration): ("ip_address", models.GenericIPAddressField()), ( "ip_type", - models.CharField( - choices=[("ipv4", "IPv4"), ("ipv6", "IPv6")], max_length=10 - ), + models.CharField(choices=[("ipv4", "IPv4"), ("ipv6", "IPv6")], max_length=10), ), ("description", models.TextField()), ("created", models.DateTimeField(auto_now_add=True)), diff --git a/website/models.py b/website/models.py index e51386be6..8d41dfe04 100644 --- a/website/models.py +++ b/website/models.py @@ -1,8 +1,6 @@ import logging import os import uuid -import ipaddress - from decimal import Decimal from urllib.parse import urlparse @@ -879,17 +877,17 @@ def __str__(self): class IpReport(models.Model): IP_TYPE_CHOICES = [ - ('ipv4', 'IPv4'), - ('ipv6', 'IPv6'), + ("ipv4", "IPv4"), + ("ipv6", "IPv6"), ] - + user = models.ForeignKey(User, null=True, blank=True, on_delete=models.CASCADE) - malicious_activity_title = models.CharField(max_length=255) - ip_address = models.GenericIPAddressField() + malicious_activity_title = models.CharField(max_length=255) + ip_address = models.GenericIPAddressField() ip_type = models.CharField(max_length=10, choices=IP_TYPE_CHOICES) description = models.TextField() created = models.DateTimeField(auto_now_add=True) reporter_ip_address = models.GenericIPAddressField(null=True, blank=True) def __str__(self): - return f"{self.ip_address} ({self.ip_type}) - {self.malicious_activity_title}" \ No newline at end of file + return f"{self.ip_address} ({self.ip_type}) - {self.malicious_activity_title}" diff --git a/website/templates/malicious_ips_list.html b/website/templates/malicious_ips_list.html index cd9383ed1..cc757bef0 100644 --- a/website/templates/malicious_ips_list.html +++ b/website/templates/malicious_ips_list.html @@ -84,46 +84,43 @@ font-size: 1.2em; } -

Reported Malicious IPs

{% for ip in malicious_ips %} -
-
- {{ ip.ip_address }} - -
- -
-

Reason: {{ ip.malicious_activity_title}}

-

{{ ip.description|default:"No additional details provided." }}

+
+
+ {{ ip.ip_address }} + +
+ +
+

Reason: {{ ip.malicious_activity_title }}

+

{{ ip.description|default:"No additional details provided." }}

+
-
{% empty %} -

No malicious IPs reported.

+

No malicious IPs reported.

{% endfor %}
-
- - + {% endblock after_js %} diff --git a/website/templates/sizzle/sizzle.html b/website/templates/sizzle/sizzle.html index 3ce7f4115..9defe586b 100644 --- a/website/templates/sizzle/sizzle.html +++ b/website/templates/sizzle/sizzle.html @@ -120,7 +120,8 @@

Your Sizzle Report

{% for user in leaderboard %} - {{ user.username }} + {{ user.username }} {{ user.formatted_duration }} diff --git a/website/templates/sizzle/user_sizzle_report.html b/website/templates/sizzle/user_sizzle_report.html index 6f796c8ea..13102a3a8 100644 --- a/website/templates/sizzle/user_sizzle_report.html +++ b/website/templates/sizzle/user_sizzle_report.html @@ -14,12 +14,12 @@

{{ user.username }}'s Sizzle Report

{% for log in response_data %} - - {{ log.date }} - {{ log.issue_title }} - {{ log.duration }} - {{ log.start_time }} - + + {{ log.date }} + {{ log.issue_title }} + {{ log.duration }} + {{ log.start_time }} + {% endfor %} diff --git a/website/views.py b/website/views.py index f4e27bd73..ab8256156 100644 --- a/website/views.py +++ b/website/views.py @@ -2622,4 +2622,6 @@ def user_sizzle_report(request, username): response_data.append(day_data) - return render(request, "sizzle/user_sizzle_report.html", {"response_data": response_data, "user": user}) + return render( + request, "sizzle/user_sizzle_report.html", {"response_data": response_data, "user": user} + )