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

            follow = Follow.query(Follow.username == user.username)
            values = {
                "username": user.username,
                "name": user.name,
                "surname": user.surname,
                "creaks": user.creaks,
                "follow": user.follow,
                "followers": user.followers,
                "id": id,
                "follows": follow,
                "noReadMsg": noReadMsg
            }
            jinja = jinja2.get_jinja2(app=self.app)
            self.response.write(jinja.render_template("showfollow.html", **values))
            return
        except:
            self.response.write("An error occurred.")
            return
Exemple #2
0
    def get(self):
        try:
            id = self.request.GET["id"]
            currentuser = ndb.Key(urlsafe=id).get()
            user = self.request.get("user", "").strip()

            user = Register.query(Register.username == user)

            if currentuser and user.count() != 0:
                for i in user:
                    user = i

                unfollow = Follow.query(
                    ndb.AND(Follow.username == currentuser.username,
                            Follow.usernameToFollow == user.username))

                if unfollow.count() == 0:
                    currentuser.follow = currentuser.follow + 1
                    currentuser.put()
                    user.followers = user.followers + 1
                    user.put()

                    follow = Follow(username=currentuser.username,
                                    usernameToFollow=user.username)
                    follow.put()
                    time.sleep(1)

                    self.redirect("/user/showusers?search=" + user.username +
                                  "&id=" + id)
                else:
                    currentuser.follow = currentuser.follow - 1
                    currentuser.put()
                    user.followers = user.followers - 1
                    user.put()

                    for i in unfollow:
                        unfollow = i

                    unfollow.key.delete()
                    self.redirect("/user/showusers?search=" + user.username +
                                  "&id=" + id)
            else:
                self.response.write("An error occurred.")
                return
        except:
            self.response.write("An error occurred.")
            return
Exemple #3
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
Exemple #4
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