| 127 | |
| 128 | |
| 129 | class BlogEditFormState(BlogPostState): |
| 130 | form_data: dict = {} |
| 131 | # post_content: str = "" |
| 132 | |
| 133 | @rx.var |
| 134 | def publish_display_date(self) -> str: |
| 135 | # return "2023-12-01" # YYYY-MM-DD |
| 136 | if not self.post: |
| 137 | return datetime.now().strftime("%Y-%m-%d") |
| 138 | if not self.post.publish_date: |
| 139 | return datetime.now().strftime("%Y-%m-%d") |
| 140 | return self.post.publish_date.strftime("%Y-%m-%d") |
| 141 | |
| 142 | @rx.var |
| 143 | def publish_display_time(self) -> str: |
| 144 | if not self.post: |
| 145 | return datetime.now().strftime("%H:%M:%S") |
| 146 | if not self.post.publish_date: |
| 147 | return datetime.now().strftime("%H:%M:%S") |
| 148 | return self.post.publish_date.strftime("%H:%M:%S") |
| 149 | |
| 150 | def handle_submit(self, form_data): |
| 151 | self.form_data = form_data |
| 152 | post_id = form_data.pop('post_id') |
| 153 | publish_date = None |
| 154 | if 'publish_date' in form_data: |
| 155 | publish_date = form_data.pop('publish_date') |
| 156 | publish_time = None |
| 157 | if 'publish_time' in form_data: |
| 158 | publish_time = form_data.pop('publish_time') |
| 159 | publish_input_string = f"{publish_date} {publish_time}" |
| 160 | try: |
| 161 | final_publish_date = datetime.strptime(publish_input_string, '%Y-%m-%d %H:%M:%S') |
| 162 | except: |
| 163 | final_publish_date = None |
| 164 | publish_active = False |
| 165 | if 'publish_active' in form_data: |
| 166 | publish_active = form_data.pop('publish_active') == "on" |
| 167 | updated_data = {**form_data} |
| 168 | updated_data['publish_active'] = publish_active |
| 169 | updated_data['publish_date'] = final_publish_date |
| 170 | self.save_post_edits(post_id, updated_data) |
| 171 | return self.to_blog_post() |
nothing calls this directly
no outgoing calls
no test coverage detected