Created
April 6, 2015 21:46
-
-
Save pielegacy/42b4b80d6ed5d41867f2 to your computer and use it in GitHub Desktop.
IT Sharing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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