mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-08-19 04:06:23 +02:00
more refactoring (rename to get_assignable_users
)
This commit is contained in:
@@ -19,7 +19,7 @@ from helpdesk.lib import (
|
|||||||
convert_value,
|
convert_value,
|
||||||
process_attachments,
|
process_attachments,
|
||||||
safe_template_context,
|
safe_template_context,
|
||||||
get_active_users,
|
get_assignable_users,
|
||||||
)
|
)
|
||||||
from helpdesk.models import (
|
from helpdesk.models import (
|
||||||
Checklist,
|
Checklist,
|
||||||
@@ -478,7 +478,10 @@ class TicketForm(AbstractTicketForm):
|
|||||||
self.fields["queue"].choices = queue_choices
|
self.fields["queue"].choices = queue_choices
|
||||||
self.fields["body"].required = body_reqd
|
self.fields["body"].required = body_reqd
|
||||||
self.fields["assigned_to"].choices = [("", "--------")] + [
|
self.fields["assigned_to"].choices = [("", "--------")] + [
|
||||||
(u.id, u.get_username()) for u in get_active_users()
|
(u.id, u.get_username())
|
||||||
|
for u in get_assignable_users(
|
||||||
|
helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_OWNERS
|
||||||
|
)
|
||||||
]
|
]
|
||||||
self._add_form_custom_fields()
|
self._add_form_custom_fields()
|
||||||
|
|
||||||
@@ -635,13 +638,9 @@ class TicketCCForm(forms.ModelForm):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(TicketCCForm, self).__init__(*args, **kwargs)
|
super(TicketCCForm, self).__init__(*args, **kwargs)
|
||||||
if helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_CC:
|
self.fields["user"].queryset = get_assignable_users(
|
||||||
users = User.objects.filter(is_active=True, is_staff=True).order_by(
|
helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_CC
|
||||||
User.USERNAME_FIELD
|
)
|
||||||
)
|
|
||||||
else:
|
|
||||||
users = User.objects.filter(is_active=True).order_by(User.USERNAME_FIELD)
|
|
||||||
self.fields["user"].queryset = users
|
|
||||||
|
|
||||||
|
|
||||||
class TicketCCUserForm(forms.ModelForm):
|
class TicketCCUserForm(forms.ModelForm):
|
||||||
@@ -649,13 +648,9 @@ class TicketCCUserForm(forms.ModelForm):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(TicketCCUserForm, self).__init__(*args, **kwargs)
|
super(TicketCCUserForm, self).__init__(*args, **kwargs)
|
||||||
if helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_CC:
|
self.fields["user"].queryset = get_assignable_users(
|
||||||
users = User.objects.filter(is_active=True, is_staff=True).order_by(
|
helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_CC
|
||||||
User.USERNAME_FIELD
|
)
|
||||||
)
|
|
||||||
else:
|
|
||||||
users = User.objects.filter(is_active=True).order_by(User.USERNAME_FIELD)
|
|
||||||
self.fields["user"].queryset = users
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = TicketCC
|
model = TicketCC
|
||||||
|
@@ -284,10 +284,10 @@ def daily_time_spent_calculation(earliest, latest, open_hours):
|
|||||||
return time_spent_seconds
|
return time_spent_seconds
|
||||||
|
|
||||||
|
|
||||||
def get_active_users() -> QuerySet:
|
def get_assignable_users(filter_staff: bool) -> QuerySet:
|
||||||
users = User.objects.filter(is_active=True).order_by(User.USERNAME_FIELD)
|
users = User.objects.filter(is_active=True)
|
||||||
|
|
||||||
if helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_OWNERS:
|
if filter_staff:
|
||||||
users = users.filter(is_staff=True)
|
users = users.filter(is_staff=True)
|
||||||
|
|
||||||
return users
|
return users.order_by(User.USERNAME_FIELD)
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
{% trans "Unassigned" %}
|
{% trans "Unassigned" %}
|
||||||
</option>
|
</option>
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% for u in user_choices %}
|
{% for u in assignable_users %}
|
||||||
<option value='{{ u.id }}'{% if u.id|in_list:query_params.filtering.assigned_to__id__in %} selected='selected'{% endif %}>
|
<option value='{{ u.id }}'{% if u.id|in_list:query_params.filtering.assigned_to__id__in %} selected='selected'{% endif %}>
|
||||||
{{ u.get_username }}
|
{{ u.get_username }}
|
||||||
</option>
|
</option>
|
||||||
|
@@ -159,7 +159,14 @@
|
|||||||
<dd><input type='text' name='title' value='{{ ticket.title|escape }}' /></dd>
|
<dd><input type='text' name='title' value='{{ ticket.title|escape }}' /></dd>
|
||||||
|
|
||||||
<dt><label for='id_owner'>{% trans "Owner" %}</label></dt>
|
<dt><label for='id_owner'>{% trans "Owner" %}</label></dt>
|
||||||
<dd><select id='id_owner' name='owner'><option value='0'>{% trans "Unassign" %}</option>{% for u in active_users %}{% if u.id == ticket.assigned_to.id %}<option value='{{ u.id }}' selected>{{ u }}</option>{% else %}<option value='{{ u.id }}'>{{ u }}</option>{% endif %}{% endfor %}</select></dd>
|
<dd>
|
||||||
|
<select id='id_owner' name='owner'>
|
||||||
|
<option value='0'>{% trans "Unassign" %}</option>
|
||||||
|
{% for u in assignable_users %}
|
||||||
|
<option value='{{ u.id }}'{% if u.id == ticket.assigned_to.id %} selected{% endif %}>{{ u }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</dd>
|
||||||
|
|
||||||
<dt><label for='id_priority'>{% trans "Priority" %}</label></dt>
|
<dt><label for='id_priority'>{% trans "Priority" %}</label></dt>
|
||||||
<dd><select id='id_priority' name='priority'>{% for p in priorities %}{% if p.0 == ticket.priority %}<option value='{{ p.0 }}' selected='selected'>{{ p.1 }}</option>{% else %}<option value='{{ p.0 }}'>{{ p.1 }}</option>{% endif %}{% endfor %}</select></dd>
|
<dd><select id='id_priority' name='priority'>{% for p in priorities %}{% if p.0 == ticket.priority %}<option value='{{ p.0 }}' selected='selected'>{{ p.1 }}</option>{% else %}<option value='{{ p.0 }}'>{{ p.1 }}</option>{% endif %}{% endfor %}</select></dd>
|
||||||
|
@@ -111,7 +111,7 @@
|
|||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label='{% trans "Assign To" %}'>
|
<optgroup label='{% trans "Assign To" %}'>
|
||||||
<option value='unassign'>{% trans "Nobody (Unassign)" %}</option>
|
<option value='unassign'>{% trans "Nobody (Unassign)" %}</option>
|
||||||
{% for u in user_choices %}
|
{% for u in assignable_users %}
|
||||||
<option value='assign_{{ u.id }}'>{{ u.get_username }}</option>
|
<option value='assign_{{ u.id }}'>{{ u.get_username }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</optgroup>
|
</optgroup>
|
||||||
|
@@ -56,7 +56,11 @@ from helpdesk.forms import (
|
|||||||
TicketResolvesForm,
|
TicketResolvesForm,
|
||||||
UserSettingsForm,
|
UserSettingsForm,
|
||||||
)
|
)
|
||||||
from helpdesk.lib import queue_template_context, safe_template_context, get_active_users
|
from helpdesk.lib import (
|
||||||
|
queue_template_context,
|
||||||
|
safe_template_context,
|
||||||
|
get_assignable_users,
|
||||||
|
)
|
||||||
from helpdesk.models import (
|
from helpdesk.models import (
|
||||||
Checklist,
|
Checklist,
|
||||||
ChecklistTask,
|
ChecklistTask,
|
||||||
@@ -133,7 +137,9 @@ def get_user_queues(user) -> dict[str, str]:
|
|||||||
|
|
||||||
def get_form_extra_kwargs(user) -> dict[str, object]:
|
def get_form_extra_kwargs(user) -> dict[str, object]:
|
||||||
return {
|
return {
|
||||||
"active_users": get_active_users(),
|
"assignable_users": get_assignable_users(
|
||||||
|
helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_OWNERS
|
||||||
|
),
|
||||||
"queues": get_user_queues(user),
|
"queues": get_user_queues(user),
|
||||||
"priorities": Ticket.PRIORITY_CHOICES,
|
"priorities": Ticket.PRIORITY_CHOICES,
|
||||||
}
|
}
|
||||||
@@ -1177,7 +1183,9 @@ def ticket_list(request):
|
|||||||
dict(
|
dict(
|
||||||
context,
|
context,
|
||||||
default_tickets_per_page=request.user.usersettings_helpdesk.tickets_per_page,
|
default_tickets_per_page=request.user.usersettings_helpdesk.tickets_per_page,
|
||||||
user_choices=User.objects.filter(is_active=True, is_staff=True),
|
assignable_users=get_assignable_users(
|
||||||
|
helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_OWNERS
|
||||||
|
),
|
||||||
kb_items=kbitem,
|
kb_items=kbitem,
|
||||||
queue_choices=huser.get_queues(),
|
queue_choices=huser.get_queues(),
|
||||||
status_choices=Ticket.STATUS_CHOICES,
|
status_choices=Ticket.STATUS_CHOICES,
|
||||||
|
Reference in New Issue
Block a user