def create(request): if request.method == "POST": query = request.POST.copy() form = EditForm(query) if form.is_valid(): try: with transaction.atomic(): d = form.cleaned_data ip_address = ".".join([d[x] for x in ["ip_address1", "ip_address2", "ip_address3", "ip_address4"]]) participant = Participant( display_name=d["display_name"], direction=d["direction"], type=d["type"], ip_address=ip_address, alias_name=d["alias_name"], alias_type=d["alias_type"], model=d["model"], audio_only_flg=d["audio_only_flg"], info=d["info"], bitrate=d["bitrate"], software_version=d["software_version"], phone1=d["phone1"], video_protocol=d["video_protocol"], cascade_role=d["cascade_role"], sip_address=d["sip_address"], sip_address_type=d["sip_address_type"], ) participant.save() except Exception: logger.exception(None) raise return render(request, "participant/complete.html", {"message": u"端末を更新しました。"}) else: form = EditForm() return render(request, "participant/edit.html", {"edit_type": "create", "form": form})
def update(request, participant_id=None): try: participant = Participant.objects.get(pk=participant_id) except Participant.DoesNotExist: raise Http404(u"端末が存在しません。") if request.method == "POST": query = request.POST.copy() form = EditForm(query) if form.is_valid(): try: with transaction.atomic(): d = form.cleaned_data ip_address = ".".join([d[x] for x in ["ip_address1", "ip_address2", "ip_address3", "ip_address4"]]) participant.display_name = d["display_name"] participant.direction = d["direction"] participant.type = d["type"] participant.ip_address = ip_address participant.alias_name = d["alias_name"] participant.alias_type = d["alias_type"] participant.model = d["model"] participant.audio_only_flg = d["audio_only_flg"] participant.info = d["info"] participant.bitrate = d["bitrate"] participant.software_version = d["software_version"] participant.phone1 = d["phone1"] participant.video_protocol = d["video_protocol"] participant.cascade_role = d["cascade_role"] participant.sip_address = d["sip_address"] participant.sip_address_type = d["sip_address_type"] participant.save() except Exception: logger.exception(None) raise return render(request, "participant/complete.html", {"message": u"端末を更新しました。"}) else: ip_address1, ip_address2, ip_address3, ip_address4 = participant.ip_address.split(".") form = EditForm( initial={ "display_name": participant.display_name, "direction": participant.direction, "type": participant.type, "ip_address1": ip_address1, "ip_address2": ip_address2, "ip_address3": ip_address3, "ip_address4": ip_address4, "alias_name": participant.alias_name, "alias_type": participant.alias_type, "model": participant.model, "audio_only_flg": participant.audio_only_flg, "info": participant.info, "bitrate": participant.bitrate, "software_version": participant.software_version, "phone1": participant.phone1, "video_protocol": participant.video_protocol, "cascade_role": participant.cascade_role, "sip_address": participant.sip_address, "sip_address_type": participant.sip_address_type, } ) return render(request, "participant/edit.html", {"edit_type": "update", "form": form, "participant": participant})