예제 #1
0
def CrmTicket(request):
    """ Retrieves an individual CRM Ticket. """

    context = {'initialize':''}
    constants = settings.CONSTANTS
    ticketid = request.REQUEST.get("ticketid", "")     

    if request.method == 'POST':  
        form = NewTicketForm(request.POST)
        if form.is_valid():
            ticket = {}
            ticket['title'] = form.cleaned_data.get('title')
            ticket['description'] = form.cleaned_data.get('description')
            if ticketid == "": 
                ticket['*****@*****.**'] = 'contacts(' + request.user.userprofile.crmid + ')'

            json_data = json.dumps(ticket)

            headers = {'OData-MaxVersion': '4.0',
                    'OData-Version': '4.0',
                    'Content-Type': 'application/json; charset=utf-',
                    'Authorization': 'Bearer ' + request.session['token'],
                    'accept': 'application/json'
                    }

            if ticketid == "": #New
                response = requests.post(constants['RESOURCE_URI'] + '/api/data/incidents', data=json_data, headers=headers)
            else: #Update
                response = requests.patch(constants['RESOURCE_URI'] + '/api/data/incidents(' + ticketid + ')', data=json_data, headers=headers)

        return HttpResponseRedirect('CrmTickets.html')
    else:
        if ticketid == "": 
            #New form
            form = NewTicketForm()
        
            return render(request, 'app/CrmTicket.html', {'form': form, 'is_new': True})
        else: 
            headers = {'OData-MaxVersion': '4.0',
               'OData-Version': '4.0',
               'Accept': 'application/json',
               'Authorization': 'Bearer ' + request.session['token'],
               'Prefer': 'odata.include-annotations="mscrm.formattedvalue"'
              }

            response = requests.get(constants['RESOURCE_URI'] + '/api/data/incidents(' + ticketid + ')?$select=ticketnumber,title,description', headers=headers)

            item_dict = json.loads(response.text)
        
            form = NewTicketForm({
                'title': item_dict['title'],
                'description': item_dict['description']
                })

            return render(request, 'app/CrmTicket.html', {'form': form, 'is_new': False, 'ticketnumber': item_dict['ticketnumber']})
예제 #2
0
 def post(self, request, id):
     form = NewTicketForm(request.POST)
     if form.is_valid():
         t = Ticket.objects.create(
             name=form.cleaned_data["name"],
             showing_id=form.cleaned_data["showing_id"],
             purchased_at=datetime.now(),
         )
         return redirect("ticket_detail", t.id)
     else:
         form = NewTicketForm()
         return render(request, "new_ticket.html", {"movie": purchase, "form": form})
예제 #3
0
 def post(self, request, id):
     form = NewTicketForm(request.POST)
     if form.is_valid():
         show_id = request.POST["showing_id"]
         showing = Showing.objects.get(id=show_id)
         ticket = Ticket.objects.create(
             name=request.POST["name"], 
             showing=showing
         )
         return redirect("ticket_detail", ticket.id)
     else:
         movie = Movie.objects.get(id=id)
         form = NewTicketForm()
         return render(request, "new_ticket.html", {"movie": movie, "form": form})
예제 #4
0
def new_ticket(request, id):
    movie = Movie.objects.get(id=id)
    form = NewTicketForm(request.POST)
    if request.method == "GET":
        return render(request, "new_ticket.html", {"movie": movie, "form": form})
    elif request.method == "POST":
        if form.is_valid():
            name = form.cleaned_data["name"]
            showing_id = form.cleaned_data["showing_id"]
            new_ticket = Ticket.objects.create(
                name=name, purchased_at=datetime.now(), showing_id=showing_id
            )
            new_ticket.save()
            return redirect("ticket_detail", new_ticket.id)
        else:
            return render(request, "new_ticket.html", {"movie": movie, "form": form})
예제 #5
0
 def get(self, request, id):
     purchase = Movie.objects.get(id=id)
     forms = NewTicketForm()
     return render(request, "new_ticket.html", {"movie": purchase, "form": forms})
예제 #6
0
def CrmTicket(request):
    """ Retrieves an individual CRM Ticket. """

    context = {'initialize': ''}
    constants = settings.CONSTANTS
    ticketid = request.REQUEST.get("ticketid", "")

    if request.method == 'POST':
        form = NewTicketForm(request.POST)
        if form.is_valid():
            ticket = {}
            ticket['title'] = form.cleaned_data.get('title')
            ticket['description'] = form.cleaned_data.get('description')
            if ticketid == "":
                ticket[
                    '*****@*****.**'] = 'contacts(' + request.user.userprofile.crmid + ')'

            json_data = json.dumps(ticket)

            headers = {
                'OData-MaxVersion': '4.0',
                'OData-Version': '4.0',
                'Content-Type': 'application/json; charset=utf-',
                'Authorization': 'Bearer ' + request.session['token'],
                'accept': 'application/json'
            }

            if ticketid == "":  #New
                response = requests.post(constants['RESOURCE_URI'] +
                                         '/api/data/incidents',
                                         data=json_data,
                                         headers=headers)
            else:  #Update
                response = requests.patch(constants['RESOURCE_URI'] +
                                          '/api/data/incidents(' + ticketid +
                                          ')',
                                          data=json_data,
                                          headers=headers)

        return HttpResponseRedirect('CrmTickets.html')
    else:
        if ticketid == "":
            #New form
            form = NewTicketForm()

            return render(request, 'app/CrmTicket.html', {
                'form': form,
                'is_new': True
            })
        else:
            headers = {
                'OData-MaxVersion': '4.0',
                'OData-Version': '4.0',
                'Accept': 'application/json',
                'Authorization': 'Bearer ' + request.session['token'],
                'Prefer': 'odata.include-annotations="mscrm.formattedvalue"'
            }

            response = requests.get(constants['RESOURCE_URI'] +
                                    '/api/data/incidents(' + ticketid +
                                    ')?$select=ticketnumber,title,description',
                                    headers=headers)

            item_dict = json.loads(response.text)

            form = NewTicketForm({
                'title': item_dict['title'],
                'description': item_dict['description']
            })

            return render(
                request, 'app/CrmTicket.html', {
                    'form': form,
                    'is_new': False,
                    'ticketnumber': item_dict['ticketnumber']
                })