From 7c05040d7bf3dedcfc0682cc359cb93fc2047828 Mon Sep 17 00:00:00 2001 From: alpcentaur Date: Wed, 27 Dec 2023 15:48:11 +0000 Subject: [PATCH 1/3] created if cases for changing of year for projects that were already there, but already have a project_of_year number --- input/models.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/input/models.py b/input/models.py index de4b8b5..1bc57ab 100755 --- a/input/models.py +++ b/input/models.py @@ -104,10 +104,21 @@ class Project(Volunteer): '''we generate the autogenerated fields here''' # we don't call save with args/kwargs to avoid UNIQUE CONSTRAINT errors # but maybe there is a better solution? + startyear_tmp = 'NONE' + + if self.pid: + if self.pid[:4] != self.start.year: + startyear_tmp = self.start.year + super().save() - self.pid = str(self.start.year) + '-' + str(self.account.code) + str(self.pk).zfill(3) - # self.pid = str(self.account.code) + str(self.pk).zfill(3) - + + if startyear_tmp == 'NONE': + + self.pid = str(self.start.year) + '-' + str(self.account.code) + str(self.pk).zfill(3) + # self.pid = str(self.account.code) + str(self.pk).zfill(3) + + + # generation of field quartals if self.end.month in [1, 2, 3]: self.end_quartal = 'Q1' @@ -119,13 +130,25 @@ class Project(Volunteer): self.end_quartal = 'Q4' # generation of pid and financeID + # project of year is true if entry gets updated with changes.. but year can change!!!!!!!! + if self.project_of_year: + print('oi oi oi oi oi') + print(self.pid) - if not self.project_of_year: - #print('AAA') + + + + # project of year is false if entry gets saved as new + if not self.project_of_year or startyear_tmp != 'NONE': + print('AAA') + + print('self projekt of year', self.project_of_year, self.start.year) + # we need to determine if this is a new year with its first new project... year = self.start.year #print(year) projects = Project.objects.filter(start__year=year) + print('projects after filter of startyear of project',projects) if not projects: #print('BBB') self.project_of_year = 1 From 1454fce9baa4095460bdedcf4cb65e79be63de9c Mon Sep 17 00:00:00 2001 From: alpcentaur Date: Sat, 30 Dec 2023 17:46:15 +0000 Subject: [PATCH 2/3] corrected small error regarding pid financeid bug fix, started javascript manipulation to get browsers to not translate url to url encoded characters for otrs link bug fix --- input/admin.py | 1 + input/forms.py | 3 +++ input/models.py | 27 +++++++++++++++++++++++++-- input/static/dropdown/js/otrs_link.js | 12 ++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 input/static/dropdown/js/otrs_link.js diff --git a/input/admin.py b/input/admin.py index 209e578..1b178e5 100755 --- a/input/admin.py +++ b/input/admin.py @@ -36,6 +36,7 @@ class ProjectAdmin(admin.ModelAdmin): date_hierarchy = 'end' readonly_fields = ('end_quartal', 'project_of_year', 'pid', 'finance_id') + @admin.register(BusinessCard) class BusinessCardAdmin(admin.ModelAdmin): save_as = True diff --git a/input/forms.py b/input/forms.py index a66b828..d67ba51 100755 --- a/input/forms.py +++ b/input/forms.py @@ -26,6 +26,9 @@ class ProjectForm(FdbForm): widgets = {'start': AdminDateWidget(), 'end': AdminDateWidget(),} + class Media: + js = ('dropdown/js/otrs_link.js',) + class ExternForm(FdbForm): diff --git a/input/models.py b/input/models.py index 1bc57ab..8513fd9 100755 --- a/input/models.py +++ b/input/models.py @@ -1,7 +1,9 @@ from datetime import date - +from django.utils.http import urlencode from django.db import models from django.utils.html import format_html +import urllib +from django.utils.safestring import mark_safe from .settings import ACCOUNTS @@ -100,16 +102,37 @@ 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''' # we don't call save with args/kwargs to avoid UNIQUE CONSTRAINT errors # but maybe there is a better solution? + preotrs = self.otrs + + #postotrs = '' + #for n in range(len(preotrs)): + # if preotrs[n] == ';': + # postotrs += '\;' + # else: + # postotrs += preotrs[n] + #print(self.otrs) + #print(preotrs) + #print(postotrs) + postotrs = urllib.parse.quote(preotrs, safe=':;/=?&') + self.otrs = mark_safe(urllib.parse.unquote(postotrs)) startyear_tmp = 'NONE' if self.pid: - if self.pid[:4] != self.start.year: + print('self pid last four', self.pid[:4], self.start.year) + if int(self.pid[:4]) != int(self.start.year): startyear_tmp = self.start.year + print('the startyear_tmp is as follows ', startyear_tmp) + super().save() if startyear_tmp == 'NONE': diff --git a/input/static/dropdown/js/otrs_link.js b/input/static/dropdown/js/otrs_link.js new file mode 100644 index 0000000..49468eb --- /dev/null +++ b/input/static/dropdown/js/otrs_link.js @@ -0,0 +1,12 @@ +window.addEventListener("load", function() { +(function($) { + $(function() { + + + + html.body.style.backgroundColor = color[red]; + + + }); +})(django.jQuery); +}); From a51552d4dd2962fa0fb28a055b51812d3dfd6640 Mon Sep 17 00:00:00 2001 From: alpcentaur Date: Sat, 30 Dec 2023 19:01:06 +0000 Subject: [PATCH 3/3] 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);