def request_temp_old_visitor(request): constraint = helpers.constraint(request, "POST"); data = constraint.safe({ "visitor_id": True }); of_department = Department.objects.all().order_by("name"); of_user = UserProfile.objects.get(user_id=request.user.id); of_person = Person.objects.get(id=data['visitor_id']); of_log = Log.objects.filter( details__person_visitor_id=of_person, added_by__department_id=of_user.department_id ).order_by("-id").first(); return render(request, "ajax_temp/action_type_old_visitor.html", { 'data': data, "person": of_person, "of_date": datetime.now(), "last_log": of_log, "department": of_department, "obj_log" :Log, "document_type" : Document_type.objects.all().order_by("name"), });
def request_database_add_personal_details(request): constraint = helpers.constraint(request, "POST"); data = constraint.safe({ "first_name": True, "last_name": True, "department": False }); request.user.first_name = data['first_name']; request.user.last_name = data['last_name']; request.user.full_clean(); request.user.clean(); request.user.save(); try: of_department = Department.objects.get(id=data['department']); of_user_profile = UserProfile( user=request.user, department= of_department ); of_user_profile.full_clean(); of_user_profile.clean(); of_user_profile.save(); return redirect("/"); except Department.DoesNotExist: raise Department.DoesNotExist("Index id of department object does not exists"); pass;
def establishment_state_change_request(request): constraint = helpers.constraint(request, "POST"); data = constraint.strict([ "establishment_id", "state" ], True); data['state'] = "confirm_" + str(data['state']); of_members = building_owner.objects.get(id=data['establishment_id']); check_if_valid_action = hasattr(of_members, data['state']); if not check_if_valid_action: raise helpers.InvalidRequest("Parameter 'state' not valid action"); of_method = getattr(of_members, data['state'])(); of_members.full_clean(); of_members.clean(); of_members.save(); return render(request,"web_manage/load_ajax/establishment_respond_state.html",{ "data" : of_members }); pass;
def request_temp_log_more_details(request): try: constraint = helpers.constraint(request, "POST"); data = constraint.safe({ "log_id": True, }); of_user = UserProfile.objects.get(user_id=request.user.id); of_log = Log.objects.get( id=data['log_id'], added_by__department_id=of_user.department_id ); return render(request, "ajax_temp/log_details.html", { 'data': of_log, 'out': of_log.out(), "is_out": of_log.is_out_provided(), "LOG" : Log }); except Log.DoesNotExist: raise Log.DoesNotExist("Index id of Log object does not exists"); except UserProfile.DoesNotExist: raise UserProfile.DoesNotExist("Index id of UserProfile object does not exists"); except helpers.InvalidRequest: raise helpers.InvalidRequest("Parameters does not supply required fields") pass; pass;
def request_temp_visitor_add(request): try: constraint = helpers.constraint(request, "POST"); data = constraint.safe({ "firstname": True, "lastname": True, "middlename": False }); of_department = Department.objects.all().order_by("name"); of_user_profile = UserProfile.objects.get(id=request.user.id); return render(request, "ajax_temp/action_type_new_visitor.html", { 'data': data, "of_date": datetime.now(), "department": of_department, "user_profile" : of_user_profile, "document_type": Document_type.objects.all().order_by("name"), "log_type": Log.TypeOf }); except helpers.InvalidRequest: return HttpResponse('Gago'); pass; pass;
def r_login_request(request): try: constraint = helpers.constraint(request, "POST") data = constraint.strict(["username", "password"], True) user = auth.authenticate(username=data['username'], password=data['password'], is_staff=False, is_superuser=False) if user and not user.is_superuser: auth.login(request, user) return redirect("/home") messages.error( request, "Username and Password do not match. Please try again." "if username and password do not work your account may have been disabled", extra_tags="Account not found") return login(request) except helpers.InvalidRequest: messages.error( request, "Please dont leave blanks before submitted" " (Palihug ayaw ibilin ang mga blangko sa wala pa isumite)", extra_tags="Request not valid") return login(request) pass
def establishment_auth(request, username, format=None): try: constraint = helpers.constraint(request, "POST") data = constraint.strict(["auth.pass"], True) user = auth.authenticate(username=username, password=data['auth.pass'], is_staff=False, is_superuser=False) if not user: raise AuthenticationFailed() of_building_owner = building_owner.objects.get(user_id=user.id) if not of_building_owner.account_is_verified: raise AccountNotVerified() serializer = BuildingOwnerSerializer(of_building_owner, many=False) return Response(serializer.data) except helpers.InvalidRequest: raise ParametersNotValid() pass except building_owner.DoesNotExist as e: raise BuildingOwnerNotFound() pass pass
def r_phone_number_verification(request): of_household_profile = household_profile.objects.get(user=request.user.id); if not "sms_verification" in request.session: messages.error(request,"Verification code reset", extra_tags="Info"); return v_phone_number_verification(request); pass; try: constraint = helpers.constraint(request, "POST"); data = constraint.strict([ "verification_code" ], True); sms_verification = request.session['sms_verification']; print(sms_verification); if not (str(data['verification_code']) == str(sms_verification['value'])): messages.error(request,"Incorrect verificaton code", extra_tags="Verification code not valid"); return v_phone_number_verification(request); pass; of_household_profile.account_is_verified = of_household_profile.VERIFIED_VERIFICATION_STATE; of_household_profile.clean(); of_household_profile.save(); of_family_member = family_members( household_profile = of_household_profile, relationship = Relationship.objects.get(is_owner=True), first_name = of_household_profile.user.first_name, last_name = of_household_profile.user.last_name, date_of_birth = of_household_profile.date_of_birth, gender = of_household_profile.gender, verification_file = of_household_profile.verification_file, profile = of_household_profile.profile ); of_family_member.clean(); of_family_member.save(); return redirect("/home"); except helpers.InvalidRequest: messages.info(request,"Please fill all the fields dont leave empty.", extra_tags="Info"); return v_phone_number_verification(request); except Exception as e: of_household_profile.account_is_verified = of_household_profile.PENDING_VERIFICATION_STATE; of_household_profile.save(); raise Exception(e); pass; pass;
def get_puroks_from_barangay(request): constraint = helpers.constraint(request, "GET") data = constraint.strict(["barangay"], True) of_barangay = ref_barangay.objects.get(id=data['barangay']) of_purok = ref_purok.objects.filter(barangay=of_barangay) qs_json = serializers.serialize('json', of_purok) return HttpResponse(qs_json, content_type='application/json')
def scan(request): constraint = helpers.constraint(request, "POST"); data = constraint.strict([ "scan_result" ], True); print(data); pdb.set_trace(); pass;
def log_remove(request): constraint = helpers.constraint(request, "POST"); data = constraint.safe({ "log_id": True }); of_log = Log.objects.get(id=data['log_id']); of_log.delete(); return render(request, "ajax_temp/successfully_remove_new_log.html", { "data" : of_log });
def database_save_as_out(request): try: constraint = helpers.constraint(request, "POST"); data = constraint.safe({ "log_id": True, "receiver_name": False, "description": False }); of_user = UserProfile.objects.get(user_id=request.user.id); of_log = Log.objects.get( id=data['log_id'], added_by__department_id=of_user.department_id, ); of_out = Out( receiver_name=data['receiver_name'], log=of_log, description=data['description'], added_by=of_user ); of_out.full_clean(); of_out.clean(); of_out.save(); of_log.is_out = True; of_log.save(); return render(request, "ajax_temp/log_details.html", { 'data': of_log, 'out': of_log.out(), "is_out": of_log.is_out_provided(), "LOG" : Log }); except Log.DoesNotExist: raise Log.DoesNotExist("Index id of Log object does not exists"); except UserProfile.DoesNotExist: raise UserProfile.DoesNotExist("Index id of UserProfile object does not exists"); except helpers.InvalidRequest: raise helpers.InvalidRequest("Parameters does not supply required fields") pass;
def request_log_search(request): try: constraint = helpers.constraint(request, "POST"); data = constraint.safe({ "firstname": True, "lastname": True, "middlename": False, "pageIndex": True, "pageSize": True }); of_person = TempPerson.objects.filter( Q(fullname__icontains=data['firstname']), Q(fullname__icontains=data['lastname']), Q(first_name__icontains=data['firstname']) | Q(last_name__icontains=data['lastname']) | Q(middle_name__icontains=data['middlename']) ).order_by("-id"); if not of_person: return HttpResponse(); split = Paginator(of_person, int(data["pageSize"])); split_by = split.page(int(data['pageIndex'])); data_splitted = split_by.object_list; of_user = UserProfile.objects.get(user=request.user.id); for per in data_splitted: of_in_last = Log.objects.filter( details__person_visitor_id=per.id, added_by__department_id=of_user.department_id ).order_by("-id").first(); per.last_in = of_in_last; pass; return render(request, "ajax_temp/person_list.html", { 'data': data_splitted, "params": data, "itemCount": len(of_person) }); except helpers.InvalidRequest: return HttpResponse(); pass; pass;
def r_check_username_exist(request): constraint = helpers.constraint(request, "GET") data = constraint.strict(["username"], True) of_exists = User\ .objects\ .filter(username=data['username'])\ .exists() if of_exists: raise helpers.UsernameAlreadyExists("Phone number not available") return HttpResponse('') pass
def cancel_request_adding_family_members(request): constraint = helpers.constraint(request, "GET"); data = constraint.strict([ "family_members_id" ], True); of_family_members = family_members.objects.get( id=data['family_members_id'], household_profile__user_id=request.user.id ); of_family_members.delete(); return redirect('/household/family'); pass;
def r_check_phone_number_is_exists(request): constraint = helpers.constraint(request, "GET") data = constraint.strict(["phone_number"], True) data['phone_number'] = "".join( [char for char in data['phone_number'] if char.isalnum()]) of_household_exists = household_profile\ .objects\ .filter(phone_number=data['phone_number'])\ .exists() if of_household_exists: raise helpers.PhoneNumberAlreadyExists("Phone number not available") return HttpResponse('') pass
def r_email_verification(request): of_building_profile = building_owner.objects.get(user=request.user.id) if not "email_verification" in request.session: messages.error(request, "Verification code reset", extra_tags="Info") return v_email_verification(request) pass try: constraint = helpers.constraint(request, "POST") data = constraint.strict(["verification_code"], True) email_verification = request.session['email_verification'] if not (str(data['verification_code']) == str( email_verification['value'])): messages.error(request, "Incorrect verificaton code", extra_tags="Verification code not valid") return v_email_verification(request) pass of_building_profile.account_is_verified = of_building_profile.VERIFIED_VERIFICATION_STATE of_building_profile.clean() of_building_profile.save() return redirect("/home") except helpers.InvalidRequest: messages.info(request, "Please fill all the fields dont leave empty.", extra_tags="Info") return v_email_verification(request) except Exception as e: of_building_profile.account_is_verified = of_building_profile.PENDING_VERIFICATION_STATE of_building_profile.save() raise Exception(e) pass pass
def qr_code(request): constraint = helpers.constraint(request, "GET"); data = constraint.strict([ "family_members_id" ], True); of_members = family_members.objects.get(id=data['family_members_id']); json_returne = { "id": of_members.id }; json_object = json.dumps(json_returne, indent=None, separators=(",", ":")); format_data = base64.b64encode(bytes(str(json_object), 'utf-8')); return render(request, "household/qr_code.html", { "format_data": format_data }); pass;
def changed_state_members_request(request): constraint = helpers.constraint(request, "POST"); data = constraint.strict([ "family_members_id", "state" ], True); data['state'] = "confirm_" + str(data['state']); of_members = family_members.objects.get(id=data['family_members_id']); check_if_valid_action = hasattr(of_members, data['state']); if not check_if_valid_action: raise helpers.InvalidRequest("Parameter 'state' not valid action"); of_method = getattr(of_members, data['state'])(); of_members.save(); return render(request,"web_manage/load_ajax/household_respond_state.html",{ "data" : of_members });
def login(request): constraint = helpers.constraint(request, "POST"); data = constraint.strict([ "username", "password" ], True); user = auth.authenticate( username=data['username'], password=data['password'], is_staff = False, is_superuser=False ); if user: return HttpResponse("Success") pass; return AttributeError("Log in details not valid"); pass;
def request(request): if len(request.POST) > 0: # print(request.__class__.__name__); constraint = helpers.constraint(request) data = constraint.strict(["account", "password"], True) user = auth.authenticate(username=data['account'], password=data['password']) if user and not user.is_superuser: auth.login(request, user) return redirect("/home") str_message = """ Please enter the correct username and password for a employee account. Note that both fields may be case-sensitive. """ messages.error(request, str_message) return redirect("/")
def get_tracing_code_info(request): try: constraint = helpers.constraint(request, "POST"); data = constraint.safe({ "tracing_code": True }); of_user_profile = UserProfile.objects.get(id=request.user.id); of_log_details = Log_details.objects.get( tracing_code=data['tracing_code'] ); is_department_log = of_log_details\ .added_by\ .department_id == of_user_profile.department_id; return render(request, "ajax_temp/action_tracking_code_info.html", { 'log_details': of_log_details, 'is_department_log' : is_department_log, "obj_log" : Log, "log_details_person" : of_log_details.person_visitor }); except Log_details.DoesNotExist: raise Log.DoesNotExist("Log details id does not exists"); except UserProfile.DoesNotExist: raise UserProfile.DoesNotExist("Index id of UserProfile object does not exists"); except helpers.InvalidRequest: raise helpers.InvalidRequest("Parameters does not supply required fields") pass; pass;
def r_add_family_members(request): try: constraint = helpers.constraint(request, "POST"); data = constraint.strict([ "household_profile", "first_name", "last_name", "date_of_birth", "relationship", "gender" ], True); of_household_profile = household_profile.objects.get( id=data['household_profile'], user=request.user ); of_relationship = Relationship.objects.get(id=data['relationship']); data['is_confirm'] = family_members.CONFIRM_PENDING; form = FamilyMembersForm(data=data, files=request.FILES); validate = form.is_valid(); if not validate: print(form.errors); raise helpers.InnerInvalidRequest(); form.save(); of_message = " ".join([ "you have sent a request to verify.", "Please wait for our respond for this matter" ]); messages.success(request, of_message, extra_tags="Successfully added"); return redirect("/household/family") except helpers.InvalidRequest: messages.error(request, "Please dont leave blanks before submitted" " (Palihug ayaw ibilin ang mga blangko sa wala pa isumite)", extra_tags="Request not valid"); return family(request); except helpers.InnerInvalidRequest: messages.error(request, "Inner validition result invalid", extra_tags="Request valid but parameters not satisfy"); return family(request); except household_profile.DoesNotExist: messages.error(request, "household_profile id does not valid or not exits", extra_tags="Request not valid"); return family(request); pass; except Relationship.DoesNotExist: messages.error(request, "Relationship id does not valid or not exits", extra_tags="Request not valid"); return family(request); pass; except Exception as e: raise Exception(e); pass;
def continuedForm(request): date_accomplished = datetime.now() try: constraint = helpers.constraint(request, "POST"); data = constraint.safe({ "sur_name": True, "first_name": True, "middle_name": False, "date_of_birth": True, "pace_of_birth": True, "sex": True, "civil_status": True, "height": True, "weight": True, "citizenship": True, "res_reg": True, "res_province": True, "res_city": True, "res_brgy": True, "res_lot_no": True, "res_street": True, "res_subd": True, "res_zipcode": True, "per_reg": True, "per_province": True, "per_lot_no": True, "per_street": True, "per_subd": True, "per_zipcode": True, "per_brgy": True, "per_city": True, "mobile_no": True, "email_address": True, "name_ext": False, "telephone": False, "gsis_id_no": False, "pagibig_id_no": False, "philhealth_no": False, "sss_no": False, "tin_no": False, "agency_employee_no": False, "citizenship_country": False, "blood_type": False }) pers_info = personal_Info(sur_name=data["sur_name"], first_name=data["first_name"], middle_name=data["middle_name"], name_ext=data["name_ext"], date_of_birth=data["date_of_birth"], pace_of_birth=data["pace_of_birth"], sex=data["sex"], civil_status=data["civil_status"], height=data["height"], weight=data["weight"], blood_type=data["blood_type"], gsis_id_no=data["gsis_id_no"], pagibig_id_no=data["pagibig_id_no"], philhealth_no=data["philhealth_no"], sss_no=data["sss_no"], tin_no=data["tin_no"], agency_employee_no=data["agency_employee_no"], citizenship=data["citizenship"], citizenship_country=data["citizenship_country"], res_reg=data["res_reg"], res_province=data["res_province"], res_city=data["res_city"], res_brgy=data["res_brgy"], res_lot_no=data["res_lot_no"], res_street=data["res_street"], res_subd=data["res_subd"], res_zipcode=data["res_zipcode"], per_reg=data["per_reg"], per_province=data["per_province"], per_lot_no=data["per_lot_no"], per_street=data["per_street"], per_subd=data["per_subd"], per_zipcode=data["per_zipcode"], per_brgy=data["per_brgy"], per_city=data["per_city"], telephone=data["telephone"], mobile_no=data["mobile_no"], email_address=data["email_address"], date_accomplished=date_accomplished) pers_info.save() data = { 'pi_pk': pers_info.pi_pk } print("Data Saved") except helpers.InvalidRequest: return render(request, 'apply/continue-form.html') return render(request, 'apply/continue-form.html', data) pass;
def r_register_household(request): try: constraint = helpers.constraint(request, "POST") data = constraint.strict([ "resident_first_name", "resident_last_name", "phone_number", "username", "resident_password", "resident_date_of_birth", "resident_gender", "resident_purok", "resident_street", ], True) ''' Begin reCAPTCHA validation ''' recaptcha_response = request.POST.get('g-recaptcha-response') url = 'https://www.google.com/recaptcha/api/siteverify' values = { 'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY, 'response': recaptcha_response } r = requests.post('https://www.google.com/recaptcha/api/siteverify', data=values) result = r.json() ''' End reCAPTCHA validation ''' if not result['success']: messages.error(request, "Invalid recaptcha", extra_tags="Request not valid") raise helpers.InvalidRequest("Household profile invalid params") pass user = User.objects.create_user(username=data['username'], password=data['resident_password'], first_name=data['resident_first_name'], last_name=data['resident_last_name'], is_staff=False) my_group = Group.objects.get(id=Category.group_citizens_id) my_group.user_set.add(user) of_purok = Purok.objects.get(id=data['resident_purok']) data['phone_number'] = "".join( [char for char in data['phone_number'] if char.isalnum()]) household_form_params = { "user": user, "phone_number": data['phone_number'], "date_of_birth": data['resident_date_of_birth'], "gender": data['resident_gender'], "purok": of_purok, "account_is_verified": household_profile.PENDING_VERIFICATION_STATE, "street": data['resident_street'] } of_household_profile = HouseholdForm(data=household_form_params, files=request.FILES) validate_household_profile = of_household_profile.is_valid() if not validate_household_profile: user.delete() raise helpers.InvalidRequest("Household profile invalid params") edit = of_household_profile.save(commit=True) edit.save() user = auth.authenticate(username=data['username'], password=data['resident_password']) auth.login(request, user) return redirect("/home") except helpers.InvalidRequest: messages.error( request, "Please dont leave blanks before submitted" " (Palihug ayaw ibilin ang mga blangko sa wala pa isumite)", extra_tags="Request not valid") return v_register_household(request) except UnboundLocalError as e: messages.error( request, "Please dont leave blanks before submitted" " (Palihug ayaw ibilin ang mga blangko sa wala pa isumite)", extra_tags="Request not valid") return v_register(request) pass except Exception as e: if user: user.delete() raise Exception(e) pass
def r_register_as_building_owner(request): try: constraint = helpers.constraint(request, "POST") data = constraint.strict([ "establishment_email", "username", "password", "establishment_name", "establishment_street", "establishment_purok" ], True) ''' Begin reCAPTCHA validation ''' recaptcha_response = request.POST.get('g-recaptcha-response') url = 'https://www.google.com/recaptcha/api/siteverify' values = { 'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY, 'response': recaptcha_response } r = requests.post('https://www.google.com/recaptcha/api/siteverify', data=values) result = r.json() ''' End reCAPTCHA validation ''' if not result['success']: messages.error(request, "Invalid recaptcha", extra_tags="Request not valid") raise helpers.InvalidRequest("Household profile invalid params") pass user = User.objects.create_user(email=data['establishment_email'], username=data['username'], password=data['password'], is_staff=False) my_group = Group.objects.get(id=Category.group_building_owner_id) my_group.user_set.add(user) that_building_owner_data = { "user": user.id, "establishment_name": data['establishment_name'], "purok": data['establishment_purok'], "street": data['establishment_street'] } form = BuildingOwnerForm(data=that_building_owner_data, files=request.FILES) validate = form.is_valid() if not validate: user.delete() raise helpers.InvalidRequest("Establishment profile not valid") edit = form.save(commit=True) edit.save() user = auth.authenticate(username=data['username'], password=data['password']) auth.login(request, user) return redirect("/home") except helpers.InvalidRequest: messages.error( request, "Please dont leave blanks before submitted" " (Palihug ayaw ibilin ang mga blangko sa wala pa isumite)", extra_tags="Request not valid") return v_register(request) except UnboundLocalError as e: messages.error( request, "Please dont leave blanks before submitted" " (Palihug ayaw ibilin ang mga blangko sa wala pa isumite)", extra_tags="Request not valid") return v_register(request) pass except Exception as e: if user: user.delete() raise Exception(e) pass pass
def database_add_new_log(request): constraint = helpers.constraint(request, "POST"); data = constraint.safe({ "contact_number2": False, "purpose": False, "type": True, "visitor_id": True, "document_from": False, "document_type" : False }); try: of_user = UserProfile.objects.get(user=request.user.id); of_person = Person.objects.get(id=data['visitor_id']); log_details_params = { "person_visitor": of_person, "contact_number":data['contact_number2'], "added_by" : of_user }; if data['document_type']: log_details_params['document_type'] = Document_type.objects.get(id=data['document_type']); if data['document_from']: log_details_params['document_from'] = Department.objects.get(id=data['document_from']); of_log_details = Log_details(**log_details_params); of_log_details.full_clean(); of_log_details.clean(); of_log_details.save(); of_log = Log( type=data['type'], purpose=data['purpose'], details=of_log_details, added_by=of_user ); try: of_log.full_clean(); of_log.clean(); of_log.save(); except e : of_log_details.delete(); raise Exception(e); pass; return render(request, "ajax_temp/after_added_new_log.html", { 'log': of_log, "obj_log" : Log, "log_details_person" : of_log.details.person_visitor }); except Person.DoesNotExist: raise UserProfile.DoesNotExist("Index id of Person object does not exists"); except UserProfile.DoesNotExist: raise UserProfile.DoesNotExist("Index id of UserProfile object does not exists"); except helpers.InvalidRequest: return HttpResponse('Invalid Request'); pass;
def populate_list_log(request): constraint = helpers.constraint(request, "POST"); data = constraint.safe({ "pageIndex": True, "pageSize": True, "firstname" : False, "lastname" : False, "middlename" : False, "department" : False, "document_type" : False, "state_in_out" : False, "tracing_code" : False, "start_date" : False, "end_date" : False }, True); of_user = UserProfile.objects.get(user_id=request.user.id); of_log = Log.objects.filter( added_by__department_id=of_user.department_id ); if data['firstname'] : of_log = of_log.filter( Q(details__person_visitor__first_name__icontains=data['firstname']) ) pass; if data['lastname'] : of_log = of_log.filter( Q(details__person_visitor__last_name__icontains=data['lastname']) ) pass; if data['tracing_code'] : of_log = of_log.filter( Q(details__tracing_code__icontains=data['tracing_code']) ) pass; if data['department'] : of_log = of_log.filter( Q(details__document_from=data['department']) | Q(details__person_visitor__department=data['department']) ) pass; if data['document_type'] : of_log = of_log.filter( Q(details__document_type_id=data['document_type']) ) pass; if data['state_in_out'] : of_log = of_log.filter( Q(type=Log.IN_AND_OUT), Q(is_out=int(data['state_in_out']) > 0) ) pass; if data['start_date'] and data['end_date']: start_date = datetime.strptime(data['start_date'], "%Y-%m-%d"); end_date = datetime.strptime(data['end_date'], "%Y-%m-%d"); of_log = of_log.filter(Q(date__range=(start_date, end_date))); pass; of_log = of_log.order_by("-date","-time") if len(of_log): split = Paginator(of_log, int(data["pageSize"])); split_by = split.page(int(data['pageIndex'])); data_splitted = split_by.object_list; for per in data_splitted: of_out = Out.objects.filter(log_id=per.id).last(); per.out = of_out; else: data_splitted = []; pass; return render(request, "ajax_temp/log_list.html", { 'data': data_splitted, 'itemCount': len(of_log), "params" : data, "LOG" : Log });
def database_add_new_visitor(request): constraint = helpers.constraint(request, "POST"); data = constraint.safe({ "contact_number": False, "department": False, "first_name": True, "last_name": True, "middle_name": False, "gender": True, "purpose": False, "type": True, "contact_number2": False, "document_type": False, "document_from": False }); of_user = UserProfile.objects.get(user=request.user.id); person_params = { "first_name": data['first_name'], "last_name": data['last_name'], "middle_name": data['middle_name'], "gender": data['gender'], "added_by": of_user }; if data['contact_number']: person_params['contact_number'] = data['contact_number']; pass; if data['department']: person_params['department'] = Department.objects.get(id=data['department']); of_person = Person(**person_params); of_person.full_clean(); of_person.clean(); of_person.save(); log_details_params = { "person_visitor": of_person, "contact_number":data['contact_number2'], "added_by" : of_user }; if data['document_type']: log_details_params['document_type'] = Document_type.objects.get(id=data['document_type']); if data['document_from']: log_details_params['document_from'] = Department.objects.get(id=data['document_from']); of_log_details = Log_details(**log_details_params); of_log_details.full_clean(); of_log_details.clean(); of_log_details.save(); of_log = Log( type=data['type'], purpose=data['purpose'], details=of_log_details, added_by=of_user ); try: of_log.full_clean(); of_log.clean(); of_log.save(); except e : of_log_details.delete(); raise Exception(e); pass; return render(request, "ajax_temp/after_added_new_log.html", { 'log': of_log, "obj_log" : Log, "log_details_person" : of_log.details.person_visitor });
def generate_id_card(request): constraint = helpers.constraint(request, "GET"); data = constraint.strict([ "family_members_id" ], True); of_members = family_members.objects.get( id=data['family_members_id'], is_confirm=family_members.CONFIRM_APPROVED ); json_returne = { "id": of_members.id }; json_object = json.dumps(json_returne, indent=None, separators=(",", ":")); format_data = base64.b64encode(bytes(str(json_object), 'utf-8')); qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=20, border=0, ) qr.add_data(format_data) qr.make(fit=True) img_qr_code = qr.make_image(fill_color="black", back_color="white"); path_image_format = "static/images/id_card.jpg"; path_image_back_format = "static/images/id_card_back.jpg"; path_arial_italic = "static/font/Arial Italic.ttf"; img = Image.open(path_image_format); img_back = Image.open(path_image_back_format); draw = ImageDraw.Draw(img); draw_back = ImageDraw.Draw(img_back); font = ImageFont.truetype("arial", 25); font_italic = ImageFont.truetype(path_arial_italic, 20); birth_date = of_members.household_profile.date_of_birth.strftime("%B %d %Y"); full_name = " ".join([of_members.first_name, of_members.last_name]); address = "".join([of_members.household_profile.purok.name, ", Digos City"]); age_birthdate = " ".join([str(of_members.household_profile.get_age()), ", ", birth_date]); draw.text((187, 273), full_name, (0, 0, 0), font=font) draw.text((220, 310), address, (0, 0, 0), font=font) if of_members.household_profile.purok.barangay: draw.text((233, 348), of_members.household_profile.purok.barangay.name, (0, 0, 0), font=font); else: draw.text((233, 348), "(Not specified)", (0, 0, 0), font=font_italic); draw.text((373, 385), "23, April 11 1997", (0, 0, 0), font=font); #__________________________________________________________ #Back img_qr_w, img_qr_h = img_qr_code.size; img_back_w, img_back_h = img_back.size # offset = ((img_back_w - img_qr_w) // 2, (img_back_h - img_qr_h) // 2); j = 100, 100 img_back.paste(img_qr_code, j ) buff = BytesIO() buff2 = BytesIO() img.save(buff, "PNG") img_back.save(buff2, "PNG") img_str = base64.b64encode(buff.getvalue()); img_back = base64.b64encode(buff2.getvalue()); buff.close(); buff2.close() template = get_template("household/id_card.html"); html = template.render({ "img_front": img_str.decode('utf-8'), "img_back" : img_back.decode('utf-8'), }); ts = datetime.datetime.now().timestamp(); file_name = "PHIL-IRI_" + str(ts) + ".zip"; response = BytesIO() pdf = pisa.pisaDocument(BytesIO(html.encode("UTF-8")), response) if not pdf.err: on_print = HttpResponse(response.getvalue(), content_type='application/zip'); on_print['Content-Disposition'] = 'attachment; filename=' + file_name; return on_print; else: return HttpResponse("Error Rendering PDF", status=400)