File: //home/arjun/projects/buyercall/buyercall/blueprints/api/doc/endpoints/partnerships.py
import logging
from flask import jsonify
from flask_restx import Resource
from buyercall.lib.util_rest import rest_partnership, rest_is_partnership, requires_auth
from buyercall.blueprints.api.restx import api
log = logging.getLogger(__name__)
ns = api.namespace('partnership', description='Operations related to partnerships.')
@ns.route('/')
@api.doc(responses={
200: 'OK',
404: 'Partnership not found.',
401: 'Unauthorized request.'
})
class Details(Resource):
@requires_auth
def get(self):
"""
Retrieves partnership details.
Use this method to view the details of the partnerships.
"""
if rest_is_partnership and rest_partnership.users:
user_list = list()
account_list = list()
for part_user in rest_partnership.users:
add_user = {
'firstname': part_user.firstname,
'lastname': part_user.lastname
}
user_list.append(add_user)
if rest_partnership.partnership_accounts:
for part_account in rest_partnership.partnership_accounts:
add_account = {
'name': part_account.name,
'active_subscription': part_account.has_active_subscription
}
account_list.append(add_account)
return jsonify(
name=rest_partnership.name,
is_active=rest_partnership.active,
billing_type=rest_partnership.billing_type,
users=user_list,
accounts=account_list
)
else:
return api.abort(401)