def create_blackout(): try: blackout = Blackout.parse(request.json) except Exception as e: raise ApiError(str(e), 400) if Scope.admin in g.scopes or Scope.admin_blackouts in g.scopes: blackout.user = blackout.user or g.login else: blackout.user = g.login blackout.customer = assign_customer(wanted=blackout.customer, permission=Scope.admin_blackouts) try: blackout = blackout.create() except Exception as e: raise ApiError(str(e), 500) write_audit_trail.send(current_app._get_current_object(), event='blackout-created', message='', user=g.login, customers=g.customers, scopes=g.scopes, resource_id=blackout.id, type='blackout', request=request) if blackout: return jsonify(status='ok', id=blackout.id, blackout=blackout.serialize), 201, {'Location': absolute_url('/blackout/' + blackout.id)} else: raise ApiError('insert blackout failed', 500)
def create_blackout(): try: blackout = Blackout.parse(request.json) except Exception as e: raise ApiError(str(e), 400) if 'admin' in g.scopes or 'admin:blackouts' in g.scopes: blackout.user = blackout.user or g.user else: blackout.user = g.user blackout.customer = assign_customer(wanted=blackout.customer, permission='admin:blackouts') try: blackout = blackout.create() except Exception as e: raise ApiError(str(e), 500) if blackout: return jsonify(status="ok", id=blackout.id, blackout=blackout.serialize), 201, { 'Location': absolute_url('/blackout/' + blackout.id) } else: raise ApiError("insert blackout failed", 500)
def create_blackout(): try: blackout = Blackout.parse(request.json) except Exception as e: raise ApiError(str(e), 400) if g.get('customer', None): blackout.customer = g.get('customer') try: blackout = blackout.create() except Exception as e: raise ApiError(str(e), 500) if blackout: return jsonify(status="ok", id=blackout.id, blackout=blackout.serialize), 201, {'Location': absolute_url('/blackout/' + blackout.id)} else: raise ApiError("insert blackout failed", 500)
def create_blackout(): try: blackout = Blackout.parse(request.json) except Exception as e: raise ApiError(str(e), 400) if g.get('customer', None): blackout.customer = g.get('customer') try: blackout = blackout.create() except Exception as e: raise ApiError(str(e), 500) if blackout: return jsonify(status="ok", id=blackout.id, blackout=blackout.serialize), 201, { 'Location': absolute_url('/blackout/' + blackout.id) } else: raise ApiError("insert blackout failed", 500)