def __init__(self, *args, issues: List[Issue]=[], **kwargs): QtWidgets.QTableView.__init__(self, *args, **kwargs) self.__issues: List[Issue] = issues self.__offer: Offer = Offer() self.__update_widgets: bool = True self.setItemDelegateForRow(0, ChooseItemDelegate(self, issues=issues)) self.update_offer()
def update_offer(self): self.__offer = Offer() for issue in self.issues: if len(issue.options) == 0: self.offer.add_option(Option("")) else: self.offer.add_option(issue.options[0]) self.offer.calculate_rating()
def create_offer(): if request.method == "POST": params = request.json latitude = request.json["latitude"] longitude = request.json["longitude"] user_id = request.json["user_id"] text = request.json["text"] new_offer = Offer(latitude=latitude, longitude=longitude, text=text, created_at=arrow.utcnow(), user_id=user_id) g.db.add(new_offer) g.db.flush() g.socketio.emit("offer", new_offer.serialize(), namespace="/update") return resource_created(new_offer) else: return invalid_method()
def create_offers(self, issue_index: int, option_index: int, offer: Offer): current_offer = offer.__copy__() current_offer.add_option(self.issues[issue_index].options[option_index]) if issue_index == len(self.issues) - 1: if option_index == len(self.issues[issue_index].options) - 1: return [current_offer] offers = self.create_offers(issue_index, option_index + 1, offer) offers.append(current_offer) return offers offers = self.create_offers(issue_index + 1, 0, current_offer) if option_index < len(self.issues[issue_index].options) - 1: offers.extend(self.create_offers(issue_index, option_index + 1, offer)) return offers
def update_offers(self): self.offers.clear() issues_valid: bool = len(self.issues) > 0 for issue in self.issues: if len(issue.options) == 0: issues_valid = False if not issues_valid: return if len(self.issues) > 0: self.__offers = self.create_offers(0, 0, Offer()) for offer in self.offers: offer.calculate_rating() self.offers.sort(key=lambda _offer: _offer.rating, reverse=True)
def load_offers(): """Load posts from offers.txt into database.""" print("Offers") for row in open("seed_data/offers.txt"): row = row.rstrip() restaurant_id, item = row.split("|") offer = Offer(restaurant_id=restaurant_id, item=item) db.session.add(offer) db.session.commit()
def add_offer(restaurant_id): """Add a new offer.""" if not check_authorization(restaurant_id): return render_template("unauthorized.html") restaurant = Restaurant.query.get(restaurant_id) item = request.form.get("item") new_offer = Offer(restaurant_id=restaurant_id, item=item) db.session.add(new_offer) db.session.commit() return redirect(f"/restaurant-dashboard/{restaurant_id}")
def virtual_creation(): with dm.session_scope() as db: stores = [] for i in range(STORES_NUM): store = Store(name="Tienda {}".format(i), latitude=0.0, longitude=0.0) offers = [] for j in range(PRODUCTS_PER_STORE): pr = Product( store=store, name="Product {},{}".format(i, j), img_url= "http://www.lavozlibre.com/userfiles/2a_decada/image/FOTOS%202013/04%20ABRIL%202013/02%20ABRIL%202013/yogures.jpg", price="3€") offers.append(Offer(product=pr, offer_price="2€", store=store)) store.products.append(pr) db.add_all(offers) stores.append(store) db.add_all(stores)
def create_update_offer(): content = request.get_json() offer_id = content['offer_id'] offerer_uid = content['offerer_user_id'] expiration_date = content['expiration_date'] recurring = content['recurring'] description = content['description'] category_names = content['categories'] offer_args = { 'offerer_uid': offerer_uid, 'created_on': datetime.today(), 'modified_on': datetime.today(), 'recurring': recurring, 'description': description, 'active': True } if offer_id: offer_args['offer_id'] = offer_id if expiration_date: offer_args['expiration_date'] = expiration_date offer = Offer(**offer_args) for category_name in category_names: offer_category = Category.query.filter_by(name=category_name).first() offer.categories.append(offer_category) db.session.add(offer) db.session.commit() resp = make_response( jsonify({ 'success': True, 'offer': offer.to_dict_for_json }), 200) return resp
def load_requests_offers(num_of_users, num_requests): """ Function to load requests into the DB: arbitrary first half are requesters, second half are volunteers""" print(f"num of users {num_of_users}") requesters = round(num_of_users / 2) volunteers = num_of_users - requesters print("**** CREATING REQUESTS ****") print(f"Requesters = {requesters}") print(f"Volunteers = {volunteers}") boolean_choice = [True, False] i = 0 requester_id = 0 volunteer_id = num_of_users # volunteer_index = num_of_users # print(f"volunteer index {volunteer_index}") for i in range(requesters): requester_id = requester_id + 1 volunteer_id = volunteer_id - 1 print(f"Requester: {requester_id} Volunteer: {volunteer_id}") notes = faker.text() print(f"Notes: {notes}") fulfilled = random.choice(boolean_choice) print(f"fulfilled = {fulfilled}") created_on = faker.date() print(f"created_on: {created_on}") modified_on = created_on #service is being requested by the requester - which because # of the way we are seeding the database - the requester's address id # is the same as their id. service_needed_at = requester_id request = Request(requester_user_id=requester_id, volunteer_user_id=volunteer_id, notes=notes, fulfilled=fulfilled, created_on=created_on, modified_on=modified_on, service_needed_at=service_needed_at) print(request) i += 1 # volunteer_index -+ 1 # Add the request instance to the session so it will be stored. db.session.add(request) # Once we're done inserting all the users, commit the changes to the # database db.session.commit() print("**** CREATING VOLUNTEER OFFERS***") j = requesters print("######## j = ", j) offerer_uid = requesters for j in range(num_of_users): print("######## j = ", j) # create a volunteer offer for each of the second half of the users # created with load_users(amount_to_generate) if offerer_uid != num_of_users: offerer_uid = offerer_uid + 1 expiration_date = faker.date_this_month() print(f"expiration_date: {expiration_date}") create_on = faker.date_between() print(f"create_on: {created_on} ") modified_on = create_on recurring = random.choice(boolean_choice) print(f"recurring: {recurring}") description = faker.text() print(f"description: {description}") offer = Offer(offerer_uid=offerer_uid, expiration_date=expiration_date, created_on=created_on, modified_on=modified_on, recurring=recurring, description=description) j += 1 # Add the offer instance to the session so it will be stored. db.session.add(offer) # Once we're done inserting all the offers, commit the changes to the # database db.session.commit()
def _row_to_offer(row): if row: return Offer(row[0], row[1], row[2], row[3], (row[4], row[5]))
def more_real_creation(): with dm.session_scope() as db: stores = [ Store(name="DIA", latitude=41.6342682, longitude=-4.7174426), Store(name="Lupa", latitude=41.6364703, longitude=-4.7300158), Store(name="Sushitería Valladolid", latitude=41.652698, longitude=-4.7317036), Store(name="La tienda del alérgico", latitude=41.6547928, longitude=-4.7303049), Store(name="Pantaleón Muñoz", latitude=41.6530984, longitude=-4.7325059), ] products_dia_img = { 'Pizza Jamón Queso': 'https://s1.dia.es/medias/hc7/h5a/8830828478494.png', 'Yogur Griego': 'https://s2.dia.es/medias/hd5/ha3/8821838413854.png', 'Menestra de verduras': 'https://s0.dia.es/medias/h76/h6e/8822061498398.png', 'Brocoli, Coliflor y Zanahoria': 'https://s2.dia.es/medias/h56/haf/8823785324574.png', 'Zumo de frutas': 'https://s1.dia.es/medias/h00/h56/8823862919198.png', 'Muesli': 'https://s2.dia.es/medias/h91/hda/8823751376926.png', 'Frutas reglero': 'https://s2.dia.es/medias/h79/ha3/8846882668574.png', 'Huevos': 'https://s3.dia.es/medias/h8e/ha8/8822320496670.png', 'Merluza del cabo': 'https://s1.dia.es/medias/hc6/ha4/8823008755742.png', 'Filetes de panga empanados': 'https://s1.dia.es/medias/h01/hc0/8823923867678.png', 'Rodaja de Merluza': 'https://s0.dia.es/medias/hc1/hc0/8833209761822.png', 'Empanada de atún': 'https://stag-s2.dia.es/medias/h43/hc6/8823204511774.png', 'Pimientos de piquillo': 'https://s0.dia.es/medias/hef/hbe/8822377250846.png', 'Callos con garbanzos': 'https://s0.dia.es/medias/h92/he6/8823167680542.png', 'Paté senior': 'https://s0.dia.es/medias/hde/h66/8828547629086.png', 'Albóndigas Allinut de carne': 'https://s2.dia.es/medias/h3c/h63/8864079642654.jpg', 'Chuletas de cordero (bolsa)': 'https://s3.dia.es/medias/h28/h2b/8846911569950.png', 'Mozarella fresca': 'https://s-media-cache-ak0.pinimg.com/236x/78/9f/1d/789f1d665b51885f478de2990cbe2dd9.jpg', 'Mantequilla Light': 'https://stag-s0.dia.es/medias/ha5/h7e/8830444404766.png', 'Habas baby': 'https://s0.dia.es/medias/h5e/h6f/8823714021406.png', 'Plátano maduro': 'http://cdn0.hoy.com.do/wp-content/uploads/2014/08/PLATANO.jpg', } products_common_img = { 'Pizza muy rica': 'https://image.freepik.com/foto-gratis/muy-rica-pizza_2536312.jpg', 'Manzana': 'https://mejorconsalud.com/wp-content/uploads/2014/06/manzanas.jpg', 'Pan': 'https://www.hogarmania.com/archivos/201203/pan-beneficios-salud-668x400x80xX.jpg', 'Kiwi': 'http://www.healthline.com/hlcmsresource/images/topic_centers/Food-Nutrition/642x361_IMAGE_1_The_7_Best_Things_About_Kiwis.jpg', 'Lechuga': 'http://biotrendies.com/wp-content/uploads/2015/07/lechuga.jpg', 'Canónigos': 'http://www.esdemercado.com/images/thumbs/0002995_300.jpeg', 'Entrecot': 'http://www.recetasparainutiles.com/sites/www.recetasparainutiles.com/files/8349.jpg?1348222298', 'Chorizo': 'http://www.vegajardin.es/456-thickbox/chorizo-sarta.jpg', 'Bacalao poco fresco': 'http://www.ecestaticos.com/image/clipping/654/bac6dfb5ecb9d9938151fa81146df205/los-filetes-de-bacalao-salado-suelen-ser-mas-grandes-que-los-que-se-encuentran-frescos-istock.jpg', 'Naranjas': 'http://biotrendies.com/wp-content/uploads/2015/07/Naranja1.jpg', 'Almejas': 'https://t1.uc.ltmcdn.com/images/4/5/5/img_como_conservar_almejas_frescas_25554_600.jpg', 'Oreja': 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Orejas_de_cerdo_-_Cerca.jpg/300px-Orejas_de_cerdo_-_Cerca.jpg', 'Callos': 'http://www.paxinasgalegas.es/fiestas/imagenes/xxiv-festa-dos-callos-salceda-de-caselas_img197n3t0.jpg', 'Atún': 'https://www.ocu.org/-/media/ocu/images/home/alimentacion/alimentos/tests/comparar-atun/500x281_atun.jpg?h=-1&w=-1&la=es-ES&hash=5CEBB1E55D8D95B999CFEE1B17C460915B4A5EFE', 'Cordero': 'http://www.comycebaleares.com/galeria/menus/A_carne_cordero_red.jpg', 'Lomo de cerdo': 'http://burruezocongelados.es/imagenes/productos/301016.jpg', 'Jamón york': 'http://www.abc.es/Media/201401/24/jamon-york--478x270.jpg', 'Queso Fresco': 'http://www.gourmetsleuth.com/images/default-source/dictionary/queso-fresco.jpg?sfvrsn=6', 'Chopped': 'http://www.embutidoslaseca.com/comprar/UserFiles/Image/up/314.JPG', 'Pechuga de pavo': 'https://consejonutricion.files.wordpress.com/2012/07/pechuga_de_pavo.jpg', 'Pechuga de pollo': 'https://consejonutricion.files.wordpress.com/2012/07/pechuga_de_pavo.jpg', } products_tuples = [] for name, url in products_common_img.items(): products_tuples.append((name, url)) offers = [] for name, url in products_dia_img.items(): price = round(random.choice(range(20, 30)) / 10.0, 2) stores[0].products.append( Product(store=stores[0], name=name, img_url=url, price="{}€".format(price))) offers.append( Offer(product=stores[0].products[-1], offer_price="{}€".format(round(price - price * 0.3, 2)), store=stores[0])) for store in stores[1:]: for n in range(1, 20): pr = random.choice(products_tuples) price = round(random.choice(range(20, 30)) / 10.0, 2) store.products.append( Product(store=store, name=pr[0], img_url=pr[1], price="{}€".format(price))) offers.append( Offer(product=store.products[-1], offer_price="{}€".format( round(price - price * 0.3, 2)), store=store, when=datetime.now() - timedelta(minutes=random.choice(range(10, 20))))) db.add_all(stores) db.add_all(offers)
def getOfferList(self, token='', size=100): offer_query = Connect.getOffers(token, size) if offer_query.status_code == 200: try: offerList = offer_query.json() nextPageToken = offerList[ 'nextPageToken'] if 'nextPageToken' in offerList else None self._offerList = OfferList(nextPageToken, offerList['totalCount']) offers: List[Offer] = [] print(len(offerList['offers'])) for offer in offerList['offers']: temp_offer = Offer(offer['id']) config = offer['configuration'] temp_offer.sku = offer['sku'] temp_offer.updateTime = datetime.strptime( offer['updateTime'], '%Y-%m-%dT%H:%M:%S%z') temp_offer.availability = offer['availability'] temp_offer.dealer = offer['dealer'] temp_offer.installEquipment = offer[ 'installEquipment'] if 'installEquipment' in offer else None temp_offer.year = offer['year'] temp_offer.price = offer['price'] temp_offer.retailPrice = offer[ 'retailPrice'] if 'retailPrice' in offer else None temp_offer.configuration = OfferConfiguration(config['id']) temp_offer.configuration.make = config['make'] temp_offer.configuration.model = config['model'] temp_offer.configuration.version = config['version'] temp_offer.configuration.color = config['color'] temp_offer.configuration.edition = config['edition'] temp_offer.configuration.modification = config[ 'modification'] temp_offer.configuration.imageLink = config['imageLink'] temp_offer.promotion = OfferPromotion( offer['promotion']['special']) photoLinks = [] for link in offer['photoLinks']: photoLinks.append(link) temp_offer.photoLinks = photoLinks self._offerList.add(temp_offer) except JSONDecodeError: print('Is not JSON string, sorry')