I am making a web-app where I have made an html which has for loop to display boxes according to the number of documents in Mongodb. Each box has a check-box. Now, in the mongodb database, I want to update status column of those documents from blank to 1 which are checked. How do I return the string value of the corresponding checkbox and update the corresponding in database. This is all using Mongodb, Python and Flask.
Basically trying to trigger done() function once the checkbox is clicked and be able to pass t['Activity'] at the same time
Python Code
from pymongo import MongoClient
from flask import Flask, render_template, request, url_for
import os
from flask_pymongo import PyMongo
from FlaskWebProject6 import app
app.config["MONGO_URI"] = "mongodb://WorkAmp%5FMVP:ampitup%40futurex@workamp-mvp-shard-00-00-buabm.mongodb.net:27017,workamp-mvp-shard-00-01-buabm.mongodb.net:27017,workamp-mvp-shard-00-02-buabm.mongodb.net:27017/test?ssl=true&replicaSet=WorkAmp-MVP-shard-0&authSource=admin&retryWrites=true&w=majority"
mongo = PyMongo(app)
client = MongoClient("mongodb://WorkAmp%5FMVP:ampitup%40futurex@workamp-mvp-shard-00-00-buabm.mongodb.net:27017,workamp-mvp-shard-00-01-buabm.mongodb.net:27017,workamp-mvp-shard-00-02-buabm.mongodb.net:27017/test?ssl=true&replicaSet=WorkAmp-MVP-shard-0&authSource=admin&retryWrites=true&w=majority")
#client.server_info()
db = client.get_database('Demo01')
records = db['Daily Activities']
#records
#records.count_documents({})
#test = records.find()
#for t in test:
# print(t['Activity'])
#t['Activity']
@app.route('/')
@app.route('/admin')
def admin():
records_list = records.find()
return render_template('admin.html',records_list = records_list)
def done():
records.update_one({'Activity':'t['Activity]'},{"$set":{"Status":"1"}})
if __name__=='__main__':
app.run(host='0.0.0.0', port=8080, debug=True)
#delete_rec = {
# 'Activity':'Delete',
# 'Status':'1'}
#records.insert_one(delete_rec)
#records.delete_one({'Status':'1'})
admin.html HTML code
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="/static/content/index.css" />
<meta name="viewport" content="width = device-width, initial-scale= 1.0" />
<script src="https://kit.fontawesome.com/18264bfb6e.js" crossorigin="anonymous"></script>
<title>Admin Page</title>
</head>
<body>
<div class="side-menu">
<div class="avatar">
<img src="src/admin.jpg.png" alt="Admin Profile Image" class="icon">
<h4 class="avatar-text">ADMIN</h4>
</div>
<div class="menu-select">
<h4 class="menu-opt" id="selected">TASKS TODAY</h4>
<h4 class="menu-opt">UPCOMING</h4>
</div>
</div>
<!--
<section class = "card-area">
-->
<div class="cards-list">
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire