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 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.º 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_id="", operation=""):
        # find all comments, and list all comments
        t_values = {}
        logging.info("CommentManager get")

        # show all comments
        comments = Comment.all().order("entry")
        t_values['comments'] = comments
        return self.response.out.write(render_template("comments.html", t_values, "", True))
Exemplo n.º 5
0
def getRecentComment():
  key_ = "recent_comments"
  comms = memcache.get(key_)
  if comms is not None:
    return comms
  else:
    comms = Comment.all().order('-date').fetch(8)
    for comm in comms:
      comm.content = re.sub(u'<[^>]*?>','',comm.content)[:50]
    if not memcache.add(key_, comms, 3600):
      logging.error("Memcache set failed.")
    return comms
Exemplo n.º 6
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.º 7
0
  def get(self):  
    current_user = users.get_current_user()
    votes = Votes.for_user(current_user)
    
    team_comments = {}
    user_comments = {}
      
    if shouldShowComments():
      comments = Comment.all()
      for comment in comments:
        team_key = str(comment.team.key())
        comment.author_name = generateCommentAuthorName(comment)
        if not team_key in team_comments:
          team_comments[team_key] = []
        if comment.user == current_user:
          user_comments[team_key] = comment
        team_comments[team_key].append(comment)
            
    all_teams = filter_hidden(Team.all().fetch(1000))
    for team in all_teams:
      team.voted = (team.key() in votes.local_teams or team.key() in votes.teams)
      team_key = str(team.key())
      if shouldShowComments():
        if team_key in team_comments:
          team.comments = team_comments[team_key]
        if team_key in user_comments:
          team.user_comment = user_comments[team_key].text
    
    logout_url = users.create_logout_url("/")

    winning_teams = filter(lambda x: config['highlight_winners'] and x.annotation is not None and x.annotation != '', all_teams)
    all_teams = filter(lambda x: x not in winning_teams, all_teams)

    # Disable randomness for commenting always
    if config["list_teams_randomly"] and not shouldEnableCommenting():
      random.shuffle(all_teams)
      random.shuffle(winning_teams)
      
    self.render('list', { 'teams': all_teams,
                          'winning_teams': winning_teams,
                          'votes': votes,
                          'team_comments': team_comments,
                          'user_comments': user_comments,
                          'highlight_winners': config['highlight_winners'],
                          'enable_voting': config['enable_voting'],
                          'enable_commenting': shouldEnableCommenting(),
                          'show_winner_entry': config['show_winner_entry'],
                          'logout_url': logout_url })
Exemplo n.º 8
0
  def get(self):  
    current_user = users.get_current_user()
    votes = Votes.for_user(current_user)
    
    team_comments = {}
    user_comments = {}
      
    if shouldShowComments():
      comments = Comment.all()
      for comment in comments:
        team_key = str(comment.team.key())
        comment.author_name = comment.user.nickname().split('@', 1)[0]
        if not team_key in team_comments:
          team_comments[team_key] = []
        if comment.user == current_user:
          user_comments[team_key] = comment
        team_comments[team_key].append(comment)
            
    all_teams = Team.all().fetch(1000)
    for team in all_teams:
      team.voted = (team.key() in votes.local_teams or team.key() in votes.teams)
      team_key = str(team.key())
      if shouldShowComments():
        if team_key in team_comments:
          team.comments = team_comments[team_key]
        if team_key in user_comments:
          team.user_comment = user_comments[team_key].text
    
    logout_url = users.create_logout_url("/")

    # Disable randomness for commenting always
    if config["list_teams_randomly"] and not shouldEnableCommenting():
      random.shuffle(all_teams)
      
    self.render('list', { 'teams': all_teams,
                          'votes': votes,
                          'team_comments': team_comments,
                          'user_comments': user_comments,
                          'enable_voting': config['enable_voting'],
                          'enable_commenting': shouldEnableCommenting(),
                          'logout_url': logout_url })
Exemplo n.º 9
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.º 10
0
 def get(self):
     comments = Comment.all().order('-commentTime')
     values = {'comments': comments}
     self.generateBasePage('manage/comments.html', values)
     return
Exemplo n.º 11
0
 def get(self):
     comments=Comment.all().order('-commentTime')
     values = {'comments':comments}
     self.generateBasePage('manage/comments.html', values)
     return