示例#1
0
 def get(self):
     user = None
     posts = Post.all().order('-created')
     comments = Comments.all().order('-created')
     if (self.user):
         user = self.user
     self.render('blog.html', user=user, posts=posts, comments=comments)
示例#2
0
    def get(self, id_campanya):

        if users.is_current_user_admin():

            q = Comments.all()
            q.filter('campanya', id_campanya)

            listaEmail = []
            listaNumero = []

            x = 0

            for c in q:
                if c.userMail in listaEmail:
                    listaNumero[listaEmail.index(
                        c.userMail)] = listaNumero[listaEmail.index(
                            c.userMail)] + 1
                else:
                    listaEmail.insert(x, c.userMail)
                    listaNumero.insert(x, 1)
                    x = x + 1

            self.render_template(
                'grafico.html', {
                    "users": listaEmail,
                    "numeros": listaNumero,
                    "tam": len(listaEmail)
                })

        else:
            return webapp2.redirect('/')
示例#3
0
文件: EditPost.py 项目: breising/blog
    def post(self):
        user_id = None
        # AUTHENTICATE check for valid cookie
        user_id = auth(self.request.cookies.get('user_id'))

        postId = self.request.get("postId")

        if user_id:
            try:
                u = Users.get_by_id(int(user_id))
                q = BlogEntry.get_by_id(int(postId))
            except:
                pass
            if q:
                title = q.title
                body = q.body
                created = q.created
                last_mod = q.last_mod
                author = q.author_id
                k = q.key()

            try:
                comments = Comments.all().ancestor(k)
            except:
                pass
            # check again if user is the author..
            if user_id == author:
                title = self.request.get("title")
                body = self.request.get("body")
                postId = self.request.get("postId")

                # if field is left empty
                if title == "":
                    error = "You must enter a new title."
                    self.redirect("/editpost?postId=%s&error=%s" %
                                  (postId, error))
                if body == "":
                    error = "You must enter new content."
                    self.redirect("/editpost?postId=%s&error=%s" %
                                  (postId, error))
                else:
                    if q:
                        q.title = title
                        q.body = body
                        q.put()

                        error = "Updated post."
                        self.redirect("/focus?postId=%s&error=%s" %
                                      (postId, error))
                    else:
                        error = "error updating post"
                        self.redirect("/focus?postId=%s&error=%s" %
                                      (postId, error))
            else:
                error = "You must be author to edit."
                self.redirect("/focus?postId=%s&error=%s" % (postId, error))
        else:
            error = "Please signup and login to edit posts."
            self.redirect("/focus?postId=%s&error=%s" % (postId, error))
示例#4
0
    def post(self, module_id, campain_id):
        date = self.request.get("date")
        user = self.request.get("user")

        dt = datetime.strptime(date, '%Y-%m-%d %H:%M:%S.%f')

        q = Comments.all()
        q = q.filter('userMail = ', user)
        q = q.filter('module = ', module_id)
        q = q.filter('campanya = ', campain_id)
        q = q.filter('createDate = ', dt)

        comment = q.fetch(1)
        db.delete(comment)

        time.sleep(0.1)
        return webapp2.redirect("/foro/" + str(module_id) + "/" +
                                str(campain_id))
示例#5
0
    def post(self, module_id, campain_id):
        date = self.request.get("date")
        user = self.request.get("user")
        text = self.request.get("text")

        dt = datetime.strptime(date, '%Y-%m-%d %H:%M:%S.%f')

        q = Comments.all()
        q = q.filter('userMail = ', user)
        q = q.filter('module = ', module_id)
        q = q.filter('campanya = ', campain_id)
        q = q.filter('createDate = ', dt)

        comment = q.fetch(1)
        comment[0].text = text
        comment[0].updateDate = datetime.now()
        db.put(comment)

        time.sleep(0.1)
        return
示例#6
0
 def get(self, module_id, campain_id):
     comments = Comments.all().filter('module = ', module_id).filter(
         'campanya = ', campain_id).order('-createDate')
     modulo = Modules.get(db.Key.from_path('Modules', int(module_id)))
     self.render_template(
         "foro.html", {
             "module":
             module_id,
             "moduleName":
             modulo.name,
             "campain":
             campain_id,
             "comments":
             comments,
             "user":
             users.get_current_user().nickname()
             if users.get_current_user() != None else None,
             "user_id":
             users.get_current_user().user_id()
             if users.get_current_user() != None else None,
             "admin":
             users.is_current_user_admin()
         })
示例#7
0
文件: EditPost.py 项目: breising/blog
    def get(self):
        user_id = None
        # AUTHENTICATE check for valid cookie
        user_id = auth(self.request.cookies.get('user_id'))

        postId = self.request.get("postId")

        if user_id:
            try:
                u = Users.get_by_id(int(user_id))
                q = BlogEntry.get_by_id(int(postId))
            except:
                pass
            if q:
                title = q.title
                body = q.body
                created = q.created
                last_mod = q.last_mod
                author = q.author_id
                k = q.key()
            try:
                comments = Comments.all().ancestor(k)
            except:
                pass
            # if user is the author then ok to edit
            if user_id == author:
                self.render("edit-post.html",
                            body=body,
                            title=title,
                            postId=postId)
            else:
                error = "You must be author to edit."
                self.redirect("/focus?postId=%s&error=%s" % (postId, error))
        else:
            error = "Please signup and login to edit posts."
            self.redirect("/focus?postId=%s&error=%s" % (postId, error))
