Guest User

Untitled

a guest
Feb 15th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. git_repo/
  2. venv/
  3. project/ - All actual Python resides in here
  4. __init__.py
  5. ui/
  6. static/ - Static Flask stuff
  7. templates/ - HTML templates
  8. __init__.py
  9. db.py
  10. user.py
  11. views.py
  12. dev_server.py - Simple entry point for UI dev (i.e. `app.run()`)
  13. ...
  14.  
  15. import flask
  16. import project
  17.  
  18. app = flask.Flask(__name__)
  19.  
  20. <snip> Some logging setup, Flask config, etc. </snip>
  21.  
  22. import project.ui.views
  23.  
  24. import os
  25. import peewee
  26. import project
  27. from project.ui import app
  28.  
  29. ui_db = os.path.join(project.dir, 'db.db')
  30.  
  31. class Model(peewee.Model):
  32. class Meta:
  33. database = ui_db
  34.  
  35. import peewee
  36. import project.ui.db
  37.  
  38. class User(project.ui.db.Model):
  39. username = peewee.CharField(unique=True)
  40. password = peewee.CharField()
  41. name = peewee.CharField()
  42.  
  43. def get_user(username):
  44. try:
  45. return User.select().where(User.username == username)
  46. except peewee.DoesNotExist:
  47. return None
  48.  
  49. def check_user(username, password):
  50. u = get_user(username)
  51. if u:
  52. return u.password == password
  53. return False
  54.  
  55. import flask
  56. from project.ui import app
  57. import project.ui.user
  58.  
  59. @app.route('/login', methods=['GET', 'POST'])
  60. def route_login():
  61. # Do some stuff using project.ui.user (User, get_user and check_user)
  62. ...
  63.  
  64. # Other routes, etc
  65.  
  66. ...
  67. File ".../project/ui/user.py", line 5, in <module>
  68. class User(project.ui.db.Model):
  69. AttributeError: module 'project' has no attribute 'ui'
Add Comment
Please, Sign In to add comment