def homepage(request):
    if not request.user.is_authenticated(
    ) and helpdesk_settings.HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT:
        return HttpResponseRedirect(reverse('helpdesk:login'))

    if request.user.is_staff or \
            (request.user.is_authenticated() and
             helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE):
        try:
            if request.user.usersettings_helpdesk.settings.get(
                    'login_view_ticketlist', False):
                return HttpResponseRedirect(reverse('helpdesk:list'))
            else:
                return HttpResponseRedirect(reverse('helpdesk:dashboard'))
        except UserSettings.DoesNotExist:
            return HttpResponseRedirect(reverse('helpdesk:dashboard'))

    if request.method == 'POST':
        form = PublicTicketForm(request.POST, request.FILES)
        form.fields['queue'].choices = [('', '--------')] + [
            (q.id, q.title)
            for q in Queue.objects.filter(allow_public_submission=True)
        ]
        if form.is_valid():
            if text_is_spam(form.cleaned_data['body'], request):
                # This submission is spam. Let's not save it.
                return render(request,
                              template_name='helpdesk/public_spam.html')
            else:
                ticket = form.save()
                return HttpResponseRedirect(
                    '%s?ticket=%s&email=%s' %
                    (reverse('helpdesk:public_view'), ticket.ticket_for_url,
                     urlquote(ticket.submitter_email)))
    else:
        try:
            queue = Queue.objects.get(slug=request.GET.get('queue', None))
        except Queue.DoesNotExist:
            queue = None
        initial_data = {}
        if queue:
            initial_data['queue'] = queue.id

        if request.user.is_authenticated() and request.user.email:
            initial_data['submitter_email'] = request.user.email

        form = PublicTicketForm(initial=initial_data)
        form.fields['queue'].choices = [('', '--------')] + [
            (q.id, q.title)
            for q in Queue.objects.filter(allow_public_submission=True)
        ]

    knowledgebase_categories = KBCategory.objects.all()

    return render(
        request, 'helpdesk/public_homepage.html', {
            'form': form,
            'helpdesk_settings': helpdesk_settings,
            'kb_categories': knowledgebase_categories
        })
Example #2
0
def form_data(request):

    from helpdesk.forms import TicketForm, PublicTicketForm
    from helpdesk.models import Queue

    assignable_users = User.objects.filter(is_active=True).order_by(
        User.USERNAME_FIELD)
    initial_data = {}
    form = PublicTicketForm(initial=initial_data)

    try:
        if request.user.email:
            initial_data['submitter_email'] = request.user.email
        if 'queue' in request.GET:
            initial_data['queue'] = request.GET['queue']

        if request.user.is_staff:
            form = TicketForm(initial=initial_data)
            form.fields['queue'].choices = [
                ('', '--------')
            ] + [[q.id, q.title] for q in Queue.objects.all()]
            form.fields['assigned_to'].choices = [
                ('', '--------')
            ] + [[u.id, u.get_username()] for u in assignable_users]
        else:
            form = PublicTicketForm(initial=initial_data)
            form.fields['queue'].choices = [
                ('', '--------')
            ] + [[q.id, q.title] for q in Queue.objects.all()]

    except Exception, e:
        pass
Example #3
0
def homepage(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('login'))

    if (request.user.is_staff or (request.user.is_authenticated())):
        try:
            if getattr(request.user.usersettings.settings,
                       'login_view_ticketlist', False):
                return HttpResponseRedirect(reverse('helpdesk_list'))
            else:
                return HttpResponseRedirect(reverse('helpdesk_dashboard'))
        except UserSettings.DoesNotExist:
            return HttpResponseRedirect(reverse('helpdesk_dashboard'))

    if request.method == 'POST':
        form = PublicTicketForm(request.POST, request.FILES)
        form.fields['queue'].choices = [
            ('', '--------')
        ] + [[q.id, q.title]
             for q in Queue.objects.filter(allow_public_submission=True)]
        if form.is_valid():
            if text_is_spam(form.cleaned_data['body'], request):
                # This submission is spam. Let's not save it.
                return render_to_response('helpdesk/public_spam.html',
                                          RequestContext(request, {}))
            else:
                ticket = form.save()
                return HttpResponseRedirect(
                    '%s?ticket=%s&email=%s' %
                    (reverse('helpdesk_public_view'), ticket.ticket_for_url,
                     ticket.submitter_email))
    else:
        try:
            queue = Queue.objects.get(slug=request.GET.get('queue', None))
        except Queue.DoesNotExist:
            queue = None
        initial_data = {}
        if queue:
            initial_data['queue'] = queue.id

        if request.user.is_authenticated() and request.user.email:
            initial_data['submitter_email'] = request.user.email

        form = PublicTicketForm(initial=initial_data)
        form.fields['queue'].choices = [
            ('', '--------')
        ] + [[q.id, q.title]
             for q in Queue.objects.filter(allow_public_submission=True)]

    knowledgebase_categories = KBCategory.objects.all()

    return render_to_response(
        'helpdesk/public_homepage.html',
        RequestContext(request, {
            'form': form,
            'kb_categories': knowledgebase_categories
        }))
def homepage(request):
    if not request.user.is_authenticated() and helpdesk_settings.HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT:
        if hasattr(settings, 'LOGIN_URL') and settings.LOGIN_URL:
            return HttpResponseRedirect(settings.LOGIN_URL+'?next='+request.path)
        return HttpResponseRedirect(reverse('login')+'?next='+request.path)

    if (request.user.is_staff or (
            request.user.is_authenticated() and helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE)):
        try:
            if getattr(request.user.usersettings.settings, 'login_view_ticketlist', False):
                return HttpResponseRedirect(reverse('helpdesk_list'))
            return HttpResponseRedirect(reverse('helpdesk_dashboard'))
        except UserSettings.DoesNotExist:
            return HttpResponseRedirect(reverse('helpdesk_dashboard'))

    if request.method == 'POST':
        form = PublicTicketForm(request.POST, request.FILES)
        form.fields['queue'].choices = [('', '--------')] + [
            [q.id, q.title] for q in Queue.objects.filter(allow_public_submission=True)]
        if form.is_valid():
            if text_is_spam(form.cleaned_data['body'], request):
                # This submission is spam. Let's not save it.
                return render(request, 'helpdesk/public_spam.html', {})
            ticket = form.save()
            return HttpResponseRedirect('%s?ticket=%s&email=%s'% (
                reverse('helpdesk_public_view'),
                ticket.ticket_for_url,
                ticket.submitter_email))
    else:
        try:
            queue = Queue.objects.get(slug=request.GET.get('queue', None))
        except Queue.DoesNotExist:
            queue = None
        initial_data = {}
        if queue:
            initial_data['queue'] = queue.id

        if request.user.is_authenticated() and request.user.email:
            initial_data['submitter_email'] = request.user.email

        form = PublicTicketForm(initial=initial_data)
        form.fields['queue'].choices = [('', '--------')] + [
            [q.id, q.title] for q in Queue.objects.filter(allow_public_submission=True)]

    knowledgebase_categories = KBCategory.objects.all()
    
    public_queues = Queue.objects.filter(allow_public_submission=True)
    show_submit_form = public_queues.count() and helpdesk_settings.HELPDESK_SUBMIT_A_TICKET_PUBLIC

    return render(request, 'helpdesk/public_homepage.html',
        dict(
            form=form,
            helpdesk_settings=helpdesk_settings,
            kb_categories=knowledgebase_categories,
            show_submit_form=show_submit_form
        ))
Example #5
0
def create_ticket(request):
    """ Creates a new ticket """
    context = {'title': _(u'Create a ticket')}
    context['current_view_name'] = 'helpdesk_account_tickets_add'

    if request.method == 'POST':
        form = PublicTicketForm(request.POST.copy())
        form.fields['queue'].choices = [[
            q.id, q.title
        ] for q in Queue.objects.filter(allow_public_submission=True)]
        if form.is_valid():
            ticket = form.save()
            ticket.owner = request.user
            ticket.account = request.user.account
            ticket.save()
            request.notifications.add(
                _(u'Ticket was created successfully and will be processed shortly'
                  ), 'success')
            return HttpResponseRedirect(reverse('helpdesk_account_tickets'))
    else:
        try:
            queue = Queue.objects.get(slug=request.GET.get('queue', None))
        except Queue.DoesNotExist:
            queue = None
        initial_data = {}
        if queue:
            initial_data['queue'] = queue.id

        if request.user.is_authenticated() and request.user.account.email:
            initial_data['submitter_email'] = request.user.account.email
            initial_data['submitter'] = request.user.id

        form = PublicTicketForm(initial=initial_data)
        if 'submitter_email' in initial_data:
            PublicTicketForm.base_fields[
                'submitter_email'].widget = forms.HiddenInput()
        form.fields['queue'].choices = [[
            q.id, q.title
        ] for q in Queue.objects.filter(allow_public_submission=True)]
    context['form'] = form
    return context
