Beispiel #1
0
def add_room(request):
    if (request.method == 'POST'):
        # print request.POST
        r = Room()
        r.name = request.POST['Name']
        r.capacity = request.POST['capacity']
        temp = request.POST.get('hasAC')
        if (temp != None):
            r.hasAC = True
        else:
            r.hasAC = False
        temp = request.POST.get('hasMic')
        if (temp != None):
            r.hasMic = True
        else:
            r.hasMic = False
        temp = request.POST.get('hasProjector')
        if (temp != None):
            r.hasProjector = True
        else:
            r.hasProjector = False
        r.save()
        return redirect('/')

    return render(request, 'add_room.html', {'user': request.user})
Beispiel #2
0
    def post(self, request):
        name = request.POST.get('name')
        capacity = request.POST.get('capacity')
        projector = request.POST.get('projector')

        try:
            capacity = int(capacity)
        except:
            messages.info(request, f'Check capacity')
            return redirect(reverse('room_add'))
        if name and len(name) > 0:
            tmp_name = Room.objects.filter(name=name)
            if not tmp_name and capacity > 0:
                room = Room()
                room.name = name
                room.capacity = capacity
                room.projector = projector == 'on'
                room.save()
                return redirect(reverse('rooms'))
            else:
                messages.info(request, f'Check room name and capacity')
                return redirect(reverse('room_add'))
        else:
            messages.info(request, f'Check room name')
            return redirect(reverse('room_add'))
Beispiel #3
0
def resetRoomCount():
    try:
        room = Room.objects.get(pk=1)
        room.count = 0
        room.save()
    except Room.DoesNotExist:
        room = Room(id=1, name="sample room", count=1)
        room.save()
def create_room(number, capacity=0, commit=True, **override):
    defaults = {'name': str(number), 'beds_single': capacity, 'available_beds_single': capacity}
    defaults.update(**override)
    room = Room(**defaults)

    if commit:
        room.save()

    return room
Beispiel #5
0
 def _create_room(self, room):
     r = Room(code=room['code'],
              name=room['name'],
              floor=1,
              type=room['type'],
              access=room['access'],
              reservable=True)
     r.save()
     return r
Beispiel #6
0
    def handle(self, *args, **options):
        for file in args:
            f = open(file, "r")
            for line in f:
                l = line.split()
                room = Room()
                room.number = l[0]
                room.capacity = int(l[1])
                room.description = " ".join(l[2:])
                room.short_unlock_time = datetime.now()
                room.save()

            self.stdout.write('Successfully imported\n')
Beispiel #7
0
    def handle(self, *args, **options):
        for file in args:
            f = open(file, "r")
            for line in f:
                l = line.split()
                room = Room()
                room.number = l[0]
                room.capacity = int(l[1])
                room.description = " ".join(l[2:])
                room.short_unlock_time = timezone.now()
                room.save()

            self.stdout.write("Successfully imported\n")
Beispiel #8
0
def house_add_room(request, pk):
    house = House.objects.filter(pk=pk).get()
    if house.user != request.user:
        raise Http404
    if request.method == 'POST':
        room = Room()
        room.user = request.user
        room.house = house
        if 'name' not in request.POST:
            return render(
                request, 'houses/room_add.html', {
                    'house': house,
                    'error': 'Please make sure to fill in all required details'
                })
        else:
            room.name = request.POST['name']

        if 'price' not in request.POST:
            return render(
                request, 'houses/room_add.html', {
                    'house': house,
                    'error': 'Please make sure to fill in all required details'
                })
        else:
            room.price = request.POST['price']

        if 'description' not in request.POST:
            return render(
                request, 'houses/room_add.html', {
                    'house': house,
                    'error': 'Please make sure to fill in all required details'
                })
        else:
            room.description = request.POST['description']
        room.save()
        try:
            for file in request.FILES.getlist('images'):
                image = RoomImage()
                image.room = room
                image.user = request.user
                image.image = file
                image.save()
        except Exception:
            pass

        return redirect('room_detail', pk=room.id)

    return render(request, 'houses/room_add.html', {'house': house})
Beispiel #9
0
    def test_no_duplicate(self):
        r = Room(title="1A")
        r.save()

        url = reverse("rooms:add")
        response = self.client.post(url, {
            "title": r.title,
            "unofficial_name": "",
            "description": "",
            "occupancy": 1,
        })
        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            "A room with this title already exists.",
            )
