Ejemplo n.º 1
0
def ticket(request):
    try:
        mail = Setup.objects.first().email
    except:
        mail = False
    if mail:
        recepient = mail
    else:
        recepient = '*****@*****.**'

    form = TicketForm(request.POST or None)
    if form.is_valid():
        name = form.cleaned_data['name']
        phone = form.cleaned_data['phone']
        ticket = Ticket(name=name, phone=phone, text = u'')
        ticket.save()

        send_mail(
            u'vlifte.pro - Заявка с сайта',
            u'Имя: %s\nТелефон: %s\n' % (name, phone),
            settings.DEFAULT_FROM_EMAIL,
            [recepient, ]
        )
        return {'success': 'Сообщение успешно отправлено!'}
    else:
        return {'error': 'Сообщение не может быть отправлено!'}
Ejemplo n.º 2
0
def ticket(request):
    try:
        mail = Setup.objects.first().email
    except:
        mail = False
    if mail:
        recepient = mail
    else:
        recepient = '*****@*****.**'

    form = TicketForm(request.POST or None)
    if form.is_valid():
        name = form.cleaned_data['name']
        phone = form.cleaned_data['phone']
        ticket = Ticket(name=name, phone=phone, text=u'')
        ticket.save()

        send_mail(u'vlifte.pro - Заявка с сайта',
                  u'Имя: %s\nТелефон: %s\n' % (name, phone),
                  settings.DEFAULT_FROM_EMAIL, [
                      recepient,
                  ])
        return {'success': 'Сообщение успешно отправлено!'}
    else:
        return {'error': 'Сообщение не может быть отправлено!'}
Ejemplo n.º 3
0
    def create(self, request, *args, **kwargs):
        serializer = self.serializer_class_post(data=request.data)
        if serializer.is_valid(
        ) and 'multipart/form-data' in request.content_type:

            err = self._check_file_type(serializer.validated_data['ticket'])
            if err:
                return err

            ticket_file = serializer.validated_data['ticket']

            # process file
            data_from_ticket = ticket_utils.process_ticket(ticket_file)

            try:
                qr_code = ticket_utils.extract_qr_code(ticket_file)
                base64_encoded_qr_code_str = ticket_utils.pil_image_to_base64(
                    qr_code)
            except ValueError:
                base64_encoded_qr_code_str = None

            car_info = VagonInformation(
                train_number=data_from_ticket['train_number'])
            data_from_ticket['car_info'] = car_info.final_data

            data_from_ticket['qr_code'] = base64_encoded_qr_code_str

            closed_station_at_arrival = data_from_ticket["finish_time"].time(
            ) > datetime.strptime("23:00", "%H:%M").time()
            # arrival_station_open_hours = open_hours[data_from_ticket["finish_place"]]
            # if not arrival_station_open_hours:
            #     open_end = datetime.strptime(arrival_station_open_hours[1], "%H:%M")
            #     closed_station_at_arrival = open_end.time() < data_from_ticket["finish_time"].time()
            data_from_ticket[
                'closed_station_at_arrival'] = closed_station_at_arrival

            ticket = Ticket(**data_from_ticket)
            ticket.save()

            return Response(self.serializer_class(ticket).data,
                            status=status.HTTP_200_OK)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 4
0
def calculator(request):
    try:
        mail = Setup.objects.first().email
    except:
        mail = False
    if mail:
        recepient = mail
    else:
        recepient = '*****@*****.**'
    CalcFormSet = formset_factory(CalculatorForm)
    if request.method == "POST":
        form = TicketForm(request.POST)
        calc_formset = CalcFormSet(data=request.POST)
        if calc_formset.is_valid() and form.is_valid():
            cd = calc_formset.cleaned_data
            cd_form = form.cleaned_data
            text_name = u'Заявка: \nИмя: %s\nТелефон: %s\n' % (
                cd_form['name'], cd_form['phone'])
            text_form = ''
            # print cd

            for i in cd:
                # text_form = text_form + i['city'].name + ': ' + i['format'].name + '\n'
                if i:
                    text_form = text_form + i['city'].name + ': ' + i[
                        'format'].name + '\n'
            text = text_name + text_form

            ticket = Ticket(name=cd_form['name'],
                            phone=cd_form['phone'],
                            text=text)
            ticket.save()

            send_mail(u'vlifte.pro - Заказ рекламы с сайта', text,
                      settings.DEFAULT_FROM_EMAIL, [
                          recepient,
                      ])
            return HttpResponseRedirect('/')
    else:
        calc_formset = CalcFormSet()
        form = TicketForm()
    return HttpResponseRedirect('/')
