def slack_event(): """First controller to receive Slack event Returns: flask.Response -- Flask HTTP Response """ # Create event controller instance controller = EventController() # Execute controller process response_object = controller.main() # Response return response_object
def events(query=None, category=None, tag=None, cities=None, flags=None, page=1, next_page_url=None, prev_page_url=None, lat=None, lon=None, scroll=False, selected=None): selected_categories = category current_user = UserController().current_user if tag == Tag.TVM: cities = None events, categories, tags, event_cities = EventController().get_events( query=query, categories=category, tags=tag, cities=cities, flags=flags, page=page) chips = _parse_chips(selected_categories=selected_categories, categories=categories, tags=tags, cities=event_cities, flags=flags) vargs = { 'current_user': current_user, 'events': events, 'selected': selected, 'chips': chips, 'page': page, 'next_page_url': next_page_url, 'prev_page_url': prev_page_url } return _render_events_list(request, events, vargs, scroll=scroll, template=TEMPLATE_EXPLORE)
def event_update(event_id): current_user = UserController().current_user is_card = request.form.get('card') == 'true' choice = request.form.get('choice') if choice in UserEvent.interest_keys(): interest_key = choice else: interest_key = None callback = request.form.get('cb') if callback == "/": callback = 'events' event = EventController().update_event(event_id=event_id, interest_key=interest_key) if event: template = TEMPLATE_EVENT_CARD if is_card else TEMPLATE_EVENT_PAGE categories_set = set() tag_chips = [] for t in event.tags: categories_set.add(t.tag_type) tag_chips.append({'chip_name': t.tag_name}) category_chips = [{'chip_name': c} for c in categories_set] chips = _parse_chips(categories=category_chips, tags=tag_chips) vargs = { 'current_user': current_user, 'event': event, 'chips': chips, 'card': is_card } if request.is_xhr: if template == TEMPLATE_EVENT_PAGE: template = TEMPLATE_EVENT_PAGE_BODY return render_template(template, vargs=vargs, **vargs) if callback: return redirect(callback) return render_template(TEMPLATE_MAIN, template=template, vargs=vargs, **vargs) return redirect(request.referrer or '/')
def user_update(identifier): current_user = UserController().current_user current_user_id = UserController().current_user_id action = request.form.get('action') active = request.form.get('active') == 'true' if action == 'block': u = UserController().block_user(identifier, active) elif action == 'follow': u = UserController().follow_user(identifier, active) if u: events = [] if not Block.blocks(u.user_id, current_user_id): events = EventController().get_events_for_user_by_interested( user=u, interested=UserEvent.INTERESTED) return redirect(request.referrer or '/')
def event(event_id): event = EventController().get_event(event_id=event_id) current_user = UserController().current_user if event: template = TEMPLATE_EVENT_PAGE vargs = { 'title': event.display_name, 'current_user': current_user, 'event': event } if request.is_xhr: return render_template(template, vargs=vargs, **vargs) return render_template(TEMPLATE_MAIN, template=template, vargs=vargs, **vargs) return redirect(request.referrer or '/')
def user(identifier, interested=None, query=None, category=None, tag=None, cities=None, flags=None, lat=None, lon=None, page=1, next_page_url=None, prev_page_url=None, scroll=False, selected=None): selected_categories = category current_user = UserController().current_user current_user_id = UserController().current_user_id user = UserController().get_user(identifier) if user: events = [] categories = [] tags = [] event_cities = [] if not Block.blocks(user.user_id, current_user_id): events, categories, tags, event_cities = EventController( ).get_events_for_user_by_interested(user=user, query=query, categories=category, tags=tag, cities=cities, flags=flags, interested=interested, page=page) chips = _parse_chips(categories=categories, selected_categories=selected_categories, tags=tags, cities=event_cities, interested=interested, flags=flags, show_interested=True) vargs = { 'current_user': current_user, 'is_me': user == current_user, 'events': events, 'selected': selected, 'chips': chips, 'page': page, 'next_page_url': next_page_url, 'prev_page_url': prev_page_url } if user.user_id == current_user_id: return _render_events_list(request, events, vargs, scroll=scroll) else: vargs['user'] = user user.card_follower_count = user.follower_users_count() user.card_event_count = user.active_user_events_count() user.card_is_followed = user.is_follows_user( current_user) if current_user else False user.card_is_following = current_user.is_follows_user( user) if current_user else False user.card_is_blocked = current_user.is_blocks_user( user) if current_user else False return _render_events_list(request, events, vargs, template=TEMPLATE_USER_PAGE, scroll=scroll) return redirect(request.referrer or '/')
def card_type_init(self): super(BasicLandType, self).card_type_init() EventController.register(self, Event.TAP, self.tap_land_event)
class Route: def __init__(self, app, socketio): self.app = app self.socketio = socketio self.event_controller = EventController(app, socketio) self.image = '' def routes(self): @self.app.route('/favicon.ico') def favicon(): return send_from_directory(os.path.join(self.app.root_path, 'static/img'), 'favicon.ico', mimetype='image/vnd.microsoft.icon') @self.app.route('/') def main_route(): return render_template('start-menu.html', image='') @self.app.route('/calibration') def calibration(): return render_template('calibration.html') @self.app.route('/difficulty') def difficulty(): return render_template('difficulty.html') @self.app.route('/time') def time(): return render_template('time.html') @self.app.route('/start') def start_game(): return render_template('start_game.html') @self.app.route('/calibrate', methods=['GET']) def calibrate_screen(): try: if not self.event_controller.image_controller.is_calibrated: self.app.logger.info(self.image) image_controller = self.event_controller.image_controller image_controller.calibrate_field(self.image) self.app.logger.info(image_controller.calibrate_field.ROI) return {} except: return {} @self.app.route('/api/status_update', methods=['POST']) def status_update(): if request.method == 'POST': data = loads(request.data) # self.app.logger.info(data["lanes"]) self.image = data['camera']['image'] field_image, red_goal, blue_goal = self.event_controller.update_event( data) if field_image is not None: self.socketio.emit( 'update_image', {'image': f"data:image/jpeg;base64,{field_image}"}, room='web') if red_goal: self.socketio.emit('update_red_goal', {'goal': f"{red_goal}"}, room='web') if blue_goal: self.socketio.emit('update_blue_goal', {'goal': f"{blue_goal}"}, room='web') return "OK" @self.socketio.on('join') def on_join(data): username = data['username'] room = data['room'] join_room(room) send(username + ' has entered the room.', room=room) @self.app.route('/api/register', methods=['POST']) def register_event(): data = loads(request.data) self.event_controller.register_event(data) return "OK"
def __init__(self, app, socketio): self.app = app self.socketio = socketio self.event_controller = EventController(app, socketio) self.image = ''
def card_type_init(self): EventController.register(self, Event.PLAY, self.play_card_event)
def play_card(self, **kwargs): EventController.fire_events(obj=self, event=Event.PLAY, **kwargs)
def tap_card(self, **kwargs): EventController.fire_events(obj=self, event=Event.TAP, **kwargs)