Skip to content
Open
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
6 changes: 1 addition & 5 deletions intranet/apps/eighth/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@ def edit_profile_view(request, user_id=None):
# address_form = AddressForm(request.POST, instance=user.properties.address)
if user_form.is_valid():
user = user_form.save()
counselor_id = user_form.cleaned_data["counselor_id"]
if counselor_id:
counselor = get_user_model().objects.get(id=counselor_id)
user.counselor = counselor
# user.properties.address = address_form.save()
# user.properties.save()
user.save()
messages.success(request, "Successfully updated user profile.")
else:
messages.error(request, "An error occurred updating user profile.")
else:
user_form = ProfileEditForm(initial={"counselor_id": "" if not user.counselor else user.counselor.id}, instance=user)
user_form = ProfileEditForm(instance=user)
# address_form = AddressForm(instance=user.properties.address)

context = {"profile_user": user, "user_form": user_form, "address_form": address_form}
Expand Down
36 changes: 26 additions & 10 deletions intranet/apps/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
from .models import Address


class UserChoiceField(forms.ModelChoiceField):
"""A ModelChoiceField that returns a user's full name instead of their TJ username (which is the
default string representation)."""

def label_from_instance(self, obj):
return obj.full_name


class ProfileEditForm(forms.ModelForm):
"""A form containing editable fields in the User model."""

Expand All @@ -17,19 +25,27 @@ class ProfileEditForm(forms.ModelForm):
nickname = forms.CharField(label="Nickname", required=False)
graduation_year = forms.IntegerField(label="Graduation Year", required=False)
gender = forms.ChoiceField(choices=GENDERS, label="Sex (Male, Female, or Non-Binary)")
counselor_id = forms.IntegerField(label="Counselor ID", required=False)
counselor = UserChoiceField(
queryset=get_user_model().objects.filter(user_type="counselor").order_by("last_name", "first_name"),
label="Counselor",
required=False,
empty_label="No Counselor",
)

class Meta:
model = get_user_model()
fields = ["admin_comments", "student_id", "first_name", "middle_name", "last_name", "title", "nickname", "graduation_year", "gender"]


class UserChoiceField(forms.ModelChoiceField):
"""A ModelChoiceField that returns a user's full name instead of their TJ username (which is the
default string representation)."""

def label_from_instance(self, obj):
return obj.full_name
fields = [
"admin_comments",
"student_id",
"first_name",
"middle_name",
"last_name",
"title",
"nickname",
"graduation_year",
"gender",
"counselor",
]


class SortedUserChoiceField(forms.ModelChoiceField):
Expand Down
7 changes: 7 additions & 0 deletions intranet/templates/eighth/edit_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@
{% stylesheet 'eighth.admin' %}
{% stylesheet 'profile' %}
{% stylesheet 'eighth.profile' %}
<link rel="stylesheet" href="{% static 'vendor/selectize.js-0.12.4/dist/css/selectize.default.css' %}">
{% endblock %}

{% block js %}
{{ block.super }}
<script src="{% static 'vendor/ckeditor/ckeditor.js' %}"></script>
<script src="{% static 'js/eighth/admin.js' %}"></script>
<script src="{% static 'vendor/selectize.js-0.12.4/dist/js/standalone/selectize.min.js' %}"></script>
<script>
$(function() {
$("#id_counselor").selectize();
});
</script>
<style>
#cke_1_contents {
height: 100px !important;
Expand Down