def no_need_buy(self, post): if self.power == "admin": return True if post["user"] == self.current_user["username"]: return True if "buyer" in post and self.current_user["username"] in post["buyer"]: return True now = int(humantime(time.time(), "%H")) if post["freebegin"] <= now < post["freeend"]: return True return False
def save_image_local(self, url): if url == '404': return '{}/face/404.png'.format(self.settings["static_path"]) else: now = time.time() folder = "%s/%s/%s" % (self.settings["imagepath"], humantime(now, "%Y%m"), humantime(now, "%d")) if not os.path.isdir(folder): os.makedirs(folder) filename = url[url.rfind('/') + 1:] image = '{}/{}'.format(folder, filename) r = requests.get(url, stream=True) if r.status_code == 200: with open(image, 'wb') as f: r.raw.decode_content = True shutil.copyfileobj(r.raw, f) return image
def post(self, *args, **kwargs): now = time.time() try: if self.request.files: file = self.request.files['upload'][0] ext = os.path.splitext(file["filename"])[-1] if ext not in (".png", ".gif", ".jpg", ".bmp", ".jpeg"): self.end(False, u"不允许上传此类后缀的文件哦") self.orgname = file["filename"] filename = md5("%s%s" % (file["filename"], random_str(6))) + ext folder = "%s/%s/%s" % (self.settings["imagepath"], humantime(now, "%Y%m"), humantime(now, "%d")) if not os.path.isdir(folder): os.makedirs(folder) filename = "%s/%s" % (folder, filename) with open(filename, "wb") as fin: fin.write(file["body"]) self.end(True, u"上传成功", filename) except tornado.web.Finish, e: pass
def post(self, *args, **kwargs): now = time.time() try: if self.request.files: file = self.request.files['upload'][0] ext = os.path.splitext(file["filename"])[-1] if ext not in (".png", ".gif", ".jpg", ".bmp", ".jpeg"): self.end(False, u"不允许上传此类后缀的文件哦") self.orgname = file["filename"] filename = md5("%s%s" % (file["filename"], random_str(6))) + ext folder = "%s/%s/%s" % (self.settings["imagepath"], humantime(now, "%Y%m"), humantime(now, "%d")) if not os.path.isdir(folder): os.makedirs(folder) filename = "%s/%s" % (folder, filename) with open(filename, "wb") as fin: fin.write(file["body"]) self.end(True, u"上传成功", filename) except tornado.web.Finish, e: pass
def get(self, *args, **kwargs): tag = args[0] tag_query = Tag.select().where(Tag.content == tag).first() if tag_query: archives2tag_query = Archive2Tag.select(Archive2Tag.archive_id).where(Archive2Tag.tag_id == tag_query.id) archive_ids = [one.archive_id for one in archives2tag_query] archives = Archive.select().where( (Archive.id << archive_ids) & (Archive.status == 1) & (Archive.type == 0)).order_by( Archive.published_time.desc()) archives_groups = [{'year': year, 'archives': list(archives)} for year, archives in groupby(archives, key=lambda a: humantime(a.published_time, "%Y"))] self.render("timeline.html", archives_groups=archives_groups, first_title="Tag: %s" % tag)
def save_image_local(self, url): if url == '404': return '{}/face/404.png'.format(self.settings["static_path"]) else: now = time.time() folder = "%s/%s/%s" % (self.settings["imagepath"], humantime(now, "%Y%m"), humantime( now, "%d")) if not os.path.isdir(folder): os.makedirs(folder) filename = url[url.rfind('/') + 1:] image = '{}/{}'.format(folder, filename) r = requests.get(url, stream=True) if r.status_code == 200: with open(image, 'wb') as f: r.raw.decode_content = True shutil.copyfileobj(r.raw, f) return image
def get(self, *args, **kwargs): archives = Archive.select().where((Archive.status == 1) & (Archive.type == 0)).order_by( Archive.published_time.desc()) archives_groups = [{'year': year, 'archives': list(archives)} for year, archives in groupby(archives, key=lambda a: humantime(a.published_time, "%Y"))] self.render("timeline.html", archives_groups=archives_groups, first_title="Archives")