def workflow(self, user, voucher, event, **args): if voucher.status in states: source_status = voucher.status state = states[source_status] if event in state: voucher.status = state[event] for key, value in args.iteritems(): setattr(voucher, key, value) change = Change() change.changed_type = 'Voucher' change.changed_id = voucher.id change.event = event change.source = source_status change.destination = voucher.status change.args = json.dumps(args) change.user_id = user.id db.session.add(change) db.session.commit() else: raise Exception( '%s is not valid for %s vouchers: you may only %s' % (event, voucher.status, state.keys())) else: raise Exception('%s is not valid' % voucher.status)
def workflow(self, user, voucher, event, **args): if voucher.status in states: source_status = voucher.status state = states[source_status] if event in state: voucher.status = state[event] for key, value in args.iteritems(): setattr(voucher, key, value) change = Change() change.changed_type = 'Voucher' change.changed_id = voucher.id change.event = event change.source = source_status change.destination = voucher.status change.args = json.dumps(args) change.user_id = user.id db.session.add(change) db.session.commit() else: raise Exception('%s is not valid for %s vouchers: you may only %s' % (event, voucher.status, state.keys())) else: raise Exception('%s is not valid' % voucher.status)
def modify_form(item_id): form = UploadForm() item = Item.query.filter_by(id=item_id).first() if form.validate_on_submit(): if form.pic.data: suffix = os.path.splitext(form.pic.data.filename)[1] filename = random_string() + suffix photos.save(form.pic.data, name=filename) item.pic = filename category = Category.query.filter_by(name=form.category.data).first() item.item_name = form.item_name.data item.status = form.status.data item.location = form.location.data item.time = form.time.data item.category_id = category.id item.description = form.description.data change = Change(changer_id=current_user.id, method='modify', item_id=item.id, item_name=item.item_name, content='change a ' + form.status.data + ' item named ' + form.item_name.data) db.session.add(change) if form.store_location.data != 'No selection': storage = Storage.query.filter_by( location_name=form.store_location.data).first() item.store_location_id = storage.id db.session.commit() return 'success' return render_template('upload_form.html', form=form, current_user=current_user)
def delete(item_id): item = Item.query.filter_by(id=item_id).first() change = Change(changer_id=current_user.id, method='delete', item_id=item.id, item_name=item.item_name, content='delete a ' + item.status + ' item named ' + item.item_name) db.session.add(change) db.session.delete(item) return redirect(url_for('main.userpage'))
def ChangeStatus(item_id): item = Item.query.filter_by(id=item_id).first() change = Change(changer_id=current_user.id, method='modify', item_id=item.id, item_name=item.item_name, content='successfully return a ' + item.status + ' item named ' + item.item_name) db.session.add(change) item.status = 'success' return redirect(url_for('item.itemDetail', item_id=item_id))
def upload_form(): form = UploadForm() if form.validate_on_submit(): if not form.pic.data: flash('Please select the file') else: suffix = os.path.splitext(form.pic.data.filename)[1] filename = random_string() + suffix photos.save(form.pic.data, name=filename) category = Category.query.filter_by( name=form.category.data).first() if form.store_location.data == 'No selection': item = Item(item_name=form.item_name.data, status=form.status.data, location=form.location.data, time=form.time.data, category_id=category.id, description=form.description.data, pic=filename, uploader_id=current_user.id) else: storage = Storage.query.filter_by( location_name=form.store_location.data).first() item = Item(item_name=form.item_name.data, status=form.status.data, location=form.location.data, time=form.time.data, category_id=category.id, description=form.description.data, pic=filename, uploader_id=current_user.id, store_location_id=storage.id) db.session.add(item) item_change = Item.query.filter_by( item_name=form.item_name.data, time=form.time.data, location=form.location.data, description=form.description.data).first() change = Change(changer_id=current_user.id, method='upload', item_id=item_change.id, item_name=item_change.item_name, content='create a ' + form.status.data + ' item named ' + form.item_name.data) db.session.add(change) db.session.commit() return 'success' return render_template('upload_form.html', form=form, current_user=current_user)
def done(self, request, cleaned_data): feature_model = cleaned_data['edited_text'] print(feature_model.DTL_SEQ) if request.user.is_superuser: edit = """UPDATE Test.CPL_TEST.FEAT_DETAIL SET DTL_TYP = '%s', DTL_TEXT = '%s' WHERE pl_id = %i AND FEAT_ID = %i AND DTL_SEQ = %i""" % ( cleaned_data['detail_type'].DTL_TYPE, cleaned_data['new_text'], int(request.session['pl_id']), int(request.session['feature_id']), feature_model.DTL_SEQ) cursor.execute(edit) cnxn.commit() change = Change( user_id=request.user.username, pl_id=request.session['pl_id'], FEAT_ID=request.session['feature_id'], FEAT_NM=request.session['feature_name'], DTL_SEQ=int(feature_model.DTL_SEQ), DTL_TYPE_original=feature_model.DTL_TYPE, DTL_TEXT_original=feature_model.DTL_TEXT, DTL_TYPE_updated=cleaned_data.get('detail_type').DTL_TYPE, DTL_TEXT_updated=cleaned_data['new_text'], status='p', edit_type='e') change.save() feature_model.DTL_TEXT = cleaned_data['new_text'] feature_model.DTL_TYPE = cleaned_data['detail_type'].DTL_TYPE feature_model.save(update_fields=['DTL_TEXT', 'DTL_TYPE']) else: change = Change( user_id=request.user.username, pl_id=request.session['pl_id'], FEAT_ID=request.session['feature_id'], FEAT_NM=request.session['feature_name'], DTL_SEQ=int(feature_model.DTL_SEQ), DTL_TYPE_original=feature_model.DTL_TYPE, DTL_TEXT_original=feature_model.DTL_TEXT, DTL_TYPE_updated=cleaned_data.get('detail_type').DTL_TYPE, DTL_TEXT_updated=cleaned_data['new_text'], status='d', edit_type='e') change.save() msg = "User %s has requested a change to feature code %s" % ( request.user.username, request.session['feature_name']) messages.warning(request, msg, extra_tags=get_time()) return render(request, 'app/success.html', {'info': 'Success!'})
def done(self, request, cleaned_data): num_objects = FEAT_DETAIL.objects.filter( FEAT_ID=request.session['feature_id']).filter( pl_id=request.session['pl_id']).order_by( '-DTL_SEQ').values_list('DTL_SEQ', flat=True)[0] + 1 detail_type = cleaned_data.get('detail_type') print(num_objects) if request.user.is_superuser: insert = """INSERT INTO Test.CPL_TEST.FEAT_DETAIL (pl_id, FEAT_ID, DTL_SEQ, DTL_TYP, DTL_TEXT) VALUES (%i, %i, %i, '%s', '%s')""" % ( int(request.session['pl_id']), int(request.session['feature_id']), num_objects, detail_type.DTL_TYPE, cleaned_data['detail_text']) cursor.execute(insert) cnxn.commit() added_text = FEAT_DETAIL(pl_id=request.session['pl_id'], FEAT_ID=request.session['feature_id'], DTL_SEQ=num_objects, DTL_TYPE=detail_type.DTL_TYPE, DTL_TEXT=cleaned_data['detail_text']) added_text.save() change = Change( user_id=request.user.username, pl_id=request.session['pl_id'], FEAT_ID=request.session['feature_id'], FEAT_NM=request.session['feature_name'], DTL_SEQ=num_objects, DTL_TYPE_updated=detail_type.DTL_TYPE, #DTL_TYPE_original = null, DTL_TEXT_updated=cleaned_data['detail_text'], #DTL_TEXT_original = null, status='p', edit_type='a') else: change = Change( user_id=request.user.username, pl_id=request.session['pl_id'], FEAT_ID=request.session['feature_id'], FEAT_NM=request.session['feature_name'], DTL_SEQ=num_objects, DTL_TYPE_updated=detail_type.DTL_TYPE, #DTL_TYPE_originial = null, DTL_TEXT_updated=cleaned_data['detail_text'], #DTL_TYPE_updated = null, status='d', edit_type='a') msg = "User %s has requested a change to feature code %s" % ( request.user.username, request.session['feature_name']) messages.warning(request, msg, extra_tags=get_time()) change.save() return render(request, 'app/success.html', {'info': 'Success!'})
def done(self, request, cleaned_data): deleted_text = cleaned_data['deleted_text'].DTL_TEXT removal = FEAT_DETAIL.objects.filter(DTL_TEXT=deleted_text) if request.user.is_superuser: delete = """DELETE FROM Test.CPL_TEST.FEAT_DETAIL WHERE pl_id = %i AND FEAT_ID = %i AND DTL_SEQ = %i""" % ( int(request.session['pl_id']), int(request.session['feature_id']), int(removal.values_list('DTL_SEQ', flat=True)[0])) cursor.execute(delete) cnxn.commit() change = Change( user_id=request.user.username, pl_id=request.session['pl_id'], FEAT_ID=request.session['feature_id'], FEAT_NM=request.session['feature_name'], DTL_SEQ=removal.values_list('DTL_SEQ', flat=True)[0], DTL_TYPE_original=removal.values_list('DTL_TYPE', flat=True)[0], #DTL_TYPE_updated = null, DTL_TEXT_original=deleted_text, #DTL_TEXT_updated = Null, status='p', edit_type='r') removal.delete() else: change = Change( user_id=request.user.username, pl_id=request.session['pl_id'], FEAT_ID=request.session['feature_id'], FEAT_NM=request.session['feature_name'], DTL_SEQ=removal.values_list('DTL_SEQ', flat=True)[0], DTL_TYPE_original=removal.values_list('DTL_TYPE', flat=True)[0], #DTL_TYPE_updated = null, DTL_TEXT_original=deleted_text, #DTL_TEXT_updated = null, status='d', edit_type='r') msg = "User %s has requested a change to feature code %s" % ( request.user.username, request.session['feature_name']) messages.warning(request, msg, extra_tags=get_time()) change.save() return render(request, 'app/success.html', {'info': 'Success!'})