Exemplo n.º 1
0
 def get(self):
     recentComments = Comment.all().order('-commentTime').fetch(10)
     recentBlogs = Blog.all().order('-createTimeStamp').fetch(5)
     links = Link.all()
     template_values = {
         'recentComments': recentComments,
         'recentBlogs': recentBlogs,
         'links': links
     }
     blogid = self.param('p')
     if (blogid):
         blogid = int(blogid)
         blogs = Blog.all().filter('blog_id =', blogid).fetch(1)
         blog = blogs[0]
         comments = Comment.all().filter("ownerBlog =",
                                         blog).order('commentTime')
         template_values.update({'blog': blog, 'comments': comments})
         self.generateBasePage('singleblog.html', template_values)
     else:
         pageIndex = self.param('page')
         if (pageIndex):
             pageIndex = int(pageIndex)
         else:
             pageIndex = 1
         blogs = Blog.all().order('-createTimeStamp')
         pager = PageManager(query=blogs,
                             items_per_page=blogSystem.posts_per_page)
         blogs, links = pager.fetch(pageIndex)
         template_values.update({'blogs': blogs, 'pager': links})
         self.generateBasePage('main.html', template_values)
     return
Exemplo n.º 2
0
    def post(self):
        t_values = {}
        current_link_id = self.request.POST['current_link_id']
        link_title = self.request.POST['link_title']
        link_target = self.request.POST['link_target']
        link_sequence = self.request.POST['link_sequence']
        logging.info("LinkManager post: current_link_id = %s, link_title = %s, link_target = %s, link_sequence = %s" % (current_link_id, link_title, 'link_target', 'link_sequence'))

        if current_link_id:
            # edit existed link
            link = Link.get_by_id(long(current_link_id))
            link.title = link_title
            link.target = link_target
            link.sequence = long(link_sequence)
            link.put()
            t_values['alert_message'] = "link %s has been updated" % (link.title)
        else:
            # create new link
            link = Link(title=link_title, target=link_target, sequence=long(link_sequence))
            link.put()
            t_values['alert_message'] = "link %s has been added" % (link.title)

        # find all links
        links = Link.all().order("-date")
        t_values["links"] = links
        return self.response.out.write(render_template("links.html", t_values, "", True))
Exemplo n.º 3
0
	def update_basic_info(
		update_categories=False,
		update_tags=False,
		update_links=False,
		update_comments=False,
		update_archives=False,
		update_pages=False):

		from model import Entry,Archive,Comment,Category,Tag,Link
		basic_info = ObjCache.get(is_basicinfo=True)
		if basic_info is not None:
			info = ObjCache.get_cache_value(basic_info.cache_key)
			if update_pages:
				info['menu_pages'] = Entry.all().filter('entrytype =','page')\
							.filter('published =',True)\
							.filter('entry_parent =',0)\
							.order('menu_order').fetch(limit=1000)
			if update_archives:
				info['archives'] = Archive.all().order('-year').order('-month').fetch(12)
			if update_comments:
				info['recent_comments'] = Comment.all().order('-date').fetch(5)
			if update_links:
				info['blogroll'] = Link.all().filter('linktype =','blogroll').fetch(limit=1000)
			if update_tags:
				info['alltags'] = Tag.all().order('-tagcount').fetch(limit=100)
			if update_categories:
				info['categories'] = Category.all().fetch(limit=1000)

			logging.debug('basic_info updated')
			basic_info.update(info)
Exemplo n.º 4
0
    def get(self, page_slug=""):
        if page_slug:
            t_values = {}

            posts = Entry.all().filter("is_external_page =", True).filter("entrytype =", 'page').filter("slug =", page_slug)
            if posts.count() == 1:
                logging.warning("find one page with slug=%s" % (page_slug))
                posts = posts.fetch(limit=1)
                post = posts[0]
                t_values['post'] = post
                # dump(post)

                # find all comments
                comments = Comment.all().filter("entry =", post).order("date")
                t_values['comments'] = comments
            else:
                logging.warning("%d entries share the same slug %s" % (posts.count(), page_slug))

            links = Link.all().order("date")
            t_values['links'] = links

            categories = Category.all()
            t_values['categories'] = categories

            pages = Entry.all().filter("is_external_page =", True).filter("entrytype =", 'page').order("date")
            t_values['pages'] = pages

            return self.response.out.write(render_template("page.html", t_values, "basic", False))
        else:
            self.redirect(uri_for("weblog.index"))
Exemplo n.º 5
0
    def get(self):
        # find stats for this blog
        stats = {}
        stats['posts'] = Entry.all().filter("entrytype =", "post").filter("is_external_page =", True).count()
        stats['pages'] = Entry.all().filter("entrytype =", "page").filter("is_external_page =", True).count()
        stats['comments'] = Comment.all().count()
        stats['categories'] = Category.all().count()
        stats['links'] = Link.all().count()

        t_values = {}
        t_values['stats'] = stats
        return self.response.out.write(render_template("index.html", t_values, "", True))
