def new(request): context = common_context(request) context['title'] = _("New Ticket") if request.method != 'POST': context['form'] = NewTicketForm() return render(request, 'tickets/new.html', context) form = NewTicketForm(request.POST) if not form.is_valid(): context['form'] = form return render(request, 'tickets/new.html', context) ticket = Ticket(category=form.cleaned_data['category'], subject=form.cleaned_data['subject'], user=request.user) ticket.save() firstmsg = TicketMessage(ticket=ticket, user=request.user, message=form.cleaned_data['message']) if not request.user.is_staff: firstmsg.remote_addr = get_client_ip(request) firstmsg.save() ticket.notify_new(firstmsg) return redirect('tickets:view', id=ticket.id)
def some_settings(request): client_ip = get_client_ip(request) return { 'CLIENT_IP': client_ip, 'CLIENT_ON_VPN': is_vpn_gateway(client_ip), 'ROOT_URL': settings.ROOT_URL, 'ADDITIONAL_HTML': settings.ADDITIONAL_HTML, 'ADDITIONAL_HEADER_HTML': settings.ADDITIONAL_HEADER_HTML, }
def captcha_test(grr, request): api_url = project_settings.RECAPTCHA_API if api_url == 'TEST' and grr == 'TEST-TOKEN': # FIXME: i'm sorry. return True data = dict(secret=project_settings.RECAPTCHA_SECRET_KEY, remoteip=get_client_ip(request), response=grr) try: r = requests.post(api_url, data=data) r.raise_for_status() d = r.json() return d.get('success') except (requests.ConnectionError, requests.HTTPError, ValueError): return False
def view(request, id): ticket = get_object_or_404(Ticket, id=id) view_any_ticket = request.user.has_perm('tickets.view_any_ticket') reply_any_ticket = request.user.has_perm('tickets.reply_any_ticket') if not view_any_ticket and ticket.user != request.user: return HttpResponseNotFound() if request.user.has_perm('tickets.view_private_message'): messages = ticket.message_set.all() else: messages = ticket.message_set.filter(staff_only=False) if request.method != 'POST': ctx = dict( staff_reply=request.user.has_perm('tickets.post_private_message'), ticket=ticket, ticket_messages=messages, form=ReplyForm(), title=_("Ticket:") + " " + ticket.subject, ) ctx.update(common_context(request)) return render(request, 'tickets/view.html', ctx) if not reply_any_ticket and ticket.user != request.user: return HttpResponseNotFound() if request.POST.get('close') or request.POST.get('button_close'): ticket.is_open = False ticket.closed = timezone.now() ticket.save() return redirect('tickets:view', id=ticket.id) if request.POST.get('reopen') or request.POST.get('button_reopen'): ticket.is_open = True ticket.save() return redirect('tickets:view', id=ticket.id) if request.user.has_perm('tickets.post_private_message'): form = StaffReplyForm(request.POST) else: form = ReplyForm(request.POST) if not form.is_valid(): ctx = dict( staff_reply=request.user.has_perm('tickets.post_private_message'), ticket=ticket, ticket_messages=messages, form=form, title=_("Ticket:") + " " + ticket.subject, ) ctx.update(common_context(request)) return render(request, 'tickets/view.html', ctx) msg = TicketMessage(ticket=ticket, user=request.user, **form.cleaned_data) if not request.user.is_staff: msg.remote_addr = get_client_ip(request) msg.save() if not ticket.is_open: ticket.is_open = True ticket.save() ticket.notify_reply(msg) return redirect('tickets:view', id=ticket.id)