From: Marius Gavrilescu Date: Mon, 24 Mar 2014 06:32:53 +0000 (+0200) Subject: Fix some bugs X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=a46fb222e6ce50102b7c61a95af435afc74f5e33;p=plack-app-gruntmaster.git Fix some bugs --- diff --git a/lib/Gruntmaster/Page/Base.pm b/lib/Gruntmaster/Page/Base.pm index 0cae932..99ca432 100644 --- a/lib/Gruntmaster/Page/Base.pm +++ b/lib/Gruntmaster/Page/Base.pm @@ -88,7 +88,7 @@ sub generate{ my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$self}{$lang}, default_escape => 'HTML', use_perl => 1); $self->_generate($htc, $lang, @args); my $out = $htc->output; - utf8::downgrade($out); + utf8::encode($out); my $vary = 'Accept-Language, ' . $self->vary; [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => $vary, 'X-Forever' => 1, 'Cache-Control' => 'max-age=' . $self->max_age], [ $out ] ] } diff --git a/lib/Gruntmaster/Page/Generic.pm b/lib/Gruntmaster/Page/Generic.pm index 9c5687b..36ca445 100644 --- a/lib/Gruntmaster/Page/Generic.pm +++ b/lib/Gruntmaster/Page/Generic.pm @@ -42,7 +42,10 @@ sub list { @params{'page', 'pages'} = ($page, $pages); $rs = $rs->search(undef, {offset => ($page - 1) * PAGE_SIZE, ($page == $pages ? () : (rows => PAGE_SIZE))}); } - $rs = $rs->search(undef, {prefetch => $thing{prefetch}}) if exists $thing{prefetch}; + $rs = $rs->search(undef, { + exists $thing{prefetch} ? (prefetch => $thing{prefetch}) : (), + exists $thing{columns} ? (columns => $thing{columns}) : (), + }); my @thing = map +{rs => $_, $_->get_columns}, $rs->all; @thing = map { $thing{mangle}->(); $_ } @thing if exists $thing{mangle}; @thing = grep { $thing{choose}->() } @thing if exists $thing{choose}; @@ -86,6 +89,7 @@ sub sortby (&); sub group (&); sub mangle (&); sub prefetch; +sub columns; sub thing (&){ my %thing; @@ -97,6 +101,7 @@ sub thing (&){ local *{"group"} = sub { $thing{group} = shift }; local *{"makers"} = sub { $thing{makers} = shift }; local *{"prefetch"} = sub { $thing{prefetch} = \@_ }; + local *{"columns"} = sub { $thing{columns} = \@_ }; use strict 'refs'; shift->(); diff --git a/lib/Gruntmaster/Page/Submit.pm b/lib/Gruntmaster/Page/Submit.pm index 5eed07c..5f7d727 100644 --- a/lib/Gruntmaster/Page/Submit.pm +++ b/lib/Gruntmaster/Page/Submit.pm @@ -16,6 +16,8 @@ sub generate{ my ($self, $frm, $env) = @_; my $r = Plack::Request->new($env); my ($problem, $format, $contest, $private, $prog) = map {scalar $r->param($_)} 'problem', 'prog_format', 'contest', 'private', 'source_code'; + $problem //= $env->{'gruntmaster.problem'}; + $contest //= $env->{'gruntmaster.contest'}; my $upload = $r->upload('prog'); if (defined $upload) { my $temp = read_file $upload->path; @@ -26,7 +28,7 @@ sub generate{ return reply 'A required parameter was not supplied' if grep { !defined } $problem, $format, $prog; return reply 'Maximum source size is 10KB' if length $prog > 25 * 1024; return reply 'You must wait 30 seconds between jobs' unless time > db($env)->user($r->user)->lastjob + 30; - db($env)->user($r->user)->lastjob(time)->update; + db($env)->user($r->user)->update({lastjob => time}); db($env)->jobs->create({ defined $contest ? (contest => $contest) : (), @@ -34,9 +36,9 @@ sub generate{ extension => FORMAT_EXTENSION->{$format}, format => $format, defined $private ? (private => $private) : (), - probem => $problem, + problem => $problem, source => $prog, - user => $r->user + owner => $r->user }); $contest //= ''; diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index 8d828c0..e009d79 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -79,7 +79,7 @@ BEGIN{ generic qw/us ct pb log/; get qr,/log/src/$number\.$word, => 'Src'; - post qr,/pb/$word/submit, => 'Submit'; + post qr,/submit, => 'Submit'; post qr,/action/register, => 'Register'; post qr,/action/passwd, => 'Passwd';