Skip to content

Commit

Permalink
form cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger committed Jan 19, 2023
1 parent f010931 commit b9c1739
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion conreq/_core/initialization/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def initialize(request):
return render(request, "conreq/initialization.html")


def _display_initialization(form, request, initialization):
def _display_initialization(
form: InitializationForm, request, initialization: Initialization
):
form.full_clean()
form.save()
username = form.cleaned_data.get("username")
password = form.cleaned_data.get("password1")
Expand All @@ -49,8 +52,10 @@ def _display_initialization(form, request, initialization):
setattr(user, "is_staff", True)
setattr(user, "is_admin", True)
setattr(user, "is_superuser", True)
user.full_clean()
user.save()
login(request, user)
initialization.initialized = True
initialization.full_clean()
initialization.save()
return redirect("landing")
1 change: 1 addition & 0 deletions conreq/_core/sign_up/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def lock_invite_code(code_id: int):
def _lock_invite_code(_event):
code = InviteCode.objects.get(id=code_id)
code.locked = True
code.full_clean()
code.save()
set_locked(True)

Expand Down
2 changes: 2 additions & 0 deletions conreq/_core/sign_up/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ def sign_up(request, invite_code=None):
)

# Create and login the user
form.full_clean()
form.save()
user = authenticate(
username=form.cleaned_data.get("username"),
password=form.cleaned_data.get("password1"),
)
code.used_by = user # type: ignore
code.used_at = timezone.now()
code.full_clean()
code.save()
login(request, user)
return redirect(LOGIN_REDIRECT_URL)
Expand Down
2 changes: 1 addition & 1 deletion conreq/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ def add_unique(model, **kwargs) -> bool:
"""Save to the database only if the model is fully unique.
Returns `True` if the operation was successful."""
new_request = model(**kwargs)
new_request.clean_fields()
new_request.full_clean()
if model.objects.filter(**kwargs):
return False
new_request.save()
Expand Down
1 change: 1 addition & 0 deletions conreq/utils/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def post(self, request, *args, **kwargs):
form = self.get_form() # type: ignore
if not form.is_valid():
return self.form_invalid(form) # type: ignore
form.full_clean()
form.save()
return self.form_valid(form) # type: ignore

Expand Down

0 comments on commit b9c1739

Please sign in to comment.