Skip to content

Commit

Permalink
fix: settings vars
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed Nov 24, 2022
1 parent d004024 commit 61af593
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 49 deletions.
7 changes: 3 additions & 4 deletions uniticket/organizational_area/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 4 additions & 12 deletions uniticket/organizational_area/settings.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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'
)
10 changes: 6 additions & 4 deletions uniticket/uni_ticket/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -35,16 +35,18 @@
ORGANIZATION_USER_LABEL,
PRIORITY_LEVELS,
SHOW_HEADING_TEXT,
STRUCTURES_FOLDER,
TICKET_ATTACHMENT_FOLDER,
TICKET_CATEGORIES_FOLDER,
TICKET_DESCRIPTION_ID,
TICKET_MESSAGES_ATTACHMENT_SUBFOLDER,
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__")

Expand Down
15 changes: 9 additions & 6 deletions uniticket/uni_ticket/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
28 changes: 9 additions & 19 deletions uniticket/uni_ticket/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions uniticket/uni_ticket/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 *

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 61af593

Please sign in to comment.