dashboards.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from flask import Blueprint, render_template, request, flash, redirect, url_for
  2. from flask_login import login_required, current_user
  3. from werkzeug.security import generate_password_hash, check_password_hash
  4. from .models import User
  5. from . import db
  6. from . import clean_file as cf
  7. from . import tools
  8. from . import dispatch
  9. dashboards = Blueprint('dashboards', __name__)
  10. # Main Pages
  11. @dashboards.route('/', methods=['GET', 'POST'])
  12. def market():
  13. return render_template('market.html', user=current_user)
  14. @dashboards.route('/profile', methods=['GET', 'POST'])
  15. @login_required
  16. def profile():
  17. # fetch post request
  18. if request.method == "POST":
  19. cpasswd = request.form.get('current_password')
  20. passwd = request.form.get('password')
  21. passwd_con = request.form.get('password_confirm')
  22. # password check before update
  23. if passwd and passwd_con and cpasswd:
  24. if passwd == passwd_con and check_password_hash(current_user.password, cpasswd):
  25. npasswd_dbcall = User.query.filter_by(id=current_user.id).first()
  26. npasswd_dbcall.password = generate_password_hash(passwd_con, method='sha256')
  27. db.session.commit()
  28. flash('Updated password!', category='success')
  29. else:
  30. flash('Password update failed!', category='error')
  31. return render_template('profile.html', user=current_user)
  32. @dashboards.route('/create_art', methods=['GET', 'POST'])
  33. @login_required
  34. def create():
  35. # check POST req
  36. if request.method == "POST":
  37. new_art = request.files.get('art_img')
  38. art_name = request.form.get('art_name')
  39. art_desc = request.form.get('description')
  40. min_price = request.form.get('minimum_price')
  41. buyout_price = request.form.get('buyout_price')
  42. close_date = request.form.get('closing_date')
  43. if tools.check_fields([new_art, art_name, min_price, buyout_price, close_date]):
  44. if new_art and new_art.filename != '' and cf.allowed_file(new_art.filename):
  45. designated_fn = cf.sanitize(new_art.filename)
  46. new_art.save(f'{cf.UPLOAD_FOLDER}/{designated_fn}')
  47. dispatch.mint(designated_fn, art_name, art_desc, min_price, buyout_price, close_date)
  48. return render_template('create_art.html', user=current_user)
  49. # Pop Ups
  50. @dashboards.route('/modal_home')
  51. @login_required
  52. def modal_home():
  53. return render_template('detail_art_for_home.html', user=current_user)
  54. @dashboards.route('/modal_profile')
  55. @login_required
  56. def modal_profile():
  57. return render_template('detail_art_for_profile.html', user=current_user)