#! /usr/bin/env python _VERSION = "$Id: update.py 1212 2011-01-19 13:43:26Z darcy $" _MODDATE = "$Date: 2011-01-19 08:43:26 -0500 (Wed, 19 Jan 2011) $"[7:-2] import sys, pg, os, string from DB_ride import * db = DB_ride() #db.debug = "
%s
" print """content-type: text/html Ontario Motorcycle Rides Update Page

Ontario Motorcycle Rides Update Page

""" def send_changes(ride, diffs): fp = os.popen("/usr/sbin/sendmail -i -t", "w") fp.write("To: darcy@BikeRides.ca\n") fp.write("From: darcy@BikeRides.ca\n") if ride['email']: fp.write("Cc: %s\n" % ride['email']) if new_ride['email'] and new_ride['email'] != ride['email']: fp.write("Cc: %s\n" % new_ride['email']) fp.write("Reply-to: darcy@BikeRides.ca\n") fp.write("Subject: Change request confirmation: %s\n" % ride['name']) fp.write("\n") fp.write("Request Received to change ride ID %s\n\n" % ride['ride_id']) for x in ride.keys(): if ride[x] == None: ride[x] = '' if x in ('ride_id','club_id','ride_active','oid(public.ride)'): pass else: fp.write("%-10s %s\n" % (x+":", diffs.get(x, ride[x]))) fp.write("\n-- \nD'Arcy J.M. Cain \n") fp.write("http://www.BikeRides.ca/\n") del fp cmd = os.path.basename(sys.argv[0]) if cmd == 'update.py': if len(sys.argv) < 2: print """This page should be called with the reference number to update. The easiest way to do this is to go to the full listing of rides and click on the "Update" button of the ride you would like to update.""" else: print """This page allows you to send update requests to the maintainer. Indicate your changes below and submit the entry for updating.

IMPORTANT: In the spam check box you should add the number seventeen to the ride ID. This is to help us block spamming robots.""" try: ride = db.get('ride', sys.argv[1]) except pg.DatabaseError, value: print "

No ride number found: %s" % sys.argv[1] else: for k in ride.keys(): if ride[k] == None and k[0] != '_': ride[k] = "" print """

Current entry

Ride ID:%(ride_id)s
Spam check: (Add seventeen to %(ride_id)s)
Name:
From date:
To date (if different):
Contact:
Phone (with area code):
Email:
URL:
""" % ride else: import cgi form = cgi.FieldStorage() try: ride_id = int(form['ride_id'].value) except KeyError: ride_id = 0 try: ride = db.get('ride', ride_id) except: print "

No ride referenced by %s: %s" % (ride_id, sys.exc_value) else: try: spamcheck = int(form['spamcheck'].value) - 17 except: spamcheck = -1 if spamcheck != ride['ride_id']: print """

Sorry, you passed the Turing test and thus failed the anti-spam test. Try again.""" else: new_ride = {} if ride.has_key('oid_ride'): del ride['oid_ride'] for f in ride.keys(): if form.has_key(f): new_ride[f] = form[f].value else: new_ride[f] = "" print """

New entry

Ride ID:%(ride_id)s
Name:%(name)s
From:%(from_date)s
To:%(to_date)s
Contact:%(contact)s
Phone:%(phone)s
Email:%(email)s
URL:%(url)s
""" % new_ride diffs = {} for x in ride.keys(): if ride[x] == None: ride[x] = '' if x in ('ride_id','club_id','ride_active','oid(public.ride)'): pass elif ride[x] != new_ride[x]: diffs[x] = "%-30s (Was: %s)" % (new_ride[x], ride[x]) if diffs: try: send_changes(ride, diffs) except: print "Internal error: %s
" % sys.exc_value else: print "

Change request sent to maintainer" else: print "

No changes entered." print """


Created and Maintained by D'Arcy J.M. Cain <darcy@BikeRides.ca>
$Id: update.py 1212 2011-01-19 13:43:26Z darcy $
If you have any comments please Send mail to me.

For those that care about these things, here is the Python script that generated this page.


\[Powered by Python] \[Apache logo]
"""