-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0666bc8
commit 81250a6
Showing
10 changed files
with
446 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from django.urls import reverse | ||
from django_school_management.accounts.models import User | ||
from typing import List, Dict, Any, Set | ||
|
||
|
||
class MenuService: | ||
def __init__(self, menu_config: Dict[str, Any]): | ||
""" | ||
Initialize the MenuService with the given configuration. | ||
""" | ||
self.menu_config = menu_config | ||
|
||
def get_user_groups(self, user: User) -> Set[str]: | ||
""" | ||
Retrieve the groups of the user as a set. | ||
""" | ||
return set(user.groups.values_list("name", flat=True)) | ||
|
||
def add_urls_to_menu( | ||
self, menu_items: List[Dict[str, str]], urls: List[Dict[str, str]] | ||
) -> None: | ||
""" | ||
Add reversed URLs and titles to the menu_items list. | ||
""" | ||
for url in urls: | ||
menu_items.append( | ||
{"url": reverse(url["name"]), "title": url["title"]} | ||
) | ||
|
||
def get_menu_items(self, section: str, user: User) -> List[Dict[str, str]]: | ||
""" | ||
Retrieve menu items for a given section based on the user's groups. | ||
""" | ||
user_groups = self.get_user_groups(user) | ||
menu_items = [] | ||
|
||
if section not in self.menu_config: | ||
return menu_items | ||
|
||
for entry in self.menu_config[section]: | ||
if user_groups & entry["groups"]: | ||
self.add_urls_to_menu(menu_items, entry["urls"]) | ||
|
||
return menu_items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from django_school_management.students.constants import StudentsURLConstants | ||
from django_school_management.teachers.constants import TeachersURLConstants | ||
|
||
|
||
all_teachers = dict(name=TeachersURLConstants.all_teacher, title="Teachers") | ||
articles_manage = dict(name="articles:dashboard_manage", title="Articles") | ||
teacher_designations = dict(name=TeachersURLConstants.designations, title="Designations") | ||
write_article = dict( | ||
name="articles:publish_article_from_dashboard", | ||
title="Write Article", | ||
) | ||
|
||
add_student = { | ||
"name": StudentsURLConstants.add_student, | ||
"title": "New Application", | ||
} | ||
all_students = {"name": StudentsURLConstants.all_student, "title": "Students List"} | ||
add_result = {"name": "result:result_entry", "title": "Add Result"} | ||
results_index = {"name": "result:result_home", "title": "Results"} | ||
alumnus = {"name": StudentsURLConstants.alumnus, "title": "Alumnus"} | ||
|
||
MENU_CONFIG = { | ||
"student": [ | ||
{ | ||
"groups": {"teacher", "admin"}, | ||
"urls": [ | ||
all_students, | ||
add_result, | ||
], | ||
}, | ||
{ | ||
"groups": {"student", "teacher", "admin"}, | ||
"urls": [ | ||
results_index, | ||
alumnus, | ||
], | ||
}, | ||
{ | ||
"groups": {"academic_officer"}, | ||
"urls": [ | ||
add_student, | ||
all_students, | ||
alumnus, | ||
], | ||
}, | ||
], | ||
"teacher": [ | ||
{ | ||
"groups": {"teacher", "admin"}, | ||
"urls": [ | ||
write_article, | ||
all_teachers, | ||
], | ||
}, | ||
{ | ||
"groups": {"student"}, | ||
"urls": [all_teachers], | ||
}, | ||
{ | ||
"groups": {"editor"}, | ||
"urls": [ | ||
all_teachers, | ||
articles_manage, | ||
write_article, | ||
], | ||
}, | ||
{ | ||
"groups": {"academic_officer"}, | ||
"urls": [all_teachers], | ||
}, | ||
{ | ||
"groups": {"admin"}, | ||
"urls": [teacher_designations], | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from enum import Enum | ||
|
||
|
||
class StudentsURLEnums(Enum): | ||
students_dashboard_index = "" | ||
test_pdf = "pdf/" | ||
add_student = "add/" | ||
all_student = "all/" | ||
alumnus = "alumnus/" | ||
all_applicants = "applicants/" | ||
unpaid_registrants = "applicants/unpaid/" | ||
mark_as_paid_or_unpaid = "applicants/mark-paid/" | ||
add_counseling_data = "add-counsel-data/<int:student_id>/" | ||
admitted_student_list = "admitted-students/" | ||
admission_confirmation = "admission-confirm/" | ||
get_json_batch_data = "api/batches/<int:department_code>/" | ||
yearly_graph_api = "api/yearly-graph/" | ||
admit_student = "online-applicants/<int:pk>/admit/" | ||
paid_registrants = "paid-registrants/" | ||
rejected_registrants = "rejected-registrants/" | ||
update_online_registrant = "update-registrant/<int:pk>/" | ||
update_student = "update/<int:pk>/" | ||
student_details = "<int:pk>/detail/" | ||
delete_student = "<int:pk>/delete/" | ||
students_by_dept = "<int:pk>/students/" | ||
counsel_monthly_report = "counsel-report/" | ||
counsel_monthly_report_typed = "counsel-report/<str:response_type>/" | ||
counsel_report_monthly_with_date = "counsel-report/<str:response_type>/<date:date_param>/" | ||
|
||
|
||
class StudentsURLConstants: | ||
students_dashboard_index = f"students:{StudentsURLEnums.students_dashboard_index.name}" | ||
test_pdf = f"students:{StudentsURLEnums.test_pdf.name}" | ||
add_student = f"students:{StudentsURLEnums.add_student.name}" | ||
all_student = f"students:{StudentsURLEnums.all_student.name}" | ||
alumnus = f"students:{StudentsURLEnums.alumnus.name}" | ||
all_applicants = f"students:{StudentsURLEnums.all_applicants.name}" | ||
unpaid_registrants = f"students:{StudentsURLEnums.unpaid_registrants.name}" | ||
mark_as_paid_or_unpaid = f"students:{StudentsURLEnums.mark_as_paid_or_unpaid.name}" | ||
add_counseling_data = f"students:{StudentsURLEnums.add_counseling_data.name}" | ||
admitted_student_list = f"students:{StudentsURLEnums.admitted_student_list.name}" | ||
admission_confirmation = f"students:{StudentsURLEnums.admission_confirmation.name}" | ||
get_json_batch_data = f"students:{StudentsURLEnums.get_json_batch_data.name}" | ||
yearly_graph_api = f"students:{StudentsURLEnums.yearly_graph_api.name}" | ||
admit_student = f"students:{StudentsURLEnums.admit_student.name}" | ||
paid_registrants = f"students:{StudentsURLEnums.paid_registrants.name}" | ||
rejected_registrants = f"students:{StudentsURLEnums.rejected_registrants.name}" | ||
update_online_registrant = f"students:{StudentsURLEnums.update_online_registrant.name}" | ||
update_student = f"students:{StudentsURLEnums.update_student.name}" | ||
student_details = f"students:{StudentsURLEnums.student_details.name}" | ||
delete_student = f"students:{StudentsURLEnums.delete_student.name}" | ||
students_by_dept = f"students:{StudentsURLEnums.students_by_dept.name}" | ||
counsel_monthly_report = f"students:{StudentsURLEnums.counsel_monthly_report.name}" | ||
counsel_monthly_report_typed = f"students:{StudentsURLEnums.counsel_monthly_report_typed.name}" | ||
counsel_report_monthly_with_date = f"students:{StudentsURLEnums.counsel_report_monthly_with_date.name}" |
Oops, something went wrong.