Commits

Josh VanderLinden  committed 406849d

Automatic deploy

  • Participants
  • Parent commits 935a5a8

Comments (0)

Files changed (1)

 # HG changeset patch
 # Parent af5861e14c3b9545ff4eff244d970695c6292ebe
-#111 - Initial affiliate sales work
+#111 - affiliates have to confirm their site
 
 diff --git a/satchmo/apps/payment/views/checkout.py b/satchmo/apps/payment/views/checkout.py
 --- a/satchmo/apps/payment/views/checkout.py
 new file mode 100644
 --- /dev/null
 +++ b/satchmo/apps/satchmo_ext/affiliates/forms.py
-@@ -0,0 +1,9 @@
+@@ -0,0 +1,14 @@
 +from django import forms
 +
 +from models import Affiliate
 +    class Meta:
 +        model = Affiliate
 +        fields = ('name', 'website', 'paypal_email')
++
++class ConfirmOwnershipForm(forms.Form):
++
++    confirm_code = forms.CharField(label='Confirmation code', help_text='Enter the confirmation code for your affiliate account here.')
++
 diff --git a/satchmo/apps/satchmo_ext/affiliates/listeners.py b/satchmo/apps/satchmo_ext/affiliates/listeners.py
 new file mode 100644
 --- /dev/null
 new file mode 100644
 --- /dev/null
 +++ b/satchmo/apps/satchmo_ext/affiliates/models.py
-@@ -0,0 +1,66 @@
+@@ -0,0 +1,67 @@
 +from uuid import uuid4
 +
 +from django.db import models
 +    paypal_email = models.EmailField('Your PayPal Email Address')
 +    percentage_of_sales = models.DecimalField(max_digits=8, decimal_places=2, default='25.00')
 +    commission_paid = models.DecimalField(max_digits=8, decimal_places=2, default='0.00')
-+    is_active = models.BooleanField(blank=True, default=True)
++    is_active = models.BooleanField(blank=True, default=False)
 +    uuid = models.CharField('UUID', max_length=32, default=get_uuid, help_text="This is the unique identifier that allows affiliates to view their sales statistics.")
++    confirm_code = models.CharField('Confirmation Code', max_length=32, default=get_uuid, help_text='The code that affiliates must place on their homepage in order to validate')
 +    date_added = models.DateTimeField(auto_now_add=True)
 +    date_updated = models.DateTimeField(auto_now=True)
 +
 new file mode 100644
 --- /dev/null
 +++ b/satchmo/apps/satchmo_ext/affiliates/templates/affiliates/account.html
-@@ -0,0 +1,9 @@
+@@ -0,0 +1,19 @@
 +{% extends 'base.html' %}
 +
 +{% block title %}Affiliate Account Details{% endblock %}
 +{% block content %}
 +<h1>Affiliate Account: {{ affiliate }}</h1>
 +
++{% if affiliate.is_active %}
 +<h3>Commission to date: {{ affiliate.total_commission }}</h3>
++{% else %}
++<p>Please activate your account by adding the following code to your homepage.</p>
++
++<textarea rows="5" cols="50"><!--
++{{ affiliate.confirm_code }}
++//--></textarea>
++
++<p>When you've done that, please <a href="{% url affiliate-confirm %}?confirm_code={{ affiliate.confirm_code }}">activate your account</a>.</p>
++{% endif %}
 +{% endblock %}
 diff --git a/satchmo/apps/satchmo_ext/affiliates/templates/affiliates/affiliate_form.html b/satchmo/apps/satchmo_ext/affiliates/templates/affiliates/affiliate_form.html
 new file mode 100644
 +</table>
 +</form>
 +{% endblock %}
+diff --git a/satchmo/apps/satchmo_ext/affiliates/templates/affiliates/confirm.html b/satchmo/apps/satchmo_ext/affiliates/templates/affiliates/confirm.html
+new file mode 100644
+--- /dev/null
++++ b/satchmo/apps/satchmo_ext/affiliates/templates/affiliates/confirm.html
+@@ -0,0 +1,16 @@
++{% extends 'base.html' %}
++
++{% block title %}Affiliate Account Confirmation{% endblock %}
++
++{% block content %}
++<h1>Affiliate Account Confirmation</h1>
++
++<form action="." method="post">{% csrf_token %}
++<table>
++{{ form }}
++    <tr>
++        <td colspan="2"><input type="submit" value="Confirm Account" /></td>
++    </tr>
++</table>
++</form>
++{% endblock %}
+diff --git a/satchmo/apps/satchmo_ext/affiliates/templates/affiliates/confirm_email.txt b/satchmo/apps/satchmo_ext/affiliates/templates/affiliates/confirm_email.txt
+new file mode 100644
+--- /dev/null
++++ b/satchmo/apps/satchmo_ext/affiliates/templates/affiliates/confirm_email.txt
+@@ -0,0 +1,8 @@
++Dear {{ affiliate.name }},
++
++Thank you for signing up as an affiliate of DailyVariance.com!  Before you can earn any commission as an affiliate, you must confirm your identity and ownership of {{ affiliate.website }}.  Click the link below, or enter it in your web browser's address bar, to complete the first phase of this confirmation process.
++
++http://www.dailyvariance.com{{ affiliate.get_absolute_url }}
++
++Thanks,
++DailyVariance Publishing
 diff --git a/satchmo/apps/satchmo_ext/affiliates/templates/affiliates/masspay.txt b/satchmo/apps/satchmo_ext/affiliates/templates/affiliates/masspay.txt
 new file mode 100644
 --- /dev/null
 new file mode 100644
 --- /dev/null
 +++ b/satchmo/apps/satchmo_ext/affiliates/urls.py
