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): 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): 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!'})