aboutsummaryrefslogtreecommitdiffstats
path: root/src/dashboard
diff options
context:
space:
mode:
Diffstat (limited to 'src/dashboard')
-rw-r--r--src/dashboard/admin_utils.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/dashboard/admin_utils.py b/src/dashboard/admin_utils.py
index 222ccd3..76db762 100644
--- a/src/dashboard/admin_utils.py
+++ b/src/dashboard/admin_utils.py
@@ -17,6 +17,9 @@ from resource_inventory.models import (
)
import json
+import sys
+import inspect
+import pydoc
from django.contrib.auth.models import User
@@ -388,3 +391,38 @@ def extend_booking(booking_id, days=0, hours=0, minutes=0, weeks=0):
booking = Booking.objects.get(id=booking_id)
booking.end = booking.end + timedelta(days=days, hours=hours, minutes=minutes, weeks=weeks)
booking.save()
+
+
+def docs(function=None, fulltext=False):
+ fn = None
+
+ if isinstance(function, str):
+ try:
+ fn = globals()[function]
+ except KeyError:
+ print("Couldn't find a function by the given name")
+ return
+ elif callable(function):
+ fn = function
+ else:
+ print("docs(function: callable | str, fulltext: bool) was called with a 'function' that was neither callable nor a string name of a function")
+ print("usage: docs('some_function_in_admin_utils', fulltext=True)")
+ print("The 'fulltext' argument is used to choose if you want the complete source of the function printed. If this argument is false then you will only see the pydoc rendered documentation for the function")
+ return
+
+ if not fn:
+ print("couldn't find a function by that name")
+
+ if not fulltext:
+ print("Pydoc documents the function as such:")
+ print(pydoc.render_doc(fn))
+ else:
+ print("The full source of the function is this:")
+ print(inspect.getsource(fn))
+
+
+def admin_functions():
+ return [name for name, func in inspect.getmembers(sys.modules[__name__]) if (inspect.isfunction(func) and func.__module__ == __name__)]
+
+
+print("Hint: call `docs(<function name>)` or `admin_functions()` for help on using the admin utils")