コード例 #1
0
ファイル: views.py プロジェクト: ynka/django-zabaglione
def add_or_update_ticket(request, project_id, ticket_id=None):
    project = get_object_or_404(Project, pk=project_id)
    has_permissions_or_403(request.user, "change", project)
    adding = ticket_id is None
    if adding:
        ticket = Ticket(author=request.user, project=project)
    else:
        ticket = get_object_or_404(Ticket, pk=ticket_id)
    if request.method == 'POST':
        form = TicketForm(request.POST, instance=ticket, parent_project=project)
        if form.is_valid():
            ticket = form.save()
            if adding:
                ok_msg = _('Ticket creation successful')
                ticket.send_mails('create')
            else:
                ok_msg = _('Ticket update successfull')
                ticket.send_mails('update')

            messages.success(request, ok_msg)
            return HttpResponseRedirect(reverse('ticket_detail_url',
                                                kwargs={'project_id' : project.pk,
                                                        'object_id'  : ticket.pk}))
        else: # adding/updating failed
            if adding:
                fail_msg = _('Ticket creation failed. Correct errors and try again')
            else:
                fail_msg = _('Ticket update failed. Correct errors and try again')

            messages.error(request, fail_msg)
    else: # GET
        form = TicketForm(instance = ticket, parent_project=project)
    return render(request, 'core/add_ticket.html', {'tform' : form, 'project' : project})
コード例 #2
0
def create_ticket(request):
    form = CreateTicketForm(request.GET)

    if form.is_valid():
        Ticket.create(
            form.cleaned_data['origin_planned_stop'],
            form.cleaned_data['destination_planned_stop'],
            form.cleaned_data['ticket_type']
        )
        return JsonResponse({'success': True})
    else:
        return JsonResponse(form.errors)
コード例 #3
0
def manage_ticket_dev(request, ticket_id=None):
    # site_vars = utils.site_vars()
    # Common data
    common_data = common_ticket_data()
    if ticket_id:
        # Check if existis or raise 404
        ticket_rights = rights.get_rights_for_ticket(user=request.user,
                                                     queue=None,
                                                     ticket_id=ticket_id)
        if ticket_rights.can_view:
            actual_ticket = get_object_or_404(Ticket, pk=ticket_id)
            actual_files = Attachment.objects.filter(ticket_rel=ticket_id)
            actual_comments = Comments.objects.filter(
                ticket_rel=ticket_id).order_by('-id')
            actual_logs = Logs.objects.filter(
                log_ticket=ticket_id).order_by('-id')
            actual_microtasks = Microtasks.objects.filter(
                ticket_rel=ticket_id).order_by('-id')
        else:
            raise Http404(
                "You dont have enough permissions to see this ticket")
    else:
        # If not, assign a new ticket instance to be use as instance of form
        actual_ticket = Ticket()
    # POST mode
    if request.method == 'POST':
        form_ticket = TicketForm(request.POST,
                                 instance=actual_ticket,
                                 request=request,
                                 prefix="ticket")
        form_attach = AttachmentForm(request.POST,
                                     request.FILES,
                                     prefix="attach")
        if form_ticket.is_valid() and form_attach.is_valid():
            # The ticket part
            new_ticket_form = form_ticket.save(commit=False)
            new_ticket_form.create_user = request.user
            saved_ticket = new_ticket_form.save()
            # Seconf, save the attach part
            # instance = Attachment(
            # ticket_rel=new_ticket_form,file_name=request.FILES['attach-file_name'])
            # instance.save()
            if form_attach.has_changed():
                new_form_attach = form_attach.save(commit=False)
                new_form_attach.ticket_rel = new_ticket_form
                new_form_attach.save()
                if 'update-signal' in request.POST:
                    return redirect("/tickets/edit-dev/" + ticket_id + "")
                elif 'save-signal' in request.POST:
                    return redirect("/tickets")
            else:
                if 'save-signal' in request.POST:
                    return redirect("/tickets")
    else:
        # Non-POST mode, show only
        form_ticket = TicketForm(instance=actual_ticket,
                                 request=request,
                                 prefix="ticket")
        form_attach = AttachmentForm(instance=actual_ticket, prefix="attach")
    return render(request, 'tickets/create_edit_ticket.html', locals())
コード例 #4
0
ファイル: ticket.py プロジェクト: Thanh-TV/movie-theatre
 def save(cls, data, instance=None):
     try:
         customer_name = data.get('customer_name', '')
         ticket = instance if instance else Ticket()
         with transaction.atomic():
             for key, value in data.items():
                 setattr(ticket, key, value)
             if customer_name:
                 if ticket.customer_id:
                     customer = CustomerService.get(ticket.customer_id)
                 else:
                     customer = Customer()
                 customer.name = customer_name
                 customer.save()
                 ticket.customer_id = customer.id
             ticket.save()
             return ticket
     except Exception as ex:
         # todo: handle log
         raise ex
コード例 #5
0
    def post(self, request):

        data = {}
        data['campos_tipo_mensagem'] = ['Incidente', 'Requisição', 'Melhorias']
        data['nome_gabinete'] = request.POST['nome_gabinete']
        data['tipo_mensagem'] = request.POST['tipo_mensagem']
        data['assunto'] = request.POST['assunto']
        data['descricao'] = request.POST['descricao']

        campos_validados = checar_campos([request.POST['nome_gabinete'], \
            request.POST['tipo_mensagem'], request.POST['assunto'], \
            request.POST['descricao']])

        if campos_validados is True:

            novo_ticket = Ticket()

            # Checking if checkbox is checked
            if request.POST.get('enviar_anonimamente', False):
                anonimo = True
            else:
                anonimo = False

            titulo = request.POST['assunto']
            corpo_texto = request.POST.get('descricao')

            if anonimo is True:
                remetente = "Anonimo"
            else:
                remetente = request.user.get_full_name()

            tipo_ticket = request.POST['tipo_mensagem']
            arquivo_upload = None

            # Setting new ticket
            if request.user.is_authenticated() is False:

                response = render(request, 'login.html')
            else:
                novo_ticket.envio_anonimo = anonimo
                novo_ticket.titulo = titulo
                novo_ticket.corpo_texto = corpo_texto
                novo_ticket.remetente = remetente
                novo_ticket.gabinete_destino = None
                novo_ticket.tipo_ticket = tipo_ticket
                novo_ticket.file = arquivo_upload
                novo_ticket.save()
                gabinete = Gabinete.objects.get(nome_gabinete = \
                    request.POST['nome_gabinete'])
                gabinete.tickets.add(novo_ticket)
                tickets = gabinete.tickets.all()
                lista_tickets = list(tickets)

                response = render(request, 'perfil.html')

        else:
            messages.error(request, 'O campo %s não foi preenchido!' \
                % campos_ticket[campos_validados])
            gabinetes = Gabinete.objects.all()
            lista_gabinetes = list(gabinetes)
            response = render(request, 'ticket.html', locals())

        return response