def edit(id, yymm, dd): person = Person.get(id) if person is None: abort(404) workrec = WorkRec.get(id, yymm, dd) if workrec is None: abort(404) idm = cache.get('idm') if idm != person.idm: form = WorkRecAbsenceForm(obj=workrec) else: form = WorkRecForm(obj=workrec) if form.validate_on_submit(): workrec.populate_form(form) db.session.add(workrec) try: db.session.commit() enabled_workrec.delay(id, yymm) flash('WorkRec saved successfully.', 'success') return redirect(url_for('workrecs.index', id=id, yymm=yymm)) except: db.session.rollback() flash('Error update workrec!', 'danger') return render_template('workrecs/edit.pug', person=person, form=form, yymm=yymm)
def post_idm(idm): cache.set('idm', None, 5 * 60) person = Person.query.filter_by(idm=idm).first() if person is None: return jsonify({"message": "Not Found!"}), 404 now = datetime.now() yymm = now.strftime('%Y%m') dd = now.day hhmm = now.strftime('%H:%M') workrec = WorkRec.get(person.id, yymm, dd) creation = False if workrec is None: creation = True work_in = get_work_in(hhmm, person.staff) workrec = WorkRec(person_id=person.id, yymm=yymm, dd=dd, work_in=hhmm) else: work_in = get_work_in(workrec.work_in, person.staff) work_out = get_work_out(hhmm, person.staff) break_t = 0.0 if (work_in['value'] < 12.0) and (work_out['value'] > 13.0): break_t = 1.0 value = work_out['value'] - work_in['value'] - break_t if value < 0: value = 0 break_t = 0 over_t = 0.0 if value > 8.0: over_t = value - 8.0 workrec.work_out = hhmm workrec.value = value workrec.break_t = break_t workrec.over_t = over_t db.session.add(workrec) try: db.session.commit() enabled_workrec.delay(person.id, yymm) except: db.session.rollback() return jsonify({}), 500 if creation: result = dict(work_in=workrec.work_in, work_out='--:--') return jsonify(result), 201 result = dict(work_in=workrec.work_in, work_out=workrec.work_out) return jsonify(result), 200
def destroy(id, yymm, dd): person = Person.get(id) if person is None: abort(404) idm = cache.get('idm') workrec = WorkRec.get(id, yymm, dd) if (idm != person.idm) and ((workrec is not None) and (workrec.work_in is not None)): flash('利用者のICカードをタッチしてください', 'danger') if (workrec is not None) and ((idm == person.idm) or (workrec.work_in is None)): db.session.delete(workrec) try: db.session.commit() enabled_workrec.delay(id, yymm) flash('Entry delete successfully.', 'success') except: db.session.rollback() flash('Error delete entry!', 'danger') return redirect(url_for('workrecs.index', id=id, yymm=yymm))
def update(id, yymm): enabled_workrec.delay(id, yymm) return redirect(url_for('workrecs.index', id=id, yymm=yymm))