File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import (
27
27
"code.gitea.io/gitea/modules/setting"
28
28
"code.gitea.io/gitea/modules/templates"
29
29
"code.gitea.io/gitea/modules/translation"
30
+ "code.gitea.io/gitea/modules/util"
30
31
"code.gitea.io/gitea/modules/web/middleware"
31
32
"code.gitea.io/gitea/services/auth"
32
33
@@ -319,6 +320,11 @@ func (ctx *Context) QueryBool(key string, defaults ...bool) bool {
319
320
return (* Forms )(ctx .Req ).MustBool (key , defaults ... )
320
321
}
321
322
323
+ // QueryOptionalBool returns request form as OptionalBool with default
324
+ func (ctx * Context ) QueryOptionalBool (key string , defaults ... util.OptionalBool ) util.OptionalBool {
325
+ return (* Forms )(ctx .Req ).MustOptionalBool (key , defaults ... )
326
+ }
327
+
322
328
// HandleText handles HTTP status code
323
329
func (ctx * Context ) HandleText (status int , title string ) {
324
330
if (status / 100 == 4 ) || (status / 100 == 5 ) {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import (
13
13
"text/template"
14
14
15
15
"code.gitea.io/gitea/modules/log"
16
+ "code.gitea.io/gitea/modules/util"
16
17
)
17
18
18
19
// Forms a new enhancement of http.Request
@@ -225,3 +226,16 @@ func (f *Forms) MustBool(key string, defaults ...bool) bool {
225
226
}
226
227
return v
227
228
}
229
+
230
+ // MustOptionalBool returns request form as OptionalBool with default
231
+ func (f * Forms ) MustOptionalBool (key string , defaults ... util.OptionalBool ) util.OptionalBool {
232
+ value := (* http .Request )(f ).FormValue (key )
233
+ if len (value ) == 0 {
234
+ return util .OptionalBoolNone
235
+ }
236
+ v , err := strconv .ParseBool ((* http .Request )(f ).FormValue (key ))
237
+ if len (defaults ) > 0 && err != nil {
238
+ return defaults [0 ]
239
+ }
240
+ return util .OptionalBoolOf (v )
241
+ }
You can’t perform that action at this time.
0 commit comments