Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. from flask import Flask, redirect, render_template, request, url_for
  2. from server import app, user_input
  3. from question_class import Question
  4. from sqlalchemy import Column, ForeignKey, Integer, String
  5. from sqlalchemy.ext.declarative import declarative_base
  6. from sqlalchemy.orm import relationship,sessionmaker
  7. from sqlalchemy import create_engine
  8. from sqlite3
  9.  
  10. class Response:
  11. def __init__(self, SID, userID, option1, option2, option3, option4, option5, option6, option7, option8)
  12. self._SID = name
  13. self._userID = userID
  14. self._option1 = option1
  15. self._option2 = option2
  16. self._option3 = option3
  17. self._option4 = option4
  18. self._option5 = option5
  19. self._option6 = option6
  20. self._option7 = option7
  21. self._option8 = option8
  22.  
  23. def get_SID(self):
  24. return self._SID
  25.  
  26. def get_userID(self):
  27. return self._userID
  28.  
  29. def add_response(self):
  30. con = sqlite3.connect("library.db")
  31. cur = con.cursor()
  32.  
  33. # checks in db whether there is a response with the same SID and userID
  34. # as the one we want to add
  35. response_query = "SELECT * FROM response_pool WHERE SID=SID AND UserID=userID"
  36. curr_responses = cur.execute(response_query)
  37. con.commit()
  38.  
  39. # if there is no SID and UserID is not in db
  40. if curr_responses.rowcount == 0:
  41. # adding into response_pool
  42. cur.execute("INSERT INTO response_pool (SID,UserID,Option1,Option2,Option3,Option4,Option5,Option6,Option7,Option8)
  43. VALUES(?,?,?,?,?,?,?,?,?,?);",self._SID, self._userID, self._option1,self._option2,self._option3,self._option4,
  44. self._option5,self._option6,self._option7,self._option8))
  45.  
  46. con.commit()
  47. # if the userID has already submitted a response for that survey
  48. else:
  49. # do not add their response
  50. break
  51.  
  52. cur.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement