Skip to content
This repository was archived by the owner on Oct 2, 2021. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,4 @@ max-line-length = 80
max-complexity = 18
per-file-ignores =
src/awards/settings/dev.py: F405
# TODO: Remove these once
# https://github.com/facebook/pyre-check/pull/256,
# https://github.com/facebook/pyre-check/pull/260,
# https://github.com/facebook/pyre-check/pull/261, and
# https://github.com/facebook/pyre-check/pull/262 can be used.
src/applications/forms.py: B950
src/applications/migrations/0003_auto_20200507_0125.py: B950
src/applications/models.py: B950
src/applications/test_views.py: B950
src/awards/urls.py: B950
src/homepage/test_views.py: B950
src/users/migrations/0001_initial.py: B950
src/users/forms.py: B950
src/users/models.py: B950
src/users/views.py: B950
select = B,C,E,F,W,T4,B9
29 changes: 5 additions & 24 deletions src/applications/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class FinancialAidApplicationForm(ApplicationForm):
type = Application.Type.FINANCIAL_AID

travel_requested = forms.BooleanField(
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
label=_("Do you need assistance with travel?"),
required=False,
label=_("Do you need assistance with travel?"), required=False,
)

class Meta:
Expand All @@ -32,13 +30,9 @@ class Meta:
"lodging_requested",
)
labels = {
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
"background": _("Tell us a little bit more about yourself"),
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
"lodging_requested": _("Do you need assistance with lodging?"),
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
"reason_to_attend": _("Why are you interested in attending PyGotham?"),
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
"travel_amount": _("What is the estimated cost (USD)?"),
}
widgets = {
Expand All @@ -51,39 +45,28 @@ def clean(self) -> Dict[str, Any]:
travel_amount = cleaned_data.get("travel_amount") or 0
if travel_amount < 0:
raise forms.ValidationError(
{
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
"travel_amount": _(
"Your estimated travel costs cannot be negative."
)
}
{"travel_amount": _("Your estimated travel costs cannot be negative.")}
)

travel_requested = cleaned_data.get("travel_requested")
if travel_requested:
if not travel_amount:
raise forms.ValidationError(
{
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
"travel_amount": _(
"Your estimated travel costs must be greater than $0.00."
)
}
)
elif travel_amount:
raise forms.ValidationError(
{
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
"travel_requested": _(
"You must request travel assistance before providing an estimated cost."
)
}
msg = _(
"You must request travel assistance before providing an estimated cost."
)
raise forms.ValidationError({"travel_requested": msg})

return cleaned_data

def clean_lodging_requested(self) -> bool:
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/261.
return bool(self.cleaned_data.get("lodging_requested"))


Expand All @@ -94,9 +77,7 @@ class Meta:
model = Application
fields = ("background", "reason_to_attend")
labels = {
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
"background": _("Tell us a little bit about yourself"),
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
"reason_to_attend": _("Why are you interested in attending PyGotham?"),
}

Expand Down
1 change: 0 additions & 1 deletion src/applications/migrations/0003_auto_20200507_0125.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="application",
name="travel_amount",
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/260.
field=models.DecimalField(
blank=True, decimal_places=2, max_digits=10, null=True
),
Expand Down
19 changes: 4 additions & 15 deletions src/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,33 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _

# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
User = get_user_model()


class Application(models.Model):
# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
class Status(models.TextChoices):
PENDING = "pending"

# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
class Type(models.TextChoices):
FINANCIAL_AID = "finaid"
SCHOLARSHIP = "scholarship"

# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
# pyre-ignore[16]: Determine why this ignore is needed.
applicant = models.ForeignKey(User, on_delete=models.DO_NOTHING)
background = models.TextField(_("applicant background"))
reason_to_attend = models.TextField(_("reason the applicant wishes to attend"))
status = models.CharField(
max_length=20,
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
choices=Status.choices,
default=Status.PENDING,
max_length=20, choices=Status.choices, default=Status.PENDING,
)
type = models.CharField(
max_length=11,
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
choices=Type.choices,
default=Type.SCHOLARSHIP,
max_length=11, choices=Type.choices, default=Type.SCHOLARSHIP,
)
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/260.
travel_amount = models.DecimalField(
max_digits=10, decimal_places=2, blank=True, null=True
)
lodging_requested = models.BooleanField(null=True)

def __str__(self) -> str:
# pyre-ignore[19]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
type_ = Application.Type(self.type)
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
# pyre-ignore[16]: Determine why this ignore is needed.
return f"{type_.label} application for {self.applicant}"
1 change: 0 additions & 1 deletion src/applications/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def test_financial_aid_lodging_requested_is_treated_as_boolean() -> None:

form = FinancialAidApplicationForm(other_fields)
assert form.is_valid()
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/261.
assert form.cleaned_data["lodging_requested"] is False


Expand Down
5 changes: 0 additions & 5 deletions src/applications/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ class Meta:

class UserFactory(DjangoModelFactory):
class Meta:
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
model = get_user_model()
django_get_or_create = ("email",)

email = "user@example.org"


@pytest.mark.django_db
# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
def test_that_one_of_form_type_and_pk_is_required_by_apply(client: Client) -> None:
user = UserFactory()
qs = get_query_string(user)
Expand All @@ -46,7 +44,6 @@ def test_that_one_of_form_type_and_pk_is_required_by_apply(client: Client) -> No


@pytest.mark.django_db
# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
def test_user_can_edit_their_application(client: Client) -> None:
user = UserFactory()
qs = get_query_string(user)
Expand All @@ -67,7 +64,6 @@ def test_user_can_edit_their_application(client: Client) -> None:


@pytest.mark.django_db
# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
def test_user_can_view_their_application(client: Client) -> None:
user = UserFactory()
qs = get_query_string(user)
Expand All @@ -80,7 +76,6 @@ def test_user_can_view_their_application(client: Client) -> None:


@pytest.mark.django_db
# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
def test_user_cant_view_someone_elses_application(client: Client) -> None:
user = UserFactory()
other = UserFactory(email=f"other+{user.email}")
Expand Down
4 changes: 0 additions & 4 deletions src/applications/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@
app_name = "applications"

urlpatterns = [
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
path("edit/<int:pk>", apply, name="edit"),
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
path(
"financial-aid",
apply,
{"form_type": FinancialAidApplicationForm},
name="financial_aid",
),
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
path(
"ticket", apply, {"form_type": ScholarshipApplicationForm}, name="scholarship"
),
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
path("view/<int:pk>", view, name="view"),
]
12 changes: 2 additions & 10 deletions src/awards/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,28 @@
from users.views import login, magic_login

urlpatterns = [
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
path(
"", TemplateView.as_view(template_name="homepage/index.html"), name="homepage"
),
# pyre doesn't include stubs for the Django admin.
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
path(
"admin/login/",
RedirectView.as_view(
pattern_name=settings.LOGIN_URL, permanent=True, query_string=True
),
),
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
# pyre doesn't include stubs for the Django admin.
path("admin/", admin.site.urls), # type: ignore
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
path("apply/", include("applications.urls", namespace="applications")),
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
path("login", login, name="login"),
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
path("login/magic", magic_login, name="magic-login"),
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
# pyre-ignore[16]: Determine why this ignore is needed.
path("logout", LogoutView.as_view(), name="logout"),
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
path("users/", include("users.urls", namespace="users")),
]

if settings.DEBUG:
import debug_toolbar

urlpatterns = [
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
path("__debug__/", include(debug_toolbar.urls)),
] + urlpatterns
2 changes: 0 additions & 2 deletions src/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from django.test import Client


# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
def client() -> Client:
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
return Client()
3 changes: 0 additions & 3 deletions src/homepage/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

class UserFactory(DjangoModelFactory):
class Meta:
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
model = get_user_model()
django_get_or_create = ("email",)

email = "user@example.org"


@pytest.mark.django_db
# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
def test_login_link_is_not_shown_to_logged_in_users(client: Client) -> None:
user = UserFactory()
qs = get_query_string(user)
Expand All @@ -27,7 +25,6 @@ def test_login_link_is_not_shown_to_logged_in_users(client: Client) -> None:
assert b"log in" not in response.content.lower()


# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
def test_login_link_is_shown_to_guests(client: Client) -> None:
response = client.get("/")
assert b"log in" in response.content.lower()
1 change: 0 additions & 1 deletion src/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

class LoginForm(forms.Form):
email = forms.EmailField(
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
widget=forms.EmailInput(attrs={"placeholder": _("Email address")})
)
5 changes: 1 addition & 4 deletions src/users/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ class Migration(migrations.Migration):
),
(
"email",
# pyre-ignore[28]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
django.contrib.postgres.fields.citext.CIEmailField(
max_length=254, unique=True, verbose_name="email address"
),
),
(
"date_joined",
models.DateTimeField(
# pyre-ignore[6]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
default=django.utils.timezone.now,
verbose_name="date joined",
default=django.utils.timezone.now, verbose_name="date joined",
),
),
],
Expand Down
9 changes: 0 additions & 9 deletions src/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,23 @@
from django.utils.translation import ugettext_lazy as _


# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/272.
class UserManager(BaseUserManager):
def create_user(self, email: str, password: str) -> User:
# pyre-ignore[28]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
user = User(email=email)
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
user.save()
return user

def create_superuser(self, email: str, password: str) -> User:
# pyre-ignore[28]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
user = User(email=email, is_staff=True)
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
user.save()
return user


# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
class User(AbstractBaseUser):
# pyre-ignore[28]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
email = CIEmailField(_("email address"), unique=True)
# Blank passwords are allowed since we only allow applicants to use
# magic links to log in.
password = models.CharField(_("password"), max_length=128, blank=True)
# pyre-ignore[6]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
date_joined = models.DateTimeField(_("date joined"), default=timezone.now)

is_staff = models.BooleanField(_("user can access the admin"), default=False)
Expand All @@ -44,7 +36,6 @@ class User(AbstractBaseUser):
is_active = True

def __str__(self) -> str:
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
username, domain = self.email.split("@", 1)

# Hide the characters in the username other than the first one.
Expand Down
1 change: 0 additions & 1 deletion src/users/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

pytestmark = pytest.mark.django_db

# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
User = get_user_model()


Expand Down
3 changes: 0 additions & 3 deletions src/users/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@

TEST_EMAIL = "user@example.org"

# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
User = get_user_model()


@pytest.mark.django_db
# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
def test_login_creates_new_user(client: Client) -> None:
assert not User.objects.filter(email=TEST_EMAIL)
client.post("/login", {"email": TEST_EMAIL})
assert User.objects.get(email=TEST_EMAIL)


# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
def test_login_requires_email(client: Client) -> None:
response = client.post("/login")
assert response.status_code not in (301, 302)
Expand Down
1 change: 0 additions & 1 deletion src/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
app_name = "users"

urlpatterns = [
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
path("profile", profile, name="profile"),
]
Loading