Skip to content

Commit

Permalink
Find users
Browse files Browse the repository at this point in the history
  • Loading branch information
fsoest committed Jan 22, 2025
1 parent 6a104f6 commit 6094d19
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
10 changes: 10 additions & 0 deletions S1/waitinglists/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ class Meta:
widgets = {
"text": forms.Textarea(attrs={"rows": 3}),
}


class UserDetailForm(forms.Form):
user_id = forms.CharField(
max_length=7,
label="User ID",
widget=forms.TextInput(
attrs={"class": "form-control", "placeholder": "Enter User ID"}
),
)
15 changes: 15 additions & 0 deletions S1/waitinglists/templates/waitinglists/management.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,20 @@ <h4>Quiz Timeouts</h4>
{% endfor %}
</div>
</div>
<div class="row">
<div class="col-6">
<h4>Find User</h4>
<form method="post" action="">
{% csrf_token %}
<div class="mb-3">
{{ form.user_id.label_tag }}
{{ form.user_id }}
{% if form.user_id.errors %}
<div class="text-danger">{{ form.user_id.errors.0 }}</div>
{% endif %}
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
{% endblock %}
17 changes: 16 additions & 1 deletion S1/waitinglists/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.utils import timezone
from dotenv import load_dotenv

from .forms import AttendanceForm, CommentForm
from .forms import AttendanceForm, CommentForm, UserDetailForm
from .helpers import send_moodle_find_user, send_moodle_activity_completion, quiz_ids
from .models import Attendance, Session, WaitingList, Module, Signup, QuizCompletion
from connect.models import UserDetail
Expand Down Expand Up @@ -347,13 +347,28 @@ def management(request):
modules = Module.objects.all().order_by("name")
timeout_details = UserDetail.objects.filter(flagged_for_deletion=True)
timeout_users = [detail.user for detail in timeout_details]

if request.method == "POST":
form = UserDetailForm(request.POST)
if form.is_valid():
user_id = form.cleaned_data["user_id"]
# Check if the user exists
if User.objects.filter(username=user_id).exists():
# Redirect to the user_detail view
return redirect(reverse("user_detail", args=[user_id]))
else:
form.add_error("user_id", "User not found.")
else:
form = UserDetailForm()

context = {
"sessions": sessions,
"prefer_en": request.user.userdetail.en_preferred,
"authenticated": request.user.is_authenticated,
"is_mentor": is_mentor(request.user),
"modules": modules,
"timeout_users": timeout_users,
"form": form,
}
template = loader.get_template("waitinglists/management.html")
return HttpResponse(template.render(context, request))
Expand Down

0 comments on commit 6094d19

Please sign in to comment.