示例#8
0
文件: Focus.py 项目: breising/blog
    def get(self):
        user_id = None
        # AUTHENTICATE check for valid cookie
        user_id = auth(self.request.cookies.get('user_id'))

        if user_id:
            # get the logged in user
            try:
                u2 = Users.get_by_id(int(user_id))
            except:
                pass
            if u2:
                # get the username NOT the id
                user_name = u2.userName

            postId = self.request.get("postId")
            error = self.request.get("error")

            q = None
            # querie BlogEntry for the blog entity filtered by title
            try:
                q = BlogEntry.get_by_id(int(postId))
                title = q.title
                body = q.body
                created = q.created
                last_mod = q.last_mod
                author_id = q.author_id
                k = q.key()
            except:
                pass

            if q:
                # get the user who is the author of the blogpost
                try:
                    u = Users.get_by_id(int(author_id))
                except:
                    pass
                if u:
                    # get the authors username NOT id
                    author = u.userName

                comments = None

                # get all comments for this blogpost
                try:
                    comments = Comments.all().ancestor(k)
                except:
                    pass
                # if there are no comments....
                if not comments:
                    commentError = "No comments"
                else:
                    commentError = ""
            else:
                error = "Could not access the blog post."
                self.redirect("/welcome?error=%s" % error)

            # count likes in the database for display, all relevant likes are\
            # ancestors of the blog post with title
            count = 0
            likes = None

            try:
                likes = Likes.all().ancestor(k)
            except:
                pass

            if likes:
                # iterate through all likes for this post to count them
                for like in likes:
                    if like.user_id:
                        count += 1

            self.render("focus.html",
                        postId=postId,
                        title=title,
                        body=body,
                        created=created,
                        last_mod=last_mod,
                        author=author,
                        comments=comments,
                        error=error,
                        count=count,
                        commentError=commentError,
                        user_name=user_name)
        else:
            self.redirct("/login")
示例#9
0
文件: Focus.py 项目: breising/blog
    def post(self):
        def render_focus(title, body, created, last_mod, author, comments,
                         count, error, postId, user_name):

            self.render("focus.html",
                        title=title,
                        body=body,
                        created=created,
                        last_mod=last_mod,
                        author=author,
                        comments=comments,
                        count=count,
                        error=error,
                        postId=postId,
                        user_name=user_name)

        postId = self.request.get("postId")
        user_id = None
        # AUTHENTICATE check for valid cookie
        user_id = auth(self.request.cookies.get('user_id'))

        # get the logged in user to get username

        if user_id:

            try:
                u = Users.get_by_id(int(user_id))
            except:
                pass
            if u:
                user_name = u.userName

            # query for the usual blogPost entity properties
            try:
                q = BlogEntry.get_by_id(int(postId))
                if q:
                    title = q.title
                    body = q.body
                    created = q.created
                    last_mod = q.last_mod
                    author = u.userName
                    author_id = q.author_id
                    # k is the key to the blog post.
                    k = q.key()
            except:
                pass
            try:
                # get all comments for for the blogpost - that means get
                # all comments who are ancestors of K (the blogpost).
                comments = Comments.all().ancestor(k)
            except:
                pass

            # check if user has already liked this post
            # all Likes have a user_id property which corresponds to the
            # User who LIKED the post, so query Likes filtered by user_id
            # to get ALL the likes for this user
            try:
                z = Likes.all().filter("user_id =", user_id)
            except:
                pass
            # then get the ONE (if theres is one) that is an ancestor
            # of the blog post
            if z:
                try:
                    alreadyLiked = z.ancestor(k).get()
                except:
                    pass
            # set flag default = go
            flag = "go"
            # if there are ZERO likes in the db, you'll get an error bc
            # the query gets nothing. To prevent the error, use try/except
            try:
                if alreadyLiked.user_id:
                    flag = "nogo"
            except:
                pass

            # initialize the counter
            count = 0
            # If the logged in user is the author then error
            if user_id == author_id:
                # repaint page
                likes = Likes.all().ancestor(k)
                count = 0

                for like in likes:
                    try:
                        if like.user_id:
                            count += 1
                    except:
                        pass

                error = "You can't like your own posts."
                render_focus(title, body, created, last_mod, author, comments,
                             count, error, postId, user_name)
            else:
                # if the logged in user has already liked this post then error
                if flag == "nogo":
                    error = "Stop it....You already liked this post."
                    likes = Likes.all().ancestor(k)
                    count = 0
                    if likes:
                        for like in likes:
                            if like.user_id:
                                count += 1
                    # repaint page
                    render_focus(title, body, created, last_mod, author,
                                 comments, count, error, postId, user_name)
                else:
                    # if tests are passed....record the LIKE;
                    # record the userIDKEY in LIKES as a CHILD of the BLOGPOST
                    # increment the like so it updates the display (not the db)
                    # record like in the db - user_id is the only property and
                    # it's ancestor is the blogpost k.
                    try:
                        l = Likes(parent=k, user_id=user_id)
                    except:
                        pass

                    if l:
                        l.put()

                    error = "The Like was recorded."
                    # count ALL the existing LIKES to update display \
                    # on VIEW post
                    # filter by ancestor bc ALL likes are recorded as an \
                    # ancestor of ONE blogPost
                    likes = Likes.all().ancestor(k)
                    count = 0

                    if likes:
                        for like in likes:
                            if like.user_id:
                                count += 1

                    # repaint page
                    render_focus(title, body, created, last_mod, author,
                                 comments, count, error, postId, user_name)

        else:
            error = "Please signup and login to like a post."
            # if you are not logged in, you must sign up and login.
            self.redirect("/focus?postId=%s&error=%s" % (postId, error))