def get_system_log(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is not None: if UsersLogic.is_system_manager(username): logs_html = "" log_items = LoggerLogic.get_all_event_logs() for log_item in log_items: logs_html += loader.render_to_string( 'components/log_table_event.html', context={ 'username': log_item.username, 'time': log_item.time, 'event': log_item.event }) context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, None) } return render(request, 'system-logger.html', context=context) return HttpResponse("You don't have the privilege to be here")
def get_reviews(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') guest = request.COOKIES.get('guest_hash') context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, guest) } shop_name = request.GET.get('shop_name') shop = ShopLogic.search_shop(shop_name) if shop is not False: reviews = ShopLogic.get_shop_reviews(shop_name) string_reviews = "" for review in reviews: string_reviews += loader.render_to_string( 'components/review.html', { 'writer_name': review.writerId, 'rank': review.rank, 'description': review.description }, None, None) context.update({ 'shop_name': shop_name, 'reviews': string_reviews }) return render(request, 'shop_reviews.html', context=context) return HttpResponse(shop_not_exist) return HttpResponse(not_get_request)
def get_system_shops(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is not None: if UsersLogic.is_system_manager(username): orders_html = "" shops_html = "" shops = ShopLogic.get_all_shops() for shop in shops: shops_html += loader.render_to_string( 'components/shop.html', context={ 'shop_name': shop.name, 'status': shop.status }) context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, None) } context.update({'shops': shops_html}) return render(request, 'system-shops.html', context=context) return HttpResponse("You don't have the privilege to be here")
def get_system_users(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is not None: if UsersLogic.is_system_manager(username): users_html = "" users = UsersLogic.get_all_users() for user in users: shops_own = len( UsersLogic.get_owned_shops(user.username)) shop_manage = len( UsersLogic.get_managed_shops(user.username)) users_html += loader.render_to_string( 'components/user.html', context={ 'username': user.username, 'shop_own_count': shops_own, 'shop_manage_count': shop_manage, }) context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, None) } context.update({'users': users_html}) return render(request, 'system-users.html', context=context) return HttpResponse("You don't have the privilege to be here")
def get_order(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') purchase_id = request.GET.get('order_id') if login is not None: username = Consumer.loggedInUsers.get(login) if username is not None: items_html = "" items = ShoppingLogic.get_purchased_items_by_purchase_id( purchase_id) for item in items: full_item = ItemsLogic.get_item(item.item_id) items_html += loader.render_to_string( 'components/PurchasedItem.html', context={ 'item_id': item.item_id, 'item_url': full_item.url, 'item_name': full_item.name, 'item_quantity': item.quantity, 'item_price': item.price, 'shop_name': full_item.shop_name, }) date = ShoppingLogic.get_purchase(purchase_id).purchase_date context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, None) } context.update({ 'items': items_html, 'order_id': purchase_id, 'order_date': date }) return render(request, 'customer-order.html', context=context) return HttpResponse('You are not logged in!')
def add_discount_page(request): if request.method == 'GET': shop_name = request.GET.get('shop_name') login = request.COOKIES.get('login_hash') guest = request.COOKIES.get('guest_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is None: return HttpResponse(error_login_owner) else: return HttpResponse(error_login_owner) if not UsersLogic.is_owner_of_shop(username, shop_name): if UsersLogic.is_manager_of_shop(username, shop_name): manager = UsersLogic.get_manager(username, shop_name) if manager.discount_permission is not 1: # no permission return HttpResponse('no permission to add discount') else: return HttpResponse('fail') # not manager not owner every_html = { 'top_bar': Topbar_Navbar.get_top_bar(login), 'nav_bar': Topbar_Navbar.get_nav_bar(login, guest) } return render(request, 'shop_add_discount.html', context={ 'every_html': every_html, 'shop_name': shop_name })
def get_account(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') if login is None: login = request.GET.get('login_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is not None: # html of a logged in user system_hidden = "hidden" if UsersLogic.is_system_manager(username): system_hidden = "" details = {'state': "AFG", 'age': "AFG", 'sex': "AFG"} else: details = UsersLogic.get_user_details(username) context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, None) } context.update({ 'system_hidden': system_hidden, 'state': details.get('state'), 'age': details.get('age'), 'sex': details.get('sex') }) return render(request, 'customer-account.html', context=context) return HttpResponse('You are not logged in!')
def show_receipt(request): if request.method == 'GET': name = '' purchase_id = request.GET.get("purchase_id") amount = request.GET.get("amount") login = request.COOKIES.get('login_hash') guest = request.COOKIES.get('guest_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is not None: name = username else: if guest is not None: name = guest else: if guest is not None: name = guest context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, guest) } payment = ExternalSystems.payment.pay(float(amount), name) delivery = ExternalSystems.supply.supply_a_purchase( name, int(purchase_id)) context['payment'] = payment context['delivery'] = delivery return render(request, 'receipt.html', context=context)
def get_shop_messages(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') content = request.GET.get('content') shop_name = request.GET.get('shop_name') if login is not None: username = Consumer.loggedInUsers.get(login) if username is not None: messages_html = "" if content == 'received': messages = MessagingLogic.get_all_shop_messages( username, shop_name) if messages is not False: for message in messages: messages_html += loader.render_to_string( 'components/Message.html', context={ 'id': message.message_id, 'from': message.from_username, 'to': message.to_username, 'content': message.content }) received_on = "class=active" sent_on = "" else: return HttpResponse('fail') elif content == 'sent': messages = MessagingLogic.get_all_sent_shop_messages( username, shop_name) if messages is not False: for message in messages: messages_html += loader.render_to_string( 'components/Message.html', context={ 'id': message.message_id, 'from': message.from_username, 'to': message.to_username, 'content': message.content }) received_on = "" sent_on = "class=active" else: return HttpResponse('fail') else: return HttpResponse('You are not logged in!') context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, None) } context.update({ 'messages': messages_html, 'received_on': received_on, 'sent_on': sent_on, 'shop_name': shop_name }) return render(request, 'shop-messages.html', context=context) return HttpResponse('You are not logged in!')
def address(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') guest = request.COOKIES.get('guest_hash') context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, guest) } return render(request, 'checkout1.html', context=context)
def get_home(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') guest = request.COOKIES.get('guest_hash') items = SearchLogic.get_top_five_ranked_items() for item in items: shop_name = item.shop_name item.price = (round(item.price * item_discount(item.id, shop_name) * category_discount(item.category, shop_name), 2)) context = {'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, guest), 'items': items} return render(request, 'index.html', context=context)
def shopping_cart_items_helper(request): login = request.COOKIES.get('login_hash') guest = request.COOKIES.get('guest_hash') context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, guest) } if login is not None and Consumer.loggedInUsers.get(login) is not None: context.update(UserShoppingCartLogic.order_of_user(login)) else: if guest is not None: context.update(GuestShoppingCartLogic.order_of_guest(guest)) return context
def continuous_reporting(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is not None: context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, None) } return render(request, 'system-cont-report.html', context=context) return HttpResponse("You don't have the privilege to be here")
def get_reviews(request): if request.method == 'GET': item_id = request.GET.get('item_id') item = ItemsLogic.get_item(item_id) if item is not False: reviews = ItemsLogic.get_all_reviews_on_item(item.id) string_reviews = "" for review in reviews: string_reviews += loader.render_to_string( 'component/../../../PresentationLayer/templates/components/review.html', {'writer_name': review.writerId, 'rank': review.rank, 'description': review.description}, None, None) login = request.COOKIES.get('login_hash') guest = request.COOKIES.get('guest_hash') context = {'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, guest)} context.update({'item_name': item.name, 'shop_name': item.shop_name, 'reviews': string_reviews}) return render(request, 'item_reviews.html', context=context) return HttpResponse(shop_not_exist) return HttpResponse(not_get_request)
def watch_purchase_history(request): if request.method == 'GET': shop_name = request.GET.get('shop_name') login = request.COOKIES.get('login_hash') guest = request.COOKIES.get('guest_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is None: return HttpResponse(error_login_owner) else: return HttpResponse(error_login_owner) if not UsersLogic.is_owner_of_shop(username, shop_name): if UsersLogic.is_manager_of_shop(username, shop_name): manager = UsersLogic.get_manager(username, shop_name) if manager.permission_get_purchased_history is not 1: # no permission return HttpResponse( 'no permission to watch purchase history') else: return HttpResponse('fail') # not manager not owner every_html = { 'top_bar': Topbar_Navbar.get_top_bar(login), 'nav_bar': Topbar_Navbar.get_nav_bar(login, guest) } shop_items = ShopLogic.get_shop_purchase_history(username, shop_name) string_items = "" for item in shop_items: string_items += loader.render_to_string( 'components/purchase_item_owner.html', { 'purchase_id': item.purchase_id, 'item_id': item.item_id, 'quantity': item.quantity, 'price': item.price }) return render(request, 'shop_view_purchase_history.html', context={ 'every_html': every_html, 'items': string_items, 'shop_name': shop_name }) return HttpResponse(not_get_request)
def get_alerts(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is not None: alert_box = Consumer.user_alerts_box.get(username) alerts_html = "" if alert_box is not None: for alert in alert_box: alerts_html += "<tr> <td>" + alert.getContent( ) + "</td></tr>" context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, None) } context.update({'alerts': alerts_html}) return render(request, 'alerts-page.html', context=context) return HttpResponse('You are not logged in')
def get_system_history(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is not None: if UsersLogic.is_system_manager(username): history_html = "" purchased_items = ItemsLogic.get_all_purchased_items( username) for purchased_item in purchased_items: item = ItemsLogic.get_item(purchased_item.item_id) if item is False: item = Item(purchased_item.item_id, None, None, None, None, None, None, None, None, 0, 0, 0) purchase = ShoppingLogic.get_purchase( purchased_item.purchase_id) history_html += loader.render_to_string( 'components/purchase_history.html', context={ 'username': purchase.username, 'shop_name': item.shop_name, 'purchase_id': purchased_item.purchase_id, 'item_id': item.id, 'quantity': purchased_item.quantity, 'price': purchased_item.price }) context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, None) } context.update({'history': history_html}) return render(request, 'system-history.html', context=context) return HttpResponse("You don't have the privilege to be here")
def get_shop_to_owner(request): if request.method == 'GET': shop_name = request.GET.get('shop_name') login = request.COOKIES.get('login_hash') guest = request.COOKIES.get('guest_hash') context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, guest) } if login is not None: username = Consumer.loggedInUsers.get(login) if username is None: return HttpResponse(error_login_owner) else: return HttpResponse(error_login_owner) if UsersLogic.is_owner_of_shop(username, shop_name) is not False: shop_items = ShopLogic.get_shop_items(shop_name) string_items = "" for item in shop_items: string_items += loader.render_to_string( 'components/item_owner.html', { 'item_name': item.name, 'item_quantity': item.quantity, 'item_category': item.category, 'item_keywords': item.keyWords, 'item_price': item.price, 'item_url': item.url, 'item_id': item.id, 'shop_name': item.shop_name }) context.update({'items': string_items, 'shop_name': shop_name}) return render(request, 'shop_items_management.html', context=context) else: return HttpResponse(shop_not_exist + " with username=" + username) return HttpResponse(not_get_request)
def get_orders(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is not None: orders_html = "" orders = ShoppingLogic.get_user_purchases(username) for order in orders: orders_html += loader.render_to_string( 'components/order.html', context={ 'order_id': order.purchase_id, 'order_date': order.purchase_date, 'total_price': order.total_price, }) context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, None) } context.update({'orders': orders_html}) return render(request, 'customer-orders.html', context=context) return HttpResponse('You are not logged in!')
def delete_discount(request): if request.method == 'GET': shop_name = request.GET.get('shop_name') login = request.COOKIES.get('login_hash') guest = request.COOKIES.get('guest_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is None: return HttpResponse(error_login_owner) else: return HttpResponse(error_login_owner) if not UsersLogic.is_owner_of_shop(username, shop_name): if UsersLogic.is_manager_of_shop(username, shop_name): manager = UsersLogic.get_manager(username, shop_name) if manager.discount_permission is not 1: # no permission return HttpResponse('no permission to add discount') else: return HttpResponse('fail') # not manager not owner shop_discounts = DiscountLogic.get_all_visible_discounts_items( shop_name) string_discounts = "" for discount in shop_discounts: string_discounts += loader.render_to_string( 'components/discount.html', { 'shop_name': shop_name, 'item_id': discount.item_id, 'category': '----', 'from_date': discount.from_date, 'to_date': discount.end_date, 'percents': discount.percentage, 'type': 1, 'code': '----' }) shop_discounts = DiscountLogic.get_all_visible_discounts_categories( shop_name) for discount in shop_discounts: string_discounts += loader.render_to_string( 'components/discount.html', { 'shop_name': shop_name, 'category': discount.category, 'item_id': 0, 'from_date': discount.from_date, 'to_date': discount.end_date, 'percents': discount.percentage, 'type': 2, 'code': '----' }) shop_discounts = DiscountLogic.get_all_invisible_discounts_items( shop_name) for discount in shop_discounts: string_discounts += loader.render_to_string( 'components/discount.html', { 'shop_name': shop_name, 'item_id': discount.item_id, 'category': '----', 'from_date': discount.from_date, 'to_date': discount.end_date, 'percents': discount.percentage, 'type': 3, 'code': discount.code }) shop_discounts = DiscountLogic.get_all_invisible_discounts_categories( shop_name) for discount in shop_discounts: string_discounts += loader.render_to_string( 'components/discount.html', { 'shop_name': shop_name, 'item_id': 0, 'category': discount.category, 'from_date': discount.from_date, 'to_date': discount.end_date, 'percents': discount.percentage, 'type': 4, 'code': discount.code }) every_html = { 'top_bar': Topbar_Navbar.get_top_bar(login), 'nav_bar': Topbar_Navbar.get_nav_bar(login, guest) } return render(request, 'shop_delete_discount.html', context={ 'every_html': every_html, 'shop_name': shop_name, 'discounts': string_discounts })
def get_shop(request): if request.method == 'GET': shop_name = request.GET.get('shop_name') shop = ShopLogic.search_shop(shop_name) if shop is not False: username = None login = request.COOKIES.get('login_hash') if login is not None: username = Consumer.loggedInUsers.get(login) guest = request.COOKIES.get('guest_hash') context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, guest) } items = ShopLogic.get_shop_items(shop.name) products = "" for item in items: if item.kind == 'prize': continue products += loader.render_to_string( 'components/item.html', { 'name': item.name, 'price': "{0:.2f}".format( item.price * item_discount(item.id, shop_name) * category_discount(item.category, shop_name)), 'url': item.url, 'item_id': item.id }, None, None) owner_manager_options = "" render_edit_remove = loader.render_to_string( 'components/owner_manager_options.html', { 'path': 'owner/items', 'id_param': 'edit_remove', 'shop_name': shop_name, 'button_text': 'Edit & Remove Items' }) render_purchase_history = loader.render_to_string( 'components/owner_manager_options.html', { 'path': 'owner/purchase_history', 'id_param': 'purchase_history', 'shop_name': shop_name, 'button_text': 'Purchase History' }) render_add_item = loader.render_to_string( 'components/owner_manager_options.html', { 'path': 'owner/items/add_item', 'id_param': 'add_item', 'shop_name': shop_name, 'button_text': 'Add Item' }) render_add_discount = loader.render_to_string( 'components/owner_manager_options.html', { 'path': 'owner/add_discount', 'id_param': 'add_discount', 'shop_name': shop_name, 'button_text': 'Add Discount' }) render_delete_discount = loader.render_to_string( 'components/owner_manager_options.html', { 'path': 'owner/delete_discount', 'id_param': 'delete_discount', 'shop_name': shop_name, 'button_text': 'Delete Discount' }) if UsersLogic.is_owner_of_shop(username, shop_name): owner_manager_options += render_purchase_history + \ render_edit_remove + \ render_add_item + \ render_add_discount + \ render_delete_discount if UsersLogic.is_manager_of_shop(username, shop_name): manager = UsersLogic.get_manager(username, shop_name) if manager.permission_get_purchased_history == 1: owner_manager_options += render_purchase_history if manager.permission_edit_item == 1 or manager.permission_remove_item == 1: owner_manager_options += render_edit_remove if manager.permission_add_item == 1: owner_manager_options += render_add_item if manager.discount_permission == 1: owner_manager_options += render_add_discount + render_delete_discount context.update({ 'shop_name': shop.name, 'shop_status': shop.status, 'products': products, 'owner_manager_options': owner_manager_options }) return render(request, 'shop.html', context=context) else: login = request.COOKIES.get('login_hash') guest = request.COOKIES.get('guest') topbar = Topbar_Navbar.get_top_bar(login) navbar = Topbar_Navbar.get_nav_bar(login, guest) context = {'topbar': topbar, 'navbar': navbar} return render(request, 'ShopNotFound.html', context) return HttpResponse(not_get_request)
def get_shops(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is not None: # html of a logged in user owned_shops_html = "" owned_shops = UsersLogic.get_owned_shops(username) for owned_shop in owned_shops: shop = ShopLogic.search_shop(owned_shop.shop_name) rank = ShopLogic.get_shop_rank(shop.name) checked = "" if owned_shop.should_notify > 0: checked = 'checked="checked"' if shop.status == 'Active': status_class = 'btn btn-success btn-sm' elif shop.status == 'Inactive': status_class = 'btn btn-warning btn-sm' else: status_class = 'btn btn-danger btn-sm' owned_shops_html += loader.render_to_string( 'components/ShopYouOwn.html', context={ 'shop_name': owned_shop.shop_name, 'review': rank, 'status': shop.status, 'status_button_class': status_class, }) managed_shops_html = "" managed_shops = UsersLogic.get_managed_shops(username) yes_no_array = ['No', 'Yes'] for managed_shop in managed_shops: rank = ShopLogic.get_shop_rank(managed_shop.username) _shop = ShopLogic.search_shop(managed_shop.store_name) managed_shops_html += loader.render_to_string( 'components/ShopsYouManage.html', context={ 'shop_name': _shop.name, 'review': rank, 'status': _shop.status, 'AIP': yes_no_array[managed_shop.permission_add_item], 'RIP': yes_no_array[managed_shop.permission_remove_item], 'EIP': yes_no_array[managed_shop.permission_edit_item], 'RMP': yes_no_array[ managed_shop.permission_reply_messages], 'GAP': yes_no_array[ managed_shop.permission_get_all_messages], 'GPHP': yes_no_array[ managed_shop.permission_get_purchased_history], 'DP': yes_no_array[managed_shop.discount_permission], 'SP': yes_no_array[managed_shop.permission_set_policy], }) context = { 'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, None) } context.update({ 'owned_shops': owned_shops_html, 'managed_shops': managed_shops_html }) return render(request, 'customer-shops.html', context=context) return HttpResponse('You are not logged in!')
def search_item(request): if request.method == 'GET': login = request.COOKIES.get('login_hash') guest = request.COOKIES.get('guest') topbar = Topbar_Navbar.get_top_bar(login) navbar = Topbar_Navbar.get_nav_bar(login, guest) search_by = request.GET.get('searchBy') items = [] words = [] event = "SEARCH ITEM" if search_by == 'name': name = request.GET.get('name') suspect_sql_injection = LoggerLogic.identify_sql_injection( name, event) if suspect_sql_injection: return HttpResponse(LoggerLogic.MESSAGE_SQL_INJECTION) items = SearchLogic.search_by_name(name) for item in items: shop_name = item.shop_name item.price = (round( item.price * item_discount(item.id, shop_name) * category_discount(item.category, shop_name), 2)) if len(items) != 0: context = { 'topbar': topbar, 'items': items, 'navbar': navbar, 'len': len(items) } return render(request, 'SearchView.html', context) else: words = SearchLogic.get_similar_words(name) words = words[:5] items_names_that_exists = [] for each_item in words: item = SearchLogic.search_by_name(each_item) if len(item) != 0: items_names_that_exists.append(each_item) context = { 'topbar': topbar, 'items': items_names_that_exists, 'navbar': navbar, 'type': 'name' } if len(items_names_that_exists) != 0: return render(request, 'ItemsNotFound.html', context) else: return render(request, 'ItemNotFoundNoSuggestions.html', context) if search_by == 'category': category = request.GET.get('category') suspect_sql_injection = LoggerLogic.identify_sql_injection( category, event) if suspect_sql_injection: return HttpResponse(LoggerLogic.MESSAGE_SQL_INJECTION) items = SearchLogic.search_by_category(request.GET.get('category')) for item in items: shop_name = item.shop_name item.price = (round( item.price * item_discount(item.id, shop_name) * category_discount(item.category, shop_name), 2)) if len(items) != 0: context = { 'topbar': topbar, 'items': items, 'navbar': navbar, 'len': len(items) } return render(request, 'SearchView.html', context) else: words = SearchLogic.get_similar_words(category) words = words[:5] items_names_that_exists = [] for each_item in words: item = SearchLogic.search_by_category(each_item) if len(item) != 0: items_names_that_exists.append(each_item) context = { 'topbar': topbar, 'items': items_names_that_exists, 'navbar': navbar, 'type': 'category' } if len(items_names_that_exists) != 0: return render(request, 'ItemsNotFound.html', context) else: return render(request, 'ItemNotFoundNoSuggestions.html', context) if search_by == 'keywords': keywords = request.GET.get('keywords') suspect_sql_injection = LoggerLogic.identify_sql_injection( keywords, event) if suspect_sql_injection: return HttpResponse(LoggerLogic.MESSAGE_SQL_INJECTION) items = SearchLogic.search_by_keywords(keywords) for item in items: shop_name = item.shop_name item.price = (round( item.price * item_discount(item.id, shop_name) * category_discount(item.category, shop_name), 2)) if len(items) != 0: context = { 'topbar': topbar, 'items': items, 'navbar': navbar, 'len': len(items) } return render(request, 'SearchView.html', context) else: words = SearchLogic.get_similar_words(keywords) words = words[:5] items_names_that_exists = [] for each_item in words: item = SearchLogic.search_by_keywords(each_item) if len(item) != 0: items_names_that_exists.append(each_item) context = { 'topbar': topbar, 'items': items_names_that_exists, 'navbar': navbar, 'type': 'keywords' } if len(items_names_that_exists) != 0: return render(request, 'ItemsNotFound.html', context) else: return render(request, 'ItemNotFoundNoSuggestions.html', context)
def get_item(request): if request.method == 'GET': item_id = request.GET.get('item_id') item = ItemsLogic.get_item(item_id) if item is not False: # product = "" # product += loader.render_to_string('component/item.html', # {'name': item.name, 'price': item.price, 'url': item.url}, None, # None) right1 = "Percentage" policy_or_percentage = "0" item_percentage = "0" right2 = "Start Date" deadline_or_start_date = "None" item_start_date = "None" item_end_date = "None" right3 = "End Time" real_end_time_or_end_date = "None" headline = "Purchase Policy" price = item.price former_price = "" visibility_quantity = "visible" visibility_add_to_cart = "visible" lottery = Lotteries.get_lottery(item_id) header_of_table = "Category Discount" invisible = "" lottery_margin_left = 0 quantity_icon = 'icon-inventory.png' if lottery is not False: right1 = "Policy" policy_or_percentage = "Lottery" print(lottery.final_date) right2 = "Deadline" deadline_or_start_date = lottery.final_date right3 = "Actual End Time" invisible = "display: none;" header_of_table = "Additional details you should know before purchase" lottery_margin_left = 30 if lottery.real_end_date is not None: real_end_time_or_end_date = lottery.real_end_date visibility_quantity = "hidden" visibility_add_to_cart = "hidden" else: real_end_time_or_end_date = "---------" quantity_icon = 'tickets-icon.png' else: headline = "Discounts on Product" discount = get_visible_discount(item.id, item.shop_name) if discount is not False: item_start_date = discount.from_date item_percentage = str(discount.percentage) + "%" item_end_date = discount.end_date former_price = "$" + str(item.price) price = price*(1 - (discount.percentage / 100)) discount = get_visible_discount_category(item.category, item.shop_name) if discount is not False: deadline_or_start_date = discount.from_date policy_or_percentage = str(discount.percentage) + "%" real_end_time_or_end_date = discount.end_date former_price = "$" + str(item.price) price = price * (1 - (discount.percentage / 100)) login = request.COOKIES.get('login_hash') guest = request.COOKIES.get('guest_hash') context = {'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, guest)} item_rank = item.item_rating if item_rank is False: item_rank = "-----" else: item_rank = str(item_rank) if item.quantity < 1: visibility_add_to_cart = "hidden" context.update({'item_id': item.id, 'item_name': item.name, 'shop_name': item.shop_name, 'category': item.category, 'keyWords': item.keyWords, 'price': round(price, 2), 'former_price': former_price, 'quantity': item.quantity, 'kind': item.kind, 'item_rank': item_rank, 'url': item.url, 'policy_or_percentage': policy_or_percentage, 'headline': headline, 'deadline_or_start_date': deadline_or_start_date, 'real_end_time_or_end_date': real_end_time_or_end_date, 'right1': right1, 'right2': right2, 'right3': right3, 'invisible': invisible, 'header_of_table': header_of_table, 'lottery_margin_left': lottery_margin_left, 'item_percentage': item_percentage, 'item_start_date': item_start_date, 'item_end_date': item_end_date, 'visibility_quantity': visibility_quantity, 'visibility_add_to_cart': visibility_add_to_cart, 'quantity_icon': quantity_icon}) return render(request, 'detail.html', context=context) else: return HttpResponse(shop_not_exist) return HttpResponse(not_get_request)