Exemplo n.º 1
0
def write_files(journal, path, format):
    """Turns your journal into separate files for each entry.
    Format should be either json, md or txt."""
    make_filename = lambda entry: e.date.strftime("%C-%m-%d_{0}.{1}".format(slugify(u(e.title)), format))
    for e in journal.entries:
        full_path = os.path.join(path, make_filename(e))
        if format == 'json':
            content = json.dumps(e.to_dict(), indent=2) + "\n"
        elif format == 'md':
            content = e.to_md()
        elif format == 'txt':
            content = u(e)
        with open(full_path, 'w') as f:
            f.write(content)
    return "[Journal exported individual files in {0}]".format(path)
Exemplo n.º 2
0
    def make_link(m):
        url = m.group(1)
        proto = m.group(2)
        if require_protocol and not proto:
            return url  # not protocol, no linkify

        if proto and proto not in permitted_protocols:
            return url  # bad protocol, no linkify

        href = m.group(1)
        if not proto:
            href = "http://" + href   # no proto specified, use http

        if callable(extra_params):
            params = " " + extra_params(href).strip()
        else:
            params = extra_params

        # clip long urls. max_len is just an approximation
        max_len = 30
        if shorten and len(url) > max_len:
            before_clip = url
            if proto:
                proto_len = len(proto) + 1 + len(m.group(3) or "")  # +1 for :
            else:
                proto_len = 0

            parts = url[proto_len:].split("/")
            if len(parts) > 1:
                # Grab the whole host part plus the first bit of the path
                # The path is usually not that interesting once shortened
                # (no more slug, etc), so it really just provides a little
                # extra indication of shortening.
                url = url[:proto_len] + parts[0] + "/" + \
                    parts[1][:8].split('?')[0].split('.')[0]

            if len(url) > max_len * 1.5:  # still too long
                url = url[:max_len]

            if url != before_clip:
                amp = url.rfind('&')
                # avoid splitting html char entities
                if amp > max_len - 5:
                    url = url[:amp]
                url += "..."

                if len(url) >= len(before_clip):
                    url = before_clip
                else:
                    # full url is visible on mouse-over (for those who don't
                    # have a status bar, such as Safari by default)
                    params += ' title="%s"' % href

        return u('<a href="%s"%s>%s</a>') % (href, params, url)
Exemplo n.º 3
0
def write_files(journal, path, format):
    """Turns your journal into separate files for each entry.
    Format should be either json, md or txt."""
    make_filename = lambda entry: e.date.strftime("%Y-%m-%d_{0}.{1}".format(
        slugify(u(e.title)), format))
    for e in journal.entries:
        full_path = os.path.join(path, make_filename(e))
        if format == 'json':
            content = json.dumps(e.to_dict(), indent=2) + "\n"
        elif format in ('md', 'markdown'):
            content = e.to_md()
        elif format in ('txt', 'text'):
            content = e.__unicode__()
        with codecs.open(full_path, "w", "utf-8") as f:
            f.write(content)
    return "[Journal exported individual files in {0}]".format(path)
Exemplo n.º 4
0
 def post(self,entrytype):
   preview = self.request.get('preview')
   submitted = self.request.get('submitted')
   user = users.get_current_user()
   blog = Weblog()
   blog.title = self.request.get('title_input')
   blog.content = self.request.get('text_input')
   blog.author = user
   blog.authorEmail = user.email()
   blog.tags_commas = self.request.get('tags')
   if entrytype == 'page':
       blog.entrytype = entrytype
   template_values = {
     'entrytype': entrytype,
     'blog': blog,
     'preview': preview,
     'submitted': submitted,
     'action': "addBlog",
     'tags': self.request.get('tags'),
     }
   if preview == '1' and submitted !='1':
       self.generate('blog_add.html',template_values)
   else:
     if submitted =='1':
       try:
           permalink =  util.get_permalink(blog.date,translate.translate(util.u(blog.title,'utf-8')))
           if not permalink:
               raise Exception
       except Exception:
           template_values.update({'error':'Generate permanent link for blog error, please retry it.'})
           self.generate('blog_add.html',template_values)
           return
       #check the permalink duplication problem.
       maxpermalinkBlog = db.GqlQuery("select * from Weblog where permalink >= :1 and permalink < :2 order by permalink desc",permalink, permalink+u"\xEF\xBF\xBD").get()
       if maxpermalinkBlog is not None:
           permalink = maxpermalinkBlog.permalink+"1"
       blog.permalink =  permalink
       blog.save()
       util.flushBlogMonthCache(blog)
       util.flushBlogPagesCache()
       util.flushTagList()
       util.flushRecentFeatured()
       self.redirect('/'+blog.relative_permalink())
       return
Exemplo n.º 5
0
 def __init__(self):
     self.Util = u()
Exemplo n.º 6
0
 def __init__(self):
     self.colors = {}
     self.colors["grass"] = {"dark": (50, 248, 0), "light": (100, 248, 100)}
     self.Util = u()