From d456f97a4e00605b13150b8e02467013fd84f33c Mon Sep 17 00:00:00 2001 From: luxagraf Date: Fri, 7 Aug 2020 21:50:48 -0400 Subject: added a class name to pad fieldnotes amidst photos --- app/lib/templatetags/templatetags/get_next.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/lib/templatetags/templatetags/get_next.py (limited to 'app/lib') diff --git a/app/lib/templatetags/templatetags/get_next.py b/app/lib/templatetags/templatetags/get_next.py new file mode 100644 index 0000000..97159f5 --- /dev/null +++ b/app/lib/templatetags/templatetags/get_next.py @@ -0,0 +1,25 @@ +from django import template + +register = template.Library() + +@register.filter +def next(some_list, current_index): + """ + Returns the next element of the list using the current index if it exists. + Otherwise returns an empty string. + """ + try: + return some_list[int(current_index) + 1] # access the next element + except: + return '' # return empty string in case of exception + +@register.filter +def previous(some_list, current_index): + """ + Returns the previous element of the list using the current index if it exists. + Otherwise returns an empty string. + """ + try: + return some_list[int(current_index) - 1] # access the previous element + except: + return '' # return empty string in case of exception -- cgit v1.2.3-70-g09d2