def _payments(): page = "Money / Payments" content = "<table>" content += """ <tr> <td>ID</td> <td>Member ID</td> <td>Description</td> <td>Date</td> <td>Credit</td> <td>Debit</td> </tr> """ q = _session.query(_Payment).all() for i in q: content += "<tr>" for j in (i.id, i.member_id, i.description, i.date, i.credit, i.debit): content += "<td>%s</td>\n" % j content += """ <td> <a href='%s'>Modify</a> <a href='%s'>Delete</a> </td>\n""" % ((_ + "/modify/%d" % i.id), (_ + "/delete/%d" % i.id)) content += "</tr>" content += "</table>\n" return template_index(_root, page, content)
def _delete_post(): # TODO: add integrity checks to Payment db :D num = int(request.forms.get('num')) q = _session.query(_Member).filter(_Member.id == num).all() content = "" if len(q) > 0: _session.delete(q[0]) content = "Member %s deleted." % num else: content = "<p>How did you get here?</p>" content += "<p><a href='%s'>Membership</a></p>" % (_) page = "Membership / Delete Member" _logger.info("Member '%s' deleted." % num) return template_index(_root, page, content)
def _types_add(): t = request.forms.get("type") d = request.forms.get("duration") c = request.forms.get("cost") q = _session.query(_Membership_Type).filter(_Membership_Type.type==t).all() content = "" if len(q) > 0: content = "<p>'%s' already in use.</p>\n" % t else: mt = _Membership_Type(t, d, c) _session.add(mt) content = "<p>'%s' added successfully.</p>\n" % t content += "<p><a href='%s'>Back</a></p>" % (_ + "/types") page = "Membership / Manage Membership Types / Add" _logger.info("New membership type '%s' added." % t) return template_index(_root, page, content)
def _add_post(): m = _Member() for key, value in request.forms.items(): if key == "password": setattr(m, key, hash(value)) elif key != "submit": setattr(m, key, value) _session.add(m) page = "Membership / Add Member" content = """ <p>Member added successfully.</p> <br /> <a href='%s'>Back</a> """ % _ _logger.info("Member added.") return template_index(_root, page, content)
def _types_add(): t = request.forms.get("type") d = request.forms.get("duration") c = request.forms.get("cost") q = _session.query(_Membership_Type).filter( _Membership_Type.type == t).all() content = "" if len(q) > 0: content = "<p>'%s' already in use.</p>\n" % t else: mt = _Membership_Type(t, d, c) _session.add(mt) content = "<p>'%s' added successfully.</p>\n" % t content += "<p><a href='%s'>Back</a></p>" % (_ + "/types") page = "Membership / Manage Membership Types / Add" _logger.info("New membership type '%s' added." % t) return template_index(_root, page, content)
def _payments_new(num=""): content = """ <form action="%s" method="POST"> <table> <tr> <td>Member ID:</td> <td><input type="text" name="member_id" value="%s" /></td> </tr> <tr> <td>Description:</td> <td> <textarea name="description" rows="8" cols="40"></textarea> </td> </tr> <tr> <td>Amount:</td> <td> <table> <tr> <td> <input type="text" name="amount" /> </td> <td> <input type="radio" name="dir" value="credit" checked="yes"/> Credit<br /> <input type="radio" name="dir" value="debit"/> Debit </td> </tr> </table> </td> <tr> <tr> <td>Date:</td> <td><input type="text" name="date" /> (Default: today's date)</td> </tr> </tr> <td><input type="submit" name="submit" value="Submit" /></td> </tr> </table> </form> """ % (_ + "/payments/new", num) page = "Money / Add Payment" return template_index(_root, page, content)
def _membership(): page = "Membership" content = "<table>" content += """ <tr> <td>id</td> <td>student_id</td> <td>firstname</td> <td>lastname</td> <td>username</td> <td>password</td> <td>address1</td> <td>address2</td> <td>suburb</td> <td>state</td> <td>postcode</td> <td>homephone</td> <td>mobile</td> <td>email</td> <td>type</td> <td>joined</td> <td>paid</td> <td>begin</td> <td>end</td> <td>Controls</td> </tr> """ q = _session.query(_Member).all() for i in q: content += "<tr>" for j in (i.id, i.student_id, i.firstname, i.lastname, i.username, i.password, i.address1, i.address2, i.suburb, i.state, i.postcode, i.homephone, i.mobile, i.email, i.type, i.joined, i.paid, i.begin, i.end): content += "<td>%s</td>\n" % j content += """ <td> <a href='%s'>Modify</a> <a href='%s'>Delete</a> </td>\n""" % ((_ + "/modify/%d" % i.id), (_ + "/delete/%d" % i.id)) content += "</tr>" content += "</table>\n" return template_index(_root, page, content)
def _types(): current = """ <h2>Types</h2> <table style="border-width: 1px"> <tr> <td>Type</td> <td>Duration</td> <td>Cost</td> </tr> """ q = _session.query(_Membership_Type).all() for i in q: current += "<tr>\n" for j in (i.type, i.duration, i.cost): current += "\t<td>%s</td>\n" % j current += "</tr>\n" current += "</table>\n<br /><br />" form = """ <h2>Add Type</h2> <form id="new_user" action="%s" method="POST"> <table> <tr> <td>Type:</td> <td><input name="type" type="text" /></td> </tr> <tr> <td>Duration (in Months):</td> <td><input name="duration" type="text" /></td> </tr> <tr> <td>Cost:</td> <td><input name="cost" type="text" /></td> </tr> <tr> <td><input name="submit" type="submit" value="Submit" /></td> </tr> </table> </form> """ % (_ + "/types/add") page = "Membership / Manage Membership Types" return template_index(_root, page, (current + form))
def _delete_num(num): content = "" page = "Membership / Delete Member" q = _session.query(_Member).filter(_Member.id == num).all() if len(q) > 0: content = """ <form action="%s" method="POST"> Are you sure you want to delete Member %s?<br/> <input name="num" type="hidden" value="%s" /> <input name="submit" type="submit" value="Yes" /> <input name="bailout" type="button" value="No" onclick="javascript:history.go(-1)" /> </form> """ % ((_+"/delete"), num, num) else: content = """ <p>Member %s does not exist.</p> <p><a href="javascript:history.go(-1)">Back</a></p> """ % num return template_index(_root, page, content)
def _delete_num(num): content = "" page = "Membership / Delete Member" q = _session.query(_Member).filter(_Member.id == num).all() if len(q) > 0: content = """ <form action="%s" method="POST"> Are you sure you want to delete Member %s?<br/> <input name="num" type="hidden" value="%s" /> <input name="submit" type="submit" value="Yes" /> <input name="bailout" type="button" value="No" onclick="javascript:history.go(-1)" /> </form> """ % ((_ + "/delete"), num, num) else: content = """ <p>Member %s does not exist.</p> <p><a href="javascript:history.go(-1)">Back</a></p> """ % num return template_index(_root, page, content)
def _modify_post(): num = request.forms.get("num") _logger.debug("Attempting to modify member '%s'" % num) q = _session.query(_Member).filter(_Member.id == num).all() m = q[0] for key, value in request.forms.items(): print("%s: %s" % (key, value)) if key == "password" and (value.strip() != "" or value != None): setattr(m, key, hash(value)) #TODO HASH ME LIGHTLY elif key != "submit": setattr(m, key, value) _session.add(m) page = "Membership / Modify Member" content = """ <p>Member modified successfully.</p> <br /> <a href='%s'>Back</a> """ % _ _logger.info("Member '%s' modified." % num) return template_index(_root, page, content)
def _modify_post(): num = request.forms.get("num") _logger.debug("Attempting to modify member '%s'" % num) q = _session.query(_Member).filter(_Member.id==num).all() m = q[0] for key, value in request.forms.items(): print("%s: %s"%(key, value)) if key == "password" and (value.strip() != "" or value != None): setattr(m, key, hash(value)) #TODO HASH ME LIGHTLY elif key != "submit": setattr(m, key, value) _session.add(m) page = "Membership / Modify Member" content = """ <p>Member modified successfully.</p> <br /> <a href='%s'>Back</a> """ % _ _logger.info("Member '%s' modified." % num) return template_index(_root, page, content)
def _payments_new_post(): page = "Money / Add Payment" try: mid = request.forms.get("member_id") des = request.forms.get("description").strip() d = request.forms.get("dir").strip() a = request.forms.get("amount") dt = request.forms.get("date") dt = dateparser.parse(dt) except: return "TODO THIS AN ERROR" for k, v in request.forms.items(): print("%s: %s" % (k, v)) p = _Payment(mid, des, d, a, dt) _session.add(p) content = """ <p>Payment added.</p> <p><a href='%s'>Back</a></p> """ % (_+"/payments") return template_index(_root, page, content)
def _modify(num): page = "Membership / Modify Member" q = _session.query(_Member).filter(_Member.id == num).all() member = None if len(q) < 1: content = """ <p>Member doesn't exist.</p><br /> <p><a href="%s">Back</a></p> """ % _ return index_template(_root, page, content) else: member = q[0] opts = "" q = _session.query(_Membership_Type).all() for i in q: opts += "<option value='%s'>%s</option>\n" % (i.type, i.type) form = """ <form id="modify_user" action="%s" method="POST"> <input name="num" type="hidden" value="%s" /> <table> """ % ((_ + "/modify"), num) form += """ <tr> <td>Username:</td> <td><input name="username" type="text" value="%s" /></td> </tr> """ % member.username form += """ <tr> <td>Password:</td> <td><input name="password" type="password" /> (Leave blank unless changing password) </td> </tr> <tr><td><br/></td></tr> """ form += """ <tr> <td>Student ID:</td> <td><input name="student_id" type="text" value="%s" /></td> </tr> """ % member.student_id form += """ <tr> <td>Given name:</td> <td><input name="firstname" type="text" value="%s" /></td> </tr> """ % member.firstname form += """ <tr> <td>Surname:</td> <td><input name="lastname" type="text" value="%s" /></td> </tr> """ % member.lastname form += """ <tr> <td>Address:</td> <td><input name="address1" type="text" value="%s" /></td> </tr> """ % member.address1 form += """ <tr> <td></td> <td><input name="address2" type="text" value="%s" /></td> </tr> """ % member.address2 form += """ <tr> <td>Suburb:</td> <td><input name="suburb" type="text" value="%s" /></td> </tr> """ % member.suburb form += """ <tr> <td>State:</td> <td><input name="state" type="text" value="%s" /></td> </tr> """ % member.state form += """ <tr> <td>Postcode:</td> <td><input name="postcode" type="text" value="%s" /></td> </tr> <tr><td><br/></td></tr> """ % member.postcode form += """ <tr> <td>Home phone (optional):</td> <td><input name="homephone" type="text" value="%s" /></td> </tr> """ % member.homephone form += """ <tr> <td>Mobile phone:</td> <td><input name="mobile" type="text" value="%s" /><br/></td> </tr> """ % member.mobile form += """ <tr> <td>Email:</td> <td><input name="email" type="text" value="%s" /><br/></td> </tr> <tr><td><br/></td></tr> """ % member.email form += """ <tr> <td>Membership Type:</td> <td> <select name="type"> %s </select> </td> </tr> <tr> <td><input name="submit" type="submit" value="Modify" /></td> </tr> </table> </form> """ % (opts) return template_index(_root, page, form)
def _modify(num): page = "Membership / Modify Member" q = _session.query(_Member).filter(_Member.id==num).all() member = None if len(q) < 1: content = """ <p>Member doesn't exist.</p><br /> <p><a href="%s">Back</a></p> """ % _ return index_template(_root, page, content) else: member = q[0] opts = "" q = _session.query(_Membership_Type).all() for i in q: opts += "<option value='%s'>%s</option>\n" % (i.type, i.type) form = """ <form id="modify_user" action="%s" method="POST"> <input name="num" type="hidden" value="%s" /> <table> """ % ((_+"/modify"), num) form += """ <tr> <td>Username:</td> <td><input name="username" type="text" value="%s" /></td> </tr> """ % member.username form += """ <tr> <td>Password:</td> <td><input name="password" type="password" /> (Leave blank unless changing password) </td> </tr> <tr><td><br/></td></tr> """ form += """ <tr> <td>Student ID:</td> <td><input name="student_id" type="text" value="%s" /></td> </tr> """ % member.student_id form += """ <tr> <td>Given name:</td> <td><input name="firstname" type="text" value="%s" /></td> </tr> """ % member.firstname form += """ <tr> <td>Surname:</td> <td><input name="lastname" type="text" value="%s" /></td> </tr> """ % member.lastname form += """ <tr> <td>Address:</td> <td><input name="address1" type="text" value="%s" /></td> </tr> """ % member.address1 form += """ <tr> <td></td> <td><input name="address2" type="text" value="%s" /></td> </tr> """ % member.address2 form += """ <tr> <td>Suburb:</td> <td><input name="suburb" type="text" value="%s" /></td> </tr> """ % member.suburb form += """ <tr> <td>State:</td> <td><input name="state" type="text" value="%s" /></td> </tr> """ % member.state form += """ <tr> <td>Postcode:</td> <td><input name="postcode" type="text" value="%s" /></td> </tr> <tr><td><br/></td></tr> """ % member.postcode form += """ <tr> <td>Home phone (optional):</td> <td><input name="homephone" type="text" value="%s" /></td> </tr> """ % member.homephone form += """ <tr> <td>Mobile phone:</td> <td><input name="mobile" type="text" value="%s" /><br/></td> </tr> """ % member.mobile form += """ <tr> <td>Email:</td> <td><input name="email" type="text" value="%s" /><br/></td> </tr> <tr><td><br/></td></tr> """ % member.email form += """ <tr> <td>Membership Type:</td> <td> <select name="type"> %s </select> </td> </tr> <tr> <td><input name="submit" type="submit" value="Modify" /></td> </tr> </table> </form> """ % (opts) return template_index(_root, page, form)
def _add(): opts = "" q = _session.query(_Membership_Type).all() for i in q: opts += "<option value='%s'>%s</option>\n" % (i.type, i.type) form = """ <form id="new_user" action="%s" method="POST"> <table> <tr> <td>Username:</td> <td><input name="username" type="text" /></td> </tr> <tr> <td>Password:</td> <td><input name="password" type="password" /></td> </tr> <tr><td><br/></td></tr> <tr> <td>Student ID:</td> <td><input name="student_id" type="text" /></td> </tr> <tr> <td>Given name:</td> <td><input name="firstname" type="text" /></td> </tr> <tr> <td>Surname:</td> <td><input name="lastname" type="text" /></td> </tr> <tr> <td>Address:</td> <td><input name="address1" type="text" /></td> </tr> <tr> <td></td> <td><input name="address2" type="text" /></td> </tr> <tr> <td>Suburb:</td> <td><input name="suburb" type="text" /></td> </tr> <tr> <td>State:</td> <td><input name="state" type="text" /></td> </tr> <tr> <td>Postcode:</td> <td><input name="postcode" type="text" /></td> </tr> <tr><td><br/></td></tr> <tr> <td>Home phone (optional):</td> <td><input name="homephone" type="text" /></td> </tr> <tr> <td>Mobile phone:</td> <td><input name="mobile" type="text" /><br/></td> </tr> <tr> <td>Email:</td> <td><input name="email" type="text" /><br/></td> </tr> <tr><td><br/></td></tr> <tr> <td>Membership Type:</td> <td> <select name="type"> %s </select> </td> </tr> <tr> <td><input name="submit" type="submit" value="Submit" /></td> </tr> </table> </form> """ % ((_+"/add"), opts) page = "Membership / Add Member" return template_index(_root, page, form)
def _add(): opts = "" q = _session.query(_Membership_Type).all() for i in q: opts += "<option value='%s'>%s</option>\n" % (i.type, i.type) form = """ <form id="new_user" action="%s" method="POST"> <table> <tr> <td>Username:</td> <td><input name="username" type="text" /></td> </tr> <tr> <td>Password:</td> <td><input name="password" type="password" /></td> </tr> <tr><td><br/></td></tr> <tr> <td>Student ID:</td> <td><input name="student_id" type="text" /></td> </tr> <tr> <td>Given name:</td> <td><input name="firstname" type="text" /></td> </tr> <tr> <td>Surname:</td> <td><input name="lastname" type="text" /></td> </tr> <tr> <td>Address:</td> <td><input name="address1" type="text" /></td> </tr> <tr> <td></td> <td><input name="address2" type="text" /></td> </tr> <tr> <td>Suburb:</td> <td><input name="suburb" type="text" /></td> </tr> <tr> <td>State:</td> <td><input name="state" type="text" /></td> </tr> <tr> <td>Postcode:</td> <td><input name="postcode" type="text" /></td> </tr> <tr><td><br/></td></tr> <tr> <td>Home phone (optional):</td> <td><input name="homephone" type="text" /></td> </tr> <tr> <td>Mobile phone:</td> <td><input name="mobile" type="text" /><br/></td> </tr> <tr> <td>Email:</td> <td><input name="email" type="text" /><br/></td> </tr> <tr><td><br/></td></tr> <tr> <td>Membership Type:</td> <td> <select name="type"> %s </select> </td> </tr> <tr> <td><input name="submit" type="submit" value="Submit" /></td> </tr> </table> </form> """ % ((_ + "/add"), opts) page = "Membership / Add Member" return template_index(_root, page, form)
def _finances(): page = "Money / Finances" content = "<p>Todo.</p>" return template_index(_root, page, content)