Esempio n. 1
0
def view_ticket(request, id):
    ticket = Ticket.objects.get(id=id)
    profile = get_user_profile(request.user)
    clientprofile = get_user_profile(ticket.client)
    replyform = ReplyForm()
    replies = []
    statusform = TicketStatusForm(instance=ticket)
    categoryform = TicketCategoryForm(instance=ticket)
    ownerform = TicketOwnerForm(instance=ticket)
    priorityform = TicketPriorityForm(instance=ticket)

    try:
        reply = Reply.objects.filter(ticket=id)
        replies.extend(reply)
    except Reply.DoesNotExist:
        pass

    context = {
        'ticket': ticket,
        'profile': profile,
        'replies': replies,
        'userprofile': clientprofile,
        'statusform': statusform,
        'categoryform': categoryform,
        'ownerform': ownerform,
        'priorityform': priorityform,
        'replyform': replyform
    }
    return render(request, 'support/view_ticket.html', context)
Esempio n. 2
0
def priority(request):
    priorities = Priority.objects.all()
    context = {
        'priorities': priorities,
        'profile': get_user_profile(request.user)
    }
    return render(request, 'support/priority.html', context)
Esempio n. 3
0
def client_create_ticket(request):
    """
    If the client creating the ticket 
    """
    if request.method != 'POST':
        #Client is creating a new ticket
        form = TicketForm()
    else:
        status = Status.objects.get(id=1)
        ip = get_ip_address(request)
        client = request.user
        owner = request.user
        assigned = request.user
        form = TicketForm(request.POST)
        if form.is_valid:
            new_ticket = form.save(commit=False)
            new_ticket.ip = ip
            new_ticket.status = status
            new_ticket.client = client
            new_ticket.owner = owner
            new_ticket.assigned_by = assigned
            new_ticket.save()
            send_ticket_created_email(new_ticket)
            send_ticket_recieved_email(new_ticket)
            return HttpResponseRedirect(reverse('support:my_tickets'))

        pass
    context = {'form': form, 'profile': get_user_profile(request)}
    return render(request, 'support/create_ticket.html', context)
Esempio n. 4
0
def category(request):
    categories = Category.objects.all()
    context = {
        'categories': categories,
        'profile': get_user_profile(request.user)
    }
    return render(request, 'support/category.html', context)
Esempio n. 5
0
def create_staff_profile(request):
    """
    Creating / Editing a user profile 
    """
    #If the use has a profile, we edit that one
    profile = get_user_profile(request.user)
    try:
        userprofile = StaffProfile.objects.get(user=request.user)

        #Profile Exists, so we edit

        if request.method != 'POST':
            #Client is creating a new Profile
            form = StaffProfileForm(instance=userprofile)
        else:
            user = request.user
            form = StaffProfileForm(instance=userprofile, data=request.POST)
            if form.is_valid:
                form.save()
                return HttpResponseRedirect(reverse('support:tickets'))
    except:
        #Dealing with a new profile
        if request.method != 'POST':
            #Client is creating a new Profile
            form = StaffProfileForm()
        else:
            user = request.user
            form = StaffProfileForm(request.POST)
            if form.is_valid:
                userprofile = form.save(commit=False)
                userprofile.user = user
                userprofile.save()
                return HttpResponseRedirect(reverse('support:tickets'))
    context = {'form': form, 'profile': profile}
    return render(request, 'users/create_profile.html', context)
Esempio n. 6
0
def user_profile(request, id):
    someone = CustomUser.objects.get(id=id)
    userprofile = get_user_profile(someone)
    profile = get_user_profile(request.user)
    #We shall either create or edit a profile
    #We shall only create profiles clients, staff will create their profiles
    if userprofile:
        if request.method != 'POST':
            #Client is creating a new Profile
            form = ClientProfileForm(instance=userprofile)
        else:

            form = ClientProfileForm(instance=userprofile, data=request.POST)
            if form.is_valid:
                form.save()
                return HttpResponseRedirect(reverse('users:users'))
    else:
        #Dealing with a new profile
        if request.method != 'POST':
            #Client is creating a new Profile
            form = ClientProfileForm()
        else:

            form = ClientProfileForm(request.POST)
            if form.is_valid:
                userprofile = form.save(commit=False)
                userprofile.user = user
                userprofile.save()
                return HttpResponseRedirect(reverse('users:users'))

    context = {
        'form': form,
        'userprofile': userprofile,
        'someone': someone,
        'profile': profile
    }
    return render(request, 'users/create_client_profile.html', context)
Esempio n. 7
0
def new_priority(request):
    """
    If the client creating the ticket 
    """
    if request.method != 'POST':
        #Client is creating a new ticket
        form = PriorityForm()
    else:

        form = PriorityForm(request.POST)
        if form.is_valid:
            form.save()
            return HttpResponseRedirect(reverse('support:priority'))

        pass
    context = {'form': form, 'profile': get_user_profile(request.user)}
    return render(request, 'support/new_priority.html', context)
Esempio n. 8
0
def edit_priority(request, id):
    """
    If the client is editing a priority 
    """
    priority = Priority.objects.get(id=id)

    if request.method != 'POST':
        #Client is creating a new ticket
        form = PriorityForm(instance=priority)
    else:

        form = PriorityForm(instance=priority, data=request.POST)
        if form.is_valid:
            form.save()
            return HttpResponseRedirect(reverse('support:priority'))

        pass
    context = {
        'form': form,
        'profile': get_user_profile(request.user),
        'priority': priority
    }
    return render(request, 'support/edit_priority.html', context)
Esempio n. 9
0
def edit_status(request, id):
    """
    If the client is editing a Status 
    """
    status = Status.objects.get(id=id)

    if request.method != 'POST':
        #Client is creating a new ticket
        form = StatusForm(instance=status)
    else:

        form = StatusForm(instance=status, data=request.POST)
        if form.is_valid:
            form.save()
            return HttpResponseRedirect(reverse('support:status'))

        pass
    context = {
        'form': form,
        'profile': get_user_profile(request.user),
        'status': status
    }
    return render(request, 'support/edit_status.html', context)
Esempio n. 10
0
def edit_category(request, id):
    """
    If the client is editing a category 
    """
    category = Category.objects.get(id=id)

    if request.method != 'POST':
        #Client is creating a new ticket
        form = CategoryForm(instance=category)
    else:

        form = CategoryForm(instance=category, data=request.POST)
        if form.is_valid:
            form.save()
            return HttpResponseRedirect(reverse('support:category'))

        pass
    context = {
        'form': form,
        'profile': get_user_profile(request),
        'category': category
    }
    return render(request, 'support/edit_category.html', context)
Esempio n. 11
0
def status(request):
    statuses = Status.objects.all()
    context = {'statuses': statuses, 'profile': get_user_profile(request.user)}
    return render(request, 'support/status.html', context)
Esempio n. 12
0
def my_tickets(request):
    tickets = Ticket.objects.filter(client=request.user)
    context = {'tickets': tickets, 'profile': get_user_profile(request.user)}
    return render(request, 'support/tickets.html', context)
Esempio n. 13
0
def tickets(request):
    tickets = Ticket.objects.all()
    context = {'tickets': tickets, 'profile': get_user_profile(request.user)}
    return render(request, 'support/tickets.html', context)
Esempio n. 14
0
def users(request):
    users = CustomUser.objects.all()
    profile = get_user_profile(request.user)
    context = {'users': users, 'profile': profile}

    return render(request, 'users/users.html', context)