コード例 #1
0
ファイル: web_ui.py プロジェクト: kzhamaji/TracFullBlogPlugin
 def _parse_path(self, req):
     """ Parses the request path for the blog and returns a
     ('command', 'pagename', 'path_items', 'listing_data') tuple. """
     # Parse out the path and actions from args
     path = req.args.get("blog_path", "")
     path_items = path.split("/")
     path_items = [item for item in path_items if item]  # clean out empties
     command = pagename = ""
     listing_data = {}
     from_dt, to_dt = parse_period(path_items)
     if not path_items:
         pass  # emtpy default for return is fine
     elif len(path_items) > 1 and path_items[0].lower() in ["view", "edit", "delete"]:
         command = path_items[0].lower()
         pagename = "/".join(path_items[1:])
     elif len(path_items) == 1 and path_items[0].lower() == "archive":
         command = path_items[0].lower()
     elif len(path_items) >= 1 and path_items[0].lower() == "create":
         command = path_items[0].lower()
         pagename = req.args.get("name", "") or (len(path_items) > 1 and "/".join(path_items[1:]))
     elif len(path_items) > 1 and path_items[0].lower() in ["author", "category"]:
         command = "listing" + "-" + path_items[0].lower()
         listing_data[path_items[0].lower()] = "/".join(path_items[1:])
     elif len(path_items) == 2 and (from_dt, to_dt) != (None, None):
         command = "listing-month"
         listing_data["from_dt"] = from_dt
         listing_data["to_dt"] = to_dt
     else:
         # A request for a regular page
         command = "view"
         pagename = path
     return (command, pagename, path_items, listing_data)
コード例 #2
0
ファイル: web_ui.py プロジェクト: renwofei423/tracfullblog
 def _parse_path(self, req):
     """ Parses the request path for the blog and returns a
     ('command', 'pagename', 'path_items', 'listing_data') tuple. """
     # Parse out the path and actions from args
     path = req.args.get('blog_path', '')
     path_items = path.split('/')
     path_items = [item for item in path_items if item] # clean out empties
     command = pagename = ''
     listing_data = {}
     from_dt, to_dt = parse_period(path_items)
     if not path_items:
         pass # emtpy default for return is fine
     elif len(path_items) > 1 and path_items[0].lower() in ['view', 'edit', 'delete']:
         command = path_items[0].lower()
         pagename = '/'.join(path_items[1:])
     elif len(path_items) == 1 and path_items[0].lower() == 'archive':
         command = path_items[0].lower()
     elif len(path_items) >= 1 and path_items[0].lower() == 'create':
         command = path_items[0].lower()
         pagename = req.args.get('name','') or (len(path_items) > 1 \
                                                 and '/'.join(path_items[1:]))
     elif len(path_items) > 1 and path_items[0].lower() in ['author', 'category']:
         command = 'listing' + '-' + path_items[0].lower()
         listing_data[path_items[0].lower()] = '/'.join(path_items[1:])
     elif len(path_items) == 2 and (from_dt, to_dt) != (None, None):
         command = 'listing-month'
         listing_data['from_dt'] = from_dt
         listing_data['to_dt'] = to_dt
     else:
         # A request for a regular page
         command = 'view'
         pagename = path
     return (command, pagename, path_items, listing_data)
コード例 #3
0
ファイル: macros.py プロジェクト: kzhamaji/TracFullBlogPlugin
    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)
コード例 #4
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)
コード例 #5
0
ファイル: core.py プロジェクト: constanine/trac-qd-proejct
 def _check_new_postname(self, req, name):
     """ Does some checking on the postname to make sure it does
     not conflict with existing commands. """
     warnings = []
     name = name.lower()
     # Reserved names
     for rn in self.reserved_names:
         if name == rn:
             warnings.append(('',
                 "'%s' is a reserved name. Please change." % name))
         if name.startswith(rn + '/'):
             warnings.append(('',
                 "Name cannot start with a reserved name as first item in "
                 "path ('%s'). Please change." % rn))
     # Check to see if it is a date range
     items = name.split('/')
     if len(items) == 2 and parse_period(items) != (None, None):
         warnings.append(('',
             "'%s' is seen as a time period, and cannot "
             "be used as a name. Please change." % name))        
     return warnings
コード例 #6
0
 def _parse_path(self, req):
     """ Parses the request path for the blog and returns a
     ('command', 'pagename', 'path_items', 'listing_data') tuple. """
     # Parse out the path and actions from args
     path = req.args.get('blog_path', '')
     path_items = path.split('/')
     path_items = [item for item in path_items if item]  # clean out empties
     command = pagename = ''
     listing_data = {}
     from_dt, to_dt = parse_period(path_items)
     if not path_items:
         pass  # emtpy default for return is fine
     elif len(path_items) > 1 and path_items[0].lower() in [
             'view', 'edit', 'delete'
     ]:
         command = path_items[0].lower()
         pagename = '/'.join(path_items[1:])
     elif len(path_items) == 1 and path_items[0].lower() == 'archive':
         command = path_items[0].lower()
     elif len(path_items) >= 1 and path_items[0].lower() == 'create':
         command = path_items[0].lower()
         pagename = req.args.get('name','') or (len(path_items) > 1 \
                                                 and '/'.join(path_items[1:]))
     elif len(path_items) > 1 and path_items[0].lower() in [
             'author', 'category'
     ]:
         command = 'listing' + '-' + path_items[0].lower()
         listing_data[path_items[0].lower()] = '/'.join(path_items[1:])
     elif len(path_items) == 2 and (from_dt, to_dt) != (None, None):
         command = 'listing-month'
         listing_data['from_dt'] = from_dt
         listing_data['to_dt'] = to_dt
     else:
         # A request for a regular page
         command = 'view'
         pagename = path
     return (command, pagename, path_items, listing_data)