Skip to content

Commit

Permalink
Reformat with latest black version
Browse files Browse the repository at this point in the history
  • Loading branch information
mureytasroc committed Nov 4, 2023
1 parent 203e11c commit fb3fa1b
Show file tree
Hide file tree
Showing 23 changed files with 561 additions and 824 deletions.
2 changes: 1 addition & 1 deletion backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
black = "==21.9b0"
black = "==23.10.1"
unittest-xml-reporting = "*"
flake8 = "*"
flake8-isort = "*"
Expand Down
928 changes: 450 additions & 478 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions backend/Platform/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get(
"SECRET_KEY", "o7ql0!vuk0%rgrh9p2bihq#pege$qqlm@zo#8&t==%&za33m*2"
)
SECRET_KEY = os.environ.get("SECRET_KEY", "o7ql0!vuk0%rgrh9p2bihq#pege$qqlm@zo#8&t==%&za33m*2")

IDENTITY_RSA_PRIVATE_KEY = os.environ.get(
"IDENTITY_RSA_PRIVATE_KEY",
Expand Down Expand Up @@ -114,9 +112,7 @@
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES = {
"default": dj_database_url.config(
default="sqlite:///" + os.path.join(BASE_DIR, "db.sqlite3")
)
"default": dj_database_url.config(default="sqlite:///" + os.path.join(BASE_DIR, "db.sqlite3"))
}

# Set default PK type
Expand All @@ -126,9 +122,7 @@
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
},
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
Expand Down
4 changes: 1 addition & 3 deletions backend/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ class LabsAdminSite(admin.AdminSite):

def login(self, request, extra_context=None):
if not request.user.is_authenticated:
return redirect(
reverse("accounts:login") + "?next=" + request.GET.get("next")
)
return redirect(reverse("accounts:login") + "?next=" + request.GET.get("next"))
return super().login(request, extra_context)


Expand Down
6 changes: 2 additions & 4 deletions backend/accounts/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_email(self, pennid):
return None

return response[0]["email"]
except (requests.exceptions.RequestException):
except requests.exceptions.RequestException:
return None

def authenticate(self, request, remote_user, shibboleth_attributes):
Expand Down Expand Up @@ -70,9 +70,7 @@ def authenticate(self, request, remote_user, shibboleth_attributes):
# Update groups with every log in
user.groups.clear()
for affiliation_name in shibboleth_attributes["affiliation"]:
if (
affiliation_name
): # Some users don't have any affiliation somehow ¯\_(ツ)_/¯
if affiliation_name: # Some users don't have any affiliation somehow ¯\_(ツ)_/¯
group, _ = Group.objects.get_or_create(name=affiliation_name)
user.groups.add(group)

