|
131 | 131 | { |
132 | 132 | "data": { |
133 | 133 | "text/plain": [ |
134 | | - "datetime.datetime(2025, 9, 12, 14, 0)" |
| 134 | + "datetime.datetime(2025, 9, 11, 14, 0)" |
135 | 135 | ] |
136 | 136 | }, |
137 | 137 | "execution_count": null, |
|
1725 | 1725 | " if not resp: resp = await _wrap_call(f, req, sig.parameters)\n", |
1726 | 1726 | " for a in self.after:\n", |
1727 | 1727 | " wreq = await _wrap_req(req, _params(a))\n", |
| 1728 | + " wreq['resp'] = resp\n", |
1728 | 1729 | " nr = a(**wreq)\n", |
1729 | 1730 | " if nr: resp = nr\n", |
1730 | 1731 | " return _resp(req, resp, sig.return_annotation)\n", |
|
2878 | 2879 | "name": "stdout", |
2879 | 2880 | "output_type": "stream", |
2880 | 2881 | "text": [ |
2881 | | - "Set to 2025-09-12 08:12:01.314167\n" |
| 2882 | + "Set to 2025-09-11 16:36:20.106162\n" |
2882 | 2883 | ] |
2883 | 2884 | }, |
2884 | 2885 | { |
2885 | 2886 | "data": { |
2886 | 2887 | "text/plain": [ |
2887 | | - "'Session time: 2025-09-12 08:12:01.314167'" |
| 2888 | + "'Session time: 2025-09-11 16:36:20.106162'" |
2888 | 2889 | ] |
2889 | 2890 | }, |
2890 | 2891 | "execution_count": null, |
|
3081 | 3082 | "outputs": [], |
3082 | 3083 | "source": [ |
3083 | 3084 | "app,cli,rt = get_cli(FastHTML())\n", |
3084 | | - "setup_toasts(app)\n", |
| 3085 | + "\n", |
| 3086 | + "# Modified toast functions to test resp logic\n", |
| 3087 | + "def toast_after_(resp, req, sess):\n", |
| 3088 | + " if sk in sess and (not resp or isinstance(resp, (tuple,FT,FtResponse))):\n", |
| 3089 | + " sess['toast_duration'] = req.app.state.toast_duration\n", |
| 3090 | + " # We will activate the toast depending on the content of the response\n", |
| 3091 | + " if str('love') in str(resp): req.injects.append(render_toasts(sess))\n", |
| 3092 | + "\n", |
| 3093 | + "def setup_toasts_(app, duration=5000):\n", |
| 3094 | + " app.state.toast_duration = duration\n", |
| 3095 | + " app.hdrs += [Style(toast_css), Script(js)]\n", |
| 3096 | + " app.after.append(toast_after_)\n", |
| 3097 | + "\n", |
| 3098 | + "setup_toasts_(app)\n", |
| 3099 | + "\n", |
| 3100 | + "tm = 'Here is a toast!'\n", |
3085 | 3101 | "\n", |
3086 | 3102 | "@rt(\"/\")\n", |
3087 | 3103 | "def index(sess): \n", |
3088 | | - " add_toast(sess, \"Successful Page Load!\", \"success\")\n", |
| 3104 | + " add_toast(sess, tm, \"success\")\n", |
3089 | 3105 | " return P(\"I love toast!\")\n", |
3090 | 3106 | "\n", |
| 3107 | + "@rt(\"/no-toast\")\n", |
| 3108 | + "def no_toast(sess):\n", |
| 3109 | + " add_toast(sess, tm, \"success\")\n", |
| 3110 | + " return P(\"I hate toast!\")\n", |
| 3111 | + "\n", |
3091 | 3112 | "r = cli.get('/')\n", |
3092 | | - "assert 'Successful Page Load!' in r.text" |
| 3113 | + "assert tm in r.text\n", |
| 3114 | + "r = cli.get('/no-toast')\n", |
| 3115 | + "assert not tm in r.text" |
3093 | 3116 | ] |
3094 | 3117 | }, |
3095 | 3118 | { |
|
0 commit comments