Ejemplo n.º 5
0
def calculator(request):
    try:
        mail = Setup.objects.first().email
    except:
        mail = False
    if mail:
        recepient = mail
    else:
        recepient = '*****@*****.**'
    CalcFormSet = formset_factory(CalculatorForm)
    if request.method == "POST":
        form = TicketForm(request.POST)
        calc_formset = CalcFormSet(data=request.POST)
        if calc_formset.is_valid() and form.is_valid():
            cd = calc_formset.cleaned_data
            cd_form = form.cleaned_data
            text_name = u'Заявка: \nИмя: %s\nТелефон: %s\n' % (cd_form['name'], cd_form['phone'])
            text_form = ''
            # print cd


            for i in cd:
                # text_form = text_form + i['city'].name + ': ' + i['format'].name + '\n'
                if i:
                    text_form = text_form + i['city'].name + ': ' + i['format'].name + '\n'
            text = text_name + text_form

            ticket = Ticket(name=cd_form['name'], phone=cd_form['phone'], text = text)
            ticket.save()

            send_mail(
                u'vlifte.pro - Заказ рекламы с сайта',
                text,
                settings.DEFAULT_FROM_EMAIL,
                [recepient, ]
            )
            return HttpResponseRedirect('/')
    else:
        calc_formset = CalcFormSet()
        form = TicketForm()
    return HttpResponseRedirect('/')
Ejemplo n.º 6
0
def promo_ticket(request):
    name = request.POST.get('name', '')
    phone = request.POST.get('phone', '')
    mail = request.POST.get('mail', '')
    theme = request.POST.get('theme', '')
    r_city = request.POST.get('city', None)
    logger.error(u'name: %s, phone: %s, mail: %s, theme: %s, city: %s' %
                 (name, phone, mail, theme, r_city))
    if r_city:
        city = get_object_or_None(City, id=int(r_city))
        if city:
            ticket = Ticket(city=city, promo=True)
            if name:
                ticket.name = name
            if phone:
                ticket.phone = phone
            if mail:
                ticket.mail = mail
            ticket.save()
            return {
                'success': True,
                'name': name,
                'phone': phone,
                'mail': mail,
                'theme': theme,
                'city': city.name,
            }
        else:
            return {
                'success': False,
                'message': u'Not city found'
            }
    return {
        'success': False,
    }
Ejemplo n.º 7
0
def hanger_ticket(request):
    name = request.POST.get('name') or ''
    phone = request.POST.get('phone') or ''
    mail = request.POST.get('mail') or ''
    theme = request.POST.get('theme') or ''
    city_name = request.POST.get('city') or ''
    logger.error(u'name: %s, phone: %s, mail: %s, theme: %s, city_name: %s' %
                 (name, phone, mail, theme, urllib.unquote(city_name)))
    if city_name:
        city = City.objects.filter(name=urllib.unquote(city_name)).first()
        if city:
            moderator = city.moderator_set.filter(stand_accept=True).first()
            if moderator:
                ticket = Ticket(city=city, moderator=moderator, hanger=True)
                if name:
                    ticket.name = name
                if phone:
                    ticket.phone = phone
                if mail:
                    ticket.mail = mail
                ticket.save()
                try:
                    theme = u'Заявка с сайта hanger-reklama.com'
                    mail_title_msg = u'Новая заявка на сайте reklamadoma.com'
                    message = u'Тема: %s\nИмя: %s\nТелефон: %s\n' % (theme, ticket.name, ticket.phone)
                    send_mail(
                        mail_title_msg,
                        message,
                        settings.DEFAULT_FROM_EMAIL,
                        [ticket.moderator.user.email, ]
                    )
                except:
                    pass
                return {
                    'success': True,
                    'name': name,
                    'phone': phone,
                    'mail': mail,
                    'theme': theme,
                    'city': city.name,
                    'moderator': moderator.__unicode__()
                }
            else:
                return {
                    'success': False,
                    'message': u'Not moderator found'
                }
        else:
            return {
                'success': False,
                'message': u'Not city found'
            }
    return {
        'success': False,
    }