Example #6
0
def homepage(request):
    if request.user.is_staff or \
            (request.user.is_authenticated and
             helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE):
        try:
            if request.user.usersettings_helpdesk.settings.get(
                    'login_view_ticketlist', False):
                return HttpResponseRedirect(reverse('helpdesk:list'))
            else:
                return HttpResponseRedirect(reverse('helpdesk:dashboard'))
        except UserSettings.DoesNotExist:
            return HttpResponseRedirect(reverse('helpdesk:dashboard'))

    if request.method == 'POST':
        form = PublicTicketForm(request.POST, request.FILES)
        form.fields['queue'].choices = [('', '--------')] + [
            (q.id, q.title)
            for q in Queue.objects.filter(allow_public_submission=True)
        ]
        if form.is_valid():
            if text_is_spam(form.cleaned_data['body'], request):
                # This submission is spam. Let's not save it.
                return render(request,
                              template_name='helpdesk/public_spam.html')
            else:
                ticket = form.save()
                try:
                    return HttpResponseRedirect(
                        '%s?ticket=%s&email=%s' %
                        (reverse('helpdesk:public_view'),
                         ticket.ticket_for_url, urlquote(
                             ticket.submitter_email)))
                except ValueError:
                    # if someone enters a non-int string for the ticket
                    return HttpResponseRedirect(reverse('helpdesk:home'))
    else:
        try:
            queue = Queue.objects.get(slug=request.GET.get('queue', None))
        except Queue.DoesNotExist:
            queue = None
        initial_data = {}

        # add pre-defined data for public ticket
        if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_QUEUE'):
            slug = settings.HELPDESK_PUBLIC_TICKET_QUEUE
            queue = Queue.objects.get(slug=slug)
        if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_PRIORITY'):
            initial_data['priority'] = settings.HELPDESK_PUBLIC_TICKET_PRIORITY
        if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_DUE_DATE'):
            initial_data['due_date'] = settings.HELPDESK_PUBLIC_TICKET_DUE_DATE

        if queue:
            initial_data['queue'] = queue.id

        if request.user.is_authenticated and request.user.email:
            initial_data['submitter_email'] = request.user.email

        form = PublicTicketForm(initial=initial_data)
        form.fields['queue'].choices = [('', '--------')] + [
            (q.id, q.title)
            for q in Queue.objects.filter(allow_public_submission=True)
        ]

    knowledgebase_categories = KBCategory.objects.all()

    return render(
        request, 'helpdesk/public_homepage.html', {
            'form': form,
            'helpdesk_settings': helpdesk_settings,
            'kb_categories': knowledgebase_categories
        })
Example #7
0
def homepage(request):
    if request.user.is_staff or \
            (request.user.is_authenticated and
             helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE):
        try:
            if request.user.usersettings_helpdesk.settings.get('login_view_ticketlist', False):
                return HttpResponseRedirect(reverse('helpdesk:list'))
            else:
                return HttpResponseRedirect(reverse('helpdesk:dashboard'))
        except UserSettings.DoesNotExist:
            return HttpResponseRedirect(reverse('helpdesk:dashboard'))

    if request.method == 'POST':
        form = PublicTicketForm(request.POST, request.FILES)
        form.fields['queue'].choices = [('', '--------')] + [
            (q.id, q.title) for q in Queue.objects.filter(allow_public_submission=True)]
        if form.is_valid():
            if text_is_spam(form.cleaned_data['body'], request):
                # This submission is spam. Let's not save it.
                return render(request, template_name='helpdesk/public_spam.html')
            else:
                ticket = form.save()
                try:
                    return HttpResponseRedirect('%s?ticket=%s&email=%s' % (
                        reverse('helpdesk:public_view'),
                        ticket.ticket_for_url,
                        urlquote(ticket.submitter_email))
                    )
                except ValueError:
                    # if someone enters a non-int string for the ticket
                    return HttpResponseRedirect(reverse('helpdesk:home'))
        # form = AuthenticationForm(request.POST, request.FILES)
        # if form.is_valid():
        #     ''' Begin reCAPTCHA validation '''
        #     # recaptcha_response = request.POST.get('g-recaptcha-response')
        #     # url = 'https://www.google.com/recaptcha/api/siteverify'
        #     # values = {
        #     #     'secret': "6LeBWpkUAAAAAMKlYr6-k3JAQZFNP3LvBbTDPnRs",
        #     #     'response': recaptcha_response
        #     # }
        #     # data = urllib.urlencode(values)
        #     # req = urllib2.Request(url, data)
        #     # response = urllib2.urlopen(req)
        #     # result = json.load(response)
        #     # ''' End reCAPTCHA validation '''
        #     #
        #     # if result['success']:
        #     #     form.save()
        #     #     messages.success(request, 'New comment added with success!')
        #     # else:
        #     #     messages.error(request, 'Invalid reCAPTCHA. Please try again.')
        #     #
        #     # return redirect('login')

    else:
        try:
            queue = Queue.objects.get(slug=request.GET.get('queue', None))
        except Queue.DoesNotExist:
            queue = None
        initial_data = {}

        # add pre-defined data for public ticket
        if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_QUEUE'):
            # get the requested queue; return an error if queue not found
            try:
                queue = Queue.objects.get(slug=settings.HELPDESK_PUBLIC_TICKET_QUEUE)
            except Queue.DoesNotExist:
                return HttpResponse(status=500)
        if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_PRIORITY'):
            initial_data['priority'] = settings.HELPDESK_PUBLIC_TICKET_PRIORITY
        if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_DUE_DATE'):
            initial_data['due_date'] = settings.HELPDESK_PUBLIC_TICKET_DUE_DATE

        if queue:
            initial_data['queue'] = queue.id

        if request.user.is_authenticated and request.user.email:
            initial_data['submitter_email'] = request.user.email

        form = PublicTicketForm(initial=initial_data)
        form.fields['queue'].choices = [('', '--------')] + [
            (q.id, q.title) for q in Queue.objects.filter(allow_public_submission=True)]

    knowledgebase_categories = KBCategory.objects.all()

    return render(request, 'helpdesk/public_homepage.html', {
        'form': form,
        'helpdesk_settings': helpdesk_settings,
        'kb_categories': knowledgebase_categories
    })