Skip to content

Commit

Permalink
Run black and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
k9845 authored and thenav56 committed Jun 11, 2024
1 parent 38d8481 commit 0cdc1ec
Show file tree
Hide file tree
Showing 935 changed files with 30,363 additions and 25,223 deletions.
576 changes: 340 additions & 236 deletions api/admin.py

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions api/admin_classes.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
from django.contrib import admin
from django.db.models import Q


# Extend the model admin with methods for determining whether a user has
# country- and region-specific permissions.
# If the user does not have specific permissions for any country or region,
# the result is an empty queryset.


class RegionRestrictedAdmin(admin.ModelAdmin):
def get_request_user_regions(self, request):
permissions = request.user.get_all_permissions()
regions = []
countries = []
for permission_name in permissions:
if 'api.country_admin_' in permission_name:
if "api.country_admin_" in permission_name:
country_id = permission_name[18:]
if country_id.isdigit():
countries.append(country_id)
elif 'api.region_admin_' in permission_name:
elif "api.region_admin_" in permission_name:
region_id = permission_name[17:]
if region_id.isdigit():
regions.append(region_id)
return countries, regions

def get_filtered_queryset(self, request, queryset):
if request.user.is_superuser or request.user.has_perm('api.ifrc_admin'):
if request.user.is_superuser or request.user.has_perm("api.ifrc_admin"):
return queryset
countries, regions = self.get_request_user_regions(request)

Expand All @@ -34,8 +34,8 @@ def get_filtered_queryset(self, request, queryset):
return queryset.none()

# Create an OR filter for records relating to this country or region
country_in = getattr(self, 'country_in', None)
region_in = getattr(self, 'region_in', None)
country_in = getattr(self, "country_in", None)
region_in = getattr(self, "region_in", None)
query = Q()
has_valid_query = False
if len(countries) and country_in is not None:
Expand Down
6 changes: 3 additions & 3 deletions api/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.utils.translation import gettext_lazy as _
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _


class ApiConfig(AppConfig):
name = 'api'
verbose_name = _('api')
name = "api"
verbose_name = _("api")
19 changes: 8 additions & 11 deletions api/authentication_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

class EmailBackend(ModelBackend):
"""
To allow to authenticate with email too without needing
to implement a custom User model at this point
To allow to authenticate with email too without needing
to implement a custom User model at this point
"""

def authenticate(self, request, username=None, password=None, **kwargs):
'''
Overriding: https://github.com/django/django/blob/master/django/contrib/auth/backends.py#L36
most of it is working the same, only added a few more checks needed for the email auth
'''
"""
Overriding: https://github.com/django/django/blob/master/django/contrib/auth/backends.py#L36
most of it is working the same, only added a few more checks needed for the email auth
"""

# To make 'finally' work becase we have 'MultipleObjectsReturned' exception
# which could still result in a valid login
Expand All @@ -29,12 +29,9 @@ def authenticate(self, request, username=None, password=None, **kwargs):
# difference between an existing and a nonexistent user (#20760).
UserModel().set_password(password)
except MultipleObjectsReturned:
user = User.objects.filter(Q(username__iexact=username) | Q(email__iexact=username)).order_by('-is_active').first()
user = User.objects.filter(Q(username__iexact=username) | Q(email__iexact=username)).order_by("-is_active").first()

if shouldcheck and \
user and \
user.check_password(password) and \
self.user_can_authenticate(user):
if shouldcheck and user and user.check_password(password) and self.user_can_authenticate(user):
return user

def get_user(self, user_id):
Expand Down
7 changes: 1 addition & 6 deletions api/create_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@


def create_cron_record(name, msg, status, num_result=0):
cron_obj = {
'name': name,
'message': msg,
'num_result': num_result,
'status': status
}
cron_obj = {"name": name, "message": msg, "num_result": num_result, "status": status}
CronJob.sync_cron(cron_obj)
Loading

0 comments on commit 0cdc1ec

Please sign in to comment.