示例#1
0
    def get(self):

        # get users nickname to add on list search
        def getUsers():
            us = User.query()
            toret = []
            for u in us:
                toret.append(u.nickname)
            user_list = json.dumps(toret)
            return user_list

        jinja = jinja2.get_jinja2(app=self.app)
        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:
            #Search images by current user id
            image_info = Image.query(Image.autor == user.user_id())
            if image_info.count() == 0:
                self.redirect(
                    "/error?msg=There are no photos uploaded&handler=/main")
                return
            else:
                labels = {
                    "user_logout": users.create_logout_url("/"),
                    "images": image_info,
                    "usersearch": getUsers()
                }
                self.response.write(
                    jinja.render_template("myphotos.html", **labels))
示例#2
0
    def post(self):
        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:

            id = self.request.get('id')

            if id == "":
                self.redirect("/error?msg=Unexpected ocurred&handler=/")
                return
            else:
                # get image to update values
                image_info = Image.query(Image.id_image == id)
                if image_info.count() == 0:
                    self.redirect("/error?msg=Unexpected error&handler=/")
                    return
                else:
                    image_info = image_info.get()
                    # Verify that the user is not on the list
                    if user.email() in image_info.likes:
                        image_info.likes.remove(user.email())
                        image_info.put()
                        time.sleep(1)
示例#3
0
    def get(self):

        # get users nickname
        def getNickname(email):
            query = User.query(User.email == email)
            nickname = query.get().nickname

            return nickname

        # get users nickname to add on search list
        def getUsers():
            us = User.query()
            toret = []
            for u in us:
                toret.append(u.nickname)

            user_list = json.dumps(toret)

            return user_list

        jinja = jinja2.get_jinja2(app=self.app)
        user = users.get_current_user()
        if user == None:
            self.redirect(users.create_login_url("/"))
        else:
            user_id = user.user_id()
            user_info = User.query(User.id_user == user_id)
            user_atributes = user_info.get()

            #get user categories to not return duplicates
            user_categories = set(user_atributes.categories)

            # create nickname followers list
            toretFollowers = []
            for x in user_atributes.followers:
                toretFollowers.append(getNickname(x))

            # create nickname following list
            toretFollow = []
            for x in user_atributes.follow:
                toretFollow.append(getNickname(x))

            # get following user images
            imgs = []
            for nickname in toretFollow:
                follow_user = User.query(User.nickname == nickname)
                users_info = follow_user.get()
                imgs.append(Image.query(Image.autor == users_info.id_user))

            labels = {
                "user_logout": users.create_logout_url("/"),
                "user_info": user_info,
                "categories": user_categories,
                "current_user": True,
                "usersearch": getUsers(),
                "following": toretFollow,
                "followers": toretFollowers,
                "images": imgs
            }
            self.response.write(jinja.render_template("index.html", **labels))
示例#4
0
    def post(self):

        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:

            if self.request.get('img') == "":
                self.redirect("/error?msg=Image is mandatory&handler=/upload")
                return

            if self.request.get('title') == "":
                self.redirect("/error?msg=Title is mandatory&handler=/upload")
                return

            current_user = User.query(User.email == user.email())
            current_user = current_user.get()

            #add category in user
            category = self.request.get('category')
            category = category.lower()

            current_user.publications = current_user.publications + 1
            current_user.categories.append(category)

            current_user.put()
            time.sleep(1)

            #prepare image id
            if "@" in current_user.nickname:
                nickname = user.nickname().split("@")
                nickname = nickname[0]

            else:
                nickname = current_user.nickname
            img = Image(title=self.request.get('title'),
                        comment=self.request.get('comment'),
                        autor=user.user_id(),
                        category=category,
                        image_info=self.request.get('img'),
                        id_image=nickname + str(time.time()).replace(".", ""))

            img.put()
            time.sleep(1)

            self.redirect("/myphotos")
示例#5
0
    def post(self):

        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:
            autor = self.request.get('autor')
            id = self.request.get('id')

            if id == "":
                self.redirect("/error?msg=Unexpected error&handler=/")
                return

            if autor == "":
                self.redirect("/error?msg=Unexpected error&handler=/")
                return

            #check autor
            user_info = User.query(User.email == user.email())
            user_info = user_info.get()

            if user_info.id_user != autor:
                self.redirect(
                    "/error?msg=You dont have permissions here&handler=/")
                return
            else:
                #prepare deleting
                image_info = Image.query(Image.id_image == id)
                image_info = image_info.get()

                comment = Comment.query(Comment.image == id)

                #delete publication
                user_info.publications = user_info.publications - 1

                # delete image category in User entity
                user_info.categories.remove(image_info.category)
                user_info.put()
                time.sleep(1)

                #delete image comments in Comment entity
                for comments in comment:
                    comments.key.delete()

                #delete image
                image_info.key.delete()
                time.sleep(1)
示例#6
0
    def get(self):

        # get users nickname to add on list search
        def getUsers():
            us = User.query()
            toret = []
            for u in us:
                toret.append(u.nickname)

            user_list = json.dumps(toret)

            return user_list

        jinja = jinja2.get_jinja2(app=self.app)
        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:
            category = self.request.get('name')
            if category == "":
                self.redirect("/")
            else:
                #Check images by category
                category = category.lower()
                if category not in [
                        "culture", "extreme sports", "motor", "social",
                        "videogames", "other"
                ]:
                    self.redirect(
                        "/error?msg=There are no photos uploaded with this category&handler=/main"
                    )
                    return
                else:
                    # Search images by category
                    image_info = Image.query(Image.category == category)
                    labels = {
                        "user_logout": users.create_logout_url("/"),
                        "images": image_info,
                        "category": category,
                        "usersearch": getUsers()
                    }
                    self.response.write(
                        jinja.render_template("search_photos.html", **labels))
示例#7
0
    def get(self):

        # get users nickname
        def getNickname(email):
            query = User.query(User.email == email)
            nickname = query.get().nickname

            return nickname

        # get users nickname to add on list search
        def getUsers():
            us = User.query()
            toret = []
            for u in us:
                toret.append(u.nickname)

            user_list = json.dumps(toret)

            return user_list

        jinja = jinja2.get_jinja2(app=self.app)
        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:

            id_image = self.request.get('id')

            if id_image == "":
                self.redirect("/error?msg=Image id mandatory&handler=/main")
                return
            else:

                image_info = Image.query(Image.id_image == id_image)
                if image_info.count() == 0:
                    self.redirect(
                        "/error?msg=Image does not exist&handler=/main")
                    return
                else:
                    # get autor name
                    image_autor = image_info.get()
                    image_autor = image_autor.autor

                    # get autor attributes
                    user_info = User.query(User.id_user == image_autor)
                    if user_info.count() == 0:
                        self.redirect(
                            "/error?msg=Unexpected error&handler=/main")
                        return
                    else:
                        autor_attributes = user_info.get()
                        autor_name = autor_attributes.nickname
                        autor_email = autor_attributes.email

                        # check current user to reload data
                        current_user = False
                        if autor_name == getNickname(user.email()):
                            current_user = True

                        # check followers
                        if users.get_current_user().email(
                        ) in autor_attributes.followers:
                            follow = True
                        else:
                            follow = False

                        # get image comments
                        comments = Comment.query(
                            Comment.image == id_image).order(Comment.date)

                        labels = {
                            "image_info": image_info,
                            "autor": autor_name,
                            "current_user": current_user,
                            "user": user.email(),
                            "autor_email": autor_email,
                            "comments": comments,
                            "follow": follow,
                            "usersearch": getUsers(),
                            "user_logout": users.create_logout_url("/")
                        }

                    self.response.write(
                        jinja.render_template("image.html", **labels))