Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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.'})
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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))
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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
                          }})
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
 def collects(self):
     l = Collect.all(topic_id=self.id)
     return l
Exemplo n.º 10
0
async def list_collects(user: User = Depends(get_current_active_user)):
    collects = []
    for collect in db.collects.find():
        collects.append(Collect(**collect))

    return collects
Exemplo n.º 11
0
def create_collect():
    request_data = request.get_json()
    collect = Collect(**request_data).save()
    return jsonify(collect)
Exemplo n.º 12
0
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)