def data_account_summary(account_id): account = Account.find_account_by_id(account_id) if account is None: abort(404) badges = badge_management.badges_for_account(account.id) open_door_event = event_management.last_door_open(account) # Add to response from .badge_blueprint import badge_to_json summary = { "account": account_to_json(account), "badges": [badge_to_json(b) for b in badges], "lastDoorOpen": open_door_event.to_dict() if open_door_event else None, } # Add information about membership if current user is in a circle admin_circle = Circle.get_by_name('insight-fee') if account_management.is_account_in_circle( flask_login.current_user.account, admin_circle): membership = get_membership(account) membership_details = {} if membership is not None: membership_details['fee'] = membership.fee membership_details[ 'first_membership'] = membership.first_membership membership_details[ 'start_membership'] = membership.start_membership else: membership_details['fee'] = 0 summary['membership'] = membership_details return jsonify(summary)
def open_doors(self, account: Account, doors: List[Door]): door_circle = Circle.get_by_name('door') if not account_management.is_account_in_circle(account, door_circle): raise P2k16UserException('{} is not in the door circle'.format( account.display_name())) publishes = [] if not event_management.has_opened_door(account): system = Account.find_account_by_username("system") logger.info("First door opening for {}".format(account)) badge_management.create_badge(account, system, "first-door-opening") for door in doors: logger.info( 'Opening door. username={}, door={}, open_time={}'.format( account.username, door.key, door.open_time)) event_management.save_event(OpenDoorEvent(door.key)) publishes.append((self.prefix + door.topic, str(door.open_time))) # Make sure everything has been written to the database before actually opening the door. db.session.flush() # TODO: move this to a handler that runs after the transaction is done # TODO: we can look at the responses and see if they where successfully sent/received. for topic, open_time in publishes: logger.info("Sending message: {}: {}".format(topic, open_time)) self._client.publish(topic, open_time)