From e09743b4741d7aa183fc0035fdedbbd9258b6e56 Mon Sep 17 00:00:00 2001 From: SDE Date: Fri, 10 Jan 2025 21:48:20 +0300 Subject: [PATCH] 2.1.9 get_splited_cargo_type --- RoutesApp/forms.py | 5 +++++ RoutesApp/templatetags/__init__.py | 1 + RoutesApp/templatetags/routes_tags.py | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 RoutesApp/templatetags/__init__.py create mode 100644 RoutesApp/templatetags/routes_tags.py diff --git a/RoutesApp/forms.py b/RoutesApp/forms.py index 4ace543..1c79498 100644 --- a/RoutesApp/forms.py +++ b/RoutesApp/forms.py @@ -63,6 +63,11 @@ class RouteForm(forms.ModelForm): 'from_place', 'to_place', 'receive_msg_by_sms' ] + def __init__(self, *args, **kwargs): + super(RouteForm, self).__init__(*args, **kwargs) + self.fields['from_city'].required = True + self.fields['to_city'].required = True + def clean(self): # print('check') cleaned_data = super(RouteForm, self).clean() diff --git a/RoutesApp/templatetags/__init__.py b/RoutesApp/templatetags/__init__.py new file mode 100644 index 0000000..14c7ff2 --- /dev/null +++ b/RoutesApp/templatetags/__init__.py @@ -0,0 +1 @@ +__author__ = 'SDE' diff --git a/RoutesApp/templatetags/routes_tags.py b/RoutesApp/templatetags/routes_tags.py new file mode 100644 index 0000000..a3d94b0 --- /dev/null +++ b/RoutesApp/templatetags/routes_tags.py @@ -0,0 +1,21 @@ +__author__ = 'SDE' + +from django import template +from django.template.defaultfilters import stringfilter +from django.utils.safestring import mark_safe + +register = template.Library() + + +@register.filter +@stringfilter +def get_splited_cargo_type(value): + if not value or not '(' in value: + return value + + splited_list = value.split('(') + + s = splited_list[0] + '(' + splited_list[1] + ')' + + return mark_safe(s) +