Пример #1
0
def create_room(request):
    now = datetime.now()
    time = now.strftime("%H:%M:%S")
    hash = hashlib.md5((time + request.user.username).encode())
    room = Room(player_1_id=request.user.id, hash=hash.hexdigest())
    room.save()
    return redirect('room', room.hash)
Пример #2
0
def edit_add(request, id):
    context = {}

    # ถ้า id > 0 เข้าเงื่อนไขการแก้ไขห้อง
    if id > 0:
        room = Room.objects.get(pk=id)
        context = {'room': room, 'check': 'check'}
        if request.method == "POST":
            # แก้ไขข้อมูลห้องในฐานข้อมูล
            room.name = request.POST.get('roomname')
            room.open_time = request.POST.get('start')
            room.close_time = request.POST.get('end')
            room.capacity = request.POST.get('capacity')
            room.save()
            return redirect('manage')

    # ถ้า id = 0 เข้าเงื่อนไขการสร้างห้องใหม่
    else:
        if request.method == "POST":
            new_room = Room(name=request.POST.get('roomname'),
                            open_time=request.POST.get('start'),
                            close_time=request.POST.get('end'),
                            capacity=request.POST.get('capacity'))
            new_room.save()
            return redirect('manage')

    return render(request, 'room/admin_edit_add.html', context=context)
Пример #3
0
 def setUp(self):
     self.user = User.objects.create_user(username='******',
                                          email='*****@*****.**',
                                          password='******')
     self.token = Token.objects.create(user=self.user)
     self.client_with_token = APIClient()
     self.client_with_token.credentials(HTTP_AUTHORIZATION='Token ' +
                                        self.token.key)
     self.room = Room(name='Room1', capacity=2)
     self.room.save()
Пример #4
0
    def post(self, request, slug):
        hotel = get_object_or_404(Hotel, slug=slug)
        room_form = RoomForm(request.POST, instance=Room())
        dormitory_setting_form = DormitorySettingForm(request.POST,
                                                      instance=Dormitory())

        if room_form.is_valid():
            new_room = room_form.save(commit=False)
            new_room.hotel = hotel
            new_room.save()
            if dormitory_setting_form.is_valid():
                new_dormitory_setting = dormitory_setting_form.save(
                    commit=False)
                new_dormitory_setting.room = new_room
                new_dormitory_setting.save()
            messages.success(request, "Successfully added new room")
            return redirect('hotel_detail', slug=hotel.slug)

        template = 'room/creation.html'
        context = {
            'hotel': hotel,
            'room_form': RoomForm(),
            'dormitory_setting_form': DormitorySettingForm()
        }

        return render(request, template, context)
Пример #5
0
 def setUp(self):
     with open('secrets.json', 'r') as f:
         secret_key = json.load(f)
     LoginPlatform(name="airbnb").save()
     User(id=1,
          email='*****@*****.**',
          password=bcrypt.hashpw("qweasd123!".encode('utf-8'),
                                 bcrypt.gensalt()).decode('utf-8'),
          first_name='jiwon',
          last_name='ko',
          birth_date=datetime.datetime.strptime("1997-2-20", "%Y-%m-%d"),
          is_host=False,
          platform=LoginPlatform.objects.get(name="airbnb")).save()
     Amenity(name='amenity').save()
     Room(id=1,
          title='Room title',
          address='Room 주소',
          max_personnal='10',
          bed_room='침실',
          bed='퀸 사이즈',
          bath_room='욕실 한 개',
          price=100000,
          latitude=30,
          longitude=50,
          description='room 설명').save()
     BookingStatus(status='예약완료').save()
     PaymentMethod(name='체크카드').save()
     Booking(id=1,
             check_in=datetime.datetime.strptime("2020-08-10", "%Y-%m-%d"),
             check_out=datetime.datetime.strptime("2020-08-12", "%Y-%m-%d"),
             price=100000,
             cleaning_expense=10000,
             service_tax=3000,
             accomodation_tax=3000,
             adult=3,
             children=1,
             infants=0,
             user=User.objects.get(email='*****@*****.**'),
             room=Room.objects.get(title='Room title'),
             status=BookingStatus.objects.get(status='예약완료'),
             payment_method=PaymentMethod.objects.get(name='체크카드'),
             created_at=datetime.datetime.strptime("2020-08-09",
                                                   "%Y-%m-%d")).save()
     Review(booking=Booking.objects.get(id=1),
            content='리뷰 내용',
            cleanliness_score=4.0,
            communication_score=5.0,
            check_in_score=3.0,
            accuracy_score=2.5,
            location_score=3.5,
            satisfaction_score=4.0,
            created_at=datetime.datetime.strptime("2020-09-01",
                                                  "%Y-%m-%d")).save()
     self.token = jwt.encode(
         {
             'email': User.objects.get(email='*****@*****.**').email
         },
         secret_key['SECRET_KEY'],
         algorithm=ALGORITHM).decode('utf-8')
