def fill_product_attributes(self, allocine_product: Product): allocine_product.name = self.movie_information["title"] allocine_product.subcategoryId = subcategories.SEANCE_CINE.id allocine_product.thumbCount = 0 self.update_from_movie_information(allocine_product, self.movie_information) is_new_product_to_insert = allocine_product.id is None if is_new_product_to_insert: allocine_product.id = get_next_product_id_from_database() self.last_product_id = allocine_product.id
def fill_object_attributes(self, product: Product): product.name = trim_with_elipsis(self.product_infos["titre"], 140) product.datePublished = read_things_date( self.product_infos["date_parution"]) product.type = self.product_type product.extraData = self.product_extra_data.copy() product.extraData.update(get_extra_data_from_infos(self.product_infos)) if self.product_infos["url_extrait_pdf"] != "": if product.mediaUrls is None: product.mediaUrls = [] product.mediaUrls.append(self.product_infos["url_extrait_pdf"])
def _initialize_offer_with_new_data(offer_data: PostOfferBodyModel, subcategory: subcategories.Subcategory, venue: Venue) -> Offer: data = offer_data.dict(by_alias=True) product = Product() if data.get("url"): data["isNational"] = True product.populate_from_dict(data) offer = Offer() offer.populate_from_dict(data) offer.product = product offer.subcategoryId = subcategory.id if subcategory else None offer.product.owningOfferer = venue.managingOfferer return offer
def fill_object_attributes(self, product: Product): product.name = trim_with_elipsis(self.product_infos["titre"], 140) product.datePublished = read_things_date( self.product_infos["date_parution"]) subcategory = subcategories.ALL_SUBCATEGORIES_DICT[ self.product_subcategory_id] product.subcategoryId = subcategory.id product.extraData = self.product_extra_data.copy() product.extraData.update(get_extra_data_from_infos(self.product_infos)) if self.product_infos["url_extrait_pdf"] != "": if product.mediaUrls is None: product.mediaUrls = [] product.mediaUrls.append(self.product_infos["url_extrait_pdf"])
def create_offer(offer_data: PostOfferBodyModel, user: User) -> Offer: venue = load_or_raise_error(Venue, offer_data.venue_id) check_user_has_access_to_offerer(user, offerer_id=venue.managingOffererId) if offer_data.product_id: product = load_or_raise_error(Product, offer_data.product_id) offer = Offer( product=product, type=product.type, name=product.name, description=product.description, url=product.url, mediaUrls=product.mediaUrls, conditions=product.conditions, ageMin=product.ageMin, ageMax=product.ageMax, durationMinutes=product.durationMinutes, isNational=product.isNational, extraData=product.extraData, ) else: if offer_data.type == str(EventType.ACTIVATION): validation.check_user_can_create_activation_event(user) data = offer_data.dict(by_alias=True) product = Product() if data.get("url"): data["isNational"] = True product.populate_from_dict(data) offer = Offer() offer.populate_from_dict(data) offer.product = product offer.product.owningOfferer = venue.managingOfferer offer.venue = venue offer.bookingEmail = offer_data.booking_email offer.externalTicketOfficeUrl = offer_data.external_ticket_office_url offer.audioDisabilityCompliant = offer_data.audio_disability_compliant offer.mentalDisabilityCompliant = offer_data.mental_disability_compliant offer.motorDisabilityCompliant = offer_data.motor_disability_compliant offer.visualDisabilityCompliant = offer_data.visual_disability_compliant repository.save(offer) admin_emails.send_offer_creation_notification_to_administration( offer, user) return offer
def create_offer(offer_data: PostOfferBodyModel, user: User) -> models.Offer: venue = load_or_raise_error(VenueSQLEntity, offer_data.venue_id) ensure_current_user_has_rights(rights=RightsType.editor, offerer_id=venue.managingOffererId, user=user) if offer_data.product_id: product = load_or_raise_error(Product, offer_data.product_id) offer = models.Offer( product=product, type=product.type, name=product.name, description=product.description, url=product.url, mediaUrls=product.mediaUrls, conditions=product.conditions, ageMin=product.ageMin, ageMax=product.ageMax, durationMinutes=product.durationMinutes, isNational=product.isNational, extraData=product.extraData, ) else: if offer_data.type == str(EventType.ACTIVATION): validation.check_user_can_create_activation_event(user) data = offer_data.dict(by_alias=True) product = Product() if data.get("url"): data["isNational"] = True product.populate_from_dict(data) offer = Offer() offer.populate_from_dict(data) offer.product = product offer.product.owningOfferer = venue.managingOfferer offer.venue = venue offer.bookingEmail = offer_data.booking_email repository.save(offer) admin_emails.send_offer_creation_notification_to_administration(offer, user, mailing.send_raw_email) return offer
def fill_product_attributes(self, allocine_product: Product): allocine_product.name = self.movie_information["title"] allocine_product.type = str(EventType.CINEMA) allocine_product.thumbCount = 0 if "description" in self.movie_information: allocine_product.description = self.movie_information[ "description"] if "duration" in self.movie_information: allocine_product.durationMinutes = self.movie_information[ "duration"] if not allocine_product.extraData: allocine_product.extraData = {} if "visa" in self.movie_information: allocine_product.extraData["visa"] = self.movie_information["visa"] if "stageDirector" in self.movie_information: allocine_product.extraData[ "stageDirector"] = self.movie_information["stageDirector"] is_new_product_to_insert = allocine_product.id is None if is_new_product_to_insert: allocine_product.id = get_next_product_id_from_database() self.last_product_id = allocine_product.id
def create_booking_for_thing( amount: int = 50, date_created: datetime = datetime.utcnow(), is_cancelled: bool = False, quantity: int = 1, product_type: ThingType = ThingType.JEUX, url: str = None, user: User = None, ) -> Booking: product = Product(from_dict={"url": url, "type": str(product_type)}) offer = Offer(from_dict={"url": url, "type": str(product_type)}) stock = Stock() booking = Booking(from_dict={"amount": amount}) offer.product = product stock.offer = offer booking.stock = stock booking.quantity = quantity booking.user = user booking.isCancelled = is_cancelled booking.dateCreated = date_created return booking
def create_booking_for_event( # pylint: disable=redefined-builtin amount: int = 50, date_created: datetime = datetime.utcnow(), is_cancelled: bool = False, quantity: int = 1, type: EventType = EventType.CINEMA, user: User = None, ) -> Booking: product = Product(from_dict={"type": str(type)}) offer = Offer() stock = Stock() booking = Booking(from_dict={"amount": amount}) offer.product = product stock.offer = offer booking.stock = stock booking.quantity = quantity booking.user = user booking.isCancelled = is_cancelled booking.token = random_token() booking.dateCreated = date_created return booking
def test_an_event_is_always_physical_and_cannot_be_digital(): assert Product().isDigital is False
def create_product_with_thing_type( thing_name: str = "Test Book", thing_type: ThingType = ThingType.LIVRE_EDITION, author_name: str = "Test Author", is_national: bool = False, id_at_providers: str = None, is_digital: bool = False, is_gcu_compatible: bool = True, is_offline_only: bool = False, date_modified_at_last_provider: datetime = None, last_provider_id: int = None, media_urls: Iterable[str] = ("test/urls", ), description: str = None, thumb_count: int = 1, url: str = None, owning_offerer: Offerer = None, extra_data: Dict = None, ) -> Product: product = Product() product.type = str(thing_type) product.name = thing_name product.description = description if extra_data: product.extraData = extra_data else: product.extraData = {"author": author_name} product.isNational = is_national if id_at_providers is None: id_at_providers = "".join(random.choices(string.digits, k=13)) product.dateModifiedAtLastProvider = date_modified_at_last_provider product.lastProviderId = last_provider_id product.idAtProviders = id_at_providers product.isGcuCompatible = is_gcu_compatible product.mediaUrls = media_urls product.thumbCount = thumb_count product.url = url product.owningOfferer = owning_offerer product.description = description if is_digital: product.url = "fake/url" if is_offline_only: product.type = str(ThingType.CINEMA_ABO) return product
def create_product_with_event_type( event_name: str = "Test event", event_type: EventType = EventType.SPECTACLE_VIVANT, description: str = None, duration_minutes: Optional[int] = 60, id_at_providers: str = None, is_national: bool = False, is_duo: bool = False, thumb_count: int = 0, ) -> Product: product = Product() product.name = event_name product.description = description product.durationMinutes = duration_minutes product.thumbCount = thumb_count product.idAtProviders = id_at_providers product.isNational = is_national product.isDuo = is_duo product.type = str(event_type) product.description = description return product
def fill_object_attributes(self, product: Product): with self.zip_file.open(self.description_zip_info) as f: description = f.read().decode("iso-8859-1") product.description = description.replace("\x00", "")