Expand Down
25 changes: 6 additions & 19 deletions backend/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [("auth", "0011_update_proxy_permissions")]
Expand All @@ -23,9 +22,7 @@ class Migration(migrations.Migration):
("password", models.CharField(max_length=128, verbose_name="password")),
(
"last_login",
models.DateTimeField(
blank=True, null=True, verbose_name="last login"
),
models.DateTimeField(blank=True, null=True, verbose_name="last login"),
),
(
"is_superuser",
Expand All @@ -38,35 +35,25 @@ class Migration(migrations.Migration):
(
"username",
models.CharField(
error_messages={
"unique": "A user with that username already exists."
},
error_messages={"unique": "A user with that username already exists."},
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
max_length=150,
unique=True,
validators=[
django.contrib.auth.validators.UnicodeUsernameValidator()
],
validators=[django.contrib.auth.validators.UnicodeUsernameValidator()],
verbose_name="username",
),
),
(
"first_name",
models.CharField(
blank=True, max_length=30, verbose_name="first name"
),
models.CharField(blank=True, max_length=30, verbose_name="first name"),
),
(
"last_name",
models.CharField(
blank=True, max_length=150, verbose_name="last name"
),
models.CharField(blank=True, max_length=150, verbose_name="last name"),
),
(
"email",
models.EmailField(
blank=True, max_length=254, verbose_name="email address"
),
models.EmailField(blank=True, max_length=254, verbose_name="email address"),
),
(
"is_staff",
Expand Down
5 changes: 1 addition & 4 deletions backend/accounts/migrations/0002_auto_20200213_1711.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def copy_permissions(apps, schema_editor):
ContentType = apps.get_model("contenttypes", "ContentType")
for user in User.objects.all():
for product_permission in user.product_permission.all():
content_type = ContentType.objects.get(
app_label="accounts", model="user"
)
content_type = ContentType.objects.get(app_label="accounts", model="user")
perm, _ = Permission.objects.get_or_create(
codename=product_permission.id,
name=product_permission.name,
Expand All @@ -35,7 +33,6 @@ def copy_permissions(apps, schema_editor):


class Migration(migrations.Migration):

dependencies = [("accounts", "0001_initial")]

operations = [
Expand Down
5 changes: 1 addition & 4 deletions backend/accounts/migrations/0003_auto_20210918_2041.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def create_email_objects(apps, schema_editor):


class Migration(migrations.Migration):

dependencies = [
("accounts", "0002_auto_20200213_1711"),
]
Expand Down Expand Up @@ -114,9 +113,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="user",
name="first_name",
field=models.CharField(
blank=True, max_length=150, verbose_name="first name"
),
field=models.CharField(blank=True, max_length=150, verbose_name="first name"),
),
migrations.CreateModel(
name="PhoneNumber",
Expand Down
1 change: 0 additions & 1 deletion backend/accounts/migrations/0004_user_profile_pic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("accounts", "0003_auto_20210918_2041"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

dependencies = [
("accounts", "0004_user_profile_pic"),
]
Expand Down
22 changes: 4 additions & 18 deletions backend/accounts/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,12 @@ def _lookup_item(self, model, field_name, item, mode=None):
return model.objects.get(**item)
except ObjectDoesNotExist:
raise serializers.ValidationError(
{
field_name: [
"The object with these values does not exist: {}".format(
item
)
]
},
{field_name: ["The object with these values does not exist: {}".format(item)]},
code="invalid",
)
except MultipleObjectsReturned:
raise serializers.ValidationError(
{
field_name: [
"Multiple objects exist with these values: {}".format(item)
]
}
{field_name: ["Multiple objects exist with these values: {}".format(item)]}
)

def save(self):
Expand Down Expand Up @@ -75,19 +65,15 @@ def save(self):

for item in items:
# adds item to list
m2m_lists[field_name].append(
self._lookup_item(model, field_name, item, mode)
)
m2m_lists[field_name].append(self._lookup_item(model, field_name, item, mode))
else:
m2m["many"] = False
# handles if it's a 1:1 field
if hasattr(field, "Meta"):
model = field.Meta.model
item = self.validated_data.pop(field_name, None)
# creates/gets objects associaated with list and creates list of objects
m2m_lists[field_name] = self._lookup_item(
model, field_name, item, mode
)
m2m_lists[field_name] = self._lookup_item(model, field_name, item, mode)
else:
# handles if it's accidentally added (e.g. Integer field, character field, etc.)
ignore_fields.add(field_name)
Expand Down
23 changes: 6 additions & 17 deletions backend/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ class User(AbstractUser):
pennid = models.IntegerField(primary_key=True)
uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
preferred_name = models.CharField(max_length=225, blank=True)
profile_pic = models.ImageField(
upload_to=get_user_image_filepath, blank=True, null=True
)
profile_pic = models.ImageField(upload_to=get_user_image_filepath, blank=True, null=True)

VERIFICATION_EXPIRATION_MINUTES = 10

Expand All @@ -90,9 +88,7 @@ class Student(models.Model):
)
major = models.ManyToManyField(Major, blank=True)
school = models.ManyToManyField(School, blank=True)
graduation_year = models.PositiveIntegerField(
validators=[MinValueValidator(1740)], null=True
)
graduation_year = models.PositiveIntegerField(validators=[MinValueValidator(1740)], null=True)

def __str__(self):
return self.user.username
Expand All @@ -108,9 +104,7 @@ def ensure_student_object(sender, instance, created, **kwargs):


class Email(models.Model):
user = models.ForeignKey(
get_user_model(), related_name="emails", on_delete=models.CASCADE
)
user = models.ForeignKey(get_user_model(), related_name="emails", on_delete=models.CASCADE)
value = models.EmailField(unique=True)
primary = models.BooleanField(default=False)
verification_code = models.CharField(max_length=6, blank=True, null=True)
Expand Down Expand Up @@ -152,9 +146,7 @@ def add_privacy_resource(sender, instance, created, **kwargs):
to true.
"""
users = User.objects.all()
settings = [
PrivacySetting(user=user, resource=instance, enabled=True) for user in users
]
settings = [PrivacySetting(user=user, resource=instance, enabled=True) for user in users]
# Bulk creating for all User objects
PrivacySetting.objects.bulk_create(settings, ignore_conflicts=True)

Expand All @@ -163,9 +155,7 @@ class PrivacySetting(models.Model):
user = models.ForeignKey(
get_user_model(), related_name="privacy_setting", on_delete=models.CASCADE
)
resource = models.ForeignKey(
PrivacyResource, related_name="resource", on_delete=models.CASCADE
)
resource = models.ForeignKey(PrivacyResource, related_name="resource", on_delete=models.CASCADE)
enabled = models.BooleanField(default=True)


Expand All @@ -181,7 +171,6 @@ def load_privacy_settings(sender, instance, created, **kwargs):
if not instance.privacy_setting.exists():
resources = PrivacyResource.objects.all()
settings = [
PrivacySetting(user=instance, resource=resource, enabled=True)
for resource in resources
PrivacySetting(user=instance, resource=resource, enabled=True) for resource in resources
]
PrivacySetting.objects.bulk_create(settings, ignore_conflicts=True)
Loading

0 comments on commit fb3fa1b

Please sign in to comment.