Improved support for custom user models

Support for custom user models with a non-standard username field
This commit is contained in:
Tom Graham 2014-10-22 16:18:04 +11:00
parent b0756497dc
commit d2ac8af6c0
10 changed files with 27 additions and 27 deletions

View File

@ -529,9 +529,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: if helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_CC:
users = User.objects.filter(is_active=True, is_staff=True).order_by('username') users = User.objects.filter(is_active=True, is_staff=True).order_by(User.USERNAME_FIELD)
else: else:
users = User.objects.filter(is_active=True).order_by('username') users = User.objects.filter(is_active=True).order_by(User.USERNAME_FIELD)
self.fields['user'].queryset = users self.fields['user'].queryset = users
class Meta: class Meta:
model = TicketCC model = TicketCC

View File

@ -351,7 +351,7 @@ class Ticket(models.Model):
if self.assigned_to.get_full_name(): if self.assigned_to.get_full_name():
return self.assigned_to.get_full_name() return self.assigned_to.get_full_name()
else: else:
return self.assigned_to.username return self.assigned_to.get_username()
get_assigned_to = property(_get_assigned_to) get_assigned_to = property(_get_assigned_to)
def _get_ticket(self): def _get_ticket(self):

View File

@ -17,7 +17,7 @@
<!--link rel='stylesheet' href='{{ STATIC_URL }}helpdesk/jquery-smoothness-theme/jquery-ui-1.8.9.custom.css' type='text/css' /--> <!--link rel='stylesheet' href='{{ STATIC_URL }}helpdesk/jquery-smoothness-theme/jquery-ui-1.8.9.custom.css' type='text/css' /-->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet"> <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet">
<link rel='alternate' href='{% url 'helpdesk_rss_user' user.username %}' type='application/rss+xml' title='{% trans "My Open Tickets" %}' /> <link rel='alternate' href='{% url 'helpdesk_rss_user' user.get_username %}' type='application/rss+xml' title='{% trans "My Open Tickets" %}' />
<link rel='alternate' href='{% url 'helpdesk_rss_activity' %}' type='application/rss+xml' title='{% trans "All Recent Activity" %}' /> <link rel='alternate' href='{% url 'helpdesk_rss_activity' %}' type='application/rss+xml' title='{% trans "All Recent Activity" %}' />
<link rel='alternate' href='{% url 'helpdesk_rss_unassigned' %}' type='application/rss+xml' title='{% trans "Unassigned Tickets" %}' /> <link rel='alternate' href='{% url 'helpdesk_rss_unassigned' %}' type='application/rss+xml' title='{% trans "Unassigned Tickets" %}' />

View File

@ -26,13 +26,13 @@
{% for q in user_saved_queries_ %} {% for q in user_saved_queries_ %}
<li><a href="{% url 'helpdesk_list' %}?saved_query={{ q.id }}">{{ q.title }} <li><a href="{% url 'helpdesk_list' %}?saved_query={{ q.id }}">{{ q.title }}
{% if q.shared %} {% if q.shared %}
(Shared{% ifnotequal user q.user %} by {{ q.user.username }}{% endifnotequal %}) (Shared{% ifnotequal user q.user %} by {{ q.user.get_username }}{% endifnotequal %})
{% endif %}</a></li> {% endif %}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</li> </li>
{% endif %} {% endif %}
<li class="headerlink dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><span class="glyphicon glyphicon-user"></span> <span class="nav-text">{{ user.get_full_name|default:user.username }} <b class="caret"></b></span></a> <li class="headerlink dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><span class="glyphicon glyphicon-user"></span> <span class="nav-text">{{ user.get_full_name|default:user.get_username }} <b class="caret"></b></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href='{% url 'helpdesk_user_settings' %}'>{% trans "User Settings" %}</a></li> <li><a href='{% url 'helpdesk_user_settings' %}'>{% trans "User Settings" %}</a></li>
{% if helpdesk_settings.HELPDESK_SHOW_CHANGE_PASSWORD and user.has_usable_password %} {% if helpdesk_settings.HELPDESK_SHOW_CHANGE_PASSWORD and user.has_usable_password %}

View File

@ -6,7 +6,7 @@
<p>{% trans "The following RSS feeds are available for you to monitor using your preferred RSS software. With the exception of the 'Latest Activity' feed, all feeds provide information only on Open and Reopened cases. This ensures your RSS reader isn't full of information about closed or historical tasks." %}</p> <p>{% trans "The following RSS feeds are available for you to monitor using your preferred RSS software. With the exception of the 'Latest Activity' feed, all feeds provide information only on Open and Reopened cases. This ensures your RSS reader isn't full of information about closed or historical tasks." %}</p>
<dl> <dl>
<dt><a href='{% url 'helpdesk_rss_user' user.username %}'><img src='{{ STATIC_URL }}helpdesk/rss_icon.png' width='14' height='14' alt='{% trans "RSS Icon" %}' title='{% trans "My Open Tickets" %}' border='0' />{% trans "My Open Tickets" %}</a></dt> <dt><a href='{% url 'helpdesk_rss_user' user.get_username %}'><img src='{{ STATIC_URL }}helpdesk/rss_icon.png' width='14' height='14' alt='{% trans "RSS Icon" %}' title='{% trans "My Open Tickets" %}' border='0' />{% trans "My Open Tickets" %}</a></dt>
<dd>{% trans "A summary of your open tickets - useful for getting alerted to new tickets opened for you" %}</dd> <dd>{% trans "A summary of your open tickets - useful for getting alerted to new tickets opened for you" %}</dd>
<dt><a href='{% url 'helpdesk_rss_activity' %}'><img src='{{ STATIC_URL }}helpdesk/rss_icon.png' width='14' height='14' alt='{% trans "RSS Icon" %}' title='{% trans "Latest Activity" %}' border='0' />{% trans "Latest Activity" %}</a></dt> <dt><a href='{% url 'helpdesk_rss_activity' %}'><img src='{{ STATIC_URL }}helpdesk/rss_icon.png' width='14' height='14' alt='{% trans "RSS Icon" %}' title='{% trans "Latest Activity" %}' border='0' />{% trans "Latest Activity" %}</a></dt>
@ -28,7 +28,7 @@
<tr> <tr>
<td>{{ queue.title }}</td> <td>{{ queue.title }}</td>
<td align='center'><a href='{% url 'helpdesk_rss_queue' queue.slug %}'><img src='{{ STATIC_URL }}helpdesk/rss_icon.png' width='14' height='14' alt='{% trans "RSS Icon" %}' title='{% trans "Open Tickets" %}' border='0' /></a></td> <td align='center'><a href='{% url 'helpdesk_rss_queue' queue.slug %}'><img src='{{ STATIC_URL }}helpdesk/rss_icon.png' width='14' height='14' alt='{% trans "RSS Icon" %}' title='{% trans "Open Tickets" %}' border='0' /></a></td>
<td align='center'><a href='{% url 'helpdesk_rss_user_queue' user.username queue.slug %}'><img src='{{ STATIC_URL }}helpdesk/rss_icon.png' width='14' height='14' alt='{% trans "RSS Icon" %}' title='{% trans "My Open Tickets" %}' border='0' /></a></td> <td align='center'><a href='{% url 'helpdesk_rss_user_queue' user.get_username queue.slug %}'><img src='{{ STATIC_URL }}helpdesk/rss_icon.png' width='14' height='14' alt='{% trans "RSS Icon" %}' title='{% trans "My Open Tickets" %}' border='0' /></a></td>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>

View File

@ -106,7 +106,7 @@ $(document).ready(function() {
<select id='id_owners' name='assigned_to' multiple='selected' size='5'> <select id='id_owners' name='assigned_to' multiple='selected' size='5'>
{% for u in user_choices %} {% for u in user_choices %}
<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.username }}{% ifequal u user %} {% trans "(ME)" %}{% endifequal %} {{ u.get_username }}{% ifequal u user %} {% trans "(ME)" %}{% endifequal %}
</option> </option>
{% endfor %} {% endfor %}
</select> </select>
@ -199,7 +199,7 @@ $(document).ready(function() {
<form method='get' action='{% url 'helpdesk_list' %}'> <form method='get' action='{% url 'helpdesk_list' %}'>
<p><label for='id_query_selector'>{% trans "Query" %}</label> <select name='saved_query' id='id_query_selector'> <p><label for='id_query_selector'>{% trans "Query" %}</label> <select name='saved_query' id='id_query_selector'>
{% for q in user_saved_queries %} {% for q in user_saved_queries %}
<option value='{{ q.id }}'>{{ q.title }}{% if q.shared %} (Shared{% ifnotequal user q.user %} by {{ q.user.username }}{% endifnotequal %}){% endif %}</option> <option value='{{ q.id }}'>{{ q.title }}{% if q.shared %} (Shared{% ifnotequal user q.user %} by {{ q.user.get_username }}{% endifnotequal %}){% endif %}</option>
{% endfor %} {% endfor %}
</select></p> </select></p>
<input class="btn btn-primary" type='submit' value='{% trans "Run Query" %}'> <input class="btn btn-primary" type='submit' value='{% trans "Run Query" %}'>
@ -257,7 +257,7 @@ $(document).ready(function() {
<p><label>{% trans "Select:" %} </label> <a href='#select_all' id='select_all'>{% trans "All" %}</a> <a href='#select_none' id='select_none'>{% trans "None" %}</a> <a href='#select_inverse' id='select_inverse'>{% trans "Inverse" %}</a></p> <p><label>{% trans "Select:" %} </label> <a href='#select_all' id='select_all'>{% trans "All" %}</a> <a href='#select_none' id='select_none'>{% trans "None" %}</a> <a href='#select_inverse' id='select_inverse'>{% trans "Inverse" %}</a></p>
<p><label for='id_mass_action'>{% trans "With Selected Tickets:" %}</label> <select name='action' id='id_mass_action'><option value='take'>{% trans "Take (Assign to me)" %}</option><option value='delete'>{% trans "Delete" %}</option><optgroup label='{% trans "Close" %}'><option value='close'>{% trans "Close (Don't Send E-Mail)" %}</option><option value='close_public'>{% trans "Close (Send E-Mail)" %}</option></optgroup><optgroup label='{% trans "Assign To" %}'><option value='unassign'>{% trans "Nobody (Unassign)" %}</option>{% for u in user_choices %}<option value='assign_{{ u.id }}'>{{ u.username }}</option>{% endfor %}</optgroup></select> <input type='submit' value='Go' /></p> <p><label for='id_mass_action'>{% trans "With Selected Tickets:" %}</label> <select name='action' id='id_mass_action'><option value='take'>{% trans "Take (Assign to me)" %}</option><option value='delete'>{% trans "Delete" %}</option><optgroup label='{% trans "Close" %}'><option value='close'>{% trans "Close (Don't Send E-Mail)" %}</option><option value='close_public'>{% trans "Close (Send E-Mail)" %}</option></optgroup><optgroup label='{% trans "Assign To" %}'><option value='unassign'>{% trans "Nobody (Unassign)" %}</option>{% for u in user_choices %}<option value='assign_{{ u.id }}'>{{ u.get_username }}</option>{% endfor %}</optgroup></select> <input type='submit' value='Go' /></p>
{% csrf_token %}</form> {% csrf_token %}</form>
{% endblock %} {% endblock %}
</div> </div>

View File

@ -25,7 +25,7 @@ class TestKBDisabled(TestCase):
"""Test proper rendering of navigation.html by accessing the dashboard""" """Test proper rendering of navigation.html by accessing the dashboard"""
from django.core.urlresolvers import NoReverseMatch from django.core.urlresolvers import NoReverseMatch
self.client.login(username=get_staff_user().username, password='password') self.client.login(username=get_staff_user().get_username(), password='password')
self.assertRaises(NoReverseMatch, reverse, 'helpdesk_kb_index') self.assertRaises(NoReverseMatch, reverse, 'helpdesk_kb_index')
try: try:
response = self.client.get(reverse('helpdesk_dashboard')) response = self.client.get(reverse('helpdesk_dashboard'))

View File

@ -110,7 +110,7 @@ class API:
def api_public_create_ticket(self): def api_public_create_ticket(self):
form = TicketForm(self.request.POST) form = TicketForm(self.request.POST)
form.fields['queue'].choices = [[q.id, q.title] for q in Queue.objects.all()] form.fields['queue'].choices = [[q.id, q.title] for q in Queue.objects.all()]
form.fields['assigned_to'].choices = [[u.id, u.username] for u in User.objects.filter(is_active=True)] form.fields['assigned_to'].choices = [[u.id, u.get_username()] for u in User.objects.filter(is_active=True)]
if form.is_valid(): if form.is_valid():
ticket = form.save(user=self.request.user) ticket = form.save(user=self.request.user)

View File

@ -38,22 +38,22 @@ class OpenTicketsByUser(Feed):
if obj['queue']: if obj['queue']:
return _("Helpdesk: Open Tickets in queue %(queue)s for %(username)s") % { return _("Helpdesk: Open Tickets in queue %(queue)s for %(username)s") % {
'queue': obj['queue'].title, 'queue': obj['queue'].title,
'username': obj['user'].username, 'username': obj['user'].get_username(),
} }
else: else:
return _("Helpdesk: Open Tickets for %(username)s") % { return _("Helpdesk: Open Tickets for %(username)s") % {
'username': obj['user'].username, 'username': obj['user'].get_username(),
} }
def description(self, obj): def description(self, obj):
if obj['queue']: if obj['queue']:
return _("Open and Reopened Tickets in queue %(queue)s for %(username)s") % { return _("Open and Reopened Tickets in queue %(queue)s for %(username)s") % {
'queue': obj['queue'].title, 'queue': obj['queue'].title,
'username': obj['user'].username, 'username': obj['user'].get_username(),
} }
else: else:
return _("Open and Reopened Tickets for %(username)s") % { return _("Open and Reopened Tickets for %(username)s") % {
'username': obj['user'].username, 'username': obj['user'].get_username(),
} }
def link(self, obj): def link(self, obj):
@ -90,7 +90,7 @@ class OpenTicketsByUser(Feed):
def item_author_name(self, item): def item_author_name(self, item):
if item.assigned_to: if item.assigned_to:
return item.assigned_to.username return item.assigned_to.get_username()
else: else:
return _('Unassigned') return _('Unassigned')
@ -116,7 +116,7 @@ class UnassignedTickets(Feed):
def item_author_name(self, item): def item_author_name(self, item):
if item.assigned_to: if item.assigned_to:
return item.assigned_to.username return item.assigned_to.get_username()
else: else:
return _('Unassigned') return _('Unassigned')
@ -168,7 +168,7 @@ class OpenTicketsByQueue(Feed):
def item_author_name(self, item): def item_author_name(self, item):
if item.assigned_to: if item.assigned_to:
return item.assigned_to.username return item.assigned_to.get_username()
else: else:
return _('Unassigned') return _('Unassigned')

View File

@ -261,7 +261,7 @@ def return_ticketccstring_and_show_subscribe(user, ticket):
''' used in view_ticket() and followup_edit()''' ''' used in view_ticket() and followup_edit()'''
# create the ticketcc_string and check whether current user is already # create the ticketcc_string and check whether current user is already
# subscribed # subscribed
username = user.username.upper() username = user.get_username().upper()
useremail = user.email.upper() useremail = user.email.upper()
strings_to_check = list() strings_to_check = list()
strings_to_check.append(username) strings_to_check.append(username)
@ -364,7 +364,7 @@ def update_ticket(request, ticket_id, public=False):
if owner != 0 and ((ticket.assigned_to and owner != ticket.assigned_to.id) or not ticket.assigned_to): if owner != 0 and ((ticket.assigned_to and owner != ticket.assigned_to.id) or not ticket.assigned_to):
new_user = User.objects.get(id=owner) new_user = User.objects.get(id=owner)
f.title = _('Assigned to %(username)s') % { f.title = _('Assigned to %(username)s') % {
'username': new_user.username, 'username': new_user.get_username(),
} }
ticket.assigned_to = new_user ticket.assigned_to = new_user
reassigned = True reassigned = True
@ -571,7 +571,7 @@ def mass_update(request):
if action == 'assign' and t.assigned_to != user: if action == 'assign' and t.assigned_to != user:
t.assigned_to = user t.assigned_to = user
t.save() t.save()
f = FollowUp(ticket=t, date=timezone.now(), title=_('Assigned to %(username)s in bulk update' % {'username': user.username}), public=True, user=request.user) f = FollowUp(ticket=t, date=timezone.now(), title=_('Assigned to %(username)s in bulk update' % {'username': user.get_username()}), public=True, user=request.user)
f.save() f.save()
elif action == 'unassign' and t.assigned_to is not None: elif action == 'unassign' and t.assigned_to is not None:
t.assigned_to = None t.assigned_to = None
@ -849,14 +849,14 @@ edit_ticket = staff_member_required(edit_ticket)
def create_ticket(request): def create_ticket(request):
if helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_OWNERS: if helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_OWNERS:
assignable_users = User.objects.filter(is_active=True, is_staff=True).order_by('username') assignable_users = User.objects.filter(is_active=True, is_staff=True).order_by(User.USERNAME_FIELD)
else: else:
assignable_users = User.objects.filter(is_active=True).order_by('username') assignable_users = User.objects.filter(is_active=True).order_by(User.USERNAME_FIELD)
if request.method == 'POST': if request.method == 'POST':
form = TicketForm(request.POST, request.FILES) form = TicketForm(request.POST, request.FILES)
form.fields['queue'].choices = [('', '--------')] + [[q.id, q.title] for q in Queue.objects.all()] form.fields['queue'].choices = [('', '--------')] + [[q.id, q.title] for q in Queue.objects.all()]
form.fields['assigned_to'].choices = [('', '--------')] + [[u.id, u.username] for u in assignable_users] form.fields['assigned_to'].choices = [('', '--------')] + [[u.id, u.get_username()] for u in assignable_users]
if form.is_valid(): if form.is_valid():
ticket = form.save(user=request.user) ticket = form.save(user=request.user)
return HttpResponseRedirect(ticket.get_absolute_url()) return HttpResponseRedirect(ticket.get_absolute_url())
@ -869,7 +869,7 @@ def create_ticket(request):
form = TicketForm(initial=initial_data) form = TicketForm(initial=initial_data)
form.fields['queue'].choices = [('', '--------')] + [[q.id, q.title] for q in Queue.objects.all()] form.fields['queue'].choices = [('', '--------')] + [[q.id, q.title] for q in Queue.objects.all()]
form.fields['assigned_to'].choices = [('', '--------')] + [[u.id, u.username] for u in assignable_users] form.fields['assigned_to'].choices = [('', '--------')] + [[u.id, u.get_username()] for u in assignable_users]
if helpdesk_settings.HELPDESK_CREATE_TICKET_HIDE_ASSIGNED_TO: if helpdesk_settings.HELPDESK_CREATE_TICKET_HIDE_ASSIGNED_TO:
form.fields['assigned_to'].widget = forms.HiddenInput() form.fields['assigned_to'].widget = forms.HiddenInput()