示例#1
0
def contact(request):
    title = 'Contact'
    form = contactForm(request.POST or None)
    confirm_message = None
    e = Emitter("192.168.2.133:8090/contact")
    tracker = Tracker(e, namespace="sdp", app_id="sdp-11", encode_base64=False)

    if form.is_valid():
        name = form.cleaned_data['name']
        comment = form.cleaned_data['comment']
        subject = 'Message from Mysite.com'
        message = '%s %s' % (comment, name)
        emailFrom = form.cleaned_data['email']
        # emailTo = [settings.EMAIL_HOST_USER]
        emailTo = ['*****@*****.**']
        send_mail(
            subject,
            message,
            emailFrom,
            emailTo,
            fail_silently=True,
        )
        title = 'Thanks!'
        confirm_message = 'Thanks for the message, we will get right back to you.'
        form = None
        tracker.track_page_view("192.168.2.133:8090/contact")

    context = {
        'title': title,
        'form': form,
        'confirm_message': confirm_message,
    }
    template = 'contact.html'
    return render(request, template, context)
示例#2
0
unsent_events = []


def g(x, y):
    print(str(x) + " events sent successfully!")
    print("Events not sent. They have been stored in unsent_events:")

    for event_dict in y:
        print(event_dict)
        unsent_events.append(event_dict)


e = Emitter(URL, buffer_size=3, on_success=f, on_failure=g)

t = Tracker(e)

# This doesn't cause the emitter to send a request because the buffer_size was
# set to 3, not 1
t.track_page_view("http://www.myowndomainhere.dev")

# This does cause the emitter to try to send all 6 events
t.track_page_view("http://www.myowndomainhere.dev/signin")
t.track_page_view("http://www.myowndomainhere.dev/home")
t.track_page_view("http://www.myowndomainhere.dev/somepage")
t.track_page_view("http://www.myowndomainhere.dev/anotherpage")
t.track_page_view("http://www.myowndomainhere.dev/logout")

# Since the method is GET by default, 6 separate requests are sent
# If any of them are unsuccessful, they will be stored in the unsent_events
# variable