示例#1
0
def alter_bulletin(request):
    if request.method == 'POST':
        session = request.session
        form = BulletinForm(request.POST, hospital_id=session['hospital_id'])
        if form.is_valid():
            utils.alter_bulletin(form, session)
            return redirect('/publisher/')
    else:
        session = request.session
        session['id_bulletin'] = request.GET.get('id_bulletin',-1)
        fee = request.GET.get('fee', -1)
        availabletime = request.GET.get('availabletime', -1)
        countavailable = request.GET.get('countavailable', -1)
        countoccupied = request.GET.get('countoccupied', -1)
        department = request.GET.get('department',-1)
        doctor = request.GET.get('doctor',-1)
        form = BulletinForm(hospital_id=session['hospital_id'])
        return render(request, 'publisher/bulletin.html', {'loginname': session['loginname'],
                                                           'form': form,
                                                          'fee': fee,
                                                          'availabletime': availabletime,
                                                          'countavailable': countavailable,
                                                          'countoccupied': countoccupied,
                                                          'department': department,
                                                          'doctor': doctor,
                                                          'doctor_department': json.dumps(utils.get_doctor_department(
                                                               session['hospital_id']))
                                                           })
示例#2
0
def create_bulletin(request):
    session = request.session
    islogin = session.get('islogin', False)
    if not islogin:
        return redirect('/publisher/login')
    if request.method == 'POST':
        session = request.session
        form = BulletinForm(request.POST, hospital_id=session['hospital_id'])
        if form.is_valid():
            utils.create_bulletin(form,session)
            return redirect('/publisher/')
        else:
            error_message = '您填写的信息有错误,请重新填写!'
            return render(request, 'publisher/bulletin.html',
                          {'loginname': request.session['loginname'],
                           'form': form, 'error_message': error_message,
                           'doctor_department': json.dumps(utils.get_doctor_department(
                               session['hospital_id']))
                           })
    else:
        form= BulletinForm(hospital_id=session['hospital_id'])
        return render(request, 'publisher/bulletin.html',
                      {'loginname': request.session['loginname'],
                       'form': form,
                       'doctor_department': json.dumps(utils.get_doctor_department(session['hospital_id']))
                     })
示例#3
0
def view_bulletins():
    page = request.args.get('page', 1)
    q = request.args.get('q')
    bulletins = restful.GetBulletins(int(page), q)
    if not bulletins.has_key(restful.ITEM_OBJECTS):
        return redirect(url_for('view_bulletins'))

    bulletinforms = [
        logic.GetBulletinFormById(x[restful.ITEM_ID])
        for x in bulletins[restful.ITEM_OBJECTS]
    ]
    while None in bulletinforms:
        bulletinforms.remove(None)

    if request.method == 'POST':
        form = BulletinForm(request.form)
        if request.form.has_key('delete'):
            for x in orm.Bulletinimage.query.filter_by(
                    bulletin_id=int(form.id.data)).all():
                pathfile_server = os.path.join(UPLOAD_PATH, x.file)
                if os.path.exists(pathfile_server):
                    os.remove(pathfile_server)
            orm.db.session.delete(orm.Bulletin.query.get(int(form.id.data)))
            orm.db.session.commit()
            return redirect(url_for('view_bulletins', page=page, q=q))

    form = PageInfo()
    logic.LoadBasePageInfo('所有公告', '查看', form)

    return render_template('view_bulletins.html',
                           forms=bulletinforms,
                           form=form,
                           paging=restful.GetPagingFromResult(bulletins))
示例#4
0
def GetBulletinFormById(bulletin_id):
    bulletin = orm.Bulletin.query.get(int(bulletin_id))
    if bulletin is None: return None
    bulletinform = BulletinForm()
    bulletinform.id.data = bulletin.id
    bulletinform.title.data = bulletin.title
    bulletinform.content.data = bulletin.content
    bulletinform.valid.data = bulletin.valid
    bulletinform.source.data = bulletin.source
    return bulletinform
示例#5
0
def view_bulletin():
    bulletin_id = request.args.get('id')
    q = request.args.get('q')
    if q is not None:
        return redirect(url_for('view_bulletins', page=1, q=q))

    form = BulletinForm(request.form)

    if request.method == 'POST' and form.validate():
        if form.id.data:
            bulletin = orm.Bulletin.query.get(int(form.id.data))
            bulletin.dt = form.dt.data
            bulletin.title = form.title.data
            bulletin.content = form.content.data
            bulletin.source = form.source.data
            bulletin.author = form.author.data
            orm.db.session.commit()
        else:
            bulletin = orm.Bulletin(form.dt.data, form.title.data,
                                    form.content.data, form.source.data,
                                    form.author.data)
            orm.db.session.add(bulletin)
            orm.db.session.commit()
            form.id.data = bulletin.id

        if request.form.has_key('upload'):
            file = request.files['image']
            if file:
                file_server = str(uuid.uuid1()) + Util.file_extension(
                    file.filename)
                pathfile_server = os.path.join(UPLOAD_PATH, file_server)
                file.save(pathfile_server)
                if os.stat(pathfile_server).st_size < 1 * 1024 * 1024:
                    bulletinimage = orm.Bulletinimage(bulletin.id, file_server)
                    orm.db.session.merge(bulletinimage)
                    orm.db.session.commit()
                else:
                    os.remove(pathfile_server)
        else:
            return redirect(url_for('view_bulletin'))
    elif request.method == 'GET' and bulletin_id:
        form = logic.GetBulletinFormById(bulletin_id)
        logic.LoadBasePageInfo('修改公告', '输入并确定', form)
    else:
        form.dt.data = datetime.datetime.now()
        logic.LoadBasePageInfo('新建公告', '输入并确定', form)

    if form.id.data:
        bulletin = orm.Bulletin.query.get(int(form.id.data))
        form.bulletin = bulletin
        if form.bulletin:
            form.bulletinimages = form.bulletin.bulletinimages

    return render_template('view_bulletin.html', form=form)