json_context.py¶
This module provides utility functions to handle JSON operations and context-related operations for the Django appointment system.
Overview:¶
Module Metadata:¶
Author: Adams Pierre David Since: 1.2.0
Functions:¶
JSON Operations:¶
-
convert_appointment_to_json(request, appointments: list) -> list:
- Converts a queryset of Appointment objects to a JSON serializable format.
-
json_response(message, status=200, success=True, custom_data=None, error_code=None, kwargs)**:
- Returns a generic JSON response.
Context Operations:¶
-
get_generic_context(request, admin=True):
- Retrieves the generic context every rendered page receives:
BASE_TEMPLATE,user,is_superuser,localeandlocalized_formats. BASE_TEMPLATEisAPPOINTMENT_ADMIN_BASE_TEMPLATEwhenadminis true andAPPOINTMENT_BASE_TEMPLATEotherwise, which is how the client-facing pages and the administration pages can extend different bases.localeis the active language stripped of its region (fr-FRbecomesfr), because that is the form FullCalendar expects.localized_formatsis a dictionary the date and time pickers need, holding Django'sTIME_INPUT_FORMATS,DATE_INPUT_FORMATSandDATETIME_INPUT_FORMATSfor the active locale, plusjs_timepicker_display_formatandjs_datepicker_display_format— the same formats translated into their Moment.js equivalents, built bydate_time.py.
- Retrieves the generic context every rendered page receives:
-
get_generic_context_with_extra(request, extra, admin=True):
- Retrieves the generic context for the admin pages with additional context information.
Unauthorized Responses:¶
- handle_unauthorized_response(request, message, response_type):
- Handles unauthorized responses based on the specified response type (JSON or HTML).