[Assorted-commits] SF.net SVN: assorted:[1426] pitch-in/trunk/src/pitchin/pitchin
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-05-24 20:51:33
|
Revision: 1426 http://assorted.svn.sourceforge.net/assorted/?rev=1426&view=rev Author: yangzhang Date: 2009-05-24 20:51:27 +0000 (Sun, 24 May 2009) Log Message: ----------- ported pitch-in to django Modified Paths: -------------- pitch-in/trunk/src/pitchin/pitchin/models.py pitch-in/trunk/src/pitchin/pitchin/settings.py pitch-in/trunk/src/pitchin/pitchin/urls.py pitch-in/trunk/src/pitchin/pitchin/views.py Added Paths: ----------- pitch-in/trunk/src/pitchin/pitchin/templates/ pitch-in/trunk/src/pitchin/pitchin/templates/created.html pitch-in/trunk/src/pitchin/pitchin/templates/index.html pitch-in/trunk/src/pitchin/pitchin/templates/main.html pitch-in/trunk/src/pitchin/pitchin/templates/pool.html Modified: pitch-in/trunk/src/pitchin/pitchin/models.py =================================================================== --- pitch-in/trunk/src/pitchin/pitchin/models.py 2009-05-24 20:02:51 UTC (rev 1425) +++ pitch-in/trunk/src/pitchin/pitchin/models.py 2009-05-24 20:51:27 UTC (rev 1426) @@ -1,5 +1,5 @@ from google.appengine.ext import db -class Visitor(db.Model): - ip = db.StringProperty() - added_on = db.DateTimeProperty(auto_now_add=True) +class Pool(db.Model): + descrip = db.StringProperty() + contribs = db.BlobProperty() Modified: pitch-in/trunk/src/pitchin/pitchin/settings.py =================================================================== --- pitch-in/trunk/src/pitchin/pitchin/settings.py 2009-05-24 20:02:51 UTC (rev 1425) +++ pitch-in/trunk/src/pitchin/pitchin/settings.py 2009-05-24 20:51:27 UTC (rev 1426) @@ -1,5 +1,7 @@ # Django settings for pitchin project. +import os + DEBUG = True TEMPLATE_DEBUG = DEBUG @@ -65,10 +67,13 @@ ROOT_URLCONF = 'pitchin.urls' +ROOT_PATH = os.path.dirname(__file__) + TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. + ROOT_PATH + '/templates' ) INSTALLED_APPS = ( @@ -77,3 +82,5 @@ 'django.contrib.sessions', 'django.contrib.sites', ) + +APPEND_SLASH = False Added: pitch-in/trunk/src/pitchin/pitchin/templates/created.html =================================================================== --- pitch-in/trunk/src/pitchin/pitchin/templates/created.html (rev 0) +++ pitch-in/trunk/src/pitchin/pitchin/templates/created.html 2009-05-24 20:51:27 UTC (rev 1426) @@ -0,0 +1,12 @@ +<html> + <body> + <p> + Congrats! You've successfully created a new money pool. + Send this URL out to anyone you're inviting to + participate: + </p> + <p> + <a href="/pool?key={{key}}">http://pitch-in.appspot.com/pool?key={{key}}</a> + </p> + </body> +</html> Added: pitch-in/trunk/src/pitchin/pitchin/templates/index.html =================================================================== --- pitch-in/trunk/src/pitchin/pitchin/templates/index.html (rev 0) +++ pitch-in/trunk/src/pitchin/pitchin/templates/index.html 2009-05-24 20:51:27 UTC (rev 1426) @@ -0,0 +1,5 @@ +<html> +<body> +hi +</body> +</html> Added: pitch-in/trunk/src/pitchin/pitchin/templates/main.html =================================================================== --- pitch-in/trunk/src/pitchin/pitchin/templates/main.html (rev 0) +++ pitch-in/trunk/src/pitchin/pitchin/templates/main.html 2009-05-24 20:51:27 UTC (rev 1426) @@ -0,0 +1,23 @@ +<html> + <body> + <p style="color: red">{{error}}</p> + <p> + Using PitchIn, you can easily create and manage a money pool that others + can contribute to. + </p> + <p> + To create a pool, just enter a description of what it's for here, and you + will be provided a URL that you can distribute to the people you want to + participate in the pool. + </p> + <form action="/create" method="post"> + <div><input type="text" name="descrip"/></div> + <div><input type="submit" width="50" value="Create Pool"></div> + </form> + <p>Example descriptions:</p> + <ul> + <li>Birthday gift for Amy (we're aiming for $180 Rock Band set)</li> + <li>Holiday vacation trip</li> + </ul> + </body> +</html> Added: pitch-in/trunk/src/pitchin/pitchin/templates/pool.html =================================================================== --- pitch-in/trunk/src/pitchin/pitchin/templates/pool.html (rev 0) +++ pitch-in/trunk/src/pitchin/pitchin/templates/pool.html 2009-05-24 20:51:27 UTC (rev 1426) @@ -0,0 +1,23 @@ +<html> + <body> + <p style="color: red">{{error}}</p> + <p>Description of pool: {{descrip}}</p> + {{contribs}} + <p> + To add or update your own contribution to the pool, enter + the following information: + </p> + <form action="/pool" method="post"> + <input type="hidden" name="key" value="{{key}}"/> + <div> + <label name="name">Name:</label> + <input type="text" name="name"/> + </div> + <div> + <label name="amount">Amount:</label> + $<input type="text" name="amount"/>.00 + </div> + <div><input type="submit" value="Enter the pool!"/></div> + </form> + </body> +</html> Modified: pitch-in/trunk/src/pitchin/pitchin/urls.py =================================================================== --- pitch-in/trunk/src/pitchin/pitchin/urls.py 2009-05-24 20:02:51 UTC (rev 1425) +++ pitch-in/trunk/src/pitchin/pitchin/urls.py 2009-05-24 20:51:27 UTC (rev 1426) @@ -5,8 +5,9 @@ # admin.autodiscover() urlpatterns = patterns('', - # Example: - (r'.*', 'pitchin.views.main'), + (r'^$', 'pitchin.views.main'), + (r'^create$', 'pitchin.views.create'), + (r'^pool$', 'pitchin.views.pool'), # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: Modified: pitch-in/trunk/src/pitchin/pitchin/views.py =================================================================== --- pitch-in/trunk/src/pitchin/pitchin/views.py 2009-05-24 20:02:51 UTC (rev 1425) +++ pitch-in/trunk/src/pitchin/pitchin/views.py 2009-05-24 20:51:27 UTC (rev 1426) @@ -1,9 +1,64 @@ -from django.http import HttpResponse -from pitchin.models import Visitor +from django.http import HttpResponseRedirect +from django.shortcuts import render_to_response +from google.appengine.ext import db +from pitchin.models import Pool +import cPickle, cgi +def getPool(request): return db.get(db.Key(request.REQUEST['key'])) + +def getContribs(pool): return cPickle.loads(str(pool.contribs)) +def serContribs(contribs): return cPickle.dumps(contribs, 2) +def showContribs(pool): + contribs = getContribs(pool) + if len(contribs) == 0: + return '<p>(no participants yet)</p>' + else: + s = '<ul>' + for name, amount in contribs.iteritems(): + s += '<li>%s: $%d.00</li>' % (cgi.escape(name), amount) + s += '<li>TOTAL: $%d.00</li></ul>' % (sum(contribs.itervalues()),) + return s + +class invalid_submit(Exception): pass +def validate(pred, msg): + if not pred: raise invalid_submit(msg) + +### Views + def main(request): - visitor = Visitor() - visitor.ip = request.META["REMOTE_ADDR"] - visitor.put() - return HttpResponse( u'%s visited on %s' % (v.ip, v.added_on) - for v in Visitors.all().order('-added_on').fetch(limit=40) ) + return render_to_response('main.html') + +def create(request): + if request.REQUEST['descrip'].strip() == '': + return render_to_response('main.html', {'error': 'Must specify a description'}) + pool = Pool(descrip = request.REQUEST['descrip'], contribs = cPickle.dumps({})) + pool.put() + return render_to_response('created.html', {'key': pool.key()}) + +def pool(request): + if request.method == 'GET': return view(request) + else: return update(request) + +def view(request, error = ''): + pool = getPool(request) + return render_to_response('pool.html', + dict(error = error, + descrip = cgi.escape(pool.descrip), + contribs = showContribs(pool), + key = request.REQUEST['key'])) + +def update(request): + try: + validate(request.REQUEST['name'].strip() != '', + 'You must enter a name.') + try: amount = int(request.REQUEST['amount']) + except ValueError: raise invalid_submit('You must enter an integer dollar amount.') + except invalid_submit, ex: + return view(request, error = ex) + else: + pool = getPool(request) + contribs = getContribs(pool) + contribs[request.REQUEST['name']] = amount + pool.contribs = cPickle.dumps(contribs) + pool.put() + return HttpResponseRedirect('/pool?key=%s' % pool.key()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |