diff --git a/forms.py b/forms.py index a373eb2a..8b400931 100644 --- a/forms.py +++ b/forms.py @@ -329,6 +329,14 @@ class UserSettingsForm(forms.Form): required=False, ) + tickets_per_page = forms.IntegerField( + label=_('Number of tickets to show per page'), + help_text=_('How many tickets do you want to see on the Ticket List page?'), + required=False, + min_value=1, + max_value=1000, + ) + class EmailIgnoreForm(forms.ModelForm): class Meta: model = IgnoreEmail diff --git a/templates/helpdesk/public_view_ticket.html b/templates/helpdesk/public_view_ticket.html index 3b2a40f6..c9b8dc3a 100644 --- a/templates/helpdesk/public_view_ticket.html +++ b/templates/helpdesk/public_view_ticket.html @@ -30,7 +30,7 @@ {% if ticket.resolution %} - {% trans "Resolution" %}{% ifequal ticket.get_status_display "Resolved" %} {% trans "Accept" %}{% endifequal %} + {% trans "Resolution" %}{% ifequal ticket.get_status_display "Resolved" %} {% trans "Accept" %}{% endifequal %} {{ ticket.resolution }} diff --git a/views/public.py b/views/public.py index 12c3dd4c..7d297401 100644 --- a/views/public.py +++ b/views/public.py @@ -59,22 +59,22 @@ def homepage(request): def view_ticket(request): - ticket = request.GET.get('ticket', '') + ticket_req = request.GET.get('ticket', '') email = request.GET.get('email', '') error_message = '' - if ticket and email: - parts = ticket.split('-') + if ticket_req and email: + parts = ticket_req.split('-') queue = '-'.join(parts[0:-1]) ticket_id = parts[-1] try: - t = Ticket.objects.get(id=ticket_id, queue__slug__iexact=queue, submitter_email__iexact=email) + ticket = Ticket.objects.get(id=ticket_id, queue__slug__iexact=queue, submitter_email__iexact=email) except: - t = False + ticket = False error_message = _('Invalid ticket ID or e-mail address. Please try again.') - if t: + if ticket: if request.GET.has_key('close') and ticket.status == Ticket.RESOLVED_STATUS: from helpdesk.views.staff import update_ticket @@ -83,18 +83,17 @@ def view_ticket(request): request.POST = { 'new_status': Ticket.CLOSED_STATUS, 'public': 1, - 'owner': ticket.assigned_to, + 'owner': ticket.assigned_to.id, 'title': ticket.title, 'comment': _('Submitter accepted resolution and closed ticket'), } - request.FILES = {} request.GET = {} - return update_ticket(request, ticket_id) + return update_ticket(request, ticket_id, public=True) return render_to_response('helpdesk/public_view_ticket.html', RequestContext(request, { - 'ticket': t, + 'ticket': ticket, })) return render_to_response('helpdesk/public_view_form.html', diff --git a/views/staff.py b/views/staff.py index d3cfb968..c3e480a2 100644 --- a/views/staff.py +++ b/views/staff.py @@ -17,7 +17,7 @@ from django.core.urlresolvers import reverse from django.core.paginator import Paginator from django.db import connection from django.db.models import Q -from django.http import HttpResponseRedirect, Http404, HttpResponse +from django.http import HttpResponseRedirect, Http404, HttpResponse, HttpResponseForbidden from django.shortcuts import render_to_response, get_object_or_404 from django.template import loader, Context, RequestContext from django.utils.translation import ugettext as _ @@ -130,7 +130,10 @@ def view_ticket(request, ticket_id): view_ticket = staff_member_required(view_ticket) -def update_ticket(request, ticket_id): +def update_ticket(request, ticket_id, public=False): + if not (public or (request.user.is_authenticated() and request.user.is_active and request.user.is_staff)): + return HttpResponseForbidden(_('Sorry, you need to login to do that.')) + ticket = get_object_or_404(Ticket, id=ticket_id) comment = request.POST.get('comment', '') @@ -143,8 +146,8 @@ def update_ticket(request, ticket_id): # We need to allow the 'ticket' and 'queue' contexts to be applied to the # comment. from django.template import loader, Context - context = Context(safe_template_context(ticket)) - comment = loader.get_template_from_string(comment).render(context) + context = safe_template_context(ticket) + comment = loader.get_template_from_string(comment).render(Context(context)) if not owner and ticket.assigned_to: owner = ticket.assigned_to.id @@ -231,12 +234,10 @@ def update_ticket(request, ticket_id): ticket.resolution = comment if ticket.submitter_email and public and (f.comment or (f.new_status in (Ticket.RESOLVED_STATUS, Ticket.CLOSED_STATUS))): - context = { - 'ticket': ticket, - 'queue': ticket.queue, - 'resolution': ticket.resolution, - 'comment': f.comment, - } + context.update( + resolution=ticket.resolution, + comment=f.comment, + ) if f.new_status == Ticket.RESOLVED_STATUS: template = 'resolved_submitter' @@ -256,7 +257,8 @@ def update_ticket(request, ticket_id): if ticket.assigned_to and request.user != ticket.assigned_to and ticket.assigned_to.email: # We only send e-mails to staff members if the ticket is updated by - # another user. + # another user. The actual template varies, depending on what has been + # changed. if reassigned: template_staff = 'assigned_owner' elif f.new_status == Ticket.RESOLVED_STATUS: @@ -266,7 +268,7 @@ def update_ticket(request, ticket_id): else: template_staff = 'updated_owner' - if (not reassigned or ( reassigned and getattr(ticket.assigned_to.usersettings.settings, 'email_on_ticket_assign', False))) or (not reassigned and getattr(ticket.assigned_to.usersettings.settings, 'email_on_ticket_change', False)): + if (not reassigned or ( reassigned and ticket.assigned_to.usersettings.settings.get('email_on_ticket_assign', False))) or (not reassigned and ticket.assigned_to.usersettings.settings.get('email_on_ticket_change', False)): send_templated_mail( template_staff, context, @@ -301,7 +303,6 @@ def update_ticket(request, ticket_id): return HttpResponseRedirect(ticket.get_absolute_url()) else: return HttpResponseRedirect(ticket.ticket_url) -update_ticket = staff_member_required(update_ticket) def mass_update(request): @@ -495,7 +496,7 @@ def ticket_list(request): query_params['sortreverse'] = sortreverse ticket_qs = apply_query(Ticket.objects.select_related(), query_params) - paginator = Paginator(ticket_qs, 20) + paginator = Paginator(ticket_qs, request.user.usersettings.settings.get('tickets_per_page', 20)) try: page = int(request.GET.get('page', '1')) except ValueError: