def register_reservation(request, user_id): """ 予約情報を登録する :param request: request :param mail_address: 宿泊登録者のメールアドレス :return: ユーザー一覧画面 """ if request.method == "POST": lottery_flag = request.POST.get("lottery_flag", None) check_in_date = datetime.date.fromisoformat( request.POST.get("check_in_date", "")) check_out_date = datetime.date.fromisoformat( request.POST.get("check_out_date", "")) number_of_rooms = request.POST.get("number_of_rooms", "") number_of_guests = request.POST.get("number_of_guests", "") purpose = request.POST.get("purpose", "") # 抽選フラグが"1"の場合、抽選エンティティを作成 if lottery_flag: LotDao.create_res_by_in_and_out(user_id, check_in_date, check_out_date, number_of_rooms, number_of_guests, purpose) # 抽選フラグが指定されていない場合、予約エンティティを作成 else: ResDao.create_res_by_in_and_out(user_id, check_in_date, check_out_date, number_of_rooms, number_of_guests, purpose) # 表示するユーザー情報を取得 users = UserDao.get_users() return HttpResponseRedirect(reverse('test_reservation', args=(user_id, )))
def cancel_res(request): """予約の確定(本申込期間)""" reservation_id = request.POST.get("reservation_id", "") if reservation_id: ResDao.change_request_status_to_cancel(reservation_id) return init_my_page_screen(request)
def confirm_res_app(request): """テスト用予約の確定(本申込期間)""" #TODO delete this method reservation_id = request.POST.get("reservation_id", "") if reservation_id: ResDao.create_res_by_lottery(reservation_id) LotDao.delete_by_reservation_id(reservation_id) return HttpResponseRedirect(reverse('test_reservation', {"error": ""})) return TemplateResponse(request, URL_REBGST003)
def turn_lottery_into_reservation(request, user_id): """TODO 削除予定 抽選エンティティを予約エンティティへ変換する :param request: :param user_id: :param reservation_id: :return: """ reservation_id = int(request.POST.get("reservation_id", 0)) print("reservation_idは", reservation_id) ResDao.create_res_by_lottery(reservation_id) LotDao.delete_by_reservation_id(reservation_id) return HttpResponseRedirect(reverse('test_reservation', args=(user_id, )))
def test_delete_user(request): """ ユーザIDに紐づくユーザーを削除する :param user_id: ユーザID :return: """ user_id = int(request.POST.get("user_id", 0)) if user_id: UserDao.delete_user_by_user_id(user_id) ResDao.delete_by_user_id(user_id) LotDao.delete_by_user_id(user_id) LodginDao.delete_by_user_id(user_id) return HttpResponseRedirect(reverse('test_database'))
def delete_lottery_or_reservation(request, user_id): """ 予約IDに紐づく予約or抽選情報を削除する :param request: :param user_id: :return: """ reservation_id = int(request.POST.get("reservation_id", 0)) if reservation_id: ResDao.delete_by_reservation_id(reservation_id) LotDao.delete_by_reservation_id(reservation_id) LodginDao.delete_by_reservation_id(reservation_id) return HttpResponseRedirect(reverse('test_reservation', args=(user_id, )))
def create_login_user_res_info_by_user_id(user_id: int) -> list: """ログインユーザに紐づく抽選、宿泊情報を取得""" # 返却結果 result = [] # 対象ユーザに紐づく抽選、予約情報を取得 reservations = ResDao.get_res_list(user_id) lotteries = LotDao.get_res_list(user_id) # 抽選情報の辞書型を作成 for lottery in lotteries: lottery_dict = {JsonFactory.RES_ID: lottery.reservation_id, JsonFactory.APP_STATUS: 0, JsonFactory.IN_DATE: lottery.check_in_date, JsonFactory.OUT_DATE: lottery.check_out_date, JsonFactory.NUM_ROOMS: lottery.number_of_rooms, JsonFactory.EXPIRE: EMPTY_STR, JsonFactory.PRIORITY: lottery.priority} result.append(lottery_dict) # 予約情報の辞書型を作成 for reservation in reservations: reservation_dict = {JsonFactory.RES_ID: reservation.reservation_id, JsonFactory.APP_STATUS: reservation.request_status + 1, JsonFactory.IN_DATE: reservation.check_in_date, JsonFactory.OUT_DATE: reservation.check_out_date, JsonFactory.NUM_ROOMS: reservation.number_of_rooms, JsonFactory.EXPIRE: reservation.expire_date, JsonFactory.PRIORITY: EMPTY_STR} result.append(reservation_dict) return result
def init_my_page_screen(request): """ログイン画面からログイン処理を実施。""" if not __is_login_user(request): return TemplateResponse(request, URL_REBGST001, {"error": "セッションが切断されました"}) login_user_res_info = [] user_id = request.session[LOG_USR] if user_id: # ユーザの全ての予約・抽選を取得 login_user_res_info.extend( ResDao.get_loginuserres_dto_by_user_id(user_id)) login_user_res_info.extend( LotDao.get_loginuserres_dto_by_user_id(user_id)) # 本日以降チェックアウト予定の予約・抽選のみ出力 today = datetime.date.today() login_user_res_info = list( filter(lambda i: i.check_out_date >= today, login_user_res_info)) # チェックイン日で降順に出力 login_user_res_info = sorted(login_user_res_info, key=attrgetter('check_in_date'), reverse=True) return TemplateResponse(request, URL_REBGST003, {"login_user_res_info": login_user_res_info})
def delete_user(request): """(管理者専用)ユーザ情報を更新する""" # セッション情報に管理者IDが存在するか確認。存在しなければログイン画面へ遷移 if not __is_admini_user(request): return TemplateResponse(request, URL_REBGST001, {"error": "管理者権限がありません"}) if request.method == "POST": user_id = request.POST.get("user_id", "") if user_id: UserDao.delete_user_by_user_id(user_id) ResDao.delete_by_user_id(user_id) LotDao.delete_by_user_id(user_id) LodginDao.delete_by_user_id(user_id) # 全ユーザ情報を取得 users = UserDao.get_users() return TemplateResponse(request, URL_REBADM001, {"users": users})
def test_register_res(request, mail_address): """ 宿泊情報を登録する :param request: request :param mail_address: 宿泊登録者のメールアドレス :return: ユーザー一覧画面 """ if request.method == "POST": target_user = User.objects.get(mail_address=mail_address) check_in_date = request.POST.get("check_in_date", "") stay_term = request.POST.get("stay_term", "") number_of_rooms = request.POST.get("number_of_rooms", "") number_of_guests = request.POST.get("number_of_guests", "") purpose = request.POST.get("purpose", "") ResDao.create_res(target_user, check_in_date, stay_term, number_of_rooms, number_of_guests, purpose) # 表示するユーザー情報を取得 users = UserDao.get_users() return TemplateResponse(request, TEST_SCREEN, {"users": users})
def test_reservation(request, mail_address): """ テスト用のデータベースを作成する :param request: request :param mail_address: 宿泊対象者のメールアドレス :return: 対象ユーザーの宿泊予約一覧画面 """ # 対象のユーザーネームを取得 user = UserDao.get_user(mail_address) # 対象のユーザーアドレスに紐づく宿泊日付を取得 reservations = ResDao.get_res_list(user) return TemplateResponse(request, TEST_RES_SCREEN, {"reservations": reservations, "username": user.username})
def push_res_app_button(request): """予約を実施 """ user_id = request.session[LOG_USR] from django.http import QueryDict dic = QueryDict(request.body, encoding='utf-8') check_in_date = datetime.date.fromisoformat(dic.get('check_in_date')) check_out_date = datetime.date.fromisoformat(dic.get('check_out_date')) number_of_rooms = int(dic.get('number_of_rooms')) purpose = dic.get('purpose') error = "" #注意:現時点では宿泊人数を使用しないため、常に0を入力 number_of_guests = 0 # 抽選期間か2次申込期間かを取得 app_status_code = __get_app_status_code(check_in_date) # 予約月度が過去月度の場合、エラー情報を画面に返却 if app_status_code == ERROR: error = "予約申込対象期間外です" # 抽選の場合 if app_status_code == LOTTERY: if not LotDao.user_already_applied(user_id, check_in_date): LotDao.create_res_by_in_and_out(user_id, check_in_date, check_out_date, number_of_rooms, number_of_guests, purpose) else: error = "該当日は申込済みです" # 二次申込の場合 elif app_status_code == SECOND_APP: if not ResDao.create_res_as_second_reservation( user_id, check_in_date, check_out_date, number_of_rooms, number_of_guests, purpose): error = "二次申込が出来ませんでした" from django.http.response import JsonResponse return JsonResponse(error, safe=False)
def test_reservation(request, user_id): """ テスト用の予約作成画面へ遷移する :param request: request :param mail_address: 宿泊対象者のメールアドレス :return: 対象ユーザーの宿泊予約一覧画面 """ # 対象のユーザーネームを取得 user = UserDao.get_user(user_id) # 対象のユーザーアドレスに紐づく宿泊日付を取得 reservations = ResDao.get_res_list(user_id) lotterys = LotDao.get_res_list(user_id) return TemplateResponse( request, TEST_RES_SCREEN, { "reservations": reservations, "lotterys": lotterys, "username": user.username })
def create_res_info_by_year_month(year: int, month: int) -> list: """ カレンダー表示用のjsonデータを作成する :param month: 取得対象となるjsonデータ :return: list形式のjsonデータ """ today = datetime.date.today() app_status = JsonFactory.__get_app_status_code(year, month) # 過去月度、翌々月以降の場合、表示しない if app_status == DISABLED: return list([]) # key = 日付情報、value = タイトル、予約者、日付情報の辞書型を作成 reservation_dict = {} # 該当月度の最終日 _, lastday = calendar.monthrange(year, month) # 抽選月度の場合 if app_status == LOTTERY: for res_date_day in range(lastday): # 0,1,2,…,lastday - 1 res_date = datetime.date(year, month, res_date_day + 1).strftime('%Y-%m-%d') reservation_dict[res_date] = {JsonFactory.RES_DATE: res_date, JsonFactory.TITLE_ROOMS: JsonFactory.LOT_LABEL} # 施設利用不可日の登録 for ng in CalendarMaster.get_ngdata_in_month(year, month): ng_date = ng.strftime('%Y-%m-%d') reservation_dict[ng_date] = {JsonFactory.RES_DATE: ng_date, JsonFactory.TITLE_ROOMS: JsonFactory.BANNED_LABEL, JsonFactory.COLOR: "black", JsonFactory.TEXT_COLOR: "while"} return list(reservation_dict.values()) # 初日 first_day = 1 # 当月分表示時は本日日付以降の予約を表示 if today.month == month: first_day = today.day # 全ての日付に空の予約情報を設定 for res_date_day in range(first_day - 1, lastday): # 0,1,2,…,lastday - 1 res_date = datetime.date(year, month, res_date_day + 1).strftime('%Y-%m-%d') reservation_dict[res_date] = {JsonFactory.RES_DATE: res_date, JsonFactory.TITLE_ROOMS: 0} # 指定の年月から予約情報を取得 lod_list = LodginDao.get_lodging_date_by_year_and_month_and_grt_day(year, month, first_day) # 辞退した予約IDリストを取得 defeated_list = ResDao.get_defeated_res_list(year, month) # 辞退した予約IDを除外する(埋まっていると考えない) lod_list = list(filter(lambda x: x.reservation_id not in defeated_list, lod_list)) # 予約情報のQuerySetを取得からjson情報を作成する for lodging in lod_list: # チェックイン日と連泊日数をもとに、キーとなる日付を取得 res_date = lodging.lodging_date.strftime('%Y-%m-%d') # 日付情報に紐づくJSON情報を作成する reservation_dict.setdefault(res_date, {JsonFactory.RES_DATE: res_date, JsonFactory.TITLE_ROOMS: 0}) json_data = reservation_dict.get(res_date) # 辞書のキーに"user"が含まれる要素数 + 1をユーザ、ステータス名に付与する連続番号とする serialize_num = len(list(filter(lambda x: JsonFactory.USER in x, list(json_data.keys())))) + 1 reservation = ResDao.filter_by_reservation_id(lodging.reservation_id).first() if reservation: # ラベル(ステータス名 = ステータス) request_status = reservation.request_status status = JsonFactory.STATUS + str(serialize_num) json_data[status] = JsonFactory.STATUS_DICT[request_status] # ラベル(ユーザ = ユーザ名:予約部屋数)を設定 check_in_user = JsonFactory.USER + str(serialize_num) json_data[check_in_user] = "{username}: {rooms}部屋".format(username=reservation.username, rooms=lodging.number_of_rooms) # json_data[check_in_user] = "{username}: {rooms}部屋".format(username=UserDao.get_user(lodging.user_id).username, rooms=lodging.number_of_rooms) # ラベル(部屋数 = 部屋数)を設定 json_data[JsonFactory.TITLE_ROOMS] = json_data[JsonFactory.TITLE_ROOMS] + lodging.number_of_rooms for res_inf in reservation_dict.values(): room_count = int(res_inf[JsonFactory.TITLE_ROOMS]) if room_count > 3: res_inf[JsonFactory.TITLE_ROOMS] = JsonFactory.IN_USE_LABEL res_inf[JsonFactory.COLOR] = "black" res_inf[JsonFactory.TEXT_COLOR] = "white" else: res_inf[JsonFactory.TITLE_ROOMS] = JsonFactory.VACANT_LABEL.format(num=(4 - room_count)) # 施設利用不可日の登録 for ng in CalendarMaster.get_ngdata_in_month(year, month): ng_date = ng.strftime('%Y-%m-%d') reservation_dict[ng_date] = {JsonFactory.RES_DATE: ng_date, JsonFactory.TITLE_ROOMS: JsonFactory.BANNED_LABEL, JsonFactory.COLOR: "black", JsonFactory.TEXT_COLOR: "while"} # テスト用にreturnを実施 return list(reservation_dict.values())