-@@ -0,0 +1,14 @@
+@@ -0,0 +1,10 @@
 +from django.conf.urls.defaults import *
 +
-+from forms import AffiliateForm
 +import views
 +
-+affiliates = {
-+    'form_class': AffiliateForm
-+}
-+
 +urlpatterns = patterns('django.views.generic',
 +    url(r'^(?P<uuid>[0-9a-z]{32})/$', views.affiliate_account, name='affiliate-account'),
-+    url(r'^signup/$', 'create_update.create_object', affiliates, name='affiliate-signup'),
++    url(r'^signup/confirm/$', views.confirm_ownership, name='affiliate-confirm'),
++    url(r'^signup/$', views.become_an_affiliate, name='affiliate-signup'),
 +    url(r'^$', views.affiliate_payout, name='affiliate-payments'),
 +)
 diff --git a/satchmo/apps/satchmo_ext/affiliates/views.py b/satchmo/apps/satchmo_ext/affiliates/views.py
 new file mode 100644
 --- /dev/null
 +++ b/satchmo/apps/satchmo_ext/affiliates/views.py
-@@ -0,0 +1,38 @@
+@@ -0,0 +1,114 @@
 +from datetime import date
++import urllib2
 +
++from django.contrib import messages
 +from django.contrib.admin.views.decorators import staff_member_required
-+from django.shortcuts import render_to_response, get_object_or_404
++from django.core.mail import send_mail
++from django.shortcuts import render_to_response, get_object_or_404, redirect
 +from django.template import RequestContext
++from django.template.loader import render_to_string
 +
++from forms import AffiliateForm, ConfirmOwnershipForm
 +from models import Affiliate
 +
++def become_an_affiliate(request):
++    """Allows a visitor to sign up as an affiliate"""
++
++    if request.method == 'POST':
++        form = AffiliateForm(request.POST)
++        if form.is_valid():
++            # see if this is an existing affiliate
++            try:
++                affiliate = Affiliate.objects.get(
++                    website=form.cleaned_data['website'],
++                    paypal_email=form.cleaned_data['paypal_email']
++                )
++            except Affiliate.DoesNotExist:
++                affiliate = form.save()
++            else:
++                # mark this affiliate as inactive, because they're signing up again
++                affiliate.is_active = False
++                affiliate.save()
++
++            # we probably need to send the email again even for existing affiliates
++            send_mail(
++                'Your DailyVariance Affiliate Account',
++                render_to_response('affiliates/confirm_email.txt', {
++                    'affiliate': affiliate,
++                }),
++                'support@dailyvariance.com',
++                [affiliate.paypal_email])
++
++            messages.success(request, 'Sign-up successful! You will shortly receive an email with instructions for how to proceed.')
++            return redirect('/')
++    else:
++        form = AffiliateForm()
++
++    context = RequestContext(request, {'form': form})
++
++    return render_to_response('affiliates/affiliate_form.html', context)
++
++def confirm_ownership(request):
++    """Marks an affiliate account as active"""
++
++    if request.method == 'POST':
++        form = ConfirmOwnershipForm(request.POST)
++        if form.is_valid():
++            affiliate = get_object_or_404(Affiliate, confirm_code=form.cleaned_data['confirm_code'])
++
++            try:
++                html = urllib2.urlopen('http://%s' % affiliate.website).read()
++            except:
++                affiliate.is_active = False
++                affiliate.save()
++                messages.error(request, 'Affiliate account validation failed.')
++            else:
++                print html
++                if affiliate.confirm_code in html:
++                    affiliate.is_active = True
++                    affiliate.save()
++                    messages.success(request, 'Your affiliate account has been activated!')
++                    return redirect('/')
++                else:
++                    affiliate.is_active = False
++                    affiliate.save()
++                    messages.error(request, 'Affiliate account validation failed: confirmation code not found at %s' % affiliate.website)
++    else:
++        form = ConfirmOwnershipForm(request.REQUEST)
++
++    context = RequestContext(request, {
++        'form': form,
++    })
++
++    return render_to_response('affiliates/confirm.html', context)
++
 +def affiliate_account(request, uuid):
 +    """Displays information about an affiliate's account"""
 +