Example #1
0
 def remove_resource_tags(self, req, resource):
     req.perm(resource).require('TAGS_MODIFY')
     post = BlogPost(self.env, resource.id)
     if post.author == req.authname:
         req.perm(resource).require('BLOG_MODIFY_OWN')
     else:
         req.perm(resource).require('BLOG_MODIFY_ALL')
     post.categories = ""
     post.save(req.authname, 'Blog post categories removed via Tags plugin.')
Example #2
0
 def remove_resource_tags(self, req, resource):
     req.perm(resource).require('TAGS_MODIFY')
     post = BlogPost(self.env, resource.id)
     if post.author == req.authname:
         req.perm(resource).require('BLOG_MODIFY_OWN')
     else:
         req.perm(resource).require('BLOG_MODIFY_ALL')
     post.categories = ""
     post.save(req.authname,
               'Blog post categories removed via Tags plugin.')
Example #3
0
 def get_months_authors_categories(self, from_dt=None, to_dt=None,
                                             user=None, perm=None):
     """ Returns a structure of post metadata:
         ([ ((year1, month1), count), ((year1, month2), count) ], # newest first
          [ (author1, count), (author2, count) ],                 # alphabetical
          [ (category1, count), (category2, count) ],             # alphabetical
          total)                                                  # num of posts
     * Use 'from_dt' and 'to_dt' (datetime objects) to restrict search to
     posts with a publish_time within the intervals (None means ignore).
     * If user and perm is provided, the list is also filtered for permissions.
     * Note also that it only fetches from most recent version. """
     blog_posts = get_blog_posts(self.env, from_dt=from_dt, to_dt=to_dt)
     a_dict = {}
     c_dict = {}
     m_dict = {}
     total = 0
     for post in blog_posts:
         if user and perm:
             # Check permissions
             bp = BlogPost(self.env, post[0], post[1])
             if not 'BLOG_VIEW' in perm(bp.resource):
                 continue # Skip this post
         post_time = post[2]
         m_dict[(post_time.year, post_time.month)] = m_dict.get(
                 (post_time.year, post_time.month), 0) + 1
         author = post[3]
         a_dict[author] = a_dict.get(author, 0) + 1
         categories = post[6] # a list
         for category in set(categories):
             c_dict[category] = c_dict.get(category, 0) + 1
         total += 1
     return ([(m, m_dict.get(m, 0)) for m in sorted(m_dict.keys(), reverse=True)],
             [(a, a_dict.get(a, 0)) for a in sorted(a_dict.keys())],
             [(c, c_dict.get(c, 0)) for c in sorted(c_dict.keys())],
             total)
Example #4
0
 def get_resource_description(self, resource, format=None, context=None,
                              **kwargs):
     bp = BlogPost(self.env, resource.id, resource.version)
     if context:
         return tag.a('Blog: '+bp.title, href=context.href.blog(resource.id))
     else:
         return 'Blog: '+bp.title
Example #5
0
    def expand_macro(self, formatter, name, content):

        # Parse content for arguments
        args_list, args_dict = parse_args(content)
        from_dt, to_dt = parse_period(list(args_dict.get('period', '').split('/')))
        category = args_dict.get('category', '')
        author = args_dict.get('author', '')
        recent = int(args_dict.get('recent', 0))
        format = args_dict.get('format', 'inline').lower()
        heading = args_dict.get('heading', '')
        max_size = int(args_dict.get('max_size', 0))
        show_meta = args_dict.get('meta', '') != 'off' and True or False

        # Get blog posts
        all_posts = get_blog_posts(self.env, author=author, category=category,
                        from_dt=from_dt, to_dt=to_dt)

        # Trim posts against permissions and count
        post_list = []
        post_instances = []
        if format in ['float', 'full']:
            recent = recent or self.env.config.getint('fullblog', 'num_items_front')
        recent = recent or len(all_posts)
        count = 0
        for post in all_posts:
            if count == recent:
                break
            bp = BlogPost(self.env, post[0])
            if 'BLOG_VIEW' in formatter.req.perm(bp.resource):
                count += 1
                post_instances.append(bp)
                post_list.append(post)

        # Rendering
        add_stylesheet(formatter.req, 'tracfullblog/css/fullblog.css')
        add_stylesheet(formatter.req, 'common/css/code.css')

        if format == 'inline':
            data = {'heading': heading,
                    'posts': post_list,
                    'blog_personal_blog': self.config.getbool(
                                                'fullblog', 'personal_blog'),
                    'show_meta': show_meta,
                    'execute_blog_macro': True}
            return Chrome(self.env).render_template(formatter.req,
                    'fullblog_macro_monthlist.html', data=data, fragment=True)

        elif format == 'full':
            return self._render_full_format(formatter, post_list,
                                post_instances, heading, max_size, show_meta)

        elif format == 'float':
            # Essentially a 'full' list - just wrapped inside a new div
            return tag.div(self._render_full_format(formatter, post_list,
                                post_instances, heading, max_size, show_meta),
                            class_="blogflash")

        else:
            raise TracError("Invalid 'format' argument used for macro %s." % name)
Example #6
0
 def check_attachment_permission(self, action, username, resource, perm):
     """ Respond to the various actions into the legacy attachment
     permissions used by the Attachment module. """
     if resource.parent.realm == 'blog':
         if action == 'ATTACHMENT_VIEW':
             return 'BLOG_VIEW' in perm(resource.parent)
         if action in ['ATTACHMENT_CREATE', 'ATTACHMENT_DELETE']:
             if 'BLOG_MODIFY_ALL' in perm(resource.parent):
                 return True
             elif 'BLOG_MODIFY_OWN' in perm(resource.parent):
                 bp = BlogPost(self.env, resource.parent.id)
                 if bp.author == username:
                     return True
                 else:
                     return False
             else:
                 return False
Example #7
0
 def resource_exists(self, resource):
     bp = BlogPost(self.env, resource.id)
     return len(bp.versions)
Example #8
0
 def describe_tagged_resource(self, req, resource):
     # The plugin already uses the title as main description
     post = BlogPost(self.env, resource.id)
     chrome = Chrome(self.env)
     return "'" + resource.id + "' by " \
                                 + chrome.format_author(req, post.author)
Example #9
0
 def get_resource_tags(self, req, resource):
     req.perm(resource).require('BLOG_VIEW')
     req.perm(resource).require('TAGS_VIEW')
     return BlogPost(self.env, resource.id).category_list