fixed a bunch of tag shenanigans
This commit is contained in:
parent
be734d28b1
commit
1fda7ef7fe
12
app.moon
12
app.moon
@ -3,8 +3,8 @@ console = require "lapis.console"
|
|||||||
|
|
||||||
import respond_to from require "lapis.application"
|
import respond_to from require "lapis.application"
|
||||||
import escape_literal, escape_identifier from require "lapis.db"
|
import escape_literal, escape_identifier from require "lapis.db"
|
||||||
import unescape from require "lapis.util"
|
import escape, unescape from require "lapis.util"
|
||||||
import create_track, update_track, escape_tag from require "helpers"
|
import create_track, update_track from require "helpers"
|
||||||
|
|
||||||
import Tracks, Tags from require "models"
|
import Tracks, Tags from require "models"
|
||||||
|
|
||||||
@ -52,6 +52,7 @@ class extends lapis.Application
|
|||||||
return render: true
|
return render: true
|
||||||
|
|
||||||
[tag: "/tag/:name(/:order[%a])(/:asc_desc)(/:page[%d])"]: =>
|
[tag: "/tag/:name(/:order[%a])(/:asc_desc)(/:page[%d])"]: =>
|
||||||
|
update_track(@params) if @params.id -- update a track if needed
|
||||||
-- validate order
|
-- validate order
|
||||||
@order = tostring(@params.order)\lower!
|
@order = tostring(@params.order)\lower!
|
||||||
unless Tags.fields[@order]
|
unless Tags.fields[@order]
|
||||||
@ -62,8 +63,13 @@ class extends lapis.Application
|
|||||||
@asc_desc = "ASC"
|
@asc_desc = "ASC"
|
||||||
@page = tonumber(@params.page) or 1
|
@page = tonumber(@params.page) or 1
|
||||||
|
|
||||||
tag_pattern = escape_literal unescape(@params.name)
|
-- create tag pattern
|
||||||
|
tag_pattern = unescape(@params.name)
|
||||||
|
if tag_pattern != tag_pattern\lower!
|
||||||
|
return redirect_to: @url_for "tag", name: escape(tag_pattern\lower!), order: @order, asc_desc: @asc_desc, page: @page
|
||||||
|
tag_pattern = escape_literal tag_pattern
|
||||||
tag_pattern = "'% " .. tag_pattern\sub(2, -2) .. " %'"
|
tag_pattern = "'% " .. tag_pattern\sub(2, -2) .. " %'"
|
||||||
|
|
||||||
tracks = Tracks\paginated "WHERE tags LIKE #{tag_pattern} ORDER BY #{escape_identifier @order} #{@asc_desc}", per_page: 32
|
tracks = Tracks\paginated "WHERE tags LIKE #{tag_pattern} ORDER BY #{escape_identifier @order} #{@asc_desc}", per_page: 32
|
||||||
@last_page = 1
|
@last_page = 1
|
||||||
if tag = Tags\find name: unescape(@params.name)
|
if tag = Tags\find name: unescape(@params.name)
|
||||||
|
@ -14,9 +14,6 @@ process_tags = (tags_str) ->
|
|||||||
table.sort taglist
|
table.sort taglist
|
||||||
return " #{table.concat taglist, " "} "
|
return " #{table.concat taglist, " "} "
|
||||||
|
|
||||||
escape_tag = (str) ->
|
|
||||||
return " #{str\gsub "[%%_]", "\\%1"} "
|
|
||||||
|
|
||||||
update_track = (user_input) ->
|
update_track = (user_input) ->
|
||||||
updates = {}
|
updates = {}
|
||||||
-- automatic tags
|
-- automatic tags
|
||||||
@ -49,7 +46,6 @@ update_track = (user_input) ->
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
:process_tags
|
:process_tags
|
||||||
:escape_tag
|
|
||||||
:update_track
|
:update_track
|
||||||
create_track: update_track
|
create_track: update_track
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ class extends Widget
|
|||||||
for track in *@tracks
|
for track in *@tracks
|
||||||
tr class: Tracks.statuses[track.status], ->
|
tr class: Tracks.statuses[track.status], ->
|
||||||
form {
|
form {
|
||||||
action: @url_for "tracks", order: @order, asc_desc: @asc_desc, page: @page
|
action: @url_for "tag", name: @params.name, order: @order, asc_desc: @asc_desc, page: @page
|
||||||
method: "POST"
|
method: "POST"
|
||||||
enctype: "multipart/form-data"
|
enctype: "multipart/form-data"
|
||||||
}, ->
|
}, ->
|
||||||
|
Reference in New Issue
Block a user