Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
Changes to be committed:
	modified:   .vscode/settings.json
	modified:   core/apps.py
	modified:   core/migrations/0001_initial.py
	modified:   core/migrations/0002_prefixes.py
	modified:   core/migrations/0003_auto_20220330_2122.py
	modified:   core/migrations/0004_auto_20220716_1651.py
	modified:   core/models.py
	modified:   core/serializers.py
	modified:   core/tests/test_models.py
	modified:   core/urls.py
	modified:   core/views.py
	modified:   docs/source/conf.py
	modified:   manage.py
	modified:   portalusers/asgi.py
	modified:   portalusers/settings.py
	modified:   portalusers/urls.py
	modified:   portalusers/utils.py
	modified:   portalusers/wsgi.py
	modified:   simple_api_info_fill.py
  • Loading branch information
HadleyKing committed Sep 13, 2022
1 parent ebe049d commit 749bd72
Show file tree
Hide file tree
Showing 19 changed files with 574 additions and 430 deletions.
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true
"python.linting.enabled": true,
"python.linting.pylintArgs": [
"--django-settings-module=portalusers.settings",
"--load-plugins=pylint_django",
],
"django.snippets.exclude": [

"cms",
"wagtail"
]
}
4 changes: 2 additions & 2 deletions core/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
class CoreConfig(AppConfig):
"""Core"""

name = 'core'
default_auto_field = 'django.db.models.AutoField'
name = "core"
default_auto_field = "django.db.models.AutoField"
62 changes: 47 additions & 15 deletions core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,58 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name='Profile',
name="Profile",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('public', models.BooleanField(blank=True, default=False)),
('affiliation', models.CharField(blank=True, max_length=1000)),
('orcid', models.CharField(blank=True, max_length=1000)),
('username', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("public", models.BooleanField(blank=True, default=False)),
("affiliation", models.CharField(blank=True, max_length=1000)),
("orcid", models.CharField(blank=True, max_length=1000)),
(
"username",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
),
migrations.CreateModel(
name='ApiInfo',
name="ApiInfo",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('username', models.CharField(blank=True, max_length=1000)),
('hostname', models.CharField(blank=True, max_length=15)),
('human_readable_hostname', models.CharField(blank=True, max_length=1000)),
('public_hostname', models.CharField(blank=True, max_length=1000)),
('token', models.CharField(blank=True, max_length=1000)),
('other_info', models.JSONField()),
('local_username', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='custom_user', to=settings.AUTH_USER_MODEL)),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("username", models.CharField(blank=True, max_length=1000)),
("hostname", models.CharField(blank=True, max_length=15)),
(
"human_readable_hostname",
models.CharField(blank=True, max_length=1000),
),
("public_hostname", models.CharField(blank=True, max_length=1000)),
("token", models.CharField(blank=True, max_length=1000)),
("other_info", models.JSONField()),
(
"local_username",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="custom_user",
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
22 changes: 15 additions & 7 deletions core/migrations/0002_prefixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@
class Migration(migrations.Migration):

dependencies = [
('core', '0001_initial'),
("core", "0001_initial"),
]

operations = [
migrations.CreateModel(
name='Prefixes',
name="Prefixes",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('username', models.CharField(max_length=100)),
('prefix', models.CharField(max_length=5)),
('registration_date', models.DateTimeField()),
('registration_certificate', models.CharField(max_length=1000)),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("username", models.CharField(max_length=100)),
("prefix", models.CharField(max_length=5)),
("registration_date", models.DateTimeField()),
("registration_certificate", models.CharField(max_length=1000)),
],
),
]
14 changes: 8 additions & 6 deletions core/migrations/0003_auto_20220330_2122.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
class Migration(migrations.Migration):

dependencies = [
('core', '0002_prefixes'),
("core", "0002_prefixes"),
]

operations = [
migrations.RemoveField(
model_name='prefixes',
name='id',
model_name="prefixes",
name="id",
),
migrations.AlterField(
model_name='prefixes',
name='prefix',
field=models.CharField(max_length=5, primary_key=True, serialize=False, unique=True),
model_name="prefixes",
name="prefix",
field=models.CharField(
max_length=5, primary_key=True, serialize=False, unique=True
),
),
]
12 changes: 8 additions & 4 deletions core/migrations/0004_auto_20220716_1651.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('core', '0003_auto_20220330_2122'),
("core", "0003_auto_20220330_2122"),
]