Exemplo n.º 6
0
    def get(self, page="1", cate_slug=""):
        t_values = {}
        page = int(page)
        logging.info("IndexHandler - get: page = %d, cate_slug = %s" % (page, cate_slug))

        # find all entries by order
        query = Entry.all().filter("is_external_page =", True).filter("entrytype =", 'post').order("-date")
        # add category filter?
        if cate_slug:
            cates = Category.all().filter("slug =", cate_slug)
            if cates:
                query = query.filter("category =", cates[0])

        # pagination
        total_posts = query.count()
        q_limit = Configuration["posts_per_page"]
        q_offset = (page - 1) * Configuration["posts_per_page"]
        logging.info("limit = %d, offset = %d" % (q_limit, q_offset))

        # get entries
        entries = query.fetch(limit=q_limit, offset=q_offset)
        t_values['entries'] = entries

        # show entries for debug purpose
        # for entry in entries:
        #     logging.info("entry title: %s, public = %s, cate = %s" % (entry.title, entry.is_external_page, entry.category.name))

        logging.info("total posts = %d, current_page = %d, posts_per_page = %d" % (total_posts, page, Configuration['posts_per_page']))
        t_values['navlist'] = generateNavList(total_posts, page, Configuration["posts_per_page"])
        # logging.info(t_values['navlist'])

        # find all links
        links = Link.all().order("date")
        t_values['links'] = links

        # find all categories
        categories = Category.all()
        t_values['categories'] = categories

        # find all pages
        pages = Entry.all().filter("is_external_page =", True).filter("entrytype =", 'page').order("date")
        t_values['pages'] = pages

        # show index page
        return self.response.out.write(render_template("index.html", t_values, "basic", False))
Exemplo n.º 7
0
    def get(self, link_id="", operation=""):
        t_values = {}
        logging.info("LinkManager: link_id = %s, operation = %s" % (link_id, operation))

        # find current_link from link_id
        if link_id:
            current_link = Link.get_by_id(long(link_id))
            if current_link:
                logging.info("found link %s from link_id: %s" % (current_link.title, link_id))
                if operation == "delete":
                    current_link.delete()
                    t_values['alert_message'] = "Link %s has been deleted." % (current_link.title)
                    # t_values['redirect_location'] = uri_for("admin.links")
                    # return self.response.out.write(render_template("alert.html", t_values, "", True))
                elif operation == "edit":
                    # pass current_link to template
                    t_values['current_link'] = current_link

        # find all links
        links = Link.all().order("-date")
        t_values["links"] = links
        return self.response.out.write(render_template("links.html", t_values, "", True))
Exemplo n.º 8
0
    def post(self, post_slug=""):
        if post_slug:
            t_values = {}

            post_id = self.request.POST['post_id']
            post = Entry.get_by_id(long(post_id))
            if post:
                # ok, we find the post, try to add comment to this post
                logging.warning("find one post with post_id %s" % (post_id))
                t_values['post'] = post
                # dump(post)

                # check google recaptcha, these two fileds might not exist due to connection to reCAPTCHA
                recaptcha_challenge_field = self.request.POST.get('recaptcha_challenge_field', "")
                recaptcha_response_field = self.request.POST.get('recaptcha_response_field', "")
                remote_ip = self.request.environ['REMOTE_ADDR']
                private_key = "6LdwFdISAAAAAOYRK7ls3O-kXPTnYDEstrLM2MRo"
                antispam_flag = False
                try:
                    result = submit(recaptcha_challenge_field, recaptcha_response_field, private_key, remote_ip)
                    logging.info("google recaptcha %s, %s" % (result.is_valid, result.error_code))
                    if result.is_valid:
                        antispam_flag = True
                except:
                    e = sys.exc_info()[0]
                    logging.info(e)

                # create comment for this post
                if antispam_flag:
                    logging.info("PostManager - add comment")
                    comm_author = self.request.POST['author']
                    comm_email = self.request.POST['email']
                    comm_weburl = self.request.POST['weburl']
                    comm_content = self.request.POST['comment']
                    comment_ip = self.request.environ['REMOTE_ADDR']
                    comm = Comment(entry=post, author=comm_author, email=comm_email, weburl=comm_weburl, content=comm_content, ip=comment_ip)
                    comm.put()
                    t_values['alert_message'] = "Thanks %s for your comment!" % (comm_author)
                else:
                    logging.warning("comment ignored because antispam failed")
                    t_values['alert_message'] = "Sorry, your comment was ignored because of reCAPTCHA failure!"

                # find all comments
                comments = Comment.all().filter("entry =", post).order("date")
                logging.info("PostHandler, post, find %d comments" % (comments.count()))
                if post_id:
                    # only update commentcount when new comment is added
                    post.commentcount = comments.count()
                    post.put()
                t_values['comments'] = comments
            else:
                logging.warning("post_id %s does not exist" % (post_id))

            links = Link.all().order("date")
            t_values['links'] = links

            categories = Category.all()
            t_values['categories'] = categories
    
            pages = Entry.all().filter("is_external_page =", True).filter("entrytype =", 'page').order("date")
            t_values['pages'] = pages

            return self.response.out.write(render_template("post.html", t_values, "basic", False))
        else:
            self.redirect(uri_for("weblog.index"))
Exemplo n.º 9
0
 def get(self):
     links = Link.all()
     values = {'links': links}
     self.generateBasePage('manage/links.html', values)
     return
Exemplo n.º 10
0
 def get(self):
     links = Link.all()
     values = {'links':links}
     self.generateBasePage('manage/links.html', values)
     return