Best Python code snippet using keyboard
order.py
Source: order.py
...148def order_delivered_page():149 if request.method == "POST":150 order_key = request.form.get("order_key")151 update_order_delivered( order_key )152 update_stock_by_order_key(order_key)...
order_management.py
Source: order_management.py
1from read_excel import *2import heapq3from random import randrange4class Delegate_Tasks:5 def __init__(self):6 self.data = Data()7 self.daily_orders = self.data.get_all_orders()8 self.heap = list()9 self.workers = self.data.get_all_workers()10 def generate_schedule(self):11 current_day = 012 while True:13 available_workers = {key : worker for key, worker in self.workers.items() if worker.get_schedule().is_available()]14 new_orders = self.daily_orders[cuurent_day]15 new_order_priorities = [(order.get_priority(), key) for key, order in new_orders.items()]16 for order in new_order_priorities:17 heapq.heappush(self.heap, order)18 employee_capabilites = dict()19 for key in available_workers():20 employee_capabilites[key] = set()21 order_capabilities = dict()22 temp_heap = self.heap.copy()23 while temp_heap:24 qualified_workers = set()25 priority, order_key = heapq.heappop(temp_heap)26 order = data.get_order(order_key)27 order_type = order.get_type()28 for key, worker in available_workers.items():29 if order_type in worker.get_certifications():30 qualified_workers.add(key)31 employee_capabilites[key].add((priority, order_key))32 order_capabilities[order_key] = qualified_workers33 while True:34 # if facility is full, move on35 priority, order_key = heapq.heappop(self.heap)36 order = data.get_order(order_key)37 qualified_workers = order_capabilities[order_key]38 candidate = None39 max_time_remaining = 040 min_max_priority_alternate = -141 for key in qualified_workers:42 worker = data.get_worker(key)43 if len(employee_capabilites[worker]) == 1:44 time_remaining = worker.get_schedule().get_time_remaining()45 if time_remaining > max_time_remaining:46 candidate = key47 max_time_remaining = time_remaining48 else if not max_time_remaining:49 other_tasks = employee_capabilites[key] - {(priority, order_key)}50 max_priority_alternate = max(other_tasks)[0]51 if max_priority_alternate < min_max_priority_alternate or min_max_priority_alternate == -1:52 candidate = key53 min_max_priority_alternate = max_priority_alternate54 if candidate:55 worker = data.get_worker(candidate)56 schedule = worker.get_schedule()57 if schedule.add_task(order_key, Time(order.get_completion_time(), 0), (worker.get_latitude(), worker.get_longitude()), (order.get_latitude(), order.get_longitude())):58 if not schedule.is_available():59 if candidate in employee_capabilites:60 employee_capabilites.remove(candidate)61 else:62 heapq.heappush(self.heap, (priority, order_key))63 else:64 heapq.heappush(self.heap, (priority, order_key))65 if order_key in order_capabilities:66 order_capabilities.remove(order_key)67 for key, tasks in employee_capabilites.items():68 if (priority, order_key) in tasks:69 tasks.remove((priority, order_key))70 no_capabilites = True71 for key, tasks in employee_capabilites.items():72 if tasks:73 no_capabilites = False74 break75 if no_capabilites:76 break77 # Update schedules at the end of each day78 for worker in self.workers.values():79 worker.get_schedule().update()...
views.py
Source: views.py
1from django.http.response import JsonResponse2from django.shortcuts import render, get_object_or_4043from basket.basket import Basket4from .models import Order, OrderItem5def add(request):6 basket = Basket(request)7 if request.POST.get('action') == 'post':8 order_key = request.POST.get('order_key')9 print(order_key)10 11 user_id = request.user.id12 baskettotal = basket.get_total_price()13 # Check if order exists14 if Order.objects.filter(order_key=order_key).exists():15 pass16 else:17 order = Order.objects.create(user_id=user_id, full_name='name', address1='add1',18 address2='add2', total_paid=baskettotal, order_key=order_key)19 order_id = order.pk20 for item in basket:21 OrderItem.objects.create(order_id=order_id, product=item['product'], price=item['price'],22 quantity=item['qty'])23 24 25 return JsonResponse({'success': order_key})26def add2(request):27 if request.POST.get('action') == 'main':28 order_key = request.POST.get('order_key')29 pay_code = request.POST.get('config')30 print(order_key)31 # Check if order exists32 if Order.objects.filter(order_key=order_key).exists():33 ord = get_object_or_404(Order, order_key=order_key)34 print(ord.pyment_code)35 print(pay_code)36 if ord.pyment_code == pay_code:37 ord.billing_status = True38 ord.save()39 40 41 42 data = {43 'is_taken': Order.objects.filter(order_key=order_key, billing_status=True).exists(),44 'is_nottaken': Order.objects.filter(order_key=order_key, billing_status=False).exists(),45 }46 return JsonResponse(data)47def payment_confirmation(data):48 Order.objects.filter(order_key=data).update(billing_status=True)49def user_orders(request):50 user_id = request.user.id51 orders = Order.objects.filter(user_id=user_id).filter(billing_status=True)...
Check out the latest blogs from LambdaTest on this topic:
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
When you hear the term Cross Browser Testing what comes immediately to your mind? Something that decodes the literal meaning i.e. testing for cross-browsers or you can say testing an application across various browsers.
Nowadays, many organizations have software products (websites or apps) that are built for a global audience. One of the trickiest parts is delivering an experience that appeals to the local audience of the target market. Catering to the needs of the local users would require localization. You would have come across internationalization and localization testing when designing for the ‘global and local’ market. There is a difference between internationalization and localization testing since the tests are developed from a different market point of view.
Just earlier this month, Apple officially announced the release of a new range of iPhone flagship models for 2018. The new models named iPhone XS, iPhone XS Max, and iPhone XR comes equipped with a lot of new features, trademark notch, and new headaches for developers. To help developers out, today we brought these new devices on LambdaTest’s cross-browser compatibility testing platform, along with the latest iOS 12 version. In addition, we also bring Mozilla Firefox browsers on the latest Android and iOS devices.
Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!