def get(self): # gets the user from the google users datastore. user = users.get_current_user() talk_key = self.request.get("talk_key") if not user: # if user is not logged in, log them in. self.redirect(users.create_login_url(self.request.uri)) return if not talk_key: talk = Talk() talk.host = user talk.users.append(user) talk.put() self.talk = talk talk_key = talk.key.id() self.redirect(str(self.request.url + "?talk_key=%i" % talk_key )) else: talk = Talk.get_by_id(long(self.request.get("talk_key"))) if talk == None: self.redirect("/home") if user not in talk.users: talk.users.append(user) talk.put() key_name = self.request.get("talk_key") channel_id = str(user.user_id() + str(talk_key)) channel_token = channel.create_channel(channel_id) template_things = {"id": key_name, "talk": talk, "user": user, "token": channel_token} self.response.write(self.render_template("index.html", "html", template_things))
def post(self): name = self.request.get("name") talk_key = self.request.get("talk_key") talk = Talk.get_by_id(long(talk_key)) talk.name = str(name) talk.put() self.redirect("chatroom?talk_key=%s&name=%s" % (str(talk_key), str(name)))
def delete_talk(netid, talk_id): if netid not in authorized_users: return redirect(url_for('index')) talk = Talk.get_by_id(talk_id) talk.delete() return redirect(url_for('index'))
def delete_talk(netid, talk_id): if netid not in ('fxh32', 'cxw158', 'jas404', 'srj15'): return redirect(url_for('index')) talk = Talk.get_by_id(talk_id) talk.delete() return redirect(url_for('index'))
def post(self): message = self.request.get("message_content") talk_key = self.request.get("talk_key") talk = Talk.get_by_id(long(talk_key)) for user in talk.users: """ Send message to those users """ client_id = str(user.user_id()) + str(talk_key) channel.send_message(client_id,message)
def vote(netid, talk_id, direction): app.logger.info(dir(netid)) app.logger.info(netid) votes = Vote.all() votes.filter('talk_id =', talk_id) votes.filter('netid =', netid) votes_res = votes.fetch(1) netid = str(netid) if len(votes.fetch(1)) < 1 or (votes_res[0].direction != 'up' and votes_res[0].direction != 'down'): # User has not voted before new_vote = Vote(direction=direction, netid=str(netid), talk_id=talk_id) talk = Talk.get_by_id(talk_id) if direction == 'up': talk.votes += 1 elif direction == 'down': talk.votes -= 1 talk.put() new_vote.put() app.logger.info("Did a vote") return redirect(url_for('index')) elif votes_res[0].direction != direction: # The user has voted and is changing vote = votes_res[0] vote.direction = direction talk = Talk.get_by_id(talk_id) if direction == 'up': talk.votes += 2 elif direction == 'down': talk.votes -= 2 talk.put() vote.put() app.logger.info("Did a exist vote") return redirect(url_for('index')) else: # User is not allowed to vote return redirect(url_for('index'))
def post(self): user = users.get_current_user() sent_message = self.request.get("message_content") talk = Talk.get_by_id(long(self.request.get("talk_key"))) message_package = {"author": str(user), "message": sent_message} talk.messages.append(message_package) talk.put() key_name = long(self.request.get("talk_key")) template_things = {"id": key_name, "talk": talk} self.response.write(self.render_template("index.html", "html", template_things))
def get(self): self.talk_key = self.request.get("talk_key") template_values = {"talk": Talk.get_by_id(long(self.talk_key)), "user": users.get_current_user(), "id": self.talk_key} self.response.write(self.render_template("chatroomRename.html", "chatroomRename", template_values))