Skip to content

Commit

Permalink
Revert "(PC-33669)[BO] feat: add top acteur tag to offers"
Browse files Browse the repository at this point in the history
This reverts commit d03fef7.
  • Loading branch information
vroullier-pass committed Jan 6, 2025
1 parent 58d6aa3 commit 331ea01
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,53 +42,37 @@
def _get_collective_offer_templates(
form: collective_offer_forms.GetCollectiveOfferTemplatesListForm,
) -> list[educational_models.CollectiveOfferTemplate]:
base_query = (
educational_models.CollectiveOfferTemplate.query.join(offerers_models.Venue)
.join(offerers_models.Offerer)
.outerjoin(offerers_models.OffererTagMapping)
.outerjoin(
offerers_models.OffererTag,
sa.and_(
offerers_models.OffererTag.id == offerers_models.OffererTagMapping.tagId,
offerers_models.OffererTag.name == "top-acteur",
),
base_query = educational_models.CollectiveOfferTemplate.query.options(
sa.orm.load_only(
educational_models.CollectiveOfferTemplate.id,
educational_models.CollectiveOfferTemplate.name,
educational_models.CollectiveOfferTemplate.formats,
educational_models.CollectiveOfferTemplate.dateCreated,
educational_models.CollectiveOfferTemplate.validation,
educational_models.CollectiveOfferTemplate.authorId,
educational_models.CollectiveOfferTemplate.rejectionReason,
),
sa.orm.joinedload(educational_models.CollectiveOfferTemplate.venue).load_only(
offerers_models.Venue.managingOffererId, offerers_models.Venue.name, offerers_models.Venue.publicName
)
.options(
sa.orm.load_only(
educational_models.CollectiveOfferTemplate.id,
educational_models.CollectiveOfferTemplate.name,
educational_models.CollectiveOfferTemplate.formats,
educational_models.CollectiveOfferTemplate.dateCreated,
educational_models.CollectiveOfferTemplate.validation,
educational_models.CollectiveOfferTemplate.authorId,
educational_models.CollectiveOfferTemplate.rejectionReason,
),
sa.orm.contains_eager(educational_models.CollectiveOfferTemplate.venue).load_only(
offerers_models.Venue.managingOffererId, offerers_models.Venue.name, offerers_models.Venue.publicName
)
# needed to check if stock is bookable and compute initial/remaining stock:
.contains_eager(offerers_models.Venue.managingOfferer)
.load_only(
offerers_models.Offerer.name, offerers_models.Offerer.isActive, offerers_models.Offerer.validationStatus
)
.options(
sa.orm.contains_eager(offerers_models.Offerer.tags),
sa.orm.joinedload(offerers_models.Offerer.confidenceRule).load_only(
offerers_models.OffererConfidenceRule.confidenceLevel
),
),
sa.orm.contains_eager(educational_models.CollectiveOfferTemplate.venue)
.joinedload(offerers_models.Venue.confidenceRule)
.load_only(offerers_models.OffererConfidenceRule.confidenceLevel),
sa.orm.joinedload(educational_models.CollectiveOfferTemplate.flaggingValidationRules).load_only(
offers_models.OfferValidationRule.name
),
sa.orm.joinedload(educational_models.CollectiveOfferTemplate.author).load_only(
users_models.User.id,
users_models.User.firstName,
users_models.User.lastName,
),
# needed to check if stock is bookable and compute initial/remaining stock:
.joinedload(offerers_models.Venue.managingOfferer)
.load_only(
offerers_models.Offerer.name, offerers_models.Offerer.isActive, offerers_models.Offerer.validationStatus
)
.joinedload(offerers_models.Offerer.confidenceRule)
.load_only(offerers_models.OffererConfidenceRule.confidenceLevel),
sa.orm.joinedload(educational_models.CollectiveOfferTemplate.venue)
.joinedload(offerers_models.Venue.confidenceRule)
.load_only(offerers_models.OffererConfidenceRule.confidenceLevel),
sa.orm.joinedload(educational_models.CollectiveOfferTemplate.flaggingValidationRules).load_only(
offers_models.OfferValidationRule.name
),
sa.orm.joinedload(educational_models.CollectiveOfferTemplate.author).load_only(
users_models.User.id,
users_models.User.firstName,
users_models.User.lastName,
),
)
if form.from_date.data:
from_datetime = date_utils.date_to_localized_datetime(form.from_date.data, datetime.datetime.min.time())
Expand All @@ -109,13 +93,19 @@ def _get_collective_offer_templates(
base_query = base_query.filter(educational_models.CollectiveOfferTemplate.venueId.in_(form.venue.data))

if form.offerer.data:
base_query = base_query.filter(offerers_models.Venue.managingOffererId.in_(form.offerer.data))
base_query = base_query.join(educational_models.CollectiveOfferTemplate.venue).filter(
offerers_models.Venue.managingOffererId.in_(form.offerer.data)
)

if form.status.data:
base_query = base_query.filter(educational_models.CollectiveOfferTemplate.validation.in_(form.status.data)) # type: ignore[attr-defined]

if form.only_validated_offerers.data:
base_query = base_query.filter(offerers_models.Offerer.isValidated)
base_query = (
base_query.join(educational_models.CollectiveOfferTemplate.venue)
.join(offerers_models.Venue.managingOfferer)
.filter(offerers_models.Offerer.isValidated)
)

if form.q.data:
search_query = form.q.data
Expand Down Expand Up @@ -423,32 +413,16 @@ def batch_reject_collective_offer_templates() -> utils.BackofficeResponse:
@list_collective_offer_templates_blueprint.route("/<int:collective_offer_template_id>/details", methods=["GET"])
@atomic()
def get_collective_offer_template_details(collective_offer_template_id: int) -> utils.BackofficeResponse:
collective_offer_template_query = (
educational_models.CollectiveOfferTemplate.query.filter(
educational_models.CollectiveOfferTemplate.id == collective_offer_template_id
)
.join(offerers_models.Venue)
.join(offerers_models.Offerer)
.outerjoin(offerers_models.OffererTagMapping)
.outerjoin(
offerers_models.OffererTag,
sa.and_(
offerers_models.OffererTag.id == offerers_models.OffererTagMapping.tagId,
offerers_models.OffererTag.name == "top-acteur",
collective_offer_template_query = educational_models.CollectiveOfferTemplate.query.filter(
educational_models.CollectiveOfferTemplate.id == collective_offer_template_id
).options(
sa.orm.joinedload(educational_models.CollectiveOfferTemplate.venue).options(
sa.orm.joinedload(offerers_models.Venue.confidenceRule).load_only(
offerers_models.OffererConfidenceRule.confidenceLevel
),
)
.options(
sa.orm.contains_eager(educational_models.CollectiveOfferTemplate.venue).options(
sa.orm.joinedload(offerers_models.Venue.confidenceRule).load_only(
offerers_models.OffererConfidenceRule.confidenceLevel
),
sa.orm.contains_eager(offerers_models.Venue.managingOfferer).options(
sa.orm.contains_eager(offerers_models.Offerer.tags),
sa.orm.joinedload(offerers_models.Offerer.confidenceRule).load_only(
offerers_models.OffererConfidenceRule.confidenceLevel
),
),
)
sa.orm.joinedload(offerers_models.Venue.managingOfferer)
.joinedload(offerers_models.Offerer.confidenceRule)
.load_only(offerers_models.OffererConfidenceRule.confidenceLevel),
)
)
collective_offer_template = collective_offer_template_query.one_or_none()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,6 @@ def _get_collective_offers(
rules_subquery.label("rules"),
)
.filter(educational_models.CollectiveOffer.id.in_(_get_collective_offer_ids_query(form).subquery()))
.join(offerers_models.Venue)
.join(offerers_models.Offerer)
.outerjoin(offerers_models.OffererTagMapping)
.outerjoin(
offerers_models.OffererTag,
sa.and_(
offerers_models.OffererTag.id == offerers_models.OffererTagMapping.tagId,
offerers_models.OffererTag.name == "top-acteur",
),
)
.options(
sa.orm.load_only(
educational_models.CollectiveOffer.id,
Expand All @@ -207,24 +197,20 @@ def _get_collective_offers(
educational_models.CollectiveStock.endDatetime,
educational_models.CollectiveStock.price,
),
sa.orm.contains_eager(educational_models.CollectiveOffer.venue).load_only(
sa.orm.joinedload(educational_models.CollectiveOffer.venue, innerjoin=True).load_only(
offerers_models.Venue.managingOffererId,
offerers_models.Venue.name,
offerers_models.Venue.publicName,
offerers_models.Venue.departementCode,
)
# needed to check if stock is bookable and compute initial/remaining stock:
.contains_eager(offerers_models.Venue.managingOfferer)
.joinedload(offerers_models.Venue.managingOfferer, innerjoin=True)
.load_only(
offerers_models.Offerer.name, offerers_models.Offerer.isActive, offerers_models.Offerer.validationStatus
)
.options(
sa.orm.contains_eager(offerers_models.Offerer.tags),
sa.orm.joinedload(offerers_models.Offerer.confidenceRule).load_only(
offerers_models.OffererConfidenceRule.confidenceLevel
),
),
sa.orm.contains_eager(educational_models.CollectiveOffer.venue)
.joinedload(offerers_models.Offerer.confidenceRule)
.load_only(offerers_models.OffererConfidenceRule.confidenceLevel),
sa.orm.joinedload(educational_models.CollectiveOffer.venue, innerjoin=True)
.joinedload(offerers_models.Venue.confidenceRule)
.load_only(offerers_models.OffererConfidenceRule.confidenceLevel),
sa.orm.joinedload(educational_models.CollectiveOffer.institution).load_only(
Expand Down Expand Up @@ -541,48 +527,34 @@ def _is_collective_offer_price_editable(collective_offer: educational_models.Col
@blueprint.route("/<int:collective_offer_id>/details", methods=["GET"])
@atomic()
def get_collective_offer_details(collective_offer_id: int) -> utils.BackofficeResponse:
collective_offer_query = (
educational_models.CollectiveOffer.query.filter(educational_models.CollectiveOffer.id == collective_offer_id)
.join(offerers_models.Venue)
.join(offerers_models.Offerer)
.outerjoin(offerers_models.OffererTagMapping)
.outerjoin(
offerers_models.OffererTag,
sa.and_(
offerers_models.OffererTag.id == offerers_models.OffererTagMapping.tagId,
offerers_models.OffererTag.name == "top-acteur",
),
)
.options(
sa.orm.joinedload(educational_models.CollectiveOffer.collectiveStock),
sa.orm.joinedload(educational_models.CollectiveOffer.collectiveStock).joinedload(
educational_models.CollectiveStock.collectiveBookings
),
sa.orm.contains_eager(educational_models.CollectiveOffer.venue).options(
sa.orm.joinedload(offerers_models.Venue.confidenceRule).load_only(
offerers_models.OffererConfidenceRule.confidenceLevel
),
sa.orm.contains_eager(offerers_models.Venue.managingOfferer).options(
sa.orm.contains_eager(offerers_models.Offerer.tags),
sa.orm.joinedload(offerers_models.Offerer.confidenceRule).load_only(
offerers_models.OffererConfidenceRule.confidenceLevel
),
),
),
sa.orm.joinedload(educational_models.CollectiveOffer.lastValidationAuthor).load_only(
users_models.User.firstName, users_models.User.lastName
),
sa.orm.joinedload(educational_models.CollectiveOffer.teacher).load_only(
educational_models.EducationalRedactor.firstName,
educational_models.EducationalRedactor.lastName,
),
sa.orm.joinedload(educational_models.CollectiveOffer.institution).load_only(
educational_models.EducationalInstitution.name
),
sa.orm.joinedload(educational_models.CollectiveOffer.template).load_only(
educational_models.CollectiveOfferTemplate.name,
collective_offer_query = educational_models.CollectiveOffer.query.filter(
educational_models.CollectiveOffer.id == collective_offer_id
).options(
sa.orm.joinedload(educational_models.CollectiveOffer.collectiveStock),
sa.orm.joinedload(educational_models.CollectiveOffer.collectiveStock).joinedload(
educational_models.CollectiveStock.collectiveBookings
),
sa.orm.joinedload(educational_models.CollectiveOffer.venue).options(
sa.orm.joinedload(offerers_models.Venue.confidenceRule).load_only(
offerers_models.OffererConfidenceRule.confidenceLevel
),
)
sa.orm.joinedload(offerers_models.Venue.managingOfferer)
.joinedload(offerers_models.Offerer.confidenceRule)
.load_only(offerers_models.OffererConfidenceRule.confidenceLevel),
),
sa.orm.joinedload(educational_models.CollectiveOffer.lastValidationAuthor).load_only(
users_models.User.firstName, users_models.User.lastName
),
sa.orm.joinedload(educational_models.CollectiveOffer.teacher).load_only(
educational_models.EducationalRedactor.firstName,
educational_models.EducationalRedactor.lastName,
),
sa.orm.joinedload(educational_models.CollectiveOffer.institution).load_only(
educational_models.EducationalInstitution.name
),
sa.orm.joinedload(educational_models.CollectiveOffer.template).load_only(
educational_models.CollectiveOfferTemplate.name,
),
)
collective_offer = collective_offer_query.one_or_none()
if not collective_offer:
Expand Down
Loading

0 comments on commit 331ea01

Please sign in to comment.