Skip to content

Commit

Permalink
Deprecate create_if_missing (#289)
Browse files Browse the repository at this point in the history
* deprecate create_if_missing

* oops

* Redirect view for deprecated hint list

---------

Co-authored-by: Evan Chen <evan@evanchen.cc>
  • Loading branch information
Incompleteusern and vEnhance committed Sep 3, 2023
1 parent 081366f commit 1545bd0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
9 changes: 2 additions & 7 deletions arch/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@ def test_disk_problem(self):

self.assertGet40X(
"hint-list",
disk_puid,
)

self.assertGet40X(
"hint-list",
"invalid-",
"invalid-disk",
)

resp = self.assertGet20X(
"hint-list-check",
"hint-list",
disk_puid,
)

Expand Down
12 changes: 8 additions & 4 deletions arch/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from django.urls import path
from django.views.generic.base import RedirectView

from . import views


class HintListDeprecatedRedirectView(RedirectView):
pattern_name = "hint-list"


urlpatterns = [
path(r"lookup/", views.lookup, name="arch-lookup"),
path(r"pk/<int:pk>/", views.HintDetailByPK.as_view(), name="hint-detail-pk"),
Expand All @@ -21,13 +27,11 @@
r"<str:puid>/",
views.HintList.as_view(),
name="hint-list",
kwargs={"create_if_missing": False},
),
path(
r"<str:puid>/otis/",
views.HintList.as_view(),
name="hint-list-check",
kwargs={"create_if_missing": True},
HintListDeprecatedRedirectView.as_view(),
name="hint-list-deprecated",
),
path(r"<str:puid>/solution/", views.view_solution, name="view-solution"),
path(r"", views.ProblemCreate.as_view(), name="arch-index"),
Expand Down
4 changes: 1 addition & 3 deletions arch/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ def setup(self, request: HttpRequest, *args: Any, **kwargs: Any):
self.problem = Problem.objects.get(puid=puid)
except Problem.DoesNotExist:
statement_exists_on_disk = get_disk_statement_from_puid(puid) is not None
if kwargs["create_if_missing"] is True and statement_exists_on_disk:
if statement_exists_on_disk:
self.problem = Problem(puid=puid)
self.problem.save()
messages.info(request, f"Created previously nonexistent problem {puid}")
elif statement_exists_on_disk:
raise Http404("Need to log in to create problems")
else:
raise Http404(f"Couldn't find {puid} in database or disk")

Expand Down

0 comments on commit 1545bd0

Please sign in to comment.