예제 #1
0
파일: tmp.py 프로젝트: nod/site33
    def post(self):
        randname = self.get_argument('random', False)
        hum = self.get_argument('human','')
        is_json = self.get_argument('json', False)
        if not human.verify(hum):
            return self.write('fail')
        tmp_ = gen_key()
        dest_dir = '{}/{}'.format(
            self.application.settings.get('tmpdown'),
            tmp_ )
        mkdir(dest_dir)
        fff = self.request.files['upfile'][0]
        fn = fff['filename']
        parts = (fn or 'up.file').split('.')
        if randname:
            fname = '{}.{}'.format(gen_key(), slugify(parts[-1]))
        else:
            if len(parts) > 1:
                fname = slugify(''.join(parts[:-1])) + "." + slugify(parts[-1])
            else: fname = slugify(parts[0])
        fh = open('{}/{}'.format(dest_dir, fname), 'wb')
        fh.write(fff['body'])
        fh.close()
        fileuri = "https://33ad.org/tmp/%s/%s" % (tmp_, fname)

        if is_json:
            self.write(json_dumps({ 'uri': fileuri }))
        else:
            self.render(
                'tmp_done.html',
                fileuri = fileuri,
                )
예제 #2
0
파일: bloglib.py 프로젝트: nod/site33
 def new_post(self, title, content, tags=None, c_at=None):
     if not isinstance(c_at, datetime): c_at = datetime.now()
     slug = '{}-{}'.format(c_at.year, str(slugify(title)))
     while slug in self: slug += '_'
     post_ = BlogPost(
         title = title,
         text = content,
         tags = tags,
         slug = slug,
         c_at = c_at,
         )
     self.save(post_)
     return slug, post_