summaryrefslogtreecommitdiff
path: root/app/lib
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/templatetags/templatetags/get_next.py25
1 files changed, 25 insertions, 0 deletions
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