mirror of
https://github.com/pretix/pretix.git
synced 2026-08-14 11:26:26 +00:00
Apply suggestions from code review
Co-authored-by: Raphael Michel <michel@rami.io>
This commit is contained in:
@@ -971,15 +971,15 @@ class ItemMetaPropertiesSerializer(I18nAwareModelSerializer):
|
||||
fields = ('id', 'name', 'default', 'required', 'allowed_values')
|
||||
|
||||
|
||||
def prefetch_by_id(items, manager, id_attr, id_filter, target_attr):
|
||||
def prefetch_by_id(items, qs, id_attr, id_filter, target_attr):
|
||||
"""
|
||||
Prefetches a related object on each item in the given list of items by searching by id or another
|
||||
unique field. The id value is read from the attribute on item specified in `id_attr`, searched on manager by the
|
||||
unique field. The id value is read from the attribute on item specified in `id_attr`, searched on queryset `qs` by the
|
||||
field specified in `id_filter`, and the resulting prefetched model object is stored into `target_attr` on the item.
|
||||
"""
|
||||
ids = [getattr(item, id_attr) for item in items if getattr(item, id_attr)]
|
||||
if ids:
|
||||
result = manager.order_by(id_filter).distinct(id_filter).in_bulk(id_list=ids, field_name=id_filter)
|
||||
result = qs.order_by(id_filter).distinct(id_filter).in_bulk(id_list=ids, field_name=id_filter)
|
||||
for item in items:
|
||||
setattr(item, target_attr, result.get(getattr(item, id_attr)))
|
||||
|
||||
@@ -993,12 +993,12 @@ class SeatSerializer(I18nAwareModelSerializer):
|
||||
model = Seat
|
||||
read_only_fields = (
|
||||
'id', 'subevent', 'zone_name', 'row_name', 'row_label',
|
||||
'seat_number', 'seat_label', 'seat_guid', 'product', 'sorting_rank', 'x', 'y',
|
||||
'seat_number', 'seat_label', 'seat_guid', 'product',
|
||||
'orderposition', 'cartposition', 'voucher',
|
||||
)
|
||||
fields = (
|
||||
'id', 'subevent', 'zone_name', 'row_name', 'row_label',
|
||||
'seat_number', 'seat_label', 'seat_guid', 'product', 'blocked', 'sorting_rank', 'x', 'y',
|
||||
'seat_number', 'seat_label', 'seat_guid', 'product', 'blocked',
|
||||
'orderposition', 'cartposition', 'voucher',
|
||||
)
|
||||
|
||||
|
||||
@@ -697,8 +697,6 @@ class SeatViewSet(ConditionalListView, viewsets.ModelViewSet):
|
||||
ctx['order_context'] = {
|
||||
'event': self.request.event,
|
||||
'pdf_data': None,
|
||||
'include': self.request.query_params.getlist('order_include'),
|
||||
'exclude': self.request.query_params.getlist('order_exclude'),
|
||||
}
|
||||
return ctx
|
||||
|
||||
|
||||
Reference in New Issue
Block a user