From 12f60bcfdf1265ba7ada13fb4cbae9f8772e468a Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Tue, 29 Sep 2020 20:40:46 +0200 Subject: [PATCH] Added can_modify_place_asset template tag. --- .../lostplaces/templatetags/lostplaces.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/django_lostplaces/lostplaces/templatetags/lostplaces.py b/django_lostplaces/lostplaces/templatetags/lostplaces.py index d5262f5..a963db7 100644 --- a/django_lostplaces/lostplaces/templatetags/lostplaces.py +++ b/django_lostplaces/lostplaces/templatetags/lostplaces.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- from django import template +from django.http import request register = template.Library() @@ -22,4 +23,13 @@ def proper_paginate(paginator, current_page, neighbors=2): end_index = paginator.num_pages page_list = [f for f in range(start_index, end_index+1)] return page_list[:(2*neighbors + 1)] - return paginator.page_range \ No newline at end of file + return paginator.page_range + +@register.simple_tag +def can_modify_place_asset(place_asset): + if request.user.is_superuser: + return True + if request.user == ( place_asset.place.submitted_by or place_asset.submitted_by): + return True + else: + return False