operations = [
migrations.AlterField(
model_name='prefixes',
name='username',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, to_field='username'),
model_name="prefixes",
name="username",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
to_field="username",
),
),
]
66 changes: 36 additions & 30 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,42 @@
from rest_framework import status
from rest_framework.response import Response


@receiver(reset_password_token_created)
def password_reset_token_created(sender, instance, reset_password_token, *args, **kwargs):
def password_reset_token_created(
sender, instance, reset_password_token, *args, **kwargs
):
"""
Create the token for a password reset.
"""
email_plaintext_message = "{}?token={}".format(reverse(
'password_reset:reset-password-request'), reset_password_token.key)
email_plaintext_message = "{}?token={}".format(
reverse("password_reset:reset-password-request"), reset_password_token.key
)

try:
send_mail(
subject='Password reset for BioCompute Portal',
message= email_plaintext_message,
subject="Password reset for BioCompute Portal",
message=email_plaintext_message,
html_message=email_plaintext_message,
from_email='[email protected]',
from_email="[email protected]",
recipient_list=[reset_password_token.user.email],
fail_silently=False,
)

except Exception as error:
print('activation_link', reset_password_token)
print("activation_link", reset_password_token)
# print('ERROR: ', error)
# TODO: Should handle when the send_mail function fails?
# return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR, data={
# "message": "Not able to send authentication email: {}".format(error)})
return Response(status=status.HTTP_201_CREATED,
data={"message": "Reset token has been requested but email was not sent."\
f" Check with your database administrator for your token. {error}"})
return Response(
status=status.HTTP_201_CREATED,
data={
"message": "Reset token has been requested but email was not sent."
f" Check with your database administrator for your token. {error}"
},
)


class Profile(models.Model):
"""Profile
Expand All @@ -55,14 +64,16 @@ class Profile(models.Model):
orcid:
User ORCID
"""

username = models.OneToOneField(User, on_delete=models.CASCADE)
public = models.BooleanField(blank = True, default=False)
affiliation = models.CharField(blank = True, max_length = 1000)
orcid = models.CharField(blank = True, max_length = 1000)
public = models.BooleanField(blank=True, default=False)
affiliation = models.CharField(blank=True, max_length=1000)
orcid = models.CharField(blank=True, max_length=1000)

def __str__(self):
"""String for representing the Profile model (in Admin site etc.)."""
return str(f'{self.username}')
return str(f"{self.username}")


class ApiInfo(models.Model):
"""API Information
Expand All @@ -86,20 +97,19 @@ class ApiInfo(models.Model):
"""

local_username = models.ForeignKey(
User,
on_delete = models.CASCADE,
related_name = 'custom_user'
User, on_delete=models.CASCADE, related_name="custom_user"
)
username = models.CharField(blank = True, max_length = 1000)
hostname = models.CharField(blank = True, max_length = 15)
human_readable_hostname = models.CharField(blank = True, max_length = 1000)
public_hostname = models.CharField(blank = True, max_length = 1000)
token = models.CharField(blank = True, max_length = 1000)
username = models.CharField(blank=True, max_length=1000)
hostname = models.CharField(blank=True, max_length=15)
human_readable_hostname = models.CharField(blank=True, max_length=1000)
public_hostname = models.CharField(blank=True, max_length=1000)
token = models.CharField(blank=True, max_length=1000)
other_info = models.JSONField()

def __str__(self):
"""String for representing the ApiInfo model (in Admin site etc.)."""
return str(f'{self.username} at {self.hostname}')
return str(f"{self.username} at {self.hostname}")


class Prefixes(models.Model):
"""Prefix Table: core_prefixes
Expand All @@ -112,14 +122,10 @@ class Prefixes(models.Model):
registration_certificate: str
"""

prefix = models.CharField(max_length = 5, primary_key=True, unique=True)
username = models.ForeignKey(
User,
on_delete=models.CASCADE,
to_field="username"
)
prefix = models.CharField(max_length=5, primary_key=True, unique=True)
username = models.ForeignKey(User, on_delete=models.CASCADE, to_field="username")
registration_date = models.DateTimeField()
registration_certificate = models.CharField(max_length = 1000)
registration_certificate = models.CharField(max_length=1000)

def __str__(self):
"""String for representing the Prefix (in Admin site etc.)."""
Expand Down
Loading

0 comments on commit 749bd72

Please sign in to comment.