diff --git a/uniticket/organizational_area/models.py b/uniticket/organizational_area/models.py index f8c58a1a..c1f90af4 100644 --- a/uniticket/organizational_area/models.py +++ b/uniticket/organizational_area/models.py @@ -6,10 +6,9 @@ from django.db import models from django.utils.translation import gettext as _ -from . settings import DEFAULT_ORGANIZATIONAL_STRUCTURE_OFFICE, LOGOS_FOLDER, STRUCTURES_FOLDER - -STRUCTURES_FOLDER = getattr(settings, 'STRUCTURES_FOLDER', STRUCTURES_FOLDER) -LOGOS_FOLDER = getattr(settings, 'LOGOS_FOLDER', LOGOS_FOLDER) +from . settings import (DEFAULT_ORGANIZATIONAL_STRUCTURE_OFFICE, + LOGOS_FOLDER, + STRUCTURES_FOLDER) def _logo_upload(instance, filename): diff --git a/uniticket/organizational_area/settings.py b/uniticket/organizational_area/settings.py index 8f255f7b..d7b5d0d4 100644 --- a/uniticket/organizational_area/settings.py +++ b/uniticket/organizational_area/settings.py @@ -1,5 +1,9 @@ from django.conf import settings + +LOGOS_FOLDER = getattr(settings, "LOGOS_FOLDER", "logos") +STRUCTURES_FOLDER = getattr(settings, "STRUCTURES_FOLDER", "structures") + # default office parameters DEFAULT_ORGANIZATIONAL_STRUCTURE_OFFICE = getattr( settings, @@ -11,15 +15,3 @@ "DEFAULT_ORGANIZATIONAL_STRUCTURE_OFFICE_DESC", "Help-Desk Office" ) - -# system upload folders -LOGOS_FOLDER = getattr( - settings, - "LOGOS_FOLDER", - 'logos' -) -STRUCTURES_FOLDER = getattr( - settings, - "STRUCTURES_FOLDER", - 'structures' -) diff --git a/uniticket/uni_ticket/models.py b/uniticket/uni_ticket/models.py index d0ff739c..0566e0d9 100644 --- a/uniticket/uni_ticket/models.py +++ b/uniticket/uni_ticket/models.py @@ -17,15 +17,15 @@ from django_form_builder.forms import BaseDynamicForm from django_form_builder.models import DynamicFieldMap, SavedFormContent from django_form_builder.utils import get_as_dict, set_as_dict + from organizational_area.models import ( OrganizationalStructure, OrganizationalStructureOffice, OrganizationalStructureOfficeEmployee, ) +from organizational_area.settings import STRUCTURES_FOLDER from .dynamic_form import DynamicForm -from .utils import * -from .validators import * from .settings import ( CATEGORY_CONDITIONS_ATTACHMENT_SUBFOLDER, CLOSING_LEVELS, @@ -35,7 +35,6 @@ ORGANIZATION_USER_LABEL, PRIORITY_LEVELS, SHOW_HEADING_TEXT, - STRUCTURES_FOLDER, TICKET_ATTACHMENT_FOLDER, TICKET_CATEGORIES_FOLDER, TICKET_DESCRIPTION_ID, @@ -43,8 +42,11 @@ TICKET_MIN_DIGITS_TO_COMPRESS, TICKET_SUBJECT_ID, TICKET_TASK_ATTACHMENT_SUBFOLDER, - TICKET_UPDATED, + TICKET_UPDATED ) +from .utils import * +from .validators import * + logger = logging.getLogger("__name__") diff --git a/uniticket/uni_ticket/settings.py b/uniticket/uni_ticket/settings.py index 2ea33067..5c1d05e0 100644 --- a/uniticket/uni_ticket/settings.py +++ b/uniticket/uni_ticket/settings.py @@ -2,8 +2,6 @@ from django.utils.translation import gettext_lazy as _ # system attachments folders -LOGOS_FOLDER = getattr(settings, "LOGOS_FOLDER", "logos") -STRUCTURES_FOLDER = getattr(settings, "STRUCTURES_FOLDER", "structures") TICKET_ATTACHMENT_FOLDER = getattr( settings, "TICKET_ATTACHMENT_FOLDER", "ticket") TICKET_CATEGORIES_FOLDER = getattr( @@ -99,10 +97,14 @@ ) # captcha -TICKET_CAPTCHA_ID = getattr(settings, "TICKET_CAPTCHA_ID", "ticket_captcha") -TICKET_CAPTCHA_HIDDEN_ID = getattr(settings, "", "ticket_captcha_hidden") +TICKET_CAPTCHA_ID = getattr( + settings, "TICKET_CAPTCHA_ID", "ticket_captcha" +) +TICKET_CAPTCHA_HIDDEN_ID = getattr( + settings, "TICKET_CAPTCHA_HIDDEN_ID", "ticket_captcha_hidden" +) TICKET_CAPTCHA_LABEL = getattr( - settings, "TICKET_CAPTCHA_HIDDEN_ID", _("Codice di verifica") + settings, "TICKET_CAPTCHA_LABEL", _("Codice di verifica") ) # new ticket submit buttons (create / generate import URL) @@ -210,7 +212,8 @@ # additional user fields to export ADDITIONAL_USER_FIELDS = getattr( settings, "ADDITIONAL_USER_FIELDS", [ - EMPLOYEE_ATTRIBUTE_NAME, USER_ATTRIBUTE_NAME] + EMPLOYEE_ATTRIBUTE_NAME, + USER_ATTRIBUTE_NAME] ) # Label diff --git a/uniticket/uni_ticket/utils.py b/uniticket/uni_ticket/utils.py index 93b2a96d..f36a452b 100644 --- a/uniticket/uni_ticket/utils.py +++ b/uniticket/uni_ticket/utils.py @@ -458,13 +458,11 @@ def send_custom_mail(subject, recipients, body, params={}, force=False): def user_is_employee(user): if not user: return False - if getattr(settings, "EMPLOYEE_ATTRIBUTE_NAME", False): - attr = getattr(user, settings.EMPLOYEE_ATTRIBUTE_NAME) - if callable(attr): - return attr() - else: - return attr - return False + attr = getattr(user, EMPLOYEE_ATTRIBUTE_NAME, False) + if callable(attr): + return attr() + else: + return attr # If operator in the same Structure # is_operator = user_is_operator(request.user, struttura) # If manage something. For alla structures @@ -528,14 +526,8 @@ def export_input_module_csv( module.ticket_category head = ["created", "user", "taxpayer_id"] - if hasattr(settings, "EMPLOYEE_ATTRIBUTE_NAME"): - head.append( - getattr(settings, "EMPLOYEE_ATTRIBUTE_LABEL", - EMPLOYEE_ATTRIBUTE_LABEL) - ) - if hasattr(settings, "USER_ATTRIBUTE_NAME"): - head.append( - getattr(settings, "USER_ATTRIBUTE_LABEL", USER_ATTRIBUTE_NAME)) + head.append(EMPLOYEE_ATTRIBUTE_NAME) + head.append(USER_ATTRIBUTE_NAME) head.extend(["status", "subject", "description"]) custom_head = [] fields = apps.get_model("uni_ticket", "TicketCategoryInputList").objects.filter( @@ -585,10 +577,8 @@ def export_input_module_csv( richiesta.created_by, richiesta.created_by.taxpayer_id, ] - if hasattr(settings, "EMPLOYEE_ATTRIBUTE_NAME"): - row.append(getattr(richiesta.created_by, EMPLOYEE_ATTRIBUTE_NAME)) - if hasattr(settings, "USER_ATTRIBUTE_NAME"): - row.append(getattr(richiesta.created_by, USER_ATTRIBUTE_NAME)) + row.append(getattr(richiesta.created_by, EMPLOYEE_ATTRIBUTE_NAME)) + row.append(getattr(richiesta.created_by, USER_ATTRIBUTE_NAME)) row.extend([status, richiesta.subject, richiesta.description]) for column in custom_head: diff --git a/uniticket/uni_ticket/views/user.py b/uniticket/uni_ticket/views/user.py index 4683b90a..5e18dd60 100644 --- a/uniticket/uni_ticket/views/user.py +++ b/uniticket/uni_ticket/views/user.py @@ -43,6 +43,7 @@ from uni_ticket.pdf_utils import response_as_pdf from uni_ticket.protocol_utils import ticket_protocol from uni_ticket.settings import ( + NEW_MESSAGE_RECEIVED_EMPLOYEE_BODY, NEW_TICKET_CREATED, NEW_TICKET_CREATED_EMPLOYEE_BODY, OPERATOR_PREFIX, @@ -55,8 +56,9 @@ TICKET_DELETED, TICKET_GENERATE_URL_BUTTON_NAME, TICKET_INPUT_MODULE_NAME, + TICKET_SHARING_USER_ERROR_MESSAGE, UNAVAILABLE_TICKET_CATEGORY, - USER_TICKET_MESSAGE, + USER_TICKET_MESSAGE ) from uni_ticket.utils import * @@ -1108,7 +1110,7 @@ def ticket_delete(request, ticket_id): messages.add_message( request, messages.ERROR, - settings.TICKET_SHARING_USER_ERROR_MESSAGE.format( + TICKET_SHARING_USER_ERROR_MESSAGE.format( ticket.created_by), ) return redirect("uni_ticket:ticket_detail", ticket_id=ticket.code) @@ -1341,7 +1343,7 @@ def ticket_message(request, ticket_id): request=request, ticket=ticket, category=category, - message_template=settings.NEW_MESSAGE_RECEIVED_EMPLOYEE_BODY, + message_template=NEW_MESSAGE_RECEIVED_EMPLOYEE_BODY, mail_params=mail_params, ) # END Send email to operators @@ -1426,7 +1428,7 @@ def dispatch(self, request, ticket_id:str, *args, **kwargs) -> Union[HttpRespons messages.add_message( request, messages.ERROR, - settings.TICKET_SHARING_USER_ERROR_MESSAGE.format( + TICKET_SHARING_USER_ERROR_MESSAGE.format( self.ticket.created_by), ) return redirect(