Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def build_display_name(resource):
- display_name = resource['ui__display_name']
- return display_name if display_name else display_name_from_resource_name(resource['name'])
- def build_base_item(resource):
- return {
- 'name': resource['name'],
- 'type': resource['unit__title'],
- 'display_name': build_display_name(resource),
- 'description': resource['description__value'],
- }
- def compose_item(resource, item):
- final_item = build_base_item(resource)
- final_item['limit'] = item
- return final_item
- def compose_renewal_item(resource, item):
- limit, from_date, till_date, delta, rn_period = item
- final_item = build_base_item(resource)
- final_item.update({
- 'limit': limit,
- 'from': from_date,
- 'till': till_date,
- 'delta': delta,
- 'renewal_period': rn_period,
- })
- return final_item
- def perform_limits_composition(connector, item_dict, composer):
- sorted_resources = connector.resources.filter(
- name__in=item_dict.keys()
- ).values(
- 'name', 'unit__title', 'ui__display_name', 'description__value',
- ).order_by(
- 'created',
- )
- return [composer(res, item_dict[res['name']]) for res in sorted_resources]
- def compose_limits(connector, item_dict):
- return perform_limits_composition(connector, item_dict, compose_item)
- def compose_renewed_limits(connector, rn_item_dict):
- return perform_limits_composition(connector, rn_item_dict, compose_renewal_item)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement