Skip to content

Instantly share code, notes, and snippets.

@pielegacy
Created April 6, 2015 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pielegacy/42b4b80d6ed5d41867f2 to your computer and use it in GitHub Desktop.
Save pielegacy/42b4b80d6ed5d41867f2 to your computer and use it in GitHub Desktop.
IT Sharing
#New Element
@route('/create')
def create():
return template("create")
@route('/create', method="POST")
def success():
term = request.forms.get('term')
define = request.forms.get('define')
cat = request.forms.get('category')
conn = sqlite3.connect('glossary.db')
#Used to get the count of the row, very inefficent
count = 1
c = conn.execute("SELECT * from table_definitions")
rows = c.fetchall()
for row in rows:
count += 1
if term != "" and define != "":
#Definitions are accepted without categories
if cat !="":
c = conn.execute("INSERT INTO table_definitions (ID, str_term, str_definition, str_category) VALUES ('%s', '%s', '%s', '%s')" %(count, term, define, cat, ))
else :
c = conn.execute("INSERT INTO table_definitions (ID, str_term, str_definition) VALUES ('%s', '%s', '%s')" %(count, term, define,))
conn.commit()
conn.close()
print(term + " added")
return template("success")
else :
conn.commit()
conn.close()
return template("failure")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment