def top_discount(): with connection.cursor() as cur: sql = "SELECT * FROM " \ "(SELECT H.HOTELID, H.NAME, H.STREET, H.ZIPCODE, H.CITY, H.COUNTRY, H.RATING, H.RATINGCOUNT, " \ "RT.ROOMTYPE_NAME, RT.DISCOUNT " \ "FROM HOTEL H, ROOM R, ROOM_TYPE RT " \ "WHERE R.HOTELID = H.HOTELID AND R.ROOMTYPEID = RT.ROOMTYPEID " \ "ORDER BY RT.DISCOUNT DESC) " \ "WHERE ROWNUM <= 6" cur.execute(sql) result = cur.fetchall() hotel_ara = [] image_locations = [] index = 1 for row in result: h = Hotel(hotelId=row[0], name=row[1], street=row[2], zipcode=row[3], city=row[4], country=row[5], rating=row[6], rating_count=row[7]) h.image_location = 'home/images/top_{}.jpg'.format(index) hotel_ara.append((h, row[8], row[9])) image_locations.append(h.image_location) index += 1 return hotel_ara, image_locations
def best_rated(): with connection.cursor() as cur: sql = "SELECT * FROM " \ "(SELECT * FROM HOTEL ORDER BY RATING DESC) " \ "WHERE ROWNUM <= 6" cur.execute(sql) result = cur.fetchall() hotel_ara = [] image_locations = [] index = 1 for row in result: h = Hotel(hotelId=row[0], name=row[1], street=row[2], zipcode=row[3], city=row[4], country=row[5], rating=row[6], rating_count=row[7]) h.image_location = 'home/images/best_{}.jpg'.format(index) hotel_ara.append(h) image_locations.append(h.image_location) index += 1 return hotel_ara, image_locations
def test_add_new_hotel_case(self): h = Hotel( title='테넷', link='https://naver.com', image= 'https://ssl.pstatic.net/imgmovie/mdi/mit110/1323/132345_P01_153355.jpg', pubDate='2001', userRating='10.00') h.save() assert h.title == '테넷' and h.link == 'https://naver.com' and h.image == 'https://ssl.pstatic.net/imgmovie/mdi/mit110/1323/132345_P01_153355.jpg' and h.pubDate == '2001' and h.userRating == '10.00'
def submit(request): name = request.POST['name'] owner = request.POST['owner'] location = request.POST['location'] review = request.POST['review'] youtube_video = request.POST['youtube_video'] hotel = Hotel(name=name, owner=owner, location=location, review=review, youtube_video=youtube_video) hotel.save() messages.success(request, 'Indeed you added a Hotel') return HttpResponseRedirect(reverse('hotel:list'))
def handle(self, *args, **options): headers = { 'Content-Type': 'plain/text', 'X-Naver-Client-Id': 'L7fdgHlj4mgWbysxowRw', 'X-Naver-Client-Secret': 'fUtZiApJSR' } url = 'https://openapi.naver.com/v1/search/movie?query=starwars&display=100&start=1&genre=&country=&yearfrom=1980&yearto=2020' res = requests.get(url=url, headers=headers) data = res.json()['items'] for mo in data: hotel = Hotel(title=mo['title'], link=mo['link'], image=mo['image'], pubDate=mo['pubDate'], userRating=mo['userRating']) hotel.save()
def get_hotel(hotel_id): with connection.cursor() as cur: sql = "SELECT * FROM HOTEL WHERE HOTELID = %s" cur.execute(sql, [hotel_id]) row = cur.fetchone() if row is None: return redirect('login:index') global hotel hotel = Hotel(hotelId=row[0], name=row[1], street=row[2], zipcode=row[3], city=row[4], country=row[5], rating=row[6], rating_count=row[7])
import random from faker import Faker from hotel.models import Hotel fake = Faker() for i in range(5): hotel = Hotel() hotel.name = fake.name() hotel.location = fake.address() hotel.stars = random.randint(1, 5) hotel.save() # print(i)
from django.shortcuts import render, redirect from django.http import HttpResponseRedirect from django.contrib import messages from django.db import connection from .models import Room, Reservation, Service from hotel.models import Hotel from django.urls import reverse import plotly.offline as opy import plotly.graph_objs as go from django.views.generic import TemplateView app_name = 'hotel_admin' hotel = Hotel(0) room_list = [] def index(request): if request.session.has_key('admin_id'): hotel_id = request.session['admin_id'] else: messages.success(request, "You must log in first") return redirect('login:index') global hotel get_hotel(hotel_id) with connection.cursor() as cur: if request.method == 'POST':
from faker import Faker from hotel.models import Hotel fake = Faker() for i in range(100): hotel = Hotel() hotel.name = fake.name() hotel.location = fake.address() hotel.stars = 5 hotel.save() # print(i)