Exemplo n.º 1
0
 async def _import(self, app: App, session: Session):
     """
     导入文章
     :param app:
     :param session:
     :return: 导入文章页面
     """
     if not session.get("login"):
         return app.render_template("login.html", ref="import")
     else:
         return app.render_template("import.html", success="")
Exemplo n.º 2
0
 async def edit(self, app: App, id: http.QueryParam, session: Session):
     """
     打开文章编辑页面
     :param app:
     :param id: 文章的id
     :ex id: `20111111111111`
     :param session:
     :return: 如果登录了,跳转到编辑页面,否则,跳转到登录页。
     """
     article = await Article.load(id=id)
     if not session.get("login"):
         return app.render_template("login.html", ref="edit", **article)
     else:
         return app.render_template("edit.html", ref="update", **article)
Exemplo n.º 3
0
    async def upload(self, app: App, article: Article, session: Session):
        """
        用于上传文章
        :param app:
        :param article: 文章相关信息
        :type article: form
        :param session:
        :return: 返回上传页面继续上传
        """
        if not session.get("login"):
            return app.render_template("login.html", ref="import")

        await self.service.upload(article)
        return app.render_template("import.html", success="success")
Exemplo n.º 4
0
 async def check(app: App, article: Article, username: FormParam,
                 password: FormParam, ref: FormParam,
                 settings: FrozenSettings, session: Session):
     if username == settings.USERNAME and password == settings.PASSWORD:
         session["login"] = f'{username}:{password}'
         if hasattr(article, "id"):
             article = await article.load()
         return app.render_template(f"{ref}.html",
                                    success="",
                                    ref=ref,
                                    **article.to_dict())
     else:
         return app.render_template("login.html",
                                    ref=ref,
                                    **article.to_dict())
Exemplo n.º 5
0
def serve_documentation(app: App):
    template_name = 'apistar/docs/index.html'
    code_style = pygments_css('emacs')
    return app.render_template(template_name,
                               document=app.document,
                               langs=['javascript', 'python'],
                               code_style=code_style)
Exemplo n.º 6
0
 async def delete(app: App, article: Article, service: ArticleService,
                  session: Session):
     if not session.get("login"):
         return app.render_template("login.html",
                                    ref="delete",
                                    id=article.id)
     await service.delete(article)
     return redirect(app.reverse_url("view:welcome:index"))
Exemplo n.º 7
0
def article(app: App, article_id: int, session: Session):
    """Article page."""
    article = models.Article.find(id=article_id)

    if not article:
        raise NotFound

    return app.render_template('article.html', article=article)
Exemplo n.º 8
0
 def index(app: App, path: QueryParam, settings: FrozenSettings):
     return app.render_template(
         'index.html',
         author=settings.AUTHOR,
         _path=path or "",
         page_size=settings.PAGE_SIZE,
         url_for=app.reverse_url,
         code_swatch="true" if settings.get_bool("NEED_CODE") else "false")
Exemplo n.º 9
0
def serve_documentation(app: App):
    template_name = "apistar/docs/index.html"
    code_style = None  # pygments_css('emacs')
    return app.render_template(
        template_name,
        document=app.document,
        langs=["javascript", "python"],
        code_style=code_style,
    )
Exemplo n.º 10
0
    async def update(self, app: App, article: Article, session: Session):
        """
        编辑之后更新文章内容
        :param app:
        :param article: 文章对象
        :type article: form
        :param session:
        :return: 如果登录了,跳转到首页,否则,跳转到登录页
        """
        if not session.get("login"):
            return app.render_template("login.html", ref="edit", **article)

        await self.service.update(article)
        return redirect(app.reverse_url("view:welcome:index"))
Exemplo n.º 11
0
    async def delete(self, app: App, id: http.QueryParam, session: Session):
        """
        删除文章接口
        :param app:
        :param id: 要删除的文章id
        :ex id: `19911111111111`
        :param session:
        :return: 如果登录了,跳转到首页,否则跳转到登录页。
        """
        article = Article(id=id)
        if not session.get("login"):
            return app.render_template("login.html",
                                       ref="delete",
                                       id=article.id)

        await self.service.delete(article)
        return redirect(app.reverse_url("view:welcome:index"))
Exemplo n.º 12
0
 def index(self, app: App, path: QueryParam = None) -> str:
     """
     首页
     :param app:
     :param path: 子路径
     :ex path:
     `"/article?a=3"`
     :param settings: 配置信息
     :return:
     ```html
     <html>...</html>
     ```
     """
     return app.render_template('index.html',
                                author=settings["AUTHOR"],
                                _path=path or "",
                                page_size=settings["PAGE_SIZE"],
                                url_for=app.reverse_url,
                                code_swatch=str(
                                    settings.get_bool("NEED_CODE")).lower())
Exemplo n.º 13
0
 async def upload(app: App, article: Article, session: Session):
     if not session.get("login"):
         return app.render_template("login.html", ref="import")
     await article.save()
     return app.render_template("import.html", success="success")
Exemplo n.º 14
0
def template_handler(app: App, name: str = None) -> http.HTMLResponse:
    return http.HTMLResponse(app.render_template('test.html', name=name))
Exemplo n.º 15
0
def home(app: App):
    return app.render_template('home.html')
Exemplo n.º 16
0
class ActionPiAPI(object):
    def __init__(self,
                 camera: ActionPiCamera,
                 host: str,
                 port: int,
                 debug=False):
        self._camera = camera
        self._host = host
        self._port = port
        self._debug = debug

        #Declaring routes
        _routes = [
            Route('/api/start', method='GET', handler=self._start_recording),
            Route('/api/stop', method='GET', handler=self._stop_recording),
            Route('/api/status', method='GET', handler=self._get_status),
            Route('/api/set', method='GET', handler=self._set),
            Route('/api/halt', method='GET', handler=self._halt),
            Route('/control', method='GET', handler=self._control),
        ]

        #Serving static files
        base_dir = os.path.dirname(__file__)
        static_dir = os.path.join(base_dir, 'static')
        templates_dir = os.path.join(base_dir, 'templates')

        self._api = App(routes=_routes,
                        static_dir=static_dir,
                        template_dir=templates_dir)

    def _start_recording(self):
        self._camera.start_recording()

    def _stop_recording(self):
        self._camera.stop_recording()

    def _set(self, val: int):
        #TODO add more logic if needed in future
        self._camera.change_framerate(val)

    def _get_status(self) -> dict:
        return {
            'system': {
                'cpu_temperature': get_cpu_temp(),
                'cpu_load': psutil.cpu_percent(interval=None),
                'mem_usage': psutil.virtual_memory().percent,
                'disk_usage': psutil.disk_usage('/').percent
            },
            'recording': self._camera.is_recording(),
            'framerate': self._camera.get_framerate()
        }

    def _control(self):
        return self._api.render_template('index.html', app=app)

    def _halt(self):
        halt_system()

    def serve(self):
        self._api.serve(self._host, self._port, self._debug)

    def close(self):
        pass
Exemplo n.º 17
0
 def main(self, app: App, path: str = ""):
     """
     Admin main page presenting a list of resources.
     """
     return app.render_template("apistar_crud/admin.html")
Exemplo n.º 18
0
def serve_documentation(app: App):
    template_name = 'apistar/docs/index.html'
    return app.render_template(template_name, document=app.document)
Exemplo n.º 19
0
def index(app: App, request: http.Request) -> dict:
    return app.render_template("tmp1.html")
Exemplo n.º 20
0
def home(app: App, session: Session):
    """Blog homepage."""
    articles = models.Article.all()
    return app.render_template('home.html', articles=articles)
Exemplo n.º 21
0
def welcome(app: App, name=None):
    return app.render_template('index.php', name=name)
Exemplo n.º 22
0
def index(app: App) -> str:
    return app.render_template("index.html")
Exemplo n.º 23
0
 async def edit(app: App, article: Article, session: Session):
     await article.load()
     if not session.get("login"):
         return app.render_template("login.html", ref="edit", **article)
     else:
         return app.render_template("edit.html", ref="update", **article)