Mercurial Hosting > lang
comparison src/edit_course.html.luan @ 24:87fe70201aa8
courses work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 31 Jul 2025 22:30:26 -0600 |
parents | |
children | 3a80ddafe5a4 |
comparison
equal
deleted
inserted
replaced
23:0c17c233c45a | 24:87fe70201aa8 |
---|---|
1 local Luan = require "luan:Luan.luan" | |
2 local error = Luan.error | |
3 local Html = require "luan:Html.luan" | |
4 local html_encode = Html.encode or error() | |
5 local Io = require "luan:Io.luan" | |
6 local Http = require "luan:http/Http.luan" | |
7 local Shared = require "site:/lib/Shared.luan" | |
8 local head = Shared.head or error() | |
9 local header = Shared.header or error() | |
10 local User = require "site:/lib/User.luan" | |
11 local current_user = User.current_required or error() | |
12 local Course = require "site:/lib/Course.luan" | |
13 local get_course_by_id = Course.get_by_id or error() | |
14 | |
15 | |
16 return function() | |
17 local user = current_user() | |
18 if user == nil then return end | |
19 local course_id = Http.request.parameters.course | |
20 local course | |
21 if course_id ~= nil then | |
22 course = get_course_by_id(course_id) or error() | |
23 course.user_id == user.id or error() | |
24 else | |
25 course = Course.new{ | |
26 language = Http.request.parameters.language or error() | |
27 name = "" | |
28 ai_system_prompt = "" | |
29 } | |
30 end | |
31 Io.stdout = Http.response.text_writer() | |
32 %> | |
33 <!doctype html> | |
34 <html lang="en"> | |
35 <head> | |
36 <% head() %> | |
37 <style> | |
38 label, | |
39 input, | |
40 textarea { | |
41 display: block; | |
42 } | |
43 </style> | |
44 </head> | |
45 <body> | |
46 <% header() %> | |
47 <form content onsubmit="ajaxForm('/save_course.js',this)" action="javascript:"> | |
48 <h1>Edit Course</h1> | |
49 <p> | |
50 Language: <%= course.language_name() %> | |
51 <input type=hidden name=language value="<%=course.language%>"> | |
52 <% if course_id ~= nil then %> | |
53 <input type=hidden name=course value="<%=course_id%>"> | |
54 <% end %> | |
55 </p> | |
56 <p> | |
57 <label prompt>Course name</label> | |
58 <input required name=name value="<%=html_encode(course.name)%>"> | |
59 </p> | |
60 <p> | |
61 <label prompt>AI system prompt</label> | |
62 <textarea required name=ai_system_prompt><%=html_encode(course.ai_system_prompt)%></textarea> | |
63 </p> | |
64 <p> | |
65 <input type=submit> | |
66 </p> | |
67 </form> | |
68 </body> | |
69 </html> | |
70 <% | |
71 end |