def insert_payment_histories(action, seasons): updater = models.user().id models.db().executemany(""" INSERT INTO TaxPaymentHistory ( year, user_id, season, action, updater_user_id) VALUES (?, ?, ?, ?, ?)""", [(year, user_id, s, action, updater) for s in seasons])
def post(body): models.db().execute(""" INSERT INTO BBS (user_id, when_, body) VALUES (?, ?, ?)""", ( models.user().id, datetime.now(), sanitize_html(body))) models.db().commit()
def update_entry(sid, comment, entry): models.db().execute(""" UPDATE Entry SET is_entry = ?, comment = ?, when_ = CURRENT_TIMESTAMP WHERE user_id = ? AND schedule_id = ?""", (entry, comment, models.user().id, sid)) models.db().commit()
def insert(title, feature_image_url, description, body): with models.db(): models.db().execute(""" INSERT INTO Report (when_, author_id, title, feature_image_url, description, description_html, body, body_html) VALUES (datetime('now', 'localtime'), ?, ?, ?, ?, ?, ?, ?)""", (models.user().id, title, feature_image_url, description, sanitize_markdown(description), body, sanitize_markdown(body))) return models.db().execute(""" SELECT id FROM Report WHERE when_ = (SELECT MAX(when_) FROM Report)""").fetchone()[0]
def test_entry_rate_reflects_only_practice(): entries.do_entry(1, "comment", True) entries.do_entry(2, "comment", True) entries.do_entry(3, "comment", True) entries.do_entry(4, "comment", True) entries.do_entry(5, "comment", True) # kokomade practice entries.do_entry(6, "comment", False) entries.do_entry(7, "comment", False) entries.do_entry(8, "comment", False) entries.do_entry(9, "comment", False) entries.do_entry(10, "comment", False) entries.do_entry(11, "comment", False) entries.do_entry(12, "comment", False) entries.do_entry(13, "comment", False) entries.do_entry(14, "comment", False) entries.do_entry(15, "comment", False) u = user() rate = stats.get_practice_entry_rate_of_year(u, 2012) assert rate.count == 5 assert rate.allcount == 5
def test_entry_rate_reflects_after_joined(): entries.do_entry(1, "comment", False) entries.do_entry(2, "comment", False) entries.do_entry(3, "comment", False) # 2012/1/4 entries.do_entry(4, "comment", True) entries.do_entry(5, "comment", True) # kokomade practice entries.do_entry(6, "comment", False) entries.do_entry(7, "comment", False) entries.do_entry(8, "comment", False) entries.do_entry(9, "comment", False) entries.do_entry(10, "comment", False) entries.do_entry(11, "comment", False) entries.do_entry(12, "comment", False) entries.do_entry(13, "comment", False) entries.do_entry(14, "comment", False) entries.do_entry(15, "comment", False) u = user() u.joined = datetime(2012, 1, 4) rate = stats.get_practice_entry_rate_of_year(u, 2012) assert rate.count == 2 assert rate.allcount == 3
def has_permission_to_delete_guest(guest_id): u = models.user() return u.is_god() or \ models.db().execute(""" SELECT COUNT(*) FROM GuestEntry WHERE id = ? AND inviter_id = ?""", (guest_id, u.id)).fetchone()[0] > 0
def do_guest_entry(sid, name, comment): models.db().execute(""" INSERT INTO GuestEntry (name, inviter_id, schedule_id, comment) VALUES (?, ?, ?, ?)""", (name, models.user().id, sid, comment)) models.db().commit()
def insert_entry(sid, comment, entry): models.db().execute(""" INSERT INTO Entry (user_id, schedule_id, is_entry, comment) VALUES (?, ?, ?, ?)""", (models.user().id, sid, entry, comment)) models.db().commit()
def find_my_entry(sid): cur = models.db().execute(""" SELECT COUNT(*) FROM Entry WHERE user_id = ? AND schedule_id = ?""", (models.user().id, sid)) return cur.fetchone()[0] > 0