コード例 #1
0
def index(request: HttpRequest):
    errors = {}
    ticket = None
    is_valid = False
    if request.method == 'POST':
        form = TicketForm(data=request.POST)
        is_valid = form.is_valid()

        phone = request.POST.get('phone')
        name = request.POST.get('name')
        email = request.POST.get('email')

        if is_valid:
            ticket = Ticket(name, email, phone)
            ticket.save()

    else:
        form = TicketForm()

    return render(request,
                  'index.html',
                  context={
                      'errors': errors,
                      'ticket': ticket,
                      'form': form
                  })
コード例 #2
0
ファイル: test_forms.py プロジェクト: FelixTheC/ticketsystem
 def test_ticket_form_invalid(self):
     form = TicketForm(data={
         'subject': '',
         'from_email': '',
         'comment': 'help',
         'file': '',
     })
     self.assertFalse(form.is_valid())
コード例 #3
0
ファイル: test_forms.py プロジェクト: FelixTheC/ticketsystem
 def test_ticket_form_valid(self):
     staff = Staff.objects.get(name='test')
     form = TicketForm(data={
         'subject': 'test',
         'project': 1, # value=1 from select field
         'from_email': staff,
         'comment': 'help',
         'file': '',
     })
     self.assertTrue(form.is_valid())
コード例 #4
0
ファイル: views.py プロジェクト: JoeCaoV/LITReview
def add_review(request, review_id_edit=False, review_id_del=False, review_id_add=False):
    # Modifier une review
    if review_id_edit:
        review = Review.objects.get(id=review_id_edit)
        form2 = ReviewForm(instance=review)
        if request.method == 'POST':
            form2 = ReviewForm(request.POST, instance=review)
            if form2.is_valid():
                form2.save()
                return redirect('/')
        context = {'form2': form2}
        return render(request, 'review.html', context)

    if review_id_del:
        review = Review.objects.get(id=review_id_del)
        review.delete()
        return redirect('/')

    if review_id_add:
        ticket = Ticket.objects.get(id=review_id_add)
        form2 = ReviewForm()
        if request.method == 'POST':
            form2 = ReviewForm(request.POST)
            if form2.is_valid():
                form2.ticket = ticket
                form2.save()
                return redirect('/')
        context = {'form2': form2, 'ticket': ticket}
        return render(request, 'review.html', context)




    # Créer une review et son ticket
    if not review_id_edit and not review_id_del:
        ticket_form = TicketForm()
        review_form = ReviewForm()
        if request.method == 'POST':
            form1 = TicketForm(request.POST, request.FILES)
            form2 = ReviewForm(request.POST)
            if form1.is_valid() and form2.is_valid():

                set_ticket = form1.save(commit=False)
                set_ticket.user = request.user

                set_rewiew = form2.save(commit=False)
                set_rewiew.ticket = set_ticket
                set_rewiew.user = request.user

                set_ticket.save()
                set_rewiew.save()
                return redirect('/')

        context = {'form1': ticket_form, 'form2': review_form}
        return render(request, 'review.html', context)
コード例 #5
0
ファイル: views.py プロジェクト: anarix/overnite_2011
def submit_ticket(request):
    if request.method == 'POST': # If the form has been submitted...
        form = TicketForm(request.POST)
        if form.is_valid():
            ticket_obj = form.save(commit=False)
            ticket_obj.user = request.user
            ticket_obj.save()
            return HttpResponseRedirect("/ticket/%d/"%(ticket_obj.id))
    else:
        form = TicketForm()
        context = RequestContext(request)
        return render_to_response("ticket/submit_ticket.html", {"form":form}, context_instance = context)
コード例 #6
0
ファイル: views.py プロジェクト: goncha/django-ticket
def new(request):
    if request.method == 'POST':
        form = TicketForm(request.POST)
        if form.is_valid():
            instance = form.instance
            instance.creator = request.user
            instance.modifier = instance.creator
            instance.create_time = timezone.now()
            instance.modify_time = instance.create_time
            instance.save()
            return redirect(instance)
    else:
        form = TicketForm()
    return render(request, 'ticket/ticket.html', {'form': form})
コード例 #7
0
ファイル: views.py プロジェクト: fidodido/rudder
def add(request):

    template = 'ticket/add.html'
    form = TicketForm()

    memberships = Membership.objects.filter(
        user=request.user
    )

    print memberships

    if request.method == 'POST':

        form = TicketForm(request.POST)

        if form.is_valid():
            
            new_ticket = form.save()

            # ademas se debe crear una reply.
            reply = Reply()
            reply.user = request.user
            reply.ticket = new_ticket
            reply.comment = request.POST.get('description')
            reply.save()

            # ademas se debe procesar los archivos subidos.
            filenames = request.POST.getlist('filename')
            filehashes = request.POST.getlist('filehash')

            print filehashes

            i = 0
            for myfile in filenames:
                attachment = Attachment()
                attachment.reply = reply
                attachment.name = myfile
                attachment.hash = filehashes[i]
                attachment.save()
                i = i + 1

            messages.add_message(request, messages.SUCCESS, 'Your data has been successfully saved')
            return redirect('tickets_view', new_ticket.slug)
        else:
            return render(request, template, {'form': form})

    return render(request, template, {'form': form, 'memberships': memberships})
コード例 #8
0
ファイル: views.py プロジェクト: blackhand/mytickets
def event_detail(request, event_id):
    """
    this view manage the detail for and event
    """
    event = get_object_or_404(Event, id=event_id)

    if request.method == 'POST':
        form = TicketForm(event, request.POST)
        if form.is_valid():
            quantity = form.cleaned_data['quantity']
            presentation = Presentation.objects.get(
                    event = event,
                    day = form.cleaned_data['date']
                    )

            import pdb
            pdb.set_trace()

            for t in range(0,quantity):
                ticket = Ticket(
                    presentation = presentation,
                    zone = form.cleaned_data['zone'],
                    bought_by = request.user,
                    )
                ticket.save()
                zone = ticket.zone
                zone.quantity -= 1
                zone.save()

            return HttpResponseRedirect(
                    reverse(
                        'buy_sucess',
                        args=[str(presentation.id), str(zone.id)]))

    queryset = Event.objects.all()
    dates = list()
    form = TicketForm(event)
    extra_context = {
            'form': form
            }

    return object_detail(request,
            queryset = queryset,
            object_id = event_id,
            template_object_name = 'event',
            extra_context = extra_context)
コード例 #9
0
ファイル: views.py プロジェクト: goncha/django-ticket
def detail(request, ticket_id):
    instance = get_object_or_404(Ticket, pk=ticket_id)
    if request.method == 'GET':
        form = TicketForm(instance=instance)
    else:
        form = TicketForm(request.POST)
        if form.is_valid():
            new_instance = form.instance
            new_instance.pk = instance.pk
            new_instance.creator = instance.creator
            new_instance.create_time = instance.create_time
            new_instance.modifier = request.user
            new_instance.modify_time = timezone.now()
            new_instance.save()

            return redirect(form.instance)
    return render(request, 'ticket/ticket.html', {'form': form})
コード例 #10
0
ファイル: views.py プロジェクト: fidodido/rudder
def edit(request, ticket_slug):

    template = 'ticket/edit.html'
    ticket = Ticket.objects.get(slug=ticket_slug)

    form = TicketForm(instance=ticket)
    
    if request.method == 'POST':

        form = TicketForm(request.POST, instance=ticket)

        if form.is_valid():
            new_ticket = form.save()
            messages.add_message(request, messages.SUCCESS, 'Your data has been successfully saved')
            return redirect('tickets_view', new_ticket.slug)
        else:
            return render(request, template, {'form': form})

    return render(request, template, {'form': form, 'ticket': ticket})
