반응형
오늘은 Toast Grid 내부 특정 셀에 Toast Grid 내장 함수 및 API 를이용해서 클릭 시 선택하여 해당 열에 저장되어 있는 DB를 조회한 후 Modal을 통해서 View 해준다음 동시에 수정이 가능하도록 코딩을 해보았다 !! 막혔던 부은 Submit을 한 다음 리프레쉬 했을 시 Oracle Error가 떴는데 view단에서 문제점을 찾았다 ! 새로고침을 할때마다 render가 되기때문에 계속 form데이터가 전송이 되었던것이다! 해결방법으로는 render를 시키는것이 아니라 redirect를 해줌으로써 해결이 가능했다!

여러가지 DB를 조회한 후 수정 및 삭제를 함으로써 DB내부 돌아가는 로직과 view단에 대해 더 자세히 알게된것같다! 앞으로도 더 파이팅파이팅이다!
개발 view단
def etclist(request):
order = Order_list.objects.all()
erp = Erp_list.objects.all()
username = request.user.username
userid = request.user.id
if request.POST:
req = request.POST
if req.get('type') == 'addUser':
Factoryfile = Factory()
UserProfile = User()
UserProfile.username = req.get('id')
UserProfile.set_password(req.get('pw'))
UserProfile.first_name = req.get('factory')
UserProfile.last_name = req.get('last_name')
Factoryfile.name = req.get('factory')
if req.get('rank') == '2':
UserProfile.is_superuser = '0'
UserProfile.is_staff = '0'
if req.get('rank') == '1':
UserProfile.is_superuser = '0'
UserProfile.is_staff = '1'
if req.get('rank') == '0':
UserProfile.is_superuser = '1'
UserProfile.is_staff = '1'
UserProfile.save()
Factoryfile.userinfo = UserProfile
Factoryfile.save()
if req.get('type') == 'erpUser':
idx = req.get('shop_idx')
erpdata = Erp_list.objects.get(id=idx)
erpdata.SHOP_ID = req.get('shop_id')
erpdata.SHOP_PW = req.get('shop_pw')
erpdata.SHOP_URL = req.get('shop_url')
erpdata.MODIFY_USER = username
erpdata.save()
if req.get('type') == 'accountuser':
x = req.get('id')
tgfactory = Factory.objects.get(id=x)
tguser = tgfactory.userinfo
if req.get('pw_check'):
tguser.set_password(req.get('pw'))
tguser.save()
tguser.first_name = req.get('first_name')
tguser.last_name = req.get('last_name')
tgfactory.name = req.get('factory')
tguser.save()
tgfactory.save()
return redirect('B2C:etclist')
context = {
'order': order,
'erp': erp,
'username': username,
}
개발 API
if req.get('action') == 'logindetail':
idx = req.get('tgid')
factory_list = Factory.objects.get(id=idx)
context = {
'factory_list': factory_list,
}
return render(request, 'B2C/modal/logindetail.html', context)
개발 Script
<script>
$(document).ready(function () {
$('.pw_check').hide()
$('#add_pw1').attr("disabled", true)
$('#add_pw2').attr("disabled", true)
})
$('input[id="pw_check"]').on("change", function () {
if (this.checked) {
$('.pw_check').show()
$('#add_pw1').attr("disabled", false)
$('#add_pw2').attr("disabled", false)
} else {
$('.pw_check').hide()
$('#add_pw1').attr("disabled", true)
$('#add_pw2').attr("disabled", true)
}
});
$('.pw2').on("propertychange change paste input", function () {
let pass1 = $("#add_pw1").val();
let pass2 = $("#add_pw2").val();
if (pass1 != "" || pass2 != "") {
if (pass1 == pass2) {
$('#checkPw').html('일치');
$('#checkPw').attr('style', 'color:green');
} else {
$('#checkPw').html('불일치');
$('#checkPw').attr('style', 'color:red');
}
}
})
$('#accountuserrBtn').on('click', function () {
let pass1 = $("#add_pw1").val();
let pass2 = $("#add_pw2").val();
if ($('input[id="pw_check"]').is(':checked')) {
if (pass1 != pass2 || $("#add_pw1").val().length == 0) {
alert("비밀번호의 형식이 틀렸습니다.")
return false;
}
}
$('#accountuser').submit()
});
</script>
개발 HTML
<form id="accountuser" method="post" action='{% url 'B2C:etclist' %}'>
<div class="modal-dialog">
<div class="modal-content" style="width:800px; height:600px">
<div class="modal-header">
<h4 class="modal-title" style="color: #2a3954; font-weight: bolder; ">상세 정보</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="container">
<table class="shadow table table-bordered table-hover" id="account_modal"
style="text-align: center">
{% csrf_token %}
<input type="hidden" name="type" value="accountuser">
<input type="hidden" name="id" value="{{ factory_list.id }}">
<tbody>
<tr>
<th>아이디</th>
<td style="display: flex;">
<input type="text" value="{{ factory_list.userinfo.username }}" class="form-control" id="user_id" name="user_id" autocomplete="off" readonly/>
</td>
</tr>
<tr>
<th>비밀번호 변경</th>
<td><input type="checkbox" name="pw_check" id="pw_check">
<label for="pw_check">비밀번호 변경이 필요하시면 선택해주세요.</label>
</td>
</tr>
<tr class="pw_check">
<th>비밀번호</th>
<td><input type="password" class="form-control pw1" name="pw" id="add_pw1" tvalue="패스워드">
</td>
</tr>
<tr class="pw_check">
<th>비밀번호 확인</th>
<td>
<input type="password" class="form-control pw2" name="pw2" id="add_pw2"
tvalue="패스워드 확인">
<p id="checkPw" size="2"></p>
</td>
</tr>
<tr>
<th>명칭
</th>
<td><input type="text" class="form-control" value="{{ factory_list.name }}" name="factory" tvalue="공장" autocomplete="off"></td>
<tr/>
<tr>
<th>담당자명
</th>
<td><input type="text" class="form-control" value="{{ factory_list.userinfo.first_name }}" name="first_name" tvalue="담당자명" autocomplete="off"></td>
<tr/>
<tr>
<th>담당자 사번
</th>
<td><input type="text" class="form-control" value="{{ factory_list.userinfo.last_name }}" name="last_name" tvalue="담당자 사번" autocomplete="off"></td>
<tr/>
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<div class="color_btn2 btn btn-secondary" id="accountuserrBtn">정보 변경</div>
<button id="bgcolor" type="button" class="color_btn btn btn-secondary"
data-bs-dismiss="modal">닫기
</button>
</div>
</div>
</div>
</form>
반응형
'Django' 카테고리의 다른 글
2022-08-29 개발일기 [Django, Toast UI] (0) | 2022.08.29 |
---|---|
2022-08-09 개발일기 [Django, DjangoTemplate] (0) | 2022.08.09 |
2022-07-25 개발일기 [Django] (0) | 2022.07.25 |
2022-06-15 개발일기 [Django] (0) | 2022.06.15 |
2022-06-10 개발일기 [Django, ORM] (0) | 2022.06.10 |