def get_ticket(request): filmid=request.GET.get('filmid','') tickets=long(request.POST['number_of_tickets']) film=Film.objects.get(film_id__exact=filmid) hallid=film.hall_id film_hall=Hall.objects.get(hall_id__exact=hallid) total_seats=film_hall.total_seats seats_allocated=film_hall.total_seats_allocated seats_available=total_seats - seats_allocated amount_payable=tickets*film.ticket_charge user=User.objects.get(username__exact=request.user) enduser=EndUser.objects.using('remote').get(user_id__exact=user.id) if(enduser.credits < amount_payable): return render_to_response('no_credits.html',{"film": Film.objects.get(film_id__exact=filmid) },context_instance=RequestContext(request)) if(seats_available<tickets): return render_to_response('no_seats.html',{"film": Film.objects.get(film_id__exact=filmid) },context_instance=RequestContext(request)) else: film_hall.total_seats_allocated +=tickets film_hall.save() enduser.credits-=amount_payable enduser.save(using='remote') ticket=Ticket(film_name=film.film_name,end_user=request.user,purchase_datetime=now,ticket_amount=amount_payable) ticket.save() return render_to_response('download_ticket.html',{"film":film,"filmid":filmid,"user":user.id,"date":now,"amount":amount_payable, 'credits':amount_payable, 'remain':enduser.credits},context_instance=RequestContext(request))
def customer_service_add_ticket(request): customerservice_user_id = request.session.get('customerservice_user_id', None) customer_service = request.session.get('customer_service', None) if customerservice_user_id and customer_service: template = "customerservice/customerservice_add_ticket.html" context = dict() if request.POST: form = ticket_form.TicketForm(request.POST) if form.is_valid(): f_c_d = form.cleaned_data device_id = request.session.get('device_id', None) if device_id: device = Device.objects.get(pk=device_id) ticket = Ticket(problem_title = f_c_d['problem_title'], problem_description = f_c_d['problem_description'],\ status = f_c_d['status'], device_concerned = device) ticket.save() return HttpResponse("Good job adding this ticket") else: return HttpResponse( "There is no device to add a problem to") else: return HttpResponse("The form is invalid") else: form = ticket_form.TicketForm() context['form'] = form return render(request, template, context) else: response_redirect_url = reverse('customer_service_login') return HttpResponseRedirect(response_redirect_url)
def buy(request, id): # print(request.path_info.split("/buy/")[0]+"/buy/",type(request.path_info),'------------') ids = request.GET['id_str'] id_li = ids.split(" ") schedule = get_object_or_404(Schedule, id=id) seats = [get_object_or_404(Seat, id=int(seat_id)) for seat_id in id_li] if request.method == 'POST': with transaction.atomic(): save_id = transaction.savepoint() order = Order() money = len(seats) * schedule.ticket_money order.money = money order.schedule = schedule order.save() for seat in seats: if seat.status: if seat.ticket_set.filter(schedule=schedule): print('=-=---===========================') transaction.savepoint_rollback(save_id) # raise # return JsonResponse({'res':5, 'errmsg':'错误'}) messages.info(request, "您选的座位已被购买,请重选!") return redirect( reverse('ticket_seat', args=(schedule.id, ))) seat.status = True seat.save() schedule.ticket_counts -= 1 schedule.save() # order.save() ticket = Ticket(schedule=schedule, seat=seat, order=order) ticket.save() transaction.savepoint_commit(save_id) return render(request, 'ticket/ok.html') # order_time = (datetime.datetime.now() + datetime.timedelta(minutes=1)).replace(tzinfo=pytz.timezone('UTC')) # print(order_time,'-----') # request.session['order_time'] = datetime.datetime.now() # request.session.set_expiry(60) return render( request, 'ticket/order.html', context={ 'schedule': schedule, 'seats': seats, 'ids': ids, # 'order_time':order_time })
def carShopSecurity(request): template_name = 'shop/car_shop_security.html' items = request.POST.getlist('item', []) queryset = Item.objects.filter(pk__in=items) epayco = EpayCo.objects.first() ticket = Ticket() ticket.total = queryset.aggregate(Sum('price'))['price__sum'] ticket.status = Status(Status.PENDING) ticket.save() ticket.items.set(queryset) p_description = 'demo-app-co ePayCo' p_cust_id_cliente = epayco.client_id p_key = epayco.p_key p_id_invoice = '%s' % ticket.pk p_amount = '%s' % ticket.total p_currency_code = epayco.p_currency_code signature = '{0}^{1}^{2}^{3}^{4}'.format(p_cust_id_cliente, p_key, p_id_invoice, p_amount, p_currency_code) h = hashlib.md5() h.update(signature.encode('utf-8')) p_signature = h.hexdigest() p_tax = 0 p_amount_base = 0 p_test_request = 'TRUE' if epayco.test else 'FALSE' p_url_response = epayco.url_response p_url_confirmation = epayco.url_confirmation context = { 'p_cust_id_cliente': p_cust_id_cliente, 'p_key': p_key, 'p_id_invoice': p_id_invoice, 'p_amount': p_amount, 'p_currency_code': p_currency_code, 'p_signature': p_signature, 'p_tax': p_tax, 'p_amount_base': p_amount_base, 'p_test_request': p_test_request, 'p_url_response': p_url_response, 'p_url_confirmation': p_url_confirmation, 'p_description': p_description } return render_to_response(template_name, context)
def tick(request): ticket = Ticket(fname=request.POST['firstName'], lname=request.POST['lastName'], email=request.POST['email'], age=request.POST['age'], gender=request.POST['gr'], country=request.POST['country'], city=request.POST['city'], pincode=request.POST['pincode'], number='5522') ticket.save() return redirect('/ticket')
def get_ticket(request): amount_payable=int(request.GET.get('amount','')) filmid=request.GET.get('filmid','') film=Film.objects.get(film_id__exact=filmid) user=User.objects.get(username__exact=request.user) enduser=EndUser.objects.get(user_id__exact=user.id) if(enduser.credits < amount_payable): return HttpResponse("No Enough Credits") else: enduser.credits-=amount_payable enduser.save() ticket=Ticket(film_name=film.film_name,end_user=request.user,purchase_datetime=now,ticket_amount=amount_payable) ticket.save() return render_to_response('download_ticket.html',{"filmid":filmid,"user":user.id,"date":now,"amount":amount_payable},context_instance=RequestContext(request))
def update(self, validated_data): instance = Ticket() instance.code = validated_data.get('code') instance.title = validated_data.get('title') instance.date = validated_data.get('date') instance.startTime = validated_data.get('startTime') instance.endTime = validated_data.get('endTime') instance.address = validated_data.get('address') instance.detail = validated_data.get('detail') instance.created_at = validated_data.get('created_at') instance.modify_at = validated_data.get('modify_at') instance.url_img = validated_data.get('url_img') instance.save() return instance
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)
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)
def handle(self, *args, **options): helper = MiscHelper() for schedule_id in args: try: schedule = Schedule.objects.get(pk=int(schedule_id)) ticket_type = TicketType.objects.all()[:1].get() except Schedule.DoesNotExist: raise CommandError('Lich "%s" khong ton tai' % schedule_id) total_row = helper.get_alphabet(schedule.room.total_row) total_column = schedule.room.total_column for row in total_row: for column in range(1, total_column + 1): ticket = Ticket( row=row, column=column, schedule=schedule, ticket_type=ticket_type ) ticket.save() self.stdout.write('Successfully create tickets for schedule "%s"' % schedule_id)
def create_event(request,id): is_signed_in = request.user.is_authenticated() is_admin = request.user.is_superuser djangouser = models.User.objects.filter(username=request.user.username) type1 = Type.objects.filter(id=id) typename=type1.values_list('name')[0][0] subs = Subtype.objects.filter(type=type1) if not is_admin: myuser = User.objects.filter(user=djangouser)[0] else: myuser=None if not is_admin: if myuser.userType=='owner': if request.method == 'POST': name = request.POST['event_name'] # picture = request.POST['files[]'] ticket_num = request.POST['event_ticket'] desc = request.POST['info'] date = request.POST['datepicker'] deadline = request.POST['datepicker1'] place = request.POST['event_place'] type = type1.values_list('name')[0][0] sub_type = request.POST['genre'] address = request.POST['event_addr'] ticket_price = request.POST['event_price'] duration = '2.0' event = Event(name=name,picture=None,ticket_num=ticket_num,desc=desc,date=date,deadline=deadline,place=place,type=type,sub_type=sub_type,address=address,ticket_price=ticket_price,duration=duration, rate=0,owner=myuser,available_tickets=ticket_num) event.save() for i in range(int(ticket_num)): ticket = Ticket(price=ticket_price,type='Normal',seat_num=i,event=event,buy=None,free=0) ticket.save(); return render(request, 'event-adder.html',{'guest': not is_signed_in, 'signed_in': is_signed_in, 'admin': is_admin, 'id':id,'type':typename,'subtypes':subs}) else: return redirect('/main/') else: return render(request, 'event-adder.html',{'guest': not is_signed_in, 'signed_in': is_signed_in, 'admin': is_admin, 'id':id,'type':typename,'subtypes':subs})
def email2ticket(string): """ Parse un mail et crée ou modifie le ticket concerné """ errors = [] mail = email.message_from_string(string) cur = None match = pattern_from.search(mail.get('From', '')) mail_from = mail.get('Return-Path', mail.get('Reply-To', match.groups()[0] if match else None)) references = mail.get('References', '').split() if not references: references = mail.get('In-Reply-To', '').split() if references: ticket = Ticket.objects.get(message_id__in=references) else: ticket = Ticket() # Get first part for part in mail.walk(): if part.get_content_type() in ('text/html', 'text/plain'): cur = part break if cur is None: return send_error(mail_from, ['Impossible de parser le message']) content = cur.get_payload(decode=True) if cur.get_content_type() == 'text/html': enc = cur.get_charsets()[0] content = content.decode(enc, 'ignore') content = html2text(content) match = pattern_body.search(content) if not match: errors.append('Contenu vide ou non encadré par [contenu][/contenu]') content = None else: content = match.groups()[0] user = User.objects.get(pk=settings.EMAIL_USER_PK) if references and content: # New comment form = type("", (), {})() form.cleaned_data = {'comment': content, 'internal': False} form.instance = ticket request = type("", (), {})() request.user = user post_comment(form, request) print "Ticket commenté ", ticket.pk elif not references: # New ticket try: subject = mail.get('Subject', '') match = pattern_subject.search(subject) ticket.client = Client.objects.get(pk=match.groups()[0]) subject = subject[match.span()[1]:] ticket.title = " ".join([part[0].decode(part[1] or 'utf8') for part in email.header.decode_header(subject)]) except: errors.append('Impossible de parser le sujet, client invalide ou sujet mal formé') if errors: send_error(mail_from, errors) else: ticket.message_id = mail.get('Message-ID', None) ticket.opened_by = user ticket.state = State.objects.get(pk=settings.TICKET_STATE_NEW) ticket.category = Category.objects.get(pk=settings.EMAIL_TICKET_CATEGORY_DEFAULT) ticket.text = content ticket.save() print "Ticket crée : ", ticket.pk elif errors: send_error(mail_from, errors) # Get attachements for part in mail.walk(): filename = part.get_filename() content_type = part.get_content_type() if filename and content_type in settings.IMAP_ALLOWED_CONTENT_TYPES: ticket_file = TicketFile(ticket=ticket, filename=filename, content_type=content_type, data=part.get_payload(decode=True)) ticket_file.save()