Commit b8405609 authored by colmoneill's avatar colmoneill

first commit after the reset hard back before the overly simple quizz thing.…

first commit after the reset hard back before the overly simple quizz thing. Going to integrate https://github.com/vgel/simple-quiz now
parent afe1e0d5
......@@ -9,73 +9,12 @@ from flask_mail import Mail
from flask_security.forms import RegisterForm, StringField
from wtforms.validators import DataRequired
DEBUG = True
FLATPAGES_AUTO_RELOAD = DEBUG
FLATPAGES_EXTENSION = '.md'
FLATPAGES_MARKDOWN_EXTENSIONS = ['markdown.extensions.extra', 'headerid']
app = Flask(__name__)
#app.config.from_pyfile('mysettings.cfg')
app.config.from_object(__name__)
pages = FlatPages(app)
@app.route("/")
@app.route("/index")
def index():
return render_template("home.html")
@app.route("/learn")
def learn():
articles = (p for p in pages if 'published' in p.meta)
print(articles)
# Show the 10 most recent articles, most recent first.
latest = sorted(articles, reverse=True,
key=lambda p: p.meta['published'])
return render_template("learn.html", articles=latest[:10])
@app.route('/learn/<path:path>/')
def page(path):
page = pages.get_or_404(path)
print(page)
return render_template('flatpage.html', page=page)
# @app.route("/login")
# def login():
# #return "Hello, World!"
# return render_template("login.html")
@app.route("/contact")
def contact():
#return "Hello, World!"
return render_template("contact.html")
@app.route("/event")
def event():
#return "Hello, World!"
return render_template("event.html")
#@app.errorhandler(404)
#def not_found(error):
# return render_template('error.html'), 404
# /
# ______ _ _ _____ _ _
# | ___| | | | / ___| (_) |
# | |_ | | __ _ ___| | __ \ `--. ___ ___ _ _ _ __ _| |_ _ _
# | _| | |/ _` / __| |/ / `--. \/ _ \/ __| | | | '__| | __| | | |
# | | | | (_| \__ \ < /\__/ / __/ (__| |_| | | | | |_| |_| |
# \_| |_|\__,_|___/_|\_\ \____/ \___|\___|\__,_|_| |_|\__|\__, |
# ______ __/ |
# |______| |___/
# /
# Create app
# Flask Security settings
app.config['SECRET_KEY'] = 'super-secret'
app.config['SECURITY_REGISTERABLE'] = True
app.config['SECURITY_RECOVERABLE'] = True
......@@ -92,7 +31,6 @@ app.config['MAIL_PASSWORD'] = 'testing#123'
app.config['MAIL_DEFAULT_SENDER'] = 'automatic@colm.be'
mail = Mail(app)
# MongoDB Config
app.config['MONGODB_DB'] = 'mydatabase'
app.config['MONGODB_HOST'] = 'localhost'
......@@ -101,10 +39,11 @@ app.config['MONGODB_PORT'] = 27017
# Create database connection object
db = MongoEngine(app)
# class ExtendedRegisterForm(RegisterForm):
# first_name = db.StringField('First Name')
# last_name = db.StringField('Last Name')
# Setup Flask-Security
user_datastore = MongoEngineUserDatastore(db, User, Role )
#security = Security(app, user_datastore)
security = Security(app, user_datastore, register_form=ExtendedRegisterForm)
class Role(db.Document, RoleMixin):
name = db.StringField(max_length=80, unique=True)
......@@ -116,7 +55,7 @@ class User(db.Document, UserMixin):
active = db.BooleanField(default=True)
confirmed_at = db.DateTimeField()
roles = db.ListField(db.ReferenceField(Role), default=[])
badges = db.ListField(default=[])
badges = db.ListField(default=[{'name':'cnc', 'lvl': 0},{'name':'laser', 'lvl': 0},{'name':'electronique', 'lvl': 0},{'name':'cad', 'lvl': 0},{'name':'impression3d', 'lvl': 0},{'name':'maker', 'lvl': 0}])
dashboard_view_count = db.StringField(max_length=3)
first_name = db.StringField(max_length=255)
last_name = db.StringField(max_length=255)
......@@ -125,20 +64,46 @@ class ExtendedRegisterForm(RegisterForm):
first_name = StringField('First Name', validators=[DataRequired()])
last_name = StringField('Last Name', validators=[DataRequired()])
# Setup Flask-Security
user_datastore = MongoEngineUserDatastore(db, User, Role )
#security = Security(app, user_datastore)
app = Flask(__name__)
#app.config.from_pyfile('mysettings.cfg')
app.config.from_object(__name__)
pages = FlatPages(app)
@app.route("/")
@app.route("/index")
def index():
return render_template("home.html")
@app.route("/learn")
def learn():
articles = (p for p in pages if 'published' in p.meta)
print(articles)
# Show the 10 most recent articles, most recent first.
latest = sorted(articles, reverse=True,
key=lambda p: p.meta['published'])
return render_template("learn.html", articles=latest[:10])
@app.route('/learn/<path:path>/')
def page(path):
page = pages.get_or_404(path)
print(page)
return render_template('flatpage.html', page=page)
@app.route("/contact")
def contact():
return render_template("contact.html")
security = Security(app, user_datastore, register_form=ExtendedRegisterForm)
@app.route("/event")
def event():
return render_template("event.html")
@app.errorhandler(404)
def not_found(error):
return render_template('error.html'), 404
# Create a user to test with
# Note the decorator, this runs only once on startup of the server.
# @app.before_first_request
# def create_user():
# user_datastore.create_user(email='test@gmail.com', password='password')
# Views
@app.route('/dashboard')
@login_required
def dashboard():
......@@ -151,6 +116,16 @@ def dashboard():
return render_template('dashboard.html', user=user)
# Migrate to pymongo?
# from pymongo import MongoClient
# client = MongoClient('localhost', 27017)
# bdd = client.mydatabase
# bddusers = bdd.users
# bdd.user.update({"_id" : user, "badges.name" : badge }, {"$set" : { "badges.$.lvl" : "1" }})
# APP RUN
if __name__ == '__main__':
......
{% extends "base.html" %}
{% block content %}
<div class="container">
<div class="all-col">
<h1>(404) page not found</h1>
<div class="separation-rule"></div>
<p>This page does not exist. Please check the URL spelling or revert to the navigation.</p>
</div>
</div>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment