Exemplo n.º 1
0
 def update_image(self):
     if web.ctx.method == "POST":
         image_id = web.input().get("image_id", None)
         link_url = web.input().get('link', '').strip()
         album_id = int(web.input().get('album_id'))
         file = web.input().get("file")
         try:
             flink = Images.get_or_none(Images.id == int(image_id))
             if flink:
                 f = HttpUploadedFile(file)
                 self.record_image(f=file,
                                   uuid=f.uuid(),
                                   link=link_url,
                                   call_type='update',
                                   album_id=album_id,
                                   image_id=image_id)
                 self.private_data["update_success"] = True
                 return web.seeother(self.make_url('images_list'))
         except Exception as e:
             log.error('create album failed%s' % traceback.format_exc())
             self.private_data["update_success"] = False
             self.private_data["update_message"] = u"更新相册失败"
             return web.seeother(
                 self.make_url('update_image', {'image_id': image_id}))
     if web.ctx.method == "GET":
         image_id = web.input().get("image_id", None)
         if not image_id or not image_id.isdigit():
             self.private_data["update_success"] = False
             self.private_data["update_message"] = u"参数有误"
             return web.seeother(self.make_url('images_list'))
         f_image = Images.get_or_none(Images.id == int(image_id))
         if not f_image:
             return web.seeother(self.make_url('images_list'))
         albums = Albums.select().where(Albums.status == 0). \
             order_by(Albums.id.asc()).execute()
         self.private_data["albums_list"] = albums
         self.private_data["image"] = f_image
         return self.display("admin/update_image")
Exemplo n.º 2
0
 def create_article(self):
     if web.ctx.method == "GET":
         category_list = Categories.select().where(Categories.status == 0)
         self.private_data["category_list"] = category_list
         return self.display("admin/create_article")
     else:
         inputs = self.get_input()
         title = inputs.get('name')
         content = inputs.get('content')
         summary = inputs.get("summary")
         category_id = inputs.get("category_id")
         source_url = inputs.get("source_url", "")
         keywords = str(inputs.get("keywords", "")).strip()
         image = Images.get_or_none()
         category = Categories.get_or_none(Categories.id == category_id)
         try:
             tags_list = keywords.split(",") if keywords else []
             if tags_list:
                 got_tags = Tags.select().where(Tags.name.in_(tags_list))
                 tmp_list = []
                 for tag in got_tags:
                     tmp_list.append(tag.name)
                 for tag_str in tags_list:
                     if tag_str not in tmp_list:
                         t = Tags(name=tag_str)
                         t.save()
                 db = TinyDB('settings/db.json')
                 db.truncate()
                 db.close()
             article = Articles(name=title,
                                content=content,
                                summary=summary,
                                category=category,
                                original_address=source_url,
                                keywords=keywords,
                                thumbnail=image)
             article.save()
             self.private_data["create_success"] = True
             return web.seeother(self.make_url('articles'))
         except Exception as e:
             log.error('create article failed %s' % traceback.format_exc())
             log.error('input params %s' % inputs)
             self.private_data["create_success"] = False
             return self.display("admin/create_article")
def index(image_id):
    image = Images.get_or_none(Images.id == image_id)

    return render_template("/donations/index.html", image=image)