Exemple #1
0
def location(request, room_id):
    message = convert_message_to_toastr(messages.get_messages(request))
    room = Room.objects.get(id=room_id)
    g = geocoder.google(room.city_country)
    try:
        address = room.location
    except Location.DoesNotExist:
        address = Location(room=room,
                           country=room.city_country.split(', ')[1],
                           locality=room.city_country.split(', ')[0],
                           administrative_area_level_1=g.state)
    if request.method == 'POST':
        form = LocationForm(request.POST, instance=address)
        if form.is_valid():
            route = form.cleaned_data['route']
            street_number = form.cleaned_data['street_number']
            locality = form.cleaned_data['locality']
            country = form.cleaned_data['country']
            postal_code = form.cleaned_data['postal_code']

            input_address = '%s %s, %s, %s' % (route, street_number, locality,
                                               country)
            g = geocoder.google(input_address)
            if g.ok and g.postal == postal_code:
                data = form.save()
                data.formatted_address = g.address
                data.lat = g.lat
                data.lng = g.lng
                data.save()
                messages.add_message(request, messages.SUCCESS,
                                     'edit your location successfully!')
                message = convert_message_to_toastr(
                    messages.get_messages(request))
                return render_to_response('location_map.html', {
                    'messages': message,
                    'room_id': room_id
                }, RequestContext(request))
            else:
                messages.add_message(request, messages.ERROR,
                                     'Something wrong with your location!')
                message = convert_message_to_toastr(
                    messages.get_messages(request))
                render_to_response('location.html', {
                    'form': form,
                    'room_id': room_id,
                    'messages': message
                }, RequestContext(request))
    else:
        form = LocationForm(instance=address)
        form.fields['route'].widget.attrs['placeholder'] = 'ej: gran via'
        form.fields['street_number'].widget.attrs['placeholder'] = 'ej: 18'
        form.fields['postal_code'].widget.attrs['placeholder'] = 'ej: 28020'
    return render_to_response('location.html', {
        'form': form,
        'room_id': room_id,
        'messages': message
    }, RequestContext(request))
Exemple #2
0
def home_type_view(request, room_id):
    room = Room.objects.get(id=room_id)
    message = convert_message_to_toastr(messages.get_messages(request))
    try:
        home_type = room.hometype
    except HomeType.DoesNotExist:
        home_type = HomeType(room=room)
    if request.method == 'POST':
        form = HomeTypeForm(request.POST, instance=home_type)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'edit your room type successfully!')
            return HttpResponseRedirect(
                reverse(
                    'bedrooms',
                    kwargs={'room_id': room_id},
                ))
    else:
        form = HomeTypeForm(instance=home_type)
    return render_to_response('home_type.html', {
        'form': form,
        'room_id': room_id,
        'messages': message
    }, RequestContext(request))
Exemple #3
0
def rooms(request, room_id):
    message = convert_message_to_toastr(messages.get_messages(request))
    if request.method == 'GET':
        room = Room.objects.get(id=room_id)
        zip = room.location.postal_code
        geo = {'lat': room.location.lat, 'lng': room.location.lng}
        room_nearby = Location.objects.filter(postal_code__exact=zip)
        context = {
            'room': room,
            'geo': json.dumps(geo),
            'room_nearby': room_nearby,
            'form': ReservationForm(),
            'messages': message
        }
        return render_to_response('room.html', context,
                                  RequestContext(request))
    if request.is_ajax():
        if request.method == 'DELETE':
            try:
                room = Room.objects.get(id=room_id)
                room.delete()
            except Room.DoesNotExist:
                raise 404
            other_rooms = request.user.room_set.all()
            template = render_to_response('room_list_view.html',
                                          {'rooms': other_rooms})
            return HttpResponse(template)
Exemple #4
0
def calenders(request, room_id):
    message = convert_message_to_toastr(messages.get_messages(request))
    room = Room.objects.get(id=room_id)
    try:
        calender = room.calender
    except Calender.DoesNotExist:
        calender = Calender(room=room)
    if request.method == 'POST':
        form = CalenderForm(request.POST, instance=calender)
        if form.is_valid():
            data = form.save(commit=False)
            print(data)
            start_date = data.date_range.split(' - ')[0]
            end_date = data.date_range.split(' - ')[1]
            data.start_date = datetime.strptime(start_date, '%m/%d/%Y')
            data.end_date = datetime.strptime(end_date, '%m/%d/%Y')
            data.save()
            messages.add_message(request, messages.SUCCESS,
                                 'edit your calender successfully!')
            return HttpResponseRedirect(
                reverse('price', kwargs={'room_id': room_id}))
    else:
        form = CalenderForm(instance=calender)
    return render_to_response('calender.html', {
        'form': form,
        'room_id': room_id,
        'messages': message
    }, RequestContext(request))
Exemple #5
0
def trip_list(request):
    message = convert_message_to_toastr(messages.get_messages(request))
    reservations = request.user.reservation_set.all()
    return render_to_response(
        'room_list.html', {
            'trips': reservations,
            'render_view': 'trip_list_view.html',
            'messages': message
        }, RequestContext(request))