コード例 #11
0
def send_ticket(request):
    category = Category.objects.all()
    employee = request.user.employee
    form = TicketForm(request.POST or None or request.FILES)
    category = request.POST.get('category', None)
    category_selected = Category.objects.get(id=category)
    context = {'form': form}
    if request.method == "POST":
        form.instance.employee = employee
        if form.is_valid():
            form.save()
            messages.success(
                request, f"Ticket da categoria {category_selected} \
            feito pelo funcionário {form.instance.employee} foi enviado com sucesso!"
            )
            return redirect('ticket:ticket')
        return redirect('ticket:ticket')
    context = {'form': form, 'category': category, 'employee': employee}
    return render(request, 'ticket/index.html', context)
コード例 #12
0
ファイル: views.py プロジェクト: hungrygeek/django_python
def add(request):
    if request.method =='POST':
        form = TicketForm(request.POST)
        #print repr(form.cleaned_data)
        print request.POST
        if form.is_valid():
            d = form.cleaned_data
            t = Ticket()
            t.priority = d['priority']
            t.category = d['category']
            t.summary = d['summary']
            t.filedtime = datetime.datetime.now()
            t.lasttouched = t.filedtime
            t.filedby = request.user.member
            t.origin = d['origin']
            t.status = d['status']
            t.save()
            t.punts = d['punts']
            fs = d['autofiles']
            fs = fs.split(',')
            for f in fs:
                try:
                    f = int(f)
                    af = File.objects.get(id=f)
                    t.files.add(af)
                except:
                    pass
                    
            
            t.files.add(*d['files'])
            t.assignedto.add(*d['assignedto'])
            t.save()
            #print repr(form.cleaned_data)
            return HttpResponseRedirect(('/tickets/'+str(t.id)+'/'))
            return detail(request, t.id)
    else:
        form = TicketForm()
    return newticket(request,form)
コード例 #13
0
ファイル: views.py プロジェクト: johnpgarza/handy
def ticket_new(request):
    if request.method == "POST":
        form = TicketForm(request.POST)
        if form.is_valid():
            ticket = form.save(commit=False)
            ticket.save()
            return redirect('ticket_list')
    else:
        form = TicketForm()
    return render(request, '../templates/ticket_new.html', {'form': form})
コード例 #14
0
def submit_ticket(request):
    if request.method == 'POST':  # If the form has been submitted...
        form = TicketForm(request.POST)
        if form.is_valid():
            ticket_obj = form.save(commit=False)
            ticket_obj.user = request.user
            ticket_obj.save()
            return HttpResponseRedirect("/ticket/%d/" % (ticket_obj.id))
    else:
        form = TicketForm()
        context = RequestContext(request)
        return render_to_response("ticket/submit_ticket.html", {"form": form},
                                  context_instance=context)
コード例 #15
0
def submit_ticket(request):
    if request.method == 'POST': # If the form has been submitted...
        form = TicketForm(request.POST)
        if form.is_valid():
            ticket_obj = form.save(commit=False)
            ticket_obj.user = request.user
            ticket_obj.save()
            message = "<hr/>You have new ticket<br/>****<b> %s</b> ****<br/>from<b> %s</b>"%(ticket_obj.query[:100], ticket_obj.user.username)
            for u in User.objects.filter(is_superuser=True):
                ta = TicketAlert(ticket=ticket_obj, user=u, read=False, message = message)
                ta.save()
            return HttpResponseRedirect("/ticket/%d/"%(ticket_obj.id))
    else:
        form = TicketForm()
        context = RequestContext(request)
        return render_to_response("ticket/submit_ticket.html", {"form":form}, context_instance = context)
コード例 #16
0
def index_ticket(request):
    category = Category.objects.all()
    form = TicketForm(request.POST or None)
    context = {'category': category, 'form': form}
    return render(request, 'ticket/index.html', context)