Пример #1
0
 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(idcreak=creak.key.urlsafe(), iduser=user.username)
             like.put()
             time.sleep(1)
             if user.username != creak.user:
                 notification = Notification(user=creak.user,msg="@"+user.username+" liked your creak: '"+creak.creak+"'",read=0)
                 notification.put()
                 time.sleep(1)
             self.redirect("/welcome?id="+id)
         else:
             self.response.write("An error occurred.")
     except:
         self.response.write("An error occurred.")
         return
Пример #2
0
    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("/")
Пример #3
0
    def post(self, post_id):
        key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(key)

        if not post:
            self.error(404)
            return
        """
            On posting comment, new comment tuple is created and stored,
            with relationship data of user and post.
        """
        c = ""
        if (self.user):
            # On clicking like, post-like value increases.
            if (self.request.get('like')
                    and self.request.get('like') == "update"):
                likes = db.GqlQuery("select * from Like where post_id = " +
                                    post_id + " and user_id = " +
                                    str(self.user.key().id()))

                if self.user.key().id() == post.user_id:
                    self.redirect("/blog/" + post_id +
                                  "?error=You cannot like your " + "post.!!")
                    return
                elif likes.count() == 0:
                    l = Like(parent=blog_key(),
                             user_id=self.user.key().id(),
                             post_id=int(post_id))
                    l.put()

            # On commenting, it creates new comment tuple
            if (self.request.get('comment')):
                c = Comment(parent=blog_key(),
                            user_id=self.user.key().id(),
                            post_id=int(post_id),
                            comment=self.request.get('comment'))
                c.put()
        else:
            self.redirect("/login?error=You need to login before " +
                          "performing edit, like or commenting.!!")
            return

        comments = db.GqlQuery("select * from Comment where post_id = " +
                               post_id + "order by created desc")

        likes = db.GqlQuery("select * from Like where post_id=" + post_id)

        self.render("permalink.html",
                    post=post,
                    comments=comments,
                    noOfLikes=likes.count(),
                    new=c)
Пример #4
0
    def get(self):

        usr, url_usr, userActual = Utilities.checkUser()
        if userActual is None:
            return self.redirect("/")
        try:
            if usr:
                tuit = Tuit.getTuit(self.request)
                if not Like.exists(userActual.key, tuit.key):
                    like = Like(tuit=tuit.key, user=userActual.key)
                    like.put()
                    time.sleep(2)
        finally:
            return self.redirect("/tuits/list")
Пример #5
0
    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
Пример #6
0
    def get(self):
        imagen, likes = Like.recupera_para(self.request)
        usuarios = []

        usr = users.get_current_user()
        url_usr = users.create_logout_url("/")
        usr_info = mgt_usr.retrieve(usr)

        for like in likes:
            clave_usr = like.usuario
            print("EL PRINT ESTA AQUI!!!!!!", like)
            usuarios.append(clave_usr.get())

        valores_plantilla = {
            "likes": likes,
            "usuarios": usuarios,
            "imagen": imagen,
            "usr_info": usr_info,
            "usr": usr_info,
            "url_usr": url_usr
        }

        jinja = jinja2.get_jinja2(app=self.app)
        self.response.write(
            jinja.render_template("lista_likes.html", **valores_plantilla))
Пример #7
0
    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
Пример #8
0
    def post(self):
        imagen = self.request.GET["id"]
        nombre = self.request.get("edNombre", "")
        email = self.request.get("edEmail", "")

        if len(nombre) < 0 or not(nombre) or len(email) < 0 or not(email):
            return self.redirect("/")
        else:
            usr = users.get_current_user()
            user = mgt_usr.retrieve(usr)
            print("EL PRINT ESTA AQUI!!!!!", user.key)

            like = Like(usuario=user.key, imagen=ndb.Key(urlsafe=imagen))
            like.put()
            time.sleep(1)

            return self.redirect("/")
Пример #9
0
    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))
Пример #10
0
    def get(self):
        usr, url_usr, userActual = Utilities.checkUser()
        if userActual is None:
            return self.redirect("/")
        tuit = Tuit.getTuit(self.request)
        likes = Like.getLikesByTuit(tuit.key)

        values = {
            "usr": usr,
            "url_usr": url_usr,
            "userActual": userActual,
            "tuit": tuit,
            "likes": likes,
            "Like": Like,
            "suggestedUsers": Utilities.suggestUsers(userActual),
            "title": "Likes"
        }

        jinja = jinja2.get_jinja2(app=self.app)
        self.response.write(jinja.render_template("list_likes.html", **values))
Пример #11
0
    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))
Пример #12
0
    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
Пример #13
0
    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
Пример #14
0
    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