Skip to content

Commit

Permalink
Merge pull request #471 from uw-it-aca/task/student-search
Browse files Browse the repository at this point in the history
Task/student search
  • Loading branch information
jlaney authored Feb 3, 2025
2 parents 45882b3 + ad72497 commit ae80d1e
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 27 deletions.
2 changes: 2 additions & 0 deletions compass/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
StudentVisitsView,
StudentEligibilityView,
StudentView,
StudentSearchView,
StudentCourseAnalyticsView,
StudentSigninAnalyticsView
)
Expand Down Expand Up @@ -70,6 +71,7 @@
TemplateView.as_view(template_name="unauthorized-user.html"),
name="unauthorized_user",
),
re_path(r"^api/internal/search$", StudentSearchView.as_view()),
re_path(
r"^api/internal/student/(?P<identifier>[-@:\w]+)/$",
StudentView.as_view(),
Expand Down
42 changes: 37 additions & 5 deletions compass/views/api/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def get(self, request, identifier):

person_dict = person.to_dict()
# handle case where student data not in PDS
if "student" not in person_dict:
logger.error("Student data not found for identifier: %s",
identifier)
return self.response_notfound()
if 'student' not in person_dict:
logger.error(
f'Student data not found for identifier: "{identifier}"')
return self.response_notfound('Student not found')
photo_key = PhotoDAO().generate_photo_key()
person_dict['photo_url'] = reverse('photo', kwargs={
'uwregid': person.uwregid,
Expand All @@ -72,7 +72,7 @@ def get(self, request, identifier):
person_dict['analytics_alert'] = analytics_alert
return self.response_ok(person_dict)
except PersonNotFoundException:
return self.response_notfound()
return self.response_notfound('Student not found')

def post(self, request, identifier=None):
try:
Expand Down Expand Up @@ -110,6 +110,38 @@ def post(self, request, identifier=None):
return self.response_unauthorized(err)


class StudentSearchView(BaseAPIView):
'''
API endpoint returning student search results
/api/internal/search?query=[student_number|uwnetid]
'''
def get(self, request):
identifier = request.GET.get('query', '').strip().lower()
if identifier is None or not len(identifier):
return self.response_badrequest('Missing student identifier')

try:
includes = {'include_student': True}
if valid_uwnetid(identifier):
person = get_person_by_uwnetid(identifier, **includes)
elif valid_student_number(identifier):
person = get_person_by_student_number(identifier, **includes)
else:
return self.response_badrequest('Invalid student identifier')
except PersonNotFoundException:
return self.response_notfound('Student not found')

person_dict = person.to_dict()
# handle case where student data not in PDS
if 'student' not in person_dict:
logger.error(
f'Student data not found for identifier: "{identifier}"')
return self.response_notfound('Not a student')

return self.response_ok(person_dict)


class StudentSchedulesView(BaseAPIView):
'''
API endpoint returning a student's class schedule details
Expand Down
49 changes: 32 additions & 17 deletions compass_vue/components/search-student.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<div class="input-group">
<input
type="text"
:maxlength="maxLength"
class="form-control form-control-sm"
placeholder="Student number or netid..."
aria-label="Recipient's username"
placeholder="Student number or UW netid..."
aria-label="Student number or UW netid"
v-model="searchValue"
@keyup.enter.exact="searchByStudent"
/>
<button
:disabled="searchValue.length == 0"
Expand All @@ -16,13 +18,13 @@
Search
</button>
</div>
<div v-if="!studentExists || error" class="text-danger mt-2">
No student found
<div v-if="searchError || error" class="text-danger mt-2">
{{ searchError || "Student not found" }}
</div>
</template>

<script>
import { getStudentDetail } from "@/utils/data";
import { getStudentBySearch } from "@/utils/data";
export default {
props: {
Expand All @@ -34,27 +36,40 @@ export default {
},
setup() {
return {
getStudentDetail,
getStudentBySearch,
};
},
data() {
return {
studentExists: true,
searchValue: "",
maxLength: 32,
searchError: null,
};
},
methods: {
validQuery: function (val) {
return (
val.length < 2 ||
val.length > this.maxLength ||
!(/^[a-z0-9\-\_\.]+$/).test(val)) ? false : true;
},
searchByStudent: function () {
this.getStudentDetail(this.searchValue)
.then(() => {
console.log(this.searchValue);
this.studentExists = true;
//this.$router.push("/student/" + this.searchValue);
window.location.href = "/student/" + this.searchValue;
})
.catch(() => {
this.studentExists = false;
});
this.searchError = null;
this.searchValue = this.searchValue.trim().toLowerCase();
if (this.validQuery(this.searchValue)) {
this.getStudentBySearch(this.searchValue)
.then((response) => {
return response.data;
})
.then((data) => {
window.location.href = "/student/" + this.searchValue;
})
.catch((error) => {
this.searchError = error.response.data;
});
} else {
this.searchError = "Invalid student identifier";
}
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Warning: Consider carefully before deleting an affiliation as
there is no way to undo this action.
</div>
<lable class="form-label small fw-bold">Admin Note</lable>
<label class="form-label small fw-bold">Admin Note</label>
<textarea
:class="
formErrors.notes ? 'is-invalid form-control' : 'form-control'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</div>
<div class="modal-body">
<div class="mb-3">
<lable class="form-label small fw-bold"
>Specify date below.</lable
<label class="form-label small fw-bold"
>Specify date below.</label
>
<input
type="date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</div>
<div class="modal-body">
<div class="mb-3">
<lable class="form-label small fw-bold"
>Specify date below.</lable
<label class="form-label small fw-bold"
>Specify date below.</label
>
<input
type="date"
Expand Down
8 changes: 8 additions & 0 deletions compass_vue/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ function _handleError(error) {
}
}

async function getStudentBySearch(query) {
return axios
.get("/api/internal/search?query=" + query)
.catch(_handleError);
}

async function getStudentDetail(uwnetid) {
return axios
.get("/api/internal/student/" + uwnetid + "/")
Expand Down Expand Up @@ -97,6 +103,7 @@ async function getStudentSchedules(uwregid) {
async function getStudentTranscripts(uwregid) {
return axios.get("/api/internal/student/" + uwregid + "/transcripts/");
}

async function saveStudentContact(systemkey, contact) {
let postUrl = "/api/internal/contact/";
if (contact.id !== undefined) {
Expand Down Expand Up @@ -242,6 +249,7 @@ async function getStudentSigninAnalytics(uwnetid){
}

export {
getStudentBySearch,
getStudentDetail,
saveStudent,
getEligibilities,
Expand Down

0 comments on commit ae80d1e

Please sign in to comment.