def get(self): try: id = self.request.GET["id"] user = ndb.Key(urlsafe=id).get() try: creak = self.request.get("idcreak", "").strip() creak = ndb.Key(urlsafe=creak).get() except: creak = None if creak: v = creak.key.urlsafe() likes = Like.query() for i in likes: if i.idcreak == v: i.key.delete() time.sleep(0.5) user.creaks = user.creaks - 1 user.put() creak.key.delete() time.sleep(0.5) self.redirect("/creak/showcreak?id="+id) else: self.response.write("An error ocurred.") return except: self.response.write("An error occurred.") return
def get(self): try: id = self.request.GET["id"] user = ndb.Key(urlsafe=id).get() noReadMsg = Notification.query(Notification.user == user.username, Notification.read == 0) for i in noReadMsg: if i.read == 0: noReadMsg = 0 break likes = Like.query(Like.iduser == user.username) var = [] for i in likes: var.append(ndb.Key(urlsafe=i.idcreak).get()) values = { "username": user.username, "name": user.name, "surname": user.surname, "creaks": user.creaks, "follow": user.follow, "followers": user.followers, "id": id, "liked_creaks": var, "noReadMsg": noReadMsg } jinja = jinja2.get_jinja2(app=self.app) self.response.write( jinja.render_template("showlikes.html", **values)) return except: self.response.write("An error occurred.") pass
def get(self): p = Publicacion.recupera(self.request) autor = users.get_current_user().email() yaMeGusta = Like.query(Like.autor == autor, Like.publicacion == p.key) if yaMeGusta.count() == 0: like = Like(autor=autor, publicacion=p.key) like.put() time.sleep(1) return self.redirect("/")
def get(self): publicacion = Publicacion.recupera(self.request) likes = Like.query( Like.publicacion == publicacion.key).order(-Like.fecha) user = users.get_current_user() if user: url_user = users.create_logout_url("/") else: url_user = users.create_login_url("/") jinja = jinja2.get_jinja2(app=self.app) valores = {"user": user, "url_user": url_user, "likes": likes} self.response.write(jinja.render_template("listLikes.html", **valores))
def get(self): user = users.get_current_user() publicaciones = Publicacion.query().order(-Publicacion.fecha) likes = Like.query() if user: url_user = users.create_logout_url("/") else: url_user = users.create_login_url("/") jinja = jinja2.get_jinja2(app=self.app) valores = { "user": user, "url_user": url_user, "publicaciones": publicaciones, "likes": likes } self.response.write(jinja.render_template("index.html", **valores))
def get(self): try: id = self.request.GET["id"] user = ndb.Key(urlsafe=id).get() try: idcreak = self.request.GET["idcreak"] creak = ndb.Key(urlsafe=idcreak).get() except: creak = None if creak: like = Like.query(Like.iduser == user.username) for i in like: if i.idcreak == idcreak: li = i li.key.delete() time.sleep(0.5) self.redirect("/welcome?id=" + id) else: self.response.write("An error occurred.") except: self.response.write("An error occurred.") return
def get(self): id = self.request.GET["id"] user = ndb.Key(urlsafe=id).get() follows = Follow.query(Follow.username == user.username) noReadMsg = Notification.query(Notification.user == user.username, Notification.read == 0) for i in noReadMsg: if i.read == 0: noReadMsg = 0 break creaks = [] if follows.count() != 0: for i in follows: if i.username == user.username: creaks.append(i.usernameToFollow) user_creaks = Creak.query( ndb.OR(Creak.user == user.username, Creak.user.IN(creaks))).order(-Creak.time) for n in user_creaks: i = 0 t = "" for c in n.creak: t += c if i == 54: t += c + "\n" i = 0 i += 1 n.creak = t likes = [] like = Like.query(Like.iduser == user.username) for j in like: likes.append(j.idcreak) values = { "username": user.username, "name": user.name, "surname": user.surname, "creaks": user.creaks, "follow": user.follow, "followers": user.followers, "id": id, "user_creaks": user_creaks, "like": likes, "noReadMsg": noReadMsg } else: user_creaks = Creak.query( Creak.user == user.username).order(-Creak.time) for n in user_creaks: i = 0 t = "" for c in n.creak: t += c if i == 54: t += c + "\n" i = 0 i += 1 n.creak = t likes = [] like = Like.query(Like.iduser == user.username) for j in like: likes.append(j.idcreak) values = { "username": user.username, "name": user.name, "surname": user.surname, "creaks": user.creaks, "follow": user.follow, "followers": user.followers, "id": id, "user_creaks": user_creaks, "like": likes, "noReadMsg": noReadMsg } jinja = jinja2.get_jinja2(app=self.app) self.response.write(jinja.render_template("welcome.html", **values)) return
def get(self): search = self.request.get("search", "").strip() id = self.request.GET["id"] user = ndb.Key(urlsafe=id).get() noReadMsg = Notification.query(Notification.user == user.username, Notification.read == 0) if len(search) == 0: self.response.write("User to search can not be null.") return users = Register.query(Register.username == search) if users.count() == 0: user_creaks = Creak.query( Creak.user == user.username).order(-Creak.time) for n in user_creaks: i = 0 t = "" for c in n.creak: t += c if i == 54: t += c + "\n" i = 0 i += 1 n.creak = t values = { "error_login": "******", "username": user.username, "name": user.name, "surname": user.surname, "creaks": user.creaks, "follow": user.follow, "followers": user.followers, "id": id, "user_creaks": user_creaks, "noReadMsg": noReadMsg } jinja = jinja2.get_jinja2(app=self.app) self.response.write(jinja.render_template("welcome.html", **values)) return else: for i in users: users = Register(username=i.username, name=i.name, surname=i.surname, email=i.email, creaks=i.creaks, follow=i.follow, followers=i.followers) user_creaks = Creak.query( Creak.user == users.username).order(-Creak.time) for n in user_creaks: i = 0 t = "" for c in n.creak: t += c if i == 54: t += c + "\n" i = 0 i += 1 n.creak = t follow = Follow.query( ndb.AND(Follow.username == user.username, Follow.usernameToFollow == users.username)) likes = [] like = Like.query(Like.iduser == user.username) for j in like: likes.append(j.idcreak) if follow.count() != 0: values = { "id": id, "username": user.username, "name": user.name, "surname": user.surname, "creaks": user.creaks, "follow": user.follow, "followers": user.followers, "usernameSearch": users.username, "nameSearch": users.name, "surnameSearch": users.surname, "creaksSearch": users.creaks, "followSearch": users.follow, "followersSearch": users.followers, "user_creaks": user_creaks, "followed": "followed", "like": likes, "noReadMsg": noReadMsg } jinja = jinja2.get_jinja2(app=self.app) self.response.write( jinja.render_template("viewuser.html", **values)) return else: values = { "id": id, "username": user.username, "name": user.name, "surname": user.surname, "creaks": user.creaks, "follow": user.follow, "followers": user.followers, "usernameSearch": users.username, "nameSearch": users.name, "surnameSearch": users.surname, "creaksSearch": users.creaks, "followSearch": users.follow, "followersSearch": users.followers, "user_creaks": user_creaks, "noReadMsg": noReadMsg } jinja = jinja2.get_jinja2(app=self.app) self.response.write( jinja.render_template("viewuser.html", **values)) return