Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Port of pinax.apps.waitinglist

  • Loading branch information...
commit 69c90588b68e505abab78f4de8c78bc23f1f2496 1 parent d9bc262
@paltman paltman authored
View
0  waitinglist/__init__.py
No changes.
View
11 waitinglist/admin.py
@@ -0,0 +1,11 @@
+from django.contrib import admin
+
+from waitinglist.models import WaitingListEntry
+
+
+class WaitingListEntryAdmin(admin.ModelAdmin):
+ list_display = ["email", "created"]
+ search_fields = ["email"]
+
+
+admin.site.register(WaitingListEntry, WaitingListEntryAdmin)
View
23 waitinglist/forms.py
@@ -0,0 +1,23 @@
+from django import forms
+
+from waitinglist.models import WaitingListEntry
+
+
+class WaitingListEntryForm(forms.ModelForm):
+
+ class Meta:
+ model = WaitingListEntry
+
+ def clean_email(self):
+ value = self.cleaned_data["email"]
+ try:
+ entry = WaitingListEntry.objects.get(email=value)
+ except WaitingListEntry.DoesNotExist:
+ return value
+ else:
+ raise forms.ValidationError("The email address %(email)s already "
+ "registered on %(date)s." % {
+ "email": value,
+ "date": entry.created.strftime("%m/%d/%y"),
+ }
+ )
View
14 waitinglist/models.py
@@ -0,0 +1,14 @@
+import datetime
+
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+
+
+class WaitingListEntry(models.Model):
+
+ email = models.EmailField(_("email address"), unique=True)
+ created = models.DateTimeField(_("created"), default=datetime.datetime.now, editable=False)
+
+ class Meta:
+ verbose_name = _("waiting list entry")
+ verbose_name_plural = _("waiting list entries")
View
11 waitinglist/stats.py
@@ -0,0 +1,11 @@
+import datetime
+
+from waitinglist.models import WaitingListEntry
+
+
+def stats():
+ return {
+ "waiting_list_entries": WaitingListEntry.objects.count(),
+ "waitinglist_added_last_seven_days": WaitingListEntry.objects.filter(created__gt=datetime.datetime.now() - datetime.timedelta(days=7)).count(),
+ "waitinglist_added_last_thirty_days": WaitingListEntry.objects.filter(created__gt=datetime.datetime.now() - datetime.timedelta(days=30)).count(),
+ }
View
0  waitinglist/templatetags/__init__.py
No changes.
View
35 waitinglist/templatetags/waitinglist_tags.py
@@ -0,0 +1,35 @@
+from django import template
+
+from waitinglist.forms import WaitingListEntryForm
+
+
+register = template.Library()
+
+
+class WaitingListEntryFormNode(template.Node):
+
+ def __init__(self, as_varname):
+ self.as_varname = as_varname
+
+ def get_form(self, context):
+ return WaitingListEntryForm()
+
+ def render(self, context):
+ context[self.as_varname] = self.get_form(context)
+ return ""
+
+
+@register.tag
+def waitinglist_entry_form(parser, token):
+ """
+ Get a (new) form object to post a new comment.
+
+ Syntax::
+
+ {% waitinglist_entry_form as [varname] %}
+
+ """
+ bits = token.split_contents()
+ if len(bits) != 3:
+ raise template.TemplateSyntaxError("'%s' takes one 'as' argument" % bits[0])
+ return WaitingListEntryFormNode(bits[2])
View
8 waitinglist/urls.py
@@ -0,0 +1,8 @@
+from django.conf.urls.defaults import patterns, url
+from django.views.generic.simple import direct_to_template
+
+
+urlpatterns = patterns("",
+ url(r"^list_signup/$", "waitinglist.views.list_signup", name="waitinglist_list_signup"),
+ url(r"^success/$", direct_to_template, {"template": "waitinglist/success.html"}, name="waitinglist_success"),
+)
View
25 waitinglist/views.py
@@ -0,0 +1,25 @@
+from django.core.urlresolvers import reverse
+from django.http import HttpResponseRedirect
+from django.template import RequestContext
+from django.shortcuts import render_to_response
+
+from waitinglist.forms import WaitingListEntryForm
+
+
+def list_signup(request, post_save_redirect=None):
+ if request.method == "POST":
+ form = WaitingListEntryForm(request.POST)
+ if form.is_valid():
+ form.save()
+ if post_save_redirect is None:
+ post_save_redirect = reverse("waitinglist_success")
+ if not post_save_redirect.startswith("/"):
+ post_save_redirect = reverse(post_save_redirect)
+ return HttpResponseRedirect(post_save_redirect)
+ else:
+ form = WaitingListEntryForm()
+ context = {
+ "form": form,
+ }
+ context = RequestContext(request, context)
+ return render_to_response("waitinglist/list_signup.html", context)
Please sign in to comment.
Something went wrong with that request. Please try again.