diff --git a/.gitignore b/.gitignore index 95e538e..13f83c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ +.states +assets/external/ *.db *.py[cod] .web __pycache__/ venv/ alembic/ -alembic.ini \ No newline at end of file +alembic.ini diff --git a/full_stack_python/articles/state.py b/full_stack_python/articles/state.py index e8119eb..286c18b 100644 --- a/full_stack_python/articles/state.py +++ b/full_stack_python/articles/state.py @@ -21,11 +21,11 @@ class ArticlePublicState(SessionState): limit: int = 20 @rx.var - def post_id(self): - return self.router.page.params.get("post_id", "") + def post_id(self) -> str: + return self.post_id_web @rx.var - def post_url(self): + def post_url(self) -> str: if not self.post: return f"{ARTICLE_LIST_ROUTE}" return f"{ARTICLE_LIST_ROUTE}/{self.post.id}" diff --git a/full_stack_python/auth/state.py b/full_stack_python/auth/state.py index cf8d6a4..eabe88c 100644 --- a/full_stack_python/auth/state.py +++ b/full_stack_python/auth/state.py @@ -9,25 +9,25 @@ class SessionState(reflex_local_auth.LocalAuthState): - @rx.cached_var - def my_userinfo_id(self) -> str | None: + @rx.var(cache=True) + def my_userinfo_id(self) -> int | None: if self.authenticated_user_info is None: return None return self.authenticated_user_info.id - @rx.cached_var - def my_user_id(self) -> str | None: + @rx.var(cache=True) + def my_user_id(self) -> int | None: if self.authenticated_user.id < 0: return None return self.authenticated_user.id - @rx.cached_var + @rx.var(cache=True) def authenticated_username(self) -> str | None: if self.authenticated_user.id < 0: return None return self.authenticated_user.username - @rx.cached_var + @rx.var(cache=True) def authenticated_user_info(self) -> UserInfo | None: if self.authenticated_user.id < 0: return None diff --git a/full_stack_python/blog/state.py b/full_stack_python/blog/state.py index 00f7bca..053c8ea 100644 --- a/full_stack_python/blog/state.py +++ b/full_stack_python/blog/state.py @@ -20,17 +20,17 @@ class BlogPostState(SessionState): post_publish_active: bool = False @rx.var - def blog_post_id(self): - return self.router.page.params.get("blog_id", "") + def blog_post_id(self) -> str: + return self.blog_id @rx.var - def blog_post_url(self): + def blog_post_url(self) -> str: if not self.post: return f"{BLOG_POSTS_ROUTE}" return f"{BLOG_POSTS_ROUTE}/{self.post.id}" @rx.var - def blog_post_edit_url(self): + def blog_post_edit_url(self) -> str: if not self.post: return f"{BLOG_POSTS_ROUTE}" return f"{BLOG_POSTS_ROUTE}/{self.post.id}/edit" @@ -113,6 +113,12 @@ def to_blog_post(self, edit_page=False): return rx.redirect(f"{self.blog_post_edit_url}") return rx.redirect(f"{self.blog_post_url}") + def set_post_content(self, value: str): + self.post_content = value + + def set_post_publish_active(self, value: bool): + self.post_publish_active = value + class BlogAddPostFormState(BlogPostState): form_data: dict = {} diff --git a/full_stack_python/contact/state.py b/full_stack_python/contact/state.py index c04b5d6..89bccfe 100644 --- a/full_stack_python/contact/state.py +++ b/full_stack_python/contact/state.py @@ -14,7 +14,7 @@ class ContactState(SessionState): did_submit: bool = False @rx.var - def thank_you(self): + def thank_you(self) -> str: first_name = self.form_data.get("first_name") or "" return f"Thank you {first_name}".strip() + "!" diff --git a/full_stack_python/full_stack_python.py b/full_stack_python/full_stack_python.py index abfec7e..ba8957c 100644 --- a/full_stack_python/full_stack_python.py +++ b/full_stack_python/full_stack_python.py @@ -81,7 +81,7 @@ def index() -> rx.Component: app.add_page( article_detail_page, - route=f"{navigation.routes.ARTICLE_LIST_ROUTE}/[post_id]", + route=f"{navigation.routes.ARTICLE_LIST_ROUTE}/[post_id_web]", on_load=ArticlePublicState.get_post_detail ) diff --git a/requirements.txt b/requirements.txt index d814c65..5c67d8f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -reflex==0.5.3 +reflex==0.8.18 reflex-local-auth \ No newline at end of file diff --git a/rxconfig.py b/rxconfig.py index 8b637b5..7e40f93 100644 --- a/rxconfig.py +++ b/rxconfig.py @@ -2,5 +2,9 @@ config = rx.Config( app_name="full_stack_python", - db_url="sqlite:///reflex.db", + db_url="sqlite:///reflex.db", + plugins=[ + rx.plugins.SitemapPlugin(), + rx.plugins.TailwindV4Plugin(), + ], ) \ No newline at end of file