dancer1 and DBIx: can I modify the returned result in a view?
Hi all, I'm tasked with hacking an old Dancer1 app I wrote back in 2014/2015 which basically just returns from results from a DB query. One of the fields is called 'url' and I need to tweak it, since the URL in the DB is completely wrong. I've tried poking at it in my views/search.tt file, but I can't figure out the right syntax to make it work. My results loop looks like this: <% IF results.size %> Results (found <% results.size %> matches): <ul> <% FOREACH result IN results %> <li><% result.full_name.replace("((?i)$tobold)",'<b>$1</b>') %> <ul> <% FOREACH a IN result.account %> <li><a href="<% a.url() %>" target="_blank"> Account # <% a.account_number %>, <% IF a.volume() %> Volume: <% a.volume() %>, <% END %> <% IF a.box() %> Box: <% a.box() %>, <% END %> <% IF a.folder() %> Folder: <% a.folder() %>, <% END %> <% IF a.range() %> Range: <% a.range() %> <% END %> </a> <% newurl %><br> <% END %> </ul> <% END %> And I need to pull out the a.url, do some manipulations on it, then display it. I tried doing: <% FOREACH a IN result.account %> <% a.url = a.url.replace("http://gigi.mwa.org/netpub/server.np", "https://gigi.mwa.org/imagearchive/filename/") %> <li><a href="<% a.url() %>" target="_blank"> Account # <% a.account_number %>, <% IF a.volume() %> Volume: <% a.volume() %>, <% END %> <% IF a.box() %> Box: <% a.box() %>, <% END %> <% IF a.folder() %> Folder: <% a.folder() %>, <% END %> <% IF a.range() %> Range: <% a.range() %> <% END %> </a> <% newurl %><br> <% END %> </ul> But that didn't seem to work. Should I be doing this search and replace in the lib/Foo.pm file in the _perform_search function instead? And if so, how do I deal with the DBIx resultset properly so I can loop through and update these URLs? I really don't want to have to do this in SQL somewhere, though I guess I could be convinced to do this hack until the DB itself is updated. Thanks, John
"John" == John Stoffel <john@stoffel.org> writes:
John> I'm tasked with hacking an old Dancer1 app I wrote back in 2014/2015 John> which basically just returns from results from a DB query. One of the John> fields is called 'url' and I need to tweak it, since the URL in the DB John> is completely wrong. John> I've tried poking at it in my views/search.tt file, but I can't figure John> out the right syntax to make it work. My results loop looks like John> this: John> <% IF results.size %> John> Results (found <% results.size %> matches): John> <ul> John> <% FOREACH result IN results %> John> <li><% result.full_name.replace("((?i)$tobold)",'<b>$1</b>') %> John> <ul> John> <% FOREACH a IN result.account %> John> <li><a href="<% a.url() %>" target="_blank"> John> Account # <% a.account_number %>, John> <% IF a.volume() %> Volume: <% a.volume() %>, <% END %> John> <% IF a.box() %> Box: <% a.box() %>, <% END %> John> <% IF a.folder() %> Folder: <% a.folder() %>, <% END %> John> <% IF a.range() %> Range: <% a.range() %> <% END %> John> </a> <% newurl %><br> John> <% END %> John> </ul> John> <% END %> And it turns out it's really something to be better handled in the DBIx side of the house, and I've managed to fix it using an accessor override (see the DBIx FAQ and Goodies pages) which will probably break future use of dbicdump, but since this is a simple readonly site, I don't care. So basically, in the lib/Carey/Schema/Result/Account.pm file I had to add some quick bits of code and all is well now. Cheers, John
participants (1)
-
John Stoffel