Exemple #1
0
	def post(self):
		self.response.headers["Content-Type"] = "application/json"
		try:
			user_id = self.request.POST["user"]
			channel_name = self.request.POST["channel"]
			if "nsfw" not in self.request.POST:
				nsfw = 0
			else:
				nsfw = self.request.POST["nsfw"]
			channels = Channels()
			channels.add_channel(channel_name, user_id, nsfw)
		except Exception:
			logging.exception("Failed to add a channel")
			out = {"success": 0}
			self.response.write(json.dumps(out))
		else:
			logging.info("Channel added successfully")
			out = {"success": 1}
			self.response.write(json.dumps(out))
Exemple #2
0
assets = Environment(app)
assets.url = app.static_url_path
scss = Bundle(
    'sass/main.scss',
    filters='pyscss',
    depends=('**/*.scss'),
    output='styles.css')
assets.register('scss_all', scss)


# Globals
users = {}
rooms = Channels()

# Initalize channels
rooms.add_channel('general')
msg = {'text': 'Welcome to channel #general',
       'name': 'FlackBot', 'stamp': now_stamp(), 'color': cObj('#888888')}
rooms.add_message('general', msg)


@app.route("/")
def index():
    """Show chat app"""
    return render_template('index.html')


@app.route('/new_room', methods=['POST'])
def new_room():
    """
    Handle POST request from contoller