Skip to content

Commit

Permalink
Use is instead of == for None comparisons (#1799)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkid15r authored Feb 18, 2024
1 parent dc09dce commit 7de8e73
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 43 deletions.
36 changes: 18 additions & 18 deletions company/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def wrapper(self,request,company,*args,**kwargs):
Q(managers__in=[request.user])
).filter(company_id=company).first()

if company == None:
if company is None:
return redirect("company_view")

return func(self,request,company.company_id,*args,**kwargs)
Expand All @@ -64,7 +64,7 @@ def company_view(request,*args,**kwargs):
messages.info(request,"Email not verified.")
return redirect("/")

if (user==None or isinstance(user,AnonymousUser)):
if (user is None or isinstance(user,AnonymousUser)):
messages.error(request,"Login with company or domain provided email.")
return redirect("/accounts/login/")

Expand All @@ -80,7 +80,7 @@ def company_view(request,*args,**kwargs):
Q(admin=user) |
Q(managers__in=[user])
)
if (user_companies.first()==None):
if (user_companies.first() is None):

messages.error(request,"You do not have a company, create one.")
return redirect("register_company")
Expand Down Expand Up @@ -108,7 +108,7 @@ def post(self,request,*args,**kwargs):
messages.info(request,"Email not verified.")
return redirect("/")

if (user==None or isinstance(user,AnonymousUser)):
if (user is None or isinstance(user,AnonymousUser)):
messages.error(request,"Login to create company")
return redirect("/accounts/login/")

Expand All @@ -129,7 +129,7 @@ def post(self,request,*args,**kwargs):

company = Company.objects.filter(name=data["company_name"]).first()

if (company!=None):
if (company is not None):
messages.error(request,"Company already exist.")
return redirect("register_company")

Expand Down Expand Up @@ -182,7 +182,7 @@ def get_general_info(self,company):
total_bug_hunts = Hunt.objects.filter(domain__company__company_id=company).count()
total_domains = Domain.objects.filter(company__company_id=company).count()
total_money_distributed = Issue.objects.filter(domain__company__company_id=company).aggregate(total_money=Sum('rewarded'))["total_money"]
total_money_distributed = 0 if total_money_distributed==None else total_money_distributed
total_money_distributed = 0 if total_money_distributed is None else total_money_distributed

return {
'total_company_bugs':total_company_bugs,
Expand Down Expand Up @@ -418,11 +418,11 @@ def post(self,request,company,*args,**kwargs):
"facebook": request.POST.get("facebook_url",None),
}

if domain_data["name"] == None:
if domain_data["name"] is None:
messages.error(request,"Enter domain name")
return redirect("add_domain",company)

if domain_data["url"] == None:
if domain_data["url"] is None:
messages.error(request,"Enter domain url")
return redirect("add_domain",company)

Expand Down Expand Up @@ -546,7 +546,7 @@ def get(self,request,pk,*args,**kwargs):
raise Http404("Domain not found")

total_money_distributed = Issue.objects.filter(pk=domain["id"]).aggregate(total_money=Sum('rewarded'))["total_money"]
total_money_distributed = 0 if total_money_distributed==None else total_money_distributed
total_money_distributed = 0 if total_money_distributed is None else total_money_distributed

total_bug_reported = Issue.objects.filter(pk=domain["id"]).count()
total_bug_accepted = Issue.objects.filter(pk=domain["id"], verified=True).count()
Expand Down Expand Up @@ -639,7 +639,7 @@ def post(self,request,company,*args,**kwargs):
( Q(company__admin=request.user) | Q(managers__in=[request.user]) )
).first()

if domain == None:
if domain is None:
messages.error("you are not manager of this domain.")
return redirect('company_manage_roles',company)

Expand Down Expand Up @@ -682,7 +682,7 @@ def get(self,request,pk,*args, **kwargs):
total_bug_accepted = hunt_issues.filter(verified=True).count()

total_money_distributed = hunt_issues.aggregate(total_money=Sum('rewarded'))["total_money"]
total_money_distributed = (0 if total_money_distributed==None else total_money_distributed)
total_money_distributed = (0 if total_money_distributed is None else total_money_distributed)


bughunt_leaderboard = hunt_issues.values("user__id","user__username","user__userprofile__user_avatar").filter(user__isnull=False,verified=True).annotate(count=Count('user__username')).order_by("-count")[:16]
Expand Down Expand Up @@ -790,7 +790,7 @@ def get(self,request,company,*args,**kwargs):

domains = Domain.objects.values('id','name').filter(company__company_id=company)

if hunt_id != None:
if hunt_id is not None:
return self.edit(request,company,companies,domains,hunt_id,*args,**kwargs)

context = {
Expand All @@ -808,15 +808,15 @@ def post(self,request,company,*args,**kwargs):
data = request.POST

hunt_id = data.get("hunt_id",None) # when post is for edit hunt
is_edit = True if hunt_id != None else False
is_edit = True if hunt_id is not None else False

if is_edit:
hunt = get_object_or_404(Hunt,pk=hunt_id)


domain = Domain.objects.filter(id=data.get("domain",None)).first()

if domain == None:
if domain is None:
messages.error(request,"Domain Does not exists")
return redirect('add_bughunt',company)

Expand All @@ -827,14 +827,14 @@ def post(self,request,company,*args,**kwargs):
end_date = datetime.strptime(end_date,"%m/%d/%Y").strftime("%Y-%m-%d %H:%M")

hunt_logo = request.FILES.get("logo",None)
if hunt_logo != None:
if hunt_logo is not None:
hunt_logo_file = hunt_logo.name.split(".")[0]
extension = hunt_logo.name.split(".")[-1]
hunt_logo.name = hunt_logo_file[:99] + str(uuid.uuid4()) + "." + extension
default_storage.save(f"logos/{hunt_logo.name}",hunt_logo)

webshot_logo = request.FILES.get("webshot",None)
if webshot_logo != None:
if webshot_logo is not None:
webshot_logo_file = webshot_logo.name.split(".")[0]
extension = webshot_logo.name.split(".")[-1]
webshot_logo.name = webshot_logo_file[:99] + str(uuid.uuid4()) + "." + extension
Expand All @@ -852,9 +852,9 @@ def post(self,request,company,*args,**kwargs):
hunt.end_on = end_date
hunt.is_published = False if data["publish_bughunt"] == "false" else True

if hunt_logo != None:
if hunt_logo is not None:
hunt.logo = f"logos/{hunt_logo.name}"
if webshot_logo != None:
if webshot_logo is not None:
hunt.banner = f"banners/{webshot_logo.name}"

hunt.save()
Expand Down
8 changes: 4 additions & 4 deletions website/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def retrieve(self, request,pk,*args, **kwargs):

user_profile = UserProfile.objects.filter(user__id=pk).first()

if user_profile == None:
if user_profile is None:
return Response({"detail": "Not found."},status=404)

serializer = self.get_serializer(user_profile)
Expand All @@ -93,7 +93,7 @@ def update(self, request, pk,*args, **kwargs):

user_profile = request.user.userprofile

if user_profile==None:
if user_profile is None:
return Response({"detail": "Not found."},status=404)

instance = user_profile
Expand Down Expand Up @@ -142,7 +142,7 @@ def get_queryset(self):

def get_issue_info(self,request,issue):

if issue == None:
if issue is None:
return {}

screenshots = [
Expand Down Expand Up @@ -454,7 +454,7 @@ def post(self, request, *args, **kwargs):

domain_url = request.data.get("domain_url",None)

if domain_url == None or domain_url.strip() == "":
if domain_url is None or domain_url.strip() == "":
return Response([])

domain = domain_url.replace("https://","").replace("http://","").replace("www.","")
Expand Down
2 changes: 1 addition & 1 deletion website/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UserProfileSerializer(serializers.ModelSerializer):
"""
def get_total_score(self,instance):
score = Points.objects.filter(user=instance.user).aggregate(total_score=Sum('score')).get("total_score")
if score==None: return 0
if score is None: return 0
return score

def get_activities(self,instance):
Expand Down
4 changes: 2 additions & 2 deletions website/templates/comments.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="comment_group">
{% for comment in all_comment %}
{% if comment.parent == None %}
{% if comment.parent is None %}
<blockquote>
<div class="well comment -ml-11 ">
<div class="comment-actions flex-col space-y-5 p-5">
Expand Down Expand Up @@ -43,7 +43,7 @@
</blockquote>
{% endfor %}

{% if comment.parent == None %}
{% if comment.parent is None %}
<form class="reply_form">
{% csrf_token %}
<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion website/templates/comments2.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
{% endif %}
<div class="comment_group">
{% for comment in all_comment %}
{% if comment.parent == None %}
{% if comment.parent is None %}
<article class="p-6 mb-6 text-base bg-white rounded-lg ">
<footer class="flex justify-between items-center mb-2">
<div class="grid grid-cols-9 items-center justify-between">
Expand Down
2 changes: 1 addition & 1 deletion website/templates/issue2.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<div class="w-full flex justify-between my-3">
<p class="text-3xl font-bold">Submitted:</p>

{% if object.hunt == None %}
{% if object.hunt is None %}

<span class="font-bold bg-red-600 px-5 py-1 text-white rounded-xl">Independently</span>

Expand Down
2 changes: 1 addition & 1 deletion website/templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h1 class="text-center"><span class="search-header">Search Results for </span><s
</div>
<div style="padding:0px 75px;">
<label style="font-size: 15px;">User points :</label>
{% if user.total_score == None %}
{% if user.total_score is None %}
<span style="font-size: 15px;">0</span> Point
{% else %}
<span style="font-size: 15px;">{{ user.total_score|floatformat:0 }}</span> Points
Expand Down
30 changes: 15 additions & 15 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def index(request, template="index.html"):
'end_on__year',
).annotate(total_prize=Sum("huntprize__value"))

if latest_hunts_filter != None:
if latest_hunts_filter is not None:
top_hunts = top_hunts.filter(result_published=True).order_by("-created")[:3]
else:
top_hunts = top_hunts.filter(is_published=True,result_published=False).order_by("-created")[:3]
Expand All @@ -183,7 +183,7 @@ def index(request, template="index.html"):
"top_companies":top_companies,
"top_testers":top_testers,
"top_hunts": top_hunts,
"ended_hunts": False if latest_hunts_filter == None else True
"ended_hunts": False if latest_hunts_filter is None else True
}
return render(request, template, context)

Expand Down Expand Up @@ -249,7 +249,7 @@ def newhome(request, template="new_home.html"):
# 'end_on__year',
# ).annotate(total_prize=Sum("huntprize__value"))

# if latest_hunts_filter != None:
# if latest_hunts_filter is not None:
# top_hunts = top_hunts.filter(result_published=True).order_by("-created")[:3]
# else:
# top_hunts = top_hunts.filter(is_published=True,result_published=False).order_by("-created")[:3]
Expand Down Expand Up @@ -277,7 +277,7 @@ def newhome(request, template="new_home.html"):
# "top_companies":top_companies,
# "top_testers":top_testers,
# "top_hunts": top_hunts,
# "ended_hunts": False if latest_hunts_filter == None else True
# "ended_hunts": False if latest_hunts_filter is None else True
}
return render(request, template, context)

Expand Down Expand Up @@ -778,7 +778,7 @@ def create_issue(self,form):
clean_domain = obj.domain_name.replace("www.", "").replace("https://","").replace("http://","")
domain = Domain.objects.filter(name=clean_domain).first()

domain_exists = False if domain==None else True
domain_exists = False if domain is None else True

if not domain_exists:
domain = Domain.objects.create(
Expand All @@ -788,7 +788,7 @@ def create_issue(self,form):
domain.save()

hunt = self.request.POST.get("hunt",None)
if hunt != None and hunt!="None":
if hunt is not None and hunt!="None":
hunt = Hunt.objects.filter(id=hunt).first()
obj.hunt = hunt

Expand Down Expand Up @@ -832,7 +832,7 @@ def create_issue(self,form):

team_members_id = [member["id"] for member in User.objects.values("id").filter(email__in=self.request.POST.getlist("team_members"))] + [self.request.user.id]
for member_id in team_members_id:
if member_id == None:
if member_id is None:
team_members_id.remove(member_id) # remove None values if user not exists
obj.team_members.set(team_members_id)

Expand Down Expand Up @@ -2287,7 +2287,7 @@ def comment_on_issue(request, issue_pk):
comment = request.POST.get("comment","")
replying_to_input = request.POST.get("replying_to_input","").split("#")

if issue == None:
if issue is None:
Http404("Issue does not exist, cannot comment")

if len(replying_to_input) == 2:
Expand All @@ -2296,7 +2296,7 @@ def comment_on_issue(request, issue_pk):

parent_comment = Comment.objects.filter(pk=replying_to_comment_id).first()

if parent_comment == None:
if parent_comment is None:
messages.error(request,"Parent comment doesn't exist.")
return redirect(f"/issue2/{issue_pk}")

Expand Down Expand Up @@ -2399,7 +2399,7 @@ def get_scoreboard(request):
temp["closed"] = len(each.closed_issues)
temp["modified"] = each.modified
temp["logo"] = each.logo
if each.top_tester == None:
if each.top_tester is None:
temp["top"] = "None"
else:
temp["top"] = each.top_tester.username
Expand Down Expand Up @@ -2598,15 +2598,15 @@ def get(self, request, *args, **kwargs):
if search.strip() != "":
hunts = hunts.filter(Q(name__icontains=search))

if start_date != "" and start_date != None:
if start_date != "" and start_date is not None:
start_date = datetime.strptime(start_date,"%m/%d/%Y").strftime("%Y-%m-%d %H:%M")
hunts = hunts.filter(starts_on__gte=start_date)

if end_date != "" and end_date != None:
if end_date != "" and end_date is not None:
end_date = datetime.strptime(end_date,"%m/%d/%Y").strftime("%Y-%m-%d %H:%M")
hunts = hunts.filter(end_on__gte=end_date)

if domain != "Select Domain" and domain != None:
if domain != "Select Domain" and domain is not None:
domain = Domain.objects.filter(id=domain).first()
hunts = hunts.filter(domain=domain)

Expand Down Expand Up @@ -3518,7 +3518,7 @@ def contributors_view(request,*args,**kwargs):
if str(i["id"])==contributor_id:
contributor = i

if contributor==None:
if contributor is None:
return HttpResponseNotFound("Contributor not found")

return render(request,"contributors_detail.html",context={"contributor":contributor})
Expand Down Expand Up @@ -3635,7 +3635,7 @@ def like_issue2(request, issue_pk):
def subscribe_to_domains(request, pk):

domain = Domain.objects.filter(pk=pk).first()
if domain == None:
if domain is None:
return JsonResponse("ERROR", safe=False,status=400)

already_subscribed = request.user.userprofile.subscribed_domains.filter(pk=domain.id).exists()
Expand Down

0 comments on commit 7de8e73

Please sign in to comment.