Commit 5082548d authored by colmoneill's avatar colmoneill

still haven't found what I'm looking for 馃幍 regarding this inc db element on quizz sucess

parent faf847ea
......@@ -79,23 +79,62 @@ class Role(db.Document, RoleMixin):
def __unicode__(self):
return self.name
badges = {
"cnc": {
"lvl": "0"
},
"laser": {
"lvl": "0"
},
"impression3d": {
"lvl": "0"
},
"maker": {
"lvl": "0"
},
"electronique": {
"lvl": "0"
}
}
# class Badge(db.Document): # UserMixin ? RoleMixin ?
# # _id = db.ObjectIdField(default = name)
# name = db.StringField(max_length=60)
# #_id = db.ObjectIdField(default = name)
# description = db.StringField()
# default_level = db.StringField(default=1)
# icon = db.FileField(required=False)
# color_hex = db.StringField()
# # user = db.ReferenceField(User, required=False)
# badges = {
# "cnc": {
# "lvl": "0"
# },
# "laser": {
# "lvl": "0"
# },
# "impression3d": {
# "lvl": "0"
# },
# "maker": {
# "lvl": "0"
# },
# "electronique": {
# "lvl": "0"
# }
# }
badges = [
{
"name" : "cnc",
"lvl" : "0"
},
{
"name" : "laser",
"lvl" : "5"
},
{
"name" : "impression3d",
"lvl" : "0"
},
{
"name" : "maker",
"lvl" : "0"
},
{
"name" : "electronique",
"lvl" : "0"
},
{
"name" : "badge",
"lvl" : 1
}
]
# default_role = bdd.role.find({'name': 'user'})
class User(db.Document, UserMixin):
active = db.BooleanField(default=True)
......@@ -105,6 +144,7 @@ class User(db.Document, UserMixin):
password = db.StringField(max_length=255)
confirmed_at = db.DateTimeField()
badges = db.DictField(default = badges)
# badges = db.ListField(db.EmbeddedDocumentField(Badge))
roles = db.ListField(db.ReferenceField(Role))
# badges = db.ListField( db.ReferenceField(Badges))
# dashboard_view_count = db.StringField(max_length=3, default=[0])
......@@ -230,8 +270,9 @@ def check_quiz(id):
# dbObjBadge = User.objects(id = C_user, badges=[badge])
# print(dbObjBadge)
# update = bdd.user.update({"_id": ObjectId(C_user)}, {"$set": {"badges.badge" : 1}}, upsert=True)
update = bdd.user.update({"_id": C_user, "badges": { '$elemMatch': {"badges" : badge}}}, {"$set": { "badges.$.lvl": 333 }}, upsert = True)
print(update)
# before help -- update = bdd.user.update({"_id": C_user, "badges": { '$elemMatch': {"badges" : badge}}}, {"$set": { "badges.$.lvl": 333 }}, upsert = True)
#update = bdd.user.update({"_id": C_user}, { "$set": { "badges.$[elem].lvl": "10" } }, { "arrayFilters": [{ "elem.name": badge }]})
#print(update)
# .objects(id=post.id).update(title='Example Post')
## update_Query = str('"set__badges__' + badge + '__lvl = 1", upsert = True')
## print(update_Query)
......@@ -335,5 +376,5 @@ if __name__ == '__main__':
admin = Admin(app, name='bemaker', template_mode='bootstrap3')#,base_template='microblog_master.html')
admin.add_view(UserView(User))
admin.add_view(RoleView(Role))
# admin.add_view(ModelView(Badges))
# admin.add_view(ModelView(Badge))
app.run(host='0.0.0.0', debug=True)
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