Skip to content

Commit

Permalink
Black format
Browse files Browse the repository at this point in the history
  • Loading branch information
utement committed Oct 17, 2023
1 parent 9e14521 commit 650c61d
Show file tree
Hide file tree
Showing 27 changed files with 211 additions and 251 deletions.
2 changes: 1 addition & 1 deletion django_project_base/account/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .constants import ACCOUNT_APP_ID
from .middleware import SessionMiddleware

default_app_config = '%s.apps.DjangoProjectBaseAccountsConfig' % ACCOUNT_APP_ID
default_app_config = "%s.apps.DjangoProjectBaseAccountsConfig" % ACCOUNT_APP_ID
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,33 @@


class Command(BaseCommand):
help = 'Migrate social login data from allauth to social_core'
help = "Migrate social login data from allauth to social_core"

provider_mapping: dict = {
'google': social_core.backends.google.GoogleOAuth2.name,
'facebook': social_core.backends.facebook.FacebookOAuth2.name,
'azure': social_core.backends.microsoft.MicrosoftOAuth2.name,
"google": social_core.backends.google.GoogleOAuth2.name,
"facebook": social_core.backends.facebook.FacebookOAuth2.name,
"azure": social_core.backends.microsoft.MicrosoftOAuth2.name,
}

def handle(self, *args, **options):

with connection.cursor() as cursor:
cursor.execute('select user_id, provider, extra_data from socialaccount_socialaccount;')
cursor.execute("select user_id, provider, extra_data from socialaccount_socialaccount;")
rows: list = cursor.fetchall()
for row in rows:
user_id: int = row[0]
provider: str = row[1]
extra_data: dict = json.loads(row[2]) if row[2] else {}
user_email: Optional[str] = extra_data.get('email') or extra_data.get('mail')
user_email: Optional[str] = extra_data.get("email") or extra_data.get("mail")
if user_email:
new_provider: str = self.provider_mapping.get(provider)
assert new_provider, 'New social auth provider for %s is not defined' % provider
assert new_provider, "New social auth provider for %s is not defined" % provider
payload = {
'user_id': user_id,
'provider': new_provider,
"user_id": user_id,
"provider": new_provider,
}
social_auth_records_exists: bool = UserSocialAuth.objects.filter(**payload).exists()
if not social_auth_records_exists:
payload['uid'] = user_email
payload['extra_data'] = None
payload["uid"] = user_email
payload["extra_data"] = None
UserSocialAuth.objects.create(**payload)
return 'ok'
return "ok"
4 changes: 2 additions & 2 deletions django_project_base/account/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from django_project_base.account.router import accounts_router, profile_router

urlpatterns = [
path('', include(accounts_router.urls)),
path('', include(profile_router.urls)),
path("", include(accounts_router.urls)),
path("", include(profile_router.urls)),
]
4 changes: 2 additions & 2 deletions django_project_base/base/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@


def hijack_set_is_hijacked(sender, **kwargs):
cache.set(CACHE_IMPERSONATE_USER % kwargs.get('hijacked').id, True)
cache.set(CACHE_IMPERSONATE_USER % kwargs.get("hijacked").id, True)


def hijack_delete_is_hijacked(sender, **kwargs):
cache.delete(CACHE_IMPERSONATE_USER % kwargs.get('hijacked').id)
cache.delete(CACHE_IMPERSONATE_USER % kwargs.get("hijacked").id)


hijack_started.connect(hijack_set_is_hijacked)
Expand Down
4 changes: 1 addition & 3 deletions django_project_base/licensing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
default_app_config = (
"%s.apps.DjangoProjectBaseLicensingConfig" % "django_project_base.licensing"
)
default_app_config = "%s.apps.DjangoProjectBaseLicensingConfig" % "django_project_base.licensing"
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ class Migration(migrations.Migration):
field=models.IntegerField(
choices=[
(
django_project_base.licensing.models.LicenseAccessUse.UseType[
"USE"
],
django_project_base.licensing.models.LicenseAccessUse.UseType["USE"],
"Used access",
)
],
default=django_project_base.licensing.models.LicenseAccessUse.UseType[
"USE"
],
default=django_project_base.licensing.models.LicenseAccessUse.UseType["USE"],
verbose_name="Type",
),
),
Expand All @@ -45,21 +41,15 @@ class Migration(migrations.Migration):
field=models.IntegerField(
choices=[
(
django_project_base.licensing.models.LicenseAccessUse.UseType[
"USE"
],
django_project_base.licensing.models.LicenseAccessUse.UseType["USE"],
"Used access",
),
(
django_project_base.licensing.models.LicenseAccessUse.UseType[
"ADMIN_USE"
],
django_project_base.licensing.models.LicenseAccessUse.UseType["ADMIN_USE"],
"Used access by admin",
),
],
default=django_project_base.licensing.models.LicenseAccessUse.UseType[
"USE"
],
default=django_project_base.licensing.models.LicenseAccessUse.UseType["USE"],
verbose_name="Type",
),
),
Expand Down
2 changes: 1 addition & 1 deletion django_project_base/notifications/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django_project_base.notifications.constants import NOTIFICATIONS_APP_ID

default_app_config = '%s.apps.DjangoProjectBaseNotifyConfig' % NOTIFICATIONS_APP_ID
default_app_config = "%s.apps.DjangoProjectBaseNotifyConfig" % NOTIFICATIONS_APP_ID
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ class Command(BaseCommand):
help = 'Resends notification. Example: python manage.py resend_notification "178a46c2-2aa3-4a33-bad6-9af2d76f6891" 2' # noqa: E501

def add_arguments(self, parser) -> None:
parser.add_argument('notification', type=str, help='Notification identifier (uuid string).')
parser.add_argument('user', type=str, help='User identifier (user sending notification).')
parser.add_argument("notification", type=str, help="Notification identifier (uuid string).")
parser.add_argument("user", type=str, help="User identifier (user sending notification).")

def handle(self, *args, **options):
Notification.resend(get_object_or_404(DjangoProjectBaseNotification, pk=str(options['notification'])),
str(options["user"]))
Notification.resend(
get_object_or_404(DjangoProjectBaseNotification, pk=str(options["notification"])), str(options["user"])
)
return "ok"
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,20 @@ class Migration(migrations.Migration):
models.IntegerField(
choices=[
(
django_project_base.notifications.models.DeliveryReport.Status[
"DELIVERED"
],
django_project_base.notifications.models.DeliveryReport.Status["DELIVERED"],
"Delivered",
),
(
django_project_base.notifications.models.DeliveryReport.Status[
"NOT_DELIVERED"
],
django_project_base.notifications.models.DeliveryReport.Status["NOT_DELIVERED"],
"Not Delivered",
),
(
django_project_base.notifications.models.DeliveryReport.Status[
"PENDING_DELIVERY"
],
django_project_base.notifications.models.DeliveryReport.Status["PENDING_DELIVERY"],
"Pending delivery",
),
],
db_index=True,
default=django_project_base.notifications.models.DeliveryReport.Status[
"PENDING_DELIVERY"
],
default=django_project_base.notifications.models.DeliveryReport.Status["PENDING_DELIVERY"],
),
),
(
Expand Down
7 changes: 3 additions & 4 deletions django_project_base/notifications/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
"name": "TIME_BUFFER_FOR_CURRENT_MAINTENANCE_API_QUERY",
"default": 900,
"description": "When list maintenance notifications api is called with current=true in query param, "
"maintenance notification within range of now - TIME_BUFFER_FOR_CURRENT_MAINTENANCE_API_QUERY, "
"now + TIME_BUFFER_FOR_CURRENT_MAINTENANCE_API_QUERY is returned. Maintenance notification "
"cannot be created if it overlaps with annother maintenance notification in buffer.",
"maintenance notification within range of now - TIME_BUFFER_FOR_CURRENT_MAINTENANCE_API_QUERY, "
"now + TIME_BUFFER_FOR_CURRENT_MAINTENANCE_API_QUERY is returned. Maintenance notification "
"cannot be created if it overlaps with annother maintenance notification in buffer.",
},

)
Loading

0 comments on commit 650c61d

Please sign in to comment.