Beispiel #10
0
    def test_no_duplicate(self):
        r = Room(title="1A")
        r.save()

        url = reverse("rooms:add")
        response = self.client.post(
            url, {
                "title": r.title,
                "unofficial_name": "",
                "description": "",
                "occupancy": 1,
            })
        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            "A room with this title already exists.",
        )
Beispiel #11
0
def uploadphoto(request):
    if request.method == "POST":
        uploaded_image = request.FILES['image']
        fssobj = FileSystemStorage()
        filename = fssobj.save(uploaded_image.name, uploaded_image)
        uploaded_image_url = fssobj.url(filename)

        room = Room(file=uploaded_image_url,
                    Room_owner=request.POST['owner_name'],
                    Room_location=request.POST['location'],
                    Room_phnumber=request.POST['phone_number'],
                    Room_price=request.POST['price'],
                    pub_date=request.POST['pub_date'],
                    Room_desc=request.POST['desc'])
        room.save()
        return HttpResponse(
            'You have successfully uploaded the room photo with its detail<br><br><a href="/">Go to homepage</a>'
        )
    else:
        return render(request, 'upload.html')
Beispiel #12
0
def add_room(request):
    form = RoomImageForm()
    if request.method == "POST":
        form = RoomImageForm(request.POST)
        room = Room()
        room.name = request.POST.get('name')
        room.description = request.POST.get('description')
        room.square = request.POST.get('square')
        room.price_per_m2 = request.POST.get('price_per_m2')
        room.price = request.POST.get('price')
        room.comments = request.POST.get('comments')
        room.status = get_object_or_404(Status, pk=2)
        room.save()
        roomImage = RoomImage()
        roomImage.room = get_object_or_404(Room, pk=room.pk)
        roomImage.image = request.POST.get('image')
        roomImage.save()
        return redirect('/')
    return render(request, 'add_room.html', {
        "form": form,
        "username": auth.get_user(request).username
    })
Beispiel #13
0
class TestEditRoom(TestCase):
    def setUp(self):
        self.su = User.objects.create_user(username="******", password="******")

        self.su.is_staff, self.su.is_superuser = True, True
        self.su.first_name = "Super"
        self.su.last_name = "User"
        self.su.save()

        self.r = Room(title="2E")
        self.r.save()

        self.client.login(username="******", password="******")

    def test_edit_room(self):
        url = reverse("rooms:edit", kwargs={"room_title": self.r.title})
        response = self.client.post(url, {
            "room-title": self.r.title,
            "room-unofficial_name": "Starry Night Surprise",
            "room-description": "Previous home to the best person on earth.",
            "room-occupancy": 5,
            "residents-TOTAL_FORMS": 0,
            "residents-INITIAL_FORMS": 0,
            "residents-MAX_NUM_FORMS": 50,
        },
                                    follow=True)

        url = reverse("rooms:view", kwargs={"room_title": self.r.title})
        self.assertRedirects(response, url)
        self.assertContains(response, "2E")
        self.assertContains(response, "<dd>{0}</dd>".format(5), html=True)
        self.assertContains(response, "Starry Night Surprise")
        self.assertContains(
            response,
            "Previous home to the best person on earth.",
        )
        self.assertNotContains(response, self.su.get_full_name())

    def test_no_duplicate(self):
        r = Room.objects.create(title="1A")

        url = reverse("rooms:edit", kwargs={"room_title": self.r.title})
        response = self.client.post(
            url, {
                "room-title": r.title,
                "room-unofficial_name": "",
                "room-description": "",
                "room-occupancy": 1,
                "residents-TOTAL_FORMS": 0,
                "residents-INITIAL_FORMS": 0,
                "residents-MAX_NUM_FORMS": 50,
            })

        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            "A room with this title already exists.",
        )

    def test_edit_room_minimal(self):
        url = reverse("rooms:edit", kwargs={"room_title": self.r.title})
        response = self.client.post(url, {
            "room-title": self.r.title,
            "room-unofficial_name": "",
            "room-description": "",
            "room-occupancy": 5,
            "residents-TOTAL_FORMS": 0,
            "residents-INITIAL_FORMS": 0,
            "residents-MAX_NUM_FORMS": 50,
        },
                                    follow=True)

        url = reverse("rooms:view", kwargs={"room_title": self.r.title})
        self.assertRedirects(response, url)
        self.assertContains(response, "<dd>{0}</dd>".format(5), html=True)
        self.assertNotContains(response, "Starry Night Surprise")
        self.assertNotContains(response, self.su.get_full_name())

    def test_bad_occupancy(self):
        url = reverse("rooms:edit", kwargs={"room_title": self.r.title})
        response = self.client.post(
            url, {
                "room-title": self.r.title,
                "room-unofficial_name": "Starry Night",
                "room-description": "Home to the best person on earth.",
                "room-occupancy": -1,
                "residents-TOTAL_FORMS": 0,
                "residents-INITIAL_FORMS": 0,
                "residents-MAX_NUM_FORMS": 50,
            })

        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            "Ensure this value is greater than or equal to 0.",
        )

        response = self.client.post(
            url, {
                "title": self.r.title,
                "unofficial_name": "Starry Night",
                "description": "Home to the best person on earth.",
                "occupancy": "",
                "residents-TOTAL_FORMS": 0,
                "residents-INITIAL_FORMS": 0,
                "residents-MAX_NUM_FORMS": 50,
            })

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "This field is required.")

    def test_bad_title(self):
        url = reverse("rooms:edit", kwargs={"room_title": self.r.title})
        response = self.client.post(
            url, {
                "room-title": "",
                "room-unofficial_name": "",
                "room-description": "",
                "room-occupancy": 1,
                "residents-TOTAL_FORMS": 0,
                "residents-INITIAL_FORMS": 0,
                "residents-MAX_NUM_FORMS": 50,
            })

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "This field is required.")

        response = self.client.post(
            url, {
                "room-title": "2a.",
                "room-unofficial_name": "",
                "room-description": "",
                "room-occupancy": 1,
                "residents-TOTAL_FORMS": 0,
                "residents-INITIAL_FORMS": 0,
                "residents-MAX_NUM_FORMS": 50,
            })

        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            "Only alphanumeric characters are allowed.",
        )

        response = self.client.post(
            url, {
                "room-title": "3_",
                "room-unofficial_name": "",
                "room-description": "",
                "room-occupancy": 1,
                "residents-TOTAL_FORMS": 0,
                "residents-INITIAL_FORMS": 0,
                "residents-MAX_NUM_FORMS": 50,
            })

        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            "Only alphanumeric characters are allowed.",
        )
