def real_read_card(request): resident_name = request.POST.get('name') birthday = request.POST.get('birthday') gender = request.POST.get('gender') nation = request.POST.get('nation') address = request.POST.get('address') identity = request.POST.get('identity') try: resident = Resident.objects.get(identity=identity) except Resident.DoesNotExist: resident = Resident() resident.name = resident_name resident.gender = gender if len(birthday) != 8: resident.birthday = '1900-01-01' else: resident.birthday = birthday[0:4] + '-' + birthday[ 4:6] + '-' + birthday[6:8] resident.nation = nation resident.address = address resident.identity = identity resident.save() request.session['resident_id'] = resident.id request.session['resident_name'] = resident.name request.session['resident_ehr_no'] = resident.ehr_no json_data = model_to_dict(resident, fields=['id', 'name', 'ehr_no']) return JsonResponse(json_data)
def test_card(request): name = request.GET.get('name') birthday = request.GET.get('birthday') gender = request.GET.get('gender') nation = request.GET.get('nation') address = request.GET.get('address') identity = request.GET.get('identity') try: resident = Resident.objects.get(identity=identity) except Resident.DoesNotExist: resident = Resident() resident.name = name resident.gender = gender try: year, month, day = int(birthday[:4]), int(birthday[4:6]), int( birthday[6:8]) except Exception: pass else: resident.birthday = date(year, month, day) resident.nation = nation resident.address = address resident.identity = identity resident.save() finally: candidates = list() candidates.append(resident) if resident.family: for member in resident.family.members.all(): if member is not resident and member.identity is None: candidates.append(member) json_candidates = serializers.serialize("json", candidates) return HttpResponse(json_candidates, content_type="application/javascript")