Пример #6
0
 def get(self, request, room_name, display_name, auth_code):
     #Generate a room code.
     code = get_random_string(
         length=6, allowed_chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
     #Create the room object.
     room = Room(name=room_name, code=code)
     room.save()
     #Get tokens from spotify servers. And update them.
     tokens = get_tokens(auth_code)
     host_token = tokens['access_token']
     refresh_token = tokens['refresh_token']
     #Create host with the above attributes.
     host = Host(display_name=display_name,
                 host_token=host_token,
                 host_refresh_token=refresh_token,
                 room=room)
     host.save()
     #Return code name.
     return Response(data={"created_room_code": code})
Пример #7
0
 def test_unit_room_3(self):
     print(
         " \n---------------------- TEST GDY W KAŻDEJ SALI JEST ZAJĘTA KTÓRAŚ Z GODZIN ----------------------\n "
     )
     test_list_3 = Room.show_available(date(2019, 10, 3), time(8, 0),
                                       time(20, 0), 10, 0, 'BRAK',
                                       self.room_list,
                                       self.reservation_list)
     self.assertEqual(
         type(test_list_3),
         list,
         msg='Typ zwróconych danych nie zgadza się w teście nr 3')
Пример #8
0
 def test_unit_room_2(self):
     print(
         " \n------------------------- TEST GDY JEDNA SALA NIE JEST WOLNA W OGÓLE ------------------------- \n"
     )
     test_list_2 = Room.show_available(date(2019, 10, 9), time(8, 0),
                                       time(20, 0), 10, 0, 'BRAK',
                                       self.room_list,
                                       self.busy_reservation_list)
     self.assertEqual(
         type(test_list_2),
         list,
         msg='Typ zwróconych danych nie zgadza się w teście nr 2')
     self.assertEqual(len(test_list_2),
                      4,
                      msg="Ilość sal się nie zgadza w teście nr 2")
Пример #9
0
    def test_unit_room_1(self):
        print(
            " \n------------------------- TEST, GDY 5 SAL JEST WOLNYCH NA CAŁY DZIEŃ -------------------------\n "
        )
        test_list_1 = Room.show_available(date(2019, 10, 7), time(8, 0),
                                          time(20, 0), 0, 0, 'BRAK',
                                          self.room_list,
                                          self.reservation_list)

        self.assertEqual(len(test_list_1),
                         5,
                         msg='Nieprawidłowa ilość zwróconych sal')
        self.assertEqual(
            type(test_list_1),
            list,
            msg='Nie zgadza się typ zwróconych danych w teście nr 1')
Пример #10
0
    def post(self, request):
        templateName = 'room/add.html'  #pemanggilan ke building add.html
        form = RoomForm(request.POST or None)
        if form.is_valid(
        ):  #ngecek apakah data sudah terisi semua atau belum makanya dibilang is valid
            b = Room()
            b.nama = form.cleaned_data['nama']
            b.luas = form.cleaned_data['luas']
            b.kapasitas = form.cleaned_data['kapasitas']
            b.building = form.cleaned_data['building']
            b.save()
        else:
            data = {
                'form': form,
            }
            return render(request, templateName, data)

        return redirect('room:list')
Пример #11
0
def creation(request, idRoom):
    csrfContext = RequestContext(request, idRoom)
    try:
        room = Room.objects.get(pk=idRoom)
        return render(request, 'room/roomOpen.html', csrfContext,
                      {'room': room})
    except Room.DoesNotExist:
        room = Room()
        room.pk = idRoom
        room.roomIsOpen = True
        room.save()
        return HttpResponseRedirect(reverse('room:detail', args=[idRoom]))
Пример #12
0
  def setUp(self):
    user = User.objects.create(username="******")
    user1 = User.objects.create(username="******")
    user2 = User.objects.create(username="******")
    user3 = User.objects.create(username="******")
    user4 = User.objects.create(username="******")

    backend.addQueue(user, 1, 1)
    
    sleep(1.0)
    backend.addQueue(user1, 1, 1)
    
    sleep(1.0)
    backend.addQueue(user2, 1, 2) 

    sleep(1.0)
    backend.addQueue(user3, 2, 1) 

    sleep(1.0)
    backend.addQueue(user4, 2, 1) 

    room = Room(number=121, maxPeople=1, type='S', price='10.00')
    room.save()
    availability = Slot(room=room, serie=1)
    availability.save()
 
    room1 = Room(number=122, maxPeople=2, type='D', price='10.00')
    room1.save()
    availability1 = Slot(room=room1, serie=2)
    availability1.save()

    room2 = Room(number=122, maxPeople=2, type='B', price='10.00')
    room2.save()
    availability1 = Slot(room=room2, serie=1)
    availability1.save()
    availability2 = Slot(room=room2, serie=1)
    availability2.save()
Пример #13
0
def start_exercise(request, exercise_id):

    try:
        pass
    except Exception as e:
        raise

    if request.user.is_authenticated:

        room = Room()
        room.exercise = Exercise.objects.get(pk=exercise_id)
        owner = Student.objects.get(user=request.user)
        room.owner = owner
        room.code = room.exercise.template
        room.save()

        room.particpant.add(owner)
        room.author.add(owner)
        room.save()

        return redirect('room', room_id=room.id)

    else:
        return redirect('register')
Пример #14
0
        u'名称': 'name',
        u'说明': 'comment',
        u'类别': 'rtype'
    }
    try:
        result = read_csv(reader, col_name_dict)
    except Exception, e0:
        return HttpResponseBadRequest(e0.message,
                                      content_type='application/javascript')
    rooms = []
    rtypeDict = {
        roomType.name: roomType.id
        for roomType in RoomType.objects.all()
    }
    for item in result:
        room = Room()
        room.room_type_id = rtypeDict[item['rtype']]
        room.name = item['name']
        room.sn = item['sn']
        room.comment = item['comment']
        rooms.append(room)
    Room.objects.bulk_create(rooms)
    return HttpJsonResponse('')


def delete_rooms(request):
    try:
        Room.objects.filter(id__in=request.POST['ids'].split(',')).delete()
        return HttpJsonResponse('')
    except Exception, e0:
        return HttpResponseBadRequest(u'删除失败:' + e0.message,
Пример #15
0
    def setUp(self):
        user = User.objects.create(username="******")
        user1 = User.objects.create(username="******")
        user2 = User.objects.create(username="******")
        user3 = User.objects.create(username="******")
        user4 = User.objects.create(username="******")

        backend.addQueue(user, 1, 1)

        sleep(1.0)
        backend.addQueue(user1, 1, 1)

        sleep(1.0)
        backend.addQueue(user2, 1, 2)

        sleep(1.0)
        backend.addQueue(user3, 2, 1)

        sleep(1.0)
        backend.addQueue(user4, 2, 1)

        room = Room(number=121, maxPeople=1, type='S', price='10.00')
        room.save()
        availability = Slot(room=room, serie=1)
        availability.save()

        room1 = Room(number=122, maxPeople=2, type='D', price='10.00')
        room1.save()
        availability1 = Slot(room=room1, serie=2)
        availability1.save()

        room2 = Room(number=122, maxPeople=2, type='B', price='10.00')
        room2.save()
        availability1 = Slot(room=room2, serie=1)
        availability1.save()
        availability2 = Slot(room=room2, serie=1)
        availability2.save()
Пример #16
0
    def setUpClass(cls):
        print(
            '\n ============== JEDNOSTKOWE TESTY WYŚWIETLANIA DOSTĘPNYCH SAL ============== \n'
        )
        test_room_1 = Room(id=1,
                           number=126,
                           wing='B2',
                           number_of_seats=125,
                           number_of_computers=0)
        test_room_2 = Room(id=2,
                           number=127,
                           wing='B2',
                           number_of_seats=125,
                           number_of_computers=0)
        test_room_3 = Room(id=3,
                           number=128,
                           wing='B2',
                           number_of_seats=125,
                           number_of_computers=0)
        test_room_4 = Room(id=4,
                           number=129,
                           wing='B2',
                           number_of_seats=125,
                           number_of_computers=0)
        test_room_5 = Room(id=5,
                           number=130,
                           wing='B2',
                           number_of_seats=125,
                           number_of_computers=0)

        cls.room_list = [
            test_room_1, test_room_2, test_room_3, test_room_4, test_room_5
        ]

        test_reservation_1 = Reservation(date=date(2019, 10, 3),
                                         hour=time(8, 0),
                                         user_id=1,
                                         room=test_room_1,
                                         is_cyclic=False,
                                         is_every_two_weeks=False)
        test_reservation_2 = Reservation(date=date(2019, 10, 3),
                                         hour=time(9, 45),
                                         user_id=1,
                                         room=test_room_2,
                                         is_cyclic=False,
                                         is_every_two_weeks=False)
        test_reservation_3 = Reservation(date=date(2019, 10, 3),
                                         hour=time(11, 30),
                                         user_id=1,
                                         room=test_room_3,
                                         is_cyclic=False,
                                         is_every_two_weeks=False)
        test_reservation_4 = Reservation(date=date(2019, 10, 3),
                                         hour=time(16, 45),
                                         user_id=1,
                                         room=test_room_4,
                                         is_cyclic=False,
                                         is_every_two_weeks=False)
        test_reservation_5 = Reservation(date=date(2019, 10, 3),
                                         hour=time(15, 0),
                                         user_id=1,
                                         room=test_room_5,
                                         is_cyclic=False,
                                         is_every_two_weeks=False)

        cls.reservation_list = [
            test_reservation_1, test_reservation_2, test_reservation_3,
            test_reservation_4, test_reservation_5
        ]

        test_reservation_6 = Reservation(date=date(2019, 10, 9),
                                         hour=time(8, 0),
                                         user_id=1,
                                         room=test_room_2,
                                         is_cyclic=False,
                                         is_every_two_weeks=False)
        test_reservation_7 = Reservation(date=date(2019, 10, 9),
                                         hour=time(9, 45),
                                         user_id=1,
                                         room=test_room_2,
                                         is_cyclic=False,
                                         is_every_two_weeks=False)
        test_reservation_8 = Reservation(date=date(2019, 10, 9),
                                         hour=time(11, 30),
                                         user_id=1,
                                         room=test_room_2,
                                         is_cyclic=False,
                                         is_every_two_weeks=False)
        test_reservation_9 = Reservation(date=date(2019, 10, 9),
                                         hour=time(13, 15),
                                         user_id=1,
                                         room=test_room_2,
                                         is_cyclic=False,
                                         is_every_two_weeks=False)
        test_reservation_10 = Reservation(date=date(2019, 10, 9),
                                          hour=time(15, 0),
                                          user_id=1,
                                          room=test_room_2,
                                          is_cyclic=False,
                                          is_every_two_weeks=False)
        test_reservation_11 = Reservation(date=date(2019, 10, 9),
                                          hour=time(16, 45),
                                          user_id=1,
                                          room=test_room_2,
                                          is_cyclic=False,
                                          is_every_two_weeks=False)
        test_reservation_12 = Reservation(date=date(2019, 10, 9),
                                          hour=time(18, 30),
                                          user_id=1,
                                          room=test_room_2,
                                          is_cyclic=False,
                                          is_every_two_weeks=False)

        cls.busy_reservation_list = [
            test_reservation_6, test_reservation_7, test_reservation_8,
            test_reservation_9, test_reservation_10, test_reservation_11,
            test_reservation_12
        ]
Пример #17
0
def room_input(request, action='add', room_id=None):
    if room_id:
        room = get_object_or_404(Room, pk=room_id)
    else:
        room = Room()
    return render_to_response('room/room_input.html', locals())