Beispiel #14
0
def store(request):
    if request.method == 'POST':
        r = Room()
        r.name = request.POST['name']
        r.save()
    return redirect('/rooms')
Beispiel #15
0
for room in rooms:
    try:
        building = Building.objects.get(pk= reversemap[room['buildingname']])
        continue
    except:
        print room['buildingname']
        continue
    # Check that we aren't doubling
    if building.name not in ['Main', 'Bogle', 'North B', 'North C']:
        continue
    roomobj = Room(number = room['number'],
                   sqft = room['sqft'],
                   occ = room['occ'],
                   subfree = room['subfree'],
                   numrooms = room['numrooms'],
                   floor = room['floor'],
                   gender = room['gender'],
                   avail = room['avail'],
                   adjacent = room['adjacent'],
                   ada = room['ada'],
                   bi = room['bi'],
                   con = room['con'],
                   bathroom = room['bathroom'],
                   building = building)
    roomobj.save()
    print room['number'], building




Beispiel #16
0
mapfile = open('reversemap.dat')
reversemap = pickle.load(mapfile)

for room in rooms:
    try:
        building = Building.objects.get(pk=reversemap[room['buildingname']])
        continue
    except:
        print room['buildingname']
        continue
    # Check that we aren't doubling
    if building.name not in ['Main', 'Bogle', 'North B', 'North C']:
        continue
    roomobj = Room(number=room['number'],
                   sqft=room['sqft'],
                   occ=room['occ'],
                   subfree=room['subfree'],
                   numrooms=room['numrooms'],
                   floor=room['floor'],
                   gender=room['gender'],
                   avail=room['avail'],
                   adjacent=room['adjacent'],
                   ada=room['ada'],
                   bi=room['bi'],
                   con=room['con'],
                   bathroom=room['bathroom'],
                   building=building)
    roomobj.save()
    print room['number'], building
Beispiel #17
0
class TestEditRoom(TestCase):
    def setUp(self):
        self.su = User.objects.create_user(username="******", password="******")

        self.su.is_staff, self.su.is_superuser = True, True
        self.su.first_name = "Super"
        self.su.last_name = "User"
        self.su.save()

        self.r = Room(title="2E")
        self.r.save()

        self.client.login(username="******", password="******")

    def test_edit_room(self):
        url = reverse("rooms:edit", kwargs={"room_title": self.r.title})
        response = self.client.post(url, {
            "room-title": self.r.title,
            "room-unofficial_name": "Starry Night Surprise",
            "room-description": "Previous home to the best person on earth.",
            "room-occupancy": 5,
            "residents-TOTAL_FORMS": 0,
            "residents-INITIAL_FORMS": 0,
            "residents-MAX_NUM_FORMS": 50,
            }, follow=True)

        url = reverse("rooms:view", kwargs={"room_title": self.r.title})
        self.assertRedirects(response, url)
        self.assertContains(response, "2E")
        self.assertContains(response, "<dd>{0}</dd>".format(5), html=True)
        self.assertContains(response, "Starry Night Surprise")
        self.assertContains(
            response,
            "Previous home to the best person on earth.",
            )
        self.assertNotContains(response, self.su.get_full_name())

    def test_no_duplicate(self):
        r = Room.objects.create(title="1A")

        url = reverse("rooms:edit", kwargs={"room_title": self.r.title})
        response = self.client.post(url, {
            "room-title": r.title,
            "room-unofficial_name": "",
            "room-description": "",
            "room-occupancy": 1,
            "residents-TOTAL_FORMS": 0,
            "residents-INITIAL_FORMS": 0,
            "residents-MAX_NUM_FORMS": 50,
            })

        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            "A room with this title already exists.",
            )

    def test_edit_room_minimal(self):
        url = reverse("rooms:edit", kwargs={"room_title": self.r.title})
        response = self.client.post(url, {
            "room-title": self.r.title,
            "room-unofficial_name": "",
            "room-description": "",
            "room-occupancy": 5,
            "residents-TOTAL_FORMS": 0,
            "residents-INITIAL_FORMS": 0,
            "residents-MAX_NUM_FORMS": 50,
            }, follow=True)

        url = reverse("rooms:view", kwargs={"room_title": self.r.title})
        self.assertRedirects(response, url)
        self.assertContains(response, "<dd>{0}</dd>".format(5), html=True)
        self.assertNotContains(response, "Starry Night Surprise")
        self.assertNotContains(response, self.su.get_full_name())

    def test_bad_occupancy(self):
        url = reverse("rooms:edit", kwargs={"room_title": self.r.title})
        response = self.client.post(url, {
            "room-title": self.r.title,
            "room-unofficial_name": "Starry Night",
            "room-description": "Home to the best person on earth.",
            "room-occupancy": -1,
            "residents-TOTAL_FORMS": 0,
            "residents-INITIAL_FORMS": 0,
            "residents-MAX_NUM_FORMS": 50,
            })

        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            "Ensure this value is greater than or equal to 0.",
            )

        response = self.client.post(url, {
            "title": self.r.title,
            "unofficial_name": "Starry Night",
            "description": "Home to the best person on earth.",
            "occupancy": "",
            "residents-TOTAL_FORMS": 0,
            "residents-INITIAL_FORMS": 0,
            "residents-MAX_NUM_FORMS": 50,
            })

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "This field is required.")

    def test_bad_title(self):
        url = reverse("rooms:edit", kwargs={"room_title": self.r.title})
        response = self.client.post(url, {
            "room-title": "",
            "room-unofficial_name": "",
            "room-description": "",
            "room-occupancy": 1,
            "residents-TOTAL_FORMS": 0,
            "residents-INITIAL_FORMS": 0,
            "residents-MAX_NUM_FORMS": 50,
            })

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "This field is required.")

        response = self.client.post(url, {
            "room-title": "2a.",
            "room-unofficial_name": "",
            "room-description": "",
            "room-occupancy": 1,
            "residents-TOTAL_FORMS": 0,
            "residents-INITIAL_FORMS": 0,
            "residents-MAX_NUM_FORMS": 50,
            })

        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            "Only alphanumeric characters are allowed.",
            )

        response = self.client.post(url, {
            "room-title": "3_",
            "room-unofficial_name": "",
            "room-description": "",
            "room-occupancy": 1,
            "residents-TOTAL_FORMS": 0,
            "residents-INITIAL_FORMS": 0,
            "residents-MAX_NUM_FORMS": 50,
            })

        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            "Only alphanumeric characters are allowed.",
            )