def collect_delete(id): m = Topic.get(id) u = current_user() collect_item = Collect.one(topic_id=m.id, user_id=u.id) Collect.delete(collect_item.id) c = 'n' return render_template("topic/detail.html", topic=m, u=u, c=c)
def delete_all(): Sample.objects.all().delete() Collect.objects().all().delete() LoanHistory.objects().all().delete() Equipment.objects().all().delete() Sensor.objects().all().delete() Patient.objects().all().delete() return jsonify({'message': 'deleted with success.'})
async def create_collect(collect: Collect = Depends(validate_collect), user: User = Depends(is_current_active_user_admin)): if hasattr(collect, 'id'): delattr(collect, 'id') _collect = db.collects.insert_one(collect.dict(by_alias=True)) collect.id = _collect.inserted_id return collect
def add_like(): id = int(request.args.get('id')) u = current_user() t = Topic.one(id=id) user = User.one(id=t.user_id) form = {'topic_id': t.id, 'num': 1} l = Collect.one(topic_id=t.id, user_id=u.id) if l is None: Collect.new(form, u.id) send_like(u, user, id, '') else: Collect.delete(l.id) return redirect(url_for('.detail_like', id=t.id))
def detail(id): m = Topic.get(id) u = current_user() c = 'n' # 未收藏 if Collect.one(topic_id=m.id, user_id=u.id) is not None: c = 'c' return render_template("topic/detail.html", topic=m, u=u, c=c)
async def get_patient_collects(): for patient in db.patients.find(): collects = [] for collect in db.collects.find({'patient': patient['_id']}): collects.append(Collect(**collect)) db.patient.update({'_id': patient['_id']}, {'$set': { 'collects': collects }})
def my_collect(): u = current_user() token = new_csrf_token() bs = Board.all() t = Collect.all(user_id=u.id) l = [] for c in t: l.append(Topic.one(id=c.topic_id)) return render_template("topic/collect.html", u=u, ms=l, bs=bs, token=token)
def detail_like(id): m = Topic.get(id) u = current_user() l = Collect.one(topic_id=m.id, user_id=u.id) return render_template("topic/like.html", topic=m, user=u, l=l)
def collects(self): l = Collect.all(topic_id=self.id) return l
async def list_collects(user: User = Depends(get_current_active_user)): collects = [] for collect in db.collects.find(): collects.append(Collect(**collect)) return collects
def create_collect(): request_data = request.get_json() collect = Collect(**request_data).save() return jsonify(collect)
def collect_detail(id): print('topic collected') m = Topic.get(id) u = current_user() l = Collect.add(topic_id=m.id, user_id=u.id) return render_template("topic/detail.html", topic=m, u=u, l=l)