Commit f393103a authored by erreur401's avatar erreur401

evenbrite + css + mongoEngine + admin attempt

parent 22736a1f
#!/usr/bin/python
# -*- coding: <utf-8> -*-
from flask import Flask, render_template, redirect, flash, request
from flask_flatpages import FlatPages
import markdown
......@@ -19,9 +18,15 @@ import urllib
import math
from bson import ObjectId
# EVENTBRITE API
from flask_admin import Admin
from flask_admin.form import rules
from flask_admin.contrib.pymongo import ModelView, filters
from flask_admin.model.fields import InlineFormField, InlineFieldList
from wtforms import form, fields
# EVENTBRITE API
eventbrite_url_requete = "https://www.eventbriteapi.com/v3/events/search/?q=fablab&expand=organizer&token=AYO4PV2UJHXEBOLGXG74"
DEBUG = True
FLATPAGES_AUTO_RELOAD = DEBUG
......@@ -68,32 +73,48 @@ class Role(db.Document, RoleMixin):
name = db.StringField(max_length=80, unique=True)
description = db.StringField(max_length=255)
# class Badges(db.Document):
# badge = db.StringField()
# lvl = db.StringField()
# badges_default =[
# {'cnc': '0'},
# {'laser': '0'},
# {'electronique': '0'},
# {'impression3d':'0'},
# {'maker':'0'}
# ]
class User(db.Document, UserMixin):
active = db.BooleanField(default=True)
first_name = db.StringField(max_length=255)
last_name = db.StringField(max_length=255)
email = db.StringField(max_length=255)
password = db.StringField(max_length=255)
active = db.BooleanField(default=True)
confirmed_at = db.DateTimeField()
roles = db.ListField(db.ReferenceField(Role), default=[])
# badges = db.DictField(default=[('cnc', 0),('laser', 0),('electronique', 0),('cad', 0),('impression3d', 0), ('maker', 0) ] )
roles = db.ListField( db.ReferenceField(Role), 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}])
# badges = db.ListField( db.embed(Badges))
dashboard_view_count = db.StringField(max_length=3)
first_name = db.StringField(max_length=255)
last_name = db.StringField(max_length=255)
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 )
user_datastore = MongoEngineUserDatastore(db, User, Role)
#security = Security(app, user_datastore)
security = Security(app, user_datastore, register_form=ExtendedRegisterForm)
@app.route("/")
@app.route("/index")
def index():
return render_template("home.html")
eventbrite_json = ur.urlopen(eventbrite_url_requete)
events = json.loads(eventbrite_json.read().decode())
return render_template("home.html" ,events=events)
@app.route("/learn")
def learn():
......@@ -162,11 +183,17 @@ def check_quiz(id):
# print(number_correct)
badge_ok = math.floor((len(answers_list) / 3) * 2)
# print(badge_ok)
user = current_user.get_id()
C_user = current_user.get_id()
print(C_user)
if number_correct >= badge_ok:
#award badge
print('award badge ' + badge)
bdd.user.update({"_id": ObjectId(user), "badges.name": badge}, {"$set": {"badges.$.lvl": 1}}, multi=True)
#bdd.user.update({"_id": ObjectId(user), "badges.name": badge}, {"$set": {"badges.$.lvl": 1}}, multi=True)
# .objects(id=post.id).update(title='Example Post')
update_Query = str('"set__badges__' + badge + '__lvl = 10"')
print(update_Query)
User.objects(id = C_user).update(update_Query ,True)#set__badges__laser__lvl = 22 , upsert=True) #{'badge.lvl' : 1 }, upsert = True )
# print({ "badges.name": badge,"_id": ObjectId(user)}, {"$set": {"badges.$.lvl": 2}})
#({'badges.name': 'electronique', '_id': ObjectId('5b3f847e5087266741cf1fef')}, {'$set': {'badges.$.lvl': 1}})
success_message = " Felicitation vous avez le badge : " + badge
......@@ -186,9 +213,9 @@ def contact():
@app.route("/event")
def event():
eventbrite_json = ur.urlopen("https://www.eventbriteapi.com/v3/events/search/?q=jazz&token=AYO4PV2UJHXEBOLGXG74")
eventbrite_json = ur.urlopen(eventbrite_url_requete)
events = json.loads(eventbrite_json.read().decode())
return render_template("event.html" ,events = events )
return render_template("event.html" , events = events )
@app.errorhandler(404)
def not_found(error):
......@@ -198,16 +225,31 @@ def not_found(error):
@app.route('/dashboard')
@login_required
def dashboard():
user = current_user.get_id()
print('user: ' + user)
db_user = User.objects.get(id=user).update(inc__dashboard_view_count=1, upsert=True)
C_user = current_user.get_id()
print('user: ' + C_user)
db_user = User.objects.get(id=C_user).update(inc__dashboard_view_count=1, upsert=True)
message = 'Welcome to your dashboard ' + current_user.get_id()
flash(message)
return render_template('dashboard.html', user=user)
return render_template('dashboard.html', user=C_user)
# class UserForm(form.Form):
# name = fields.StringField('Name')
# email = fields.StringField('Email')
# password = fields.StringField('Password')
class UserView(ModelView):
column_list = ('first_name', 'email' , 'badges')
column_sortable_list = ('email')
form = ExtendedRegisterForm
# APP RUN
if __name__ == '__main__':
admin = Admin(app, name='bemaker', template_mode='bootstrap3')#,base_template='microblog_master.html')
admin.add_view(UserView(bdd.user, 'User'))
app.run(host='0.0.0.0', debug=True)
......@@ -309,14 +309,13 @@ ul#menuSecond li a:hover {
.workshopList ul li .subbtn {
position: relative;
text-align: center;
}
.workshopList ul li .subbtn a {
display: block;
position: absolute;
top: 45px;
left: 0;
width: 100%;
min-height: 100%;
height: 120px a;
height-display: block;
height-position: absolute;
height-top: 45px;
height-left: 0;
height-width: 100%;
height-min-height: 100%;
}
.workshopList ul li .desc .wsdate {
background: #002B36;
......@@ -325,6 +324,36 @@ ul#menuSecond li a:hover {
padding: 3px;
border-radius: 4px;
}
.workshopList ul li .desc p {
min-height: 100px;
height: 100px;
overflow: hidden;
position: relative;
transition: height 2s;
transition: max-height 2s;
}
.workshopList ul li .desc p:before {
content: "";
font-size: 24px;
text-align: center;
line-height: 40px;
position: absolute;
width: 100%;
bottom: -10px;
height: 40px;
background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.51) 0%, white 81%);
}
.workshopList ul li .desc p.openDiv {
height: auto !important;
max-height: 1500px;
}
.workshopList ul li .desc p.openDiv:before {
content: "";
background: transparent;
}
.workshopList ul li .desc p ul li {
margin-bottom: 5px;
}
.badgesList {
margin-top: 50px;
......
......@@ -305,6 +305,8 @@ ul {
}
}
.workshopList ul {
list-style: none;
li {
......@@ -322,6 +324,7 @@ ul {
.subbtn {
position: relative;
text-align: center;
height: 120px
a {
display: block;
position: absolute;
......@@ -329,6 +332,7 @@ ul {
left: 0;
width: 100%;
min-height: 100%;
}
}
.desc .wsdate {
......@@ -338,6 +342,37 @@ ul {
padding: 3px;
border-radius: 4px;
}
.desc p{
min-height: 100px;
height: 100px;
overflow: hidden;
position: relative;
transition: height 2s;
transition: max-height 2s;
&:before{
content:'';//''↓';
font-size: 24px;
text-align: center;
line-height: 40px;
position: absolute;
width: 100%;
bottom: -10px;
height: 40px;
background: linear-gradient(to bottom, rgba(255,255,255,0) 0%, rgba(255,255,255,0) 0%, rgba(255,255,255,0.51) 0%, rgba(255,255,255,1) 81%);
}
&.openDiv{
height: auto!important;
max-height: 1500px;
}
&.openDiv:before {
content:'';
background: transparent
}
ul li{
margin-bottom: 5px;
}
}
}
}
......
......@@ -8,6 +8,33 @@ $( document ).ready(function() {
$('head').append('<style> #bg:before {background-image:'+url+';} </style>');
$('.tutoItem').css('height', $('.tutoItem').width());
$('.desc p').click(function(){
$(this).toggleClass('openDiv')
});
// var sliderHeight = "100px";
// $('.slider').each(function () {
// var current = $(this);
// current.attr("box_h", current.height());
// }
// );
// $(".slider").css("height", sliderHeight);
// $(".slider_menu").html('<a href="#">Read More</a>');
// $(".slider_menu a").click(function() { openSlider() })
// });
// function openSlider()
// {
// var open_height = $(".slider").attr("box_h") + "px";
// $(".slider").animate({"height": open_height}, {duration: "slow" });
// $(".slider_menu").html('<a href="#">Close</a>');
// $(".slider_menu a").click(function() { closeSlider() })
// }
// function closeSlider()
// {
// $(".slider").animate({"height": sliderHeight}, {duration: "slow" });
// $(".slider_menu").html('<a href="#">Read More</a>');
// $(".slider_menu a").click(function() { openSlider() })
// }
//$('.overTuto').css('height', $('.overTuto').width());
});
{% extends 'admin/model/edit.html' %}
{% block body %}
<h1>MicroBlog Edit View</h1>
{{ super() }}
{% endblock %}
......@@ -22,8 +22,8 @@
<!-- {{ current_user.badges }} -->
{{ current_user.badges.laser.lvl }}
<div class="badgesList">
<h2>TES BADGES</h2>
......@@ -33,15 +33,17 @@
<div class="col-2">
<div class="badgeItem">
{% if badge.lvl == 1 %}
<div class="badgeImg {{badge.name}} active">
<div class="badgeImg {{badge}} active">
{% elif badge.lvl == 2 %}
<div class="badgeImg {{badge.name}} fail">
<div class="badgeImg {{badge}} fail">
{% else %}
<div class="badgeImg {{badge.name}}">
<div class="badgeImg {{badge}}">
<p>{{ badge.lvl}}</p>
{% endif %}
</div>
<span>{{ badge.name }}</span>
<span>{{ badge}}</span>
<p>{{ badge.lvl}}</p>
</div>
</div>
{% endfor %}
......
......@@ -3,7 +3,7 @@
{% block content %}
<div class="container">
<div class="container workshopList">
<h1>LES ATELIERS</h1>
<p>
......@@ -17,112 +17,40 @@
<div class="spacer"></div>
<ul class="workshop">
{% for event in events %}
<p>{{ event[name.text] }}</p>
{% endfor %}
<li>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class="img">
<img src="img/3d.png">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<div class="desc">
<h3>Atelier laser pour ado</h3>
<span class="wsdate">24 . 02 . 1985</span> <span class="wsdate">18:30</span> by <a href="#">Bemaker</a>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor
</p>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class="subbtn">
<a href="#">
<button type="button" class="btn btn-info btn-lg">inscription</button>
</a>
</div>
</div>
</div>
</li>
{% for event in events.events %}
<li>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class=" col col-12 col-sm-12 col-md-2 col-lg-2">
<div class="img">
<img src="img/CNC.png">
<img src="{%if event.logo.original %}{{event.logo.original.url}}{% endif%}">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<div class="desc">
<h3>Atelier laser pour ado</h3>
<span class="wsdate">24 . 02 . 1985</span> <span class="wsdate">18:30</span>
by <span><a href="#">Imal</a></span>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.
</p>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class="subbtn">
<a href="#">
<button type="button" class="btn btn-info btn-lg">inscription</button>
</a>
</div>
</div>
</div>
</li>
<h3>{{ event.name.text }}</h3>
<li>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class="img">
<img src="img/tuto/servomotor.jpg">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<div class="desc">
<h3>des servos dans le cerveau</h3>
<span class="wsdate">24 . 02 . 1985</span> <span class="wsdate">18:30</span>
by <span><a href="#">OpenFab</a></span>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ull
<span class="wsdate">{{ event.start.local }}</span> {% if event.capacity!= None %} <span class="wsdate">max : {{ event.capacity }} ppl</span>{% endif %} by <a href="{{event.organizer.url}}">{{ event.organizer.name }}</a>
<p>
{{ event.description.text }}
</p>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class="col col-12 col-sm-12 col-md-2 col-lg-2">
<div class="subbtn">
<a href="#">
<button type="button" class="btn btn-success btn-lg">a bientot</button>
<a href="{{ event.url}}" target="_blank">
<button type="button" class="btn btn-info btn-lg">inscription</button>
</a>
</div>
</div>
</div>
<div class="cb"></div>
</li>
{% endfor %}
</ul>
</div>
......
......@@ -20,7 +20,7 @@
<div class="row no-gutter">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div class="container">
<h2>Lorem ipsum dolor sit amet</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
......@@ -91,7 +91,7 @@
</div>
</div>
</div>
</div>
......@@ -143,7 +143,7 @@
</div>
</div>
</div>
<div class="col col-12 col-sm-6 col-md-4 col-lg-3 tutoItem">
<div class="tutoBox">
......@@ -191,114 +191,41 @@
<div class="container">
<ul class="workshop">
<li>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class="img">
<img src="img/3d.png">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<div class="desc">
<h3>Atelier laser pour ado</h3>
<span class="wsdate">24 . 02 . 1985</span> <span class="wsdate">18:30</span> by <a href="#">Bemaker</a>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor
</p>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class="subbtn">
<a href="#">
<button type="button" class="btn btn-info btn-lg">inscription</button>
</a>
</div>
</div>
</div>
</li>
<li>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class="img">
<img src="img/CNC.png">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<div class="desc">
<h3>Atelier laser pour ado</h3>
<span class="wsdate">24 . 02 . 1985</span> <span class="wsdate">18:30</span>
by <span><a href="#">Imal</a></span>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.
</p>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class="subbtn">
<a href="#">
<button type="button" class="btn btn-info btn-lg">inscription</button>
</a>
</div>
</div>
</div>
</li>
<li>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class="img">
<img src="img/tuto/servomotor.jpg">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<div class="desc">
<h3>des servos dans le cerveau</h3>
<span class="wsdate">24 . 02 . 1985</span> <span class="wsdate">18:30</span>
by <span><a href="#">OpenFab</a></span>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ull
</p>
{% for event in events.events[:6] %}
<li>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class="img">
<img src="{{ event.logo.url }}">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<div class="desc">
<h3>{{ event.name.text }}</h3>
<span class="wsdate">{{ event.start.local }}</span> <span class="wsdate">max : {{ event.capacity }} ppl</span> by <a href="#">TBD</a>
<p>
{{ event.description.text }}
</p>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class="subbtn">
<a href="{{ event.url}}" target="_blank">
<button type="button" class="btn btn-info btn-lg">inscription</button>
</a>
</div>
</div>
</div>
</li>
{% endfor %}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<div class="subbtn">
<a href="#">
<button type="button" class="btn btn-success btn-lg">a bientot</button>
</a>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
......
......@@ -16,8 +16,9 @@
</div>
</div>
<div class="container-fluid">
<H3>LEARN</H3>
<div class="container-fluid">
<div class="row no-gutter">
<div class="col col-12 col-sm-12 col-md-12 col-lg-12">
<div class="row">
......@@ -42,7 +43,6 @@
</a>
</div>
</div>
{% endfor %}
......
......@@ -4,15 +4,14 @@ blinker==1.4
cffi==1.11.5
click==6.7
Flask==1.0.2
Flask-Admin==1.5.1
Flask-BabelEx==0.9.3
Flask-FlatPages==0.6
Flask-Login==0.4.1
Flask-Mail==0.9.1
flask-mongoengine==0.9.5
Flask-Principal==0.4.0
# Flask-Security following
#https://stackoverflow.com/questions/50105057/flask-security-error-valueerror-too-many-values-to-unpack
git+https://github.com/mattupstate/flask-security
Flask-Security==3.0.0
Flask-WTF==0.14.2
itsdangerous==0.24
Jinja2==2.10
......
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