def search(self): c.title="Search" if request.method=="GET": return render('search.mako') text=request.POST.get('query') if text: chanels=self.chanel_q.filter(Chanel.name.like(text)).all() c.search['results']=chanels return render('search.mako')
def signin(self): if request.method == "GET": return render("sign_in.mako") email = self.form_result.get("email") password = self.form_result.get("password") pers = self.person_q.filter_by(email=email, password=md5(password)).first() if pers: response.set_cookie("email", email) response.set_cookie("password", md5(password)) redirect("/chanel/main") return "Invalid user name and/or password %s" % dir
def display_messages(self, vars): id=session['chanel']['id'] chanel=self.chanel_q.filter_by(id=id).first() users=[x.name for x in chanel.persons] c.messages=self.message_q.filter(Message.chanel_id==chanel.id, Message.timestamp>int(vars)).all() length=len(c.messages) if length>20: c.messages=c.messages[-length:] data={} data['messages']=render('messages_json.mako') data['users']=users return json.dumps(data)
def chat_route(self, id): autorize() chanel=self.chanel_q.filter_by(name=id).first() if not chanel: return 'This chanel does not exist' user_id=session.get('person_id') if user_id!=None: user=self.person_q.filter_by(id=user_id).first() user.chanel_id=chanel.id Session.commit() session['chanel']={'id':chanel.id, 'name':chanel.name} session.save() c.user['name']=session.get('name') chanels=self.chanel_q.filter_by(owner=c.user['name']).all() c.user['chanels']=chanels c.title='#'+id c.chanel=id c.timestamp=int(time.time()) return render('croute.mako')
def index(self): return render("/new_action.mako")
def main(self): c.title='Main page' c.name=session['name'] chanels=self.chanel_q.filter_by(owner=c.name).all() c.chanels=chanels return render('cmain.mako')