def check(first_status, second_status): print 'first_status =', first_status, 'second_status =', second_status this = Item(MyLibrary(), MyCard()) this.status = first_status other = Item(MyLibrary(), MyCard()) other.status = second_status assert cmp(this, other) < 0 assert cmp(other, this) > 0
def test__build_template__no_messges_no_holds_ready_one_item_due__sets_should_notify(status, library, card): item = Item(library, card) item.status = datetime.date(2010, 2, 2) status.items = [item] hold = Hold(library, card) hold.status = (3, 5) status.holds = [hold] family = None template_values = libraryhippo.build_template([status], family) assert template_values['should_notify']
def test__items_sort__same_date__sorted_by_name(): library = MyLibrary() c = MyCard() items = [Item(library, c), Item(library, c), Item(library, c)] items[0].status = datetime.date(2009, 9, 7) items[0].title = 'B' items[1].status = datetime.date(2009, 9, 7) items[1].title = 'A' items[2].status = datetime.date(2009, 9, 7) items[2].title = 'C' items.sort() assert ['A', 'B', 'C'] == [i.title for i in items]
def test__build_template__no_messges_no_holds_ready_one_item_due__sets_should_notify( status, library, card): item = Item(library, card) item.status = datetime.date(2010, 2, 2) status.items = [item] hold = Hold(library, card) hold.status = (3, 5) status.holds = [hold] family = None template_values = libraryhippo.build_template([status], family) assert template_values['should_notify']
def mod_item(request): list_name = request.form['list'] item_name = request.form['item'] action = request.form['action'] if action == "add": list = List.get(List.name == list_name) item = Item.get_or_create(name=item_name, list=list) flash = "Added item" if action == "del": list = List.get(List.name == list_name) item = Item.get(Item.name == item_name, Item.list == list) item.delete_instance() flash = "Deleted item" return build_index(flash)
def test__build_template__one_messge_no_holds_ready_no_items_due__sets_should_notify(status, library, card): item = Item(library, card) item.status = datetime.date(2010, 2, 10) status.items = [item] hold = Hold(library, card) hold.status = (3, 5) status.holds = [hold] status.info = [CardInfo(status.library_name, status.patron_name, 'blah')] family = None template_values = libraryhippo.build_template([status], family) assert template_values['should_notify']
def select_one(conn, item_name, table_name): table = conn.load_table(table_name) result = table.find_one(name=item_name) # type: OrderedDict if result is None: raise ItemNotStoredError(f'can\'t read "{item_name}" becase it\'s not' f' stored in table "{table_name}"') return Item(**result)
def select_all(conn, table_name): sql = ''' SELECT * FROM {} '''.format(table_name) cursor = conn.execute(sql) results = cursor.fetchall() return [Item(*result[1:]) for result in results]
def mod_list(request): list_name = request.form['list'] action = request.form['action'] if action == "add": list = List.get_or_create(name=list_name) flash = "List added" if action == "delete": if 'confirm' in request.form and request.form['confirm'] == 'true': list = List.get(List.name == list_name) list.delete_instance() flash = "List deleted" else: return render_template('confirm.html', action=action, list=list_name) if action == "clear": if 'confirm' in request.form and request.form['confirm'] == 'true': list = List.get(List.name == list_name) query = Item.delete().where(Item.list == list).execute() flash = "List cleared" else: return render_template('confirm.html', action=action, list=list_name) if action == "print": list = List.get(List.name == list_name) print_list(list) flash = "Printed list" if action == "cancel": flash = "Cancelled" return build_index(flash)
def test__build_template__one_messge_no_holds_ready_no_items_due__sets_should_notify( status, library, card): item = Item(library, card) item.status = datetime.date(2010, 2, 10) status.items = [item] hold = Hold(library, card) hold.status = (3, 5) status.holds = [hold] status.info = [CardInfo(status.library_name, status.patron_name, 'blah')] family = None template_values = libraryhippo.build_template([status], family) assert template_values['should_notify']
def create_item(request: CreateItemRequest): item_id = next(item_id_generator) items[item_id] = Item( id=item_id, name=request.name, ) return CreateItemResponse(id=item_id, name=request.name)
def client_code(model_type): """When using MVC pattern, things work the same.""" cont = Controller( model_type([ Item('bread', 0.5, 20), Item('milk', 1.0, 10), Item('wine', 10.0, 5), ]), View()) cont.show_items() cont.show_items(bullet_point=True) cont.show_item('bread') cont.show_item('chocolate') cont.insert_item(Item('chocolate', 2.0, 10)) cont.insert_item(Item('bread', 1.0, 5)) cont.update_item(Item('milk', 1.2, 20)) cont.update_item(Item('ice cream', 3.5, 20)) cont.delete_item('bread') cont.delete_item('fish') cont.show_items()
def select_one(conn, item_name, table_name): sql = ''' SELECT * FROM {} WHERE name=? '''.format(table_name) cursor = conn.execute(sql, (item_name, )) result = cursor.fetchone() if result is None: raise ItemNotStoredError(f'can\'t read "{item_name}" becase it\'s not' f' stored in table "{table_name}"') return Item(*result[1:]) # exclude row id
def generate_item_list(amount=100, max_size=1000, max_value=100, savefile=False): packing_list = [] for _ in range(amount): item_packed = Item(random.randint(1, max_size), random.randint(1, max_value)) packing_list.append(item_packed) if savefile: save_to_file(packing_list, file=savefile) return packing_list
def clone(self): new_state = State() new_state.current_location = self.current_location new_state.items = [] for item in self.items: new_state.items.append(Item(item.desc, item.location)) new_state.bitflags = copy(self.bitflags) return new_state
def parse_checkouts(self, checkouts_soup): checkouts = [] checkouts_rows = checkouts_soup.findAll('tr', {'class': 'checkoutsLine'}) for row in checkouts_rows: title = row('td')[2].find('a').string author = row('td')[2].find('p').find(text=True).strip() due_date = datetime.datetime.strptime(row('td')[4].string, '%m/%d/%y').date() logging.debug('%s / %s / %s', title, author, due_date) checkout = Item(self.library, self.card) checkout.title = title checkout.author = author checkout.status = due_date checkouts.append(checkout) return checkouts
def parse_items(self, items): table_header = items.find('tr', attrs={'class': 'patFuncHeaders'}) if not table_header: return [] headers = [th.string.strip() for th in table_header('th')] entries = [] for row in table_header.findNextSiblings('tr'): entry = Item(self.library, self.card) i = 0 for cell in row('td'): column_name = headers[i] if column_name == 'TITLE': self.parse_title(cell, entry) elif column_name == 'STATUS': status = parse_status(cell) entry.status = status[0] entry.add_status_note((' '.join(status[1:])).strip()) i += 1 entries.append(entry) return entries
def parse_checkouts(self, checkouts_soup): checkouts = [] checkouts_rows = checkouts_soup.findAll('tr', {'class': 'checkoutsLine'}) for row in checkouts_rows: title = row('td')[2].find('a').string author = row('td')[2].find('p').find(text=True).strip() due_date = datetime.datetime.strptime( row('td')[4].string, '%m/%d/%y').date() logging.debug('%s / %s / %s', title, author, due_date) checkout = Item(self.library, self.card) checkout.title = title checkout.author = author checkout.status = due_date checkouts.append(checkout) return checkouts
def parse_items(self, items): table_header = items.find("tr", attrs={"class": "patFuncHeaders"}) if not table_header: return [] headers = [th.string.strip() for th in table_header("th")] entries = [] for row in table_header.findNextSiblings("tr"): entry = Item(self.library, self.card) i = 0 for cell in row.findAll(td_or_th_regex): column_name = headers[i] if column_name == "TITLE": self.parse_title(cell, entry) elif column_name == "STATUS": status = parse_status(cell) entry.status = status[0] entry.add_status_note((" ".join(status[1:])).strip()) i += 1 entries.append(entry) return entries
def test__cmp__equal_statuses__compare_same(first_status, second_status): this = Item(MyLibrary(), MyCard()) this.status = first_status other = Item(MyLibrary(), MyCard()) other.status = second_status assert 0 == cmp(this, other) assert 0 == cmp(other, this)
def generate_pareto_list(amount=100, medium_value=50, medium_size=300, max_size=1000, max_value=100, verbose=False, savefile=False): packing_list = [] percent20, percent80 = int((amount / 100) * 20), int((amount / 100) * 80) for _ in range(percent80): item_packed = Item(random.randint(1, medium_size), random.randint(1, medium_value)) packing_list.append(item_packed) for _ in range(percent20): item_packed = Item(random.randint(medium_size, max_size), random.randint(medium_value, max_value)) packing_list.append(item_packed) if verbose: for i in packing_list: print(str(i.value), str(i.size)) if savefile: save_to_file(packing_list, file=savefile) return packing_list
def test__cmp__inequal_statuses__correctly_ordered(first_status, second_status): this = Item(MyLibrary(), MyCard()) this.status = first_status other = Item(MyLibrary(), MyCard()) other.status = second_status assert cmp(this, other) < 0 assert cmp(other, this) > 0
def create(): if request.method == "POST": title = request.form['title'] price = request.form['price'] db_ses = db_session.create_session() item = Item.Item(title=title, price=price) try: db_ses.add(item) db_ses.commit() return redirect('/') except: return "Получилась ошибка" else: return render_template('create.html')
def __init__(self, data): super(StateFromDatabase, self).__init__() self.current_location = data.current_location self.items = [Item('', int(x)) for x in data.items.split(',')] self.bitflags = self.deserialise_bitflags(data.bitflags)
def select_all(conn, table_name): table = conn.load_table(table_name) results = table.all() return [Item(**result) for result in results]