Browse Source

Refactor database character update function.

master
Ben Kurtovic 8 years ago
parent
commit
9f4bc204e5
2 changed files with 7 additions and 5 deletions
  1. +1
    -1
      calefaction/auth.py
  2. +6
    -4
      calefaction/database.py

+ 1
- 1
calefaction/auth.py View File

@@ -207,7 +207,7 @@ class AuthManager:
return False return False


self._debug("Setting style to %s for char id=%d", style, cid) self._debug("Setting style to %s for char id=%d", style, cid)
g.db.set_character_style(cid, style)
g.db.update_character(cid, "style", style)


if hasattr(g, "_character_props"): if hasattr(g, "_character_props"):
delattr(g, "_character_props") delattr(g, "_character_props")


+ 6
- 4
calefaction/database.py View File

@@ -148,11 +148,13 @@ class Database:
res = self._conn.execute(query, (cid,)).fetchall() res = self._conn.execute(query, (cid,)).fetchall()
return {"name": res[0][0], "style": res[0][1]} if res else {} return {"name": res[0][0], "style": res[0][1]} if res else {}


def set_character_style(self, cid, style):
"""Update a character's style setting."""
def update_character(self, cid, prop, value):
"""Update a property for the given character."""
props = {"name": "character_name", "style": "character_style"}
field = props[prop]
with self._conn as conn: with self._conn as conn:
conn.execute("""UPDATE character SET character_style = ?
WHERE character_id = ?""", (style, cid))
conn.execute("""UPDATE character SET {} = ?
WHERE character_id = ?""".format(field), (value, cid))


def set_auth(self, cid, token, expires, refresh): def set_auth(self, cid, token, expires, refresh):
"""Set the authentication info for the given character.""" """Set the authentication info for the given character."""


Loading…
Cancel
Save