Exemple #6
0
def room_list(request):
    message = convert_message_to_toastr(messages.get_messages(request))
    user = request.user
    if user.room_set.all().count():
        user_rooms = user.room_set.all()
    else:
        user_rooms = None
    return render_to_response(
        'room_list.html', {
            'rooms': user_rooms,
            'messages': message,
            'render_view': 'room_list_view.html'
        }, RequestContext(request))
Exemple #7
0
def price(request, room_id):
    message = convert_message_to_toastr(messages.get_messages(request))
    room = Room.objects.get(id=room_id)
    try:
        p = room.price
    except Price.DoesNotExist:
        p = Price(room=room)
    if request.method == 'POST':
        form = PriceForm(request.POST, instance=p)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'edit your calender successfully!')
            return HttpResponseRedirect(
                reverse('room_section', kwargs={'room_id': room_id}))
    else:
        form = PriceForm(instance=p)
    return render_to_response('price.html', {
        'form': form,
        'room_id': room_id,
        'messages': message
    }, RequestContext(request))
Exemple #8
0
def highlights(request, room_id):
    message = convert_message_to_toastr(messages.get_messages(request))
    room = Room.objects.get(id=room_id)
    try:
        high = room.highlight
    except HighLight.DoesNotExist:
        high = HighLight(room=room)
    if request.method == 'POST':
        form = HighLightForm(request.POST, instance=high)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'edit your highlights successfully!')
            return HttpResponseRedirect(
                reverse('name_description', kwargs={'room_id': room_id}))
    else:
        form = HighLightForm(instance=high)
    return render_to_response('highlight.html', {
        'form': form,
        'room_id': room_id,
        'messages': message
    }, RequestContext(request))
Exemple #9
0
def photos(request, room_id):
    message = convert_message_to_toastr(messages.get_messages(request))
    room = Room.objects.get(id=room_id)
    try:
        photo = room.photo
    except Photo.DoesNotExist:
        photo = Photo(room=room)
    if request.method == 'POST':
        form = PhotoForm(request.POST, request.FILES, instance=photo)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'edit your photos successfully!')
            return HttpResponseRedirect(
                reverse('highlights', kwargs={'room_id': room_id}))
    else:
        form = PhotoForm(instance=photo)
    return render_to_response('photos.html', {
        'form': form,
        'room_id': room_id,
        'messages': message
    }, RequestContext(request))
Exemple #10
0
def amenities(request, room_id):
    room = Room.objects.get(id=room_id)
    message = convert_message_to_toastr(messages.get_messages(request))
    try:
        amenity = room.amenity
    except Amenity.DoesNotExist:
        amenity = Amenity(room=room)
    if request.method == 'POST':
        form = AmenityForm(request.POST, instance=amenity)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'edit your amenities successfully!')
            return HttpResponseRedirect(
                reverse('spaces', kwargs={'room_id': room_id}))
    else:
        form = AmenityForm(instance=amenity)
    return render_to_response('amenity.html', {
        'form': form,
        'room_id': room_id,
        'messages': message
    }, RequestContext(request))
Exemple #11
0
def bathrooms(request, room_id):
    room = Room.objects.get(id=room_id)
    message = convert_message_to_toastr(messages.get_messages(request))
    try:
        bathroom = room.bathroom
    except Bathroom.DoesNotExist:
        bathroom = Bathroom(room=room)
    if request.method == 'POST':
        form = BathroomForm(request.POST, instance=bathroom)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'edit your bathroom successfully!')
            return HttpResponseRedirect(
                reverse('location', kwargs={'room_id': room_id}))
    else:
        form = BathroomForm(instance=bathroom)
    return render_to_response('bathroom.html', {
        'form': form,
        'room_id': room_id,
        'messages': message
    }, RequestContext(request))
Exemple #12
0
def name_description(request, room_id):
    message = convert_message_to_toastr(messages.get_messages(request))
    room = Room.objects.get(id=room_id)
    try:
        name = room.namedescription
    except NameDescription.DoesNotExist:
        name = NameDescription(room=room)
    if request.method == 'POST':
        form = NameDescriptionForm(request.POST, instance=name)
        if form.is_valid():
            form.save()
            messages.add_message(
                request, messages.SUCCESS,
                'edit your name and description successfully!')
            return HttpResponseRedirect(
                reverse('room_section', kwargs={'room_id': room_id}))
    else:
        form = NameDescriptionForm(instance=name)
    return render_to_response('name_description.html', {
        'form': form,
        'room_id': room_id,
        'messages': message
    }, RequestContext(request))
def public_profile(request, user_id):
    message = convert_message_to_toastr(messages.get_messages(request))
    user = User.objects.get(id=user_id)
    rooms = user.room_set.all().filter(is_active=True)
    return render_to_response('public_profile.html', {'messages': message, 'userProfile': user, 'rooms': rooms}, RequestContext(request))