From a51552d4dd2962fa0fb28a055b51812d3dfd6640 Mon Sep 17 00:00:00 2001 From: alpcentaur Date: Sat, 30 Dec 2023 19:01:06 +0000 Subject: [PATCH] prettifying the otrs links as wished through a javascript function onload, in /static/dropdown/js/otrs_link.js --- input/admin.py | 4 ++++ input/models.py | 4 ---- input/static/dropdown/js/otrs_link.js | 13 ++++++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/input/admin.py b/input/admin.py index 1b178e5..1f1ffa7 100755 --- a/input/admin.py +++ b/input/admin.py @@ -36,6 +36,10 @@ class ProjectAdmin(admin.ModelAdmin): date_hierarchy = 'end' readonly_fields = ('end_quartal', 'project_of_year', 'pid', 'finance_id') + class Media: + js = ('dropdown/js/otrs_link.js',) + + @admin.register(BusinessCard) class BusinessCardAdmin(admin.ModelAdmin): diff --git a/input/models.py b/input/models.py index 8513fd9..9bdd3d7 100755 --- a/input/models.py +++ b/input/models.py @@ -102,10 +102,6 @@ class Project(Volunteer): project_of_year = models.IntegerField(default=0) end_quartal = models.CharField(max_length=15, null=True, blank=True, verbose_name="Quartal Projekt Ende") - def some_otrs(self): - """ This returns a HTML anchor (hyperlink) to somewhere """ - return u'Link' % self.otrs - some_otrs.allow_tags = True def save(self,*args,**kwargs): '''we generate the autogenerated fields here''' diff --git a/input/static/dropdown/js/otrs_link.js b/input/static/dropdown/js/otrs_link.js index 49468eb..778bb43 100644 --- a/input/static/dropdown/js/otrs_link.js +++ b/input/static/dropdown/js/otrs_link.js @@ -2,10 +2,17 @@ window.addEventListener("load", function() { (function($) { $(function() { - - - html.body.style.backgroundColor = color[red]; + let otrs_link = document.querySelector(".field-otrs > div > p.url > a").href; + console.log(otrs_link); + alert(otrs_link); + let otrs_link_pret = otrs_link.replace(/%3B/g, ";"); + let otrs_link_pretty = otrs_link_pret.replace(/%3D/g, "="); + + console.log(otrs_link_pretty); + + document.querySelector(".field-otrs > div > p.url > a").href = otrs_link_pretty; + }); })(django.jQuery);