From 58a0ba09590653e5afceb39431f7fa893d26c86f Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 21 Mar 2014 08:32:03 +0200 Subject: [PATCH] Fix pb and log --- app.psgi | 1 + lib/Gruntmaster/Page/Generic.pm | 15 ++++++++------- tmpl/log.en | 4 ++-- tmpl/pb.en | 8 ++++---- tmpl/pb_entry.en | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app.psgi b/app.psgi index e662e26..2f92d9a 100644 --- a/app.psgi +++ b/app.psgi @@ -91,6 +91,7 @@ sub authenticate { Log::Log4perl->init('log.conf'); my $access_logger = Log::Log4perl->get_logger('access'); +$ENV{DBIC_NULLABLE_KEY_NOWARN} = 1; builder { enable_if { $_[0]->{PATH_INFO} eq '/ok' } sub { sub{ [200, [], []] }}; diff --git a/lib/Gruntmaster/Page/Generic.pm b/lib/Gruntmaster/Page/Generic.pm index fe9525d..9c5687b 100644 --- a/lib/Gruntmaster/Page/Generic.pm +++ b/lib/Gruntmaster/Page/Generic.pm @@ -31,13 +31,15 @@ sub makepkg { sub list { my ($thing, $lang, $env) = @_; my %thing = %$thing; + my %params; #debug $env => "Contest is $ct"; $thing{makers} //= sub { db(shift)->resultset($thing{rsname}) }; my $rs = $thing{makers}->($env); $rs = $rs->search(undef, {order_by => 'me.id'}) unless $rs->is_ordered; if (my $page = $env->{'gruntmaster.page'}) { - my $pages = $rs->count / PAGE_SIZE; + my $pages = int ($rs->count / PAGE_SIZE); $page = $pages if $page == -1; + @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}; @@ -45,7 +47,6 @@ sub list { @thing = map { $thing{mangle}->(); $_ } @thing if exists $thing{mangle}; @thing = grep { $thing{choose}->() } @thing if exists $thing{choose}; @thing = sort { $thing{sortby}->() } @thing if exists $thing{sortby}; - my %params; $thing{group} //= sub { $thing{id} }; for (@thing) { my $group = $thing{group}->(); @@ -116,23 +117,23 @@ thing { makers { my $env = $_[0]; my $db = db $env; - return $db->contest($env->{'gruntmaster.contest'})->problems->search(undef, {order_by => 'problem.id'}) if exists $env->{'gruntmaster.contest'}; return $db->problems->search({owner => $env->{'gruntmaster.user'}}) if exists $env->{'gruntmaster.user'}; - $db->problems->search({private => 0}); + return $db->problems->search({'contest_problems.contest' => $env->{'gruntmaster.contest'}}, {join => 'contest_problems'}) if exists $env->{'gruntmaster.contest'}; + $db->problems->search({-or => ['contest_problems.contest' => undef, 'contest.stop' => {'<=', time}], 'me.private' => 0}, {join => {'contest_problems' => 'contest'}}); }; sortby { $a->{name} cmp $b->{name}}; group { $_->{level} }; mangle { my $env = shift; $_->{owner_name} = $_->{rs}->owner->name; - $_->{cansubmit} = $_->{contest} ? time < $_->{rs}->contest->stop : 1; + $_->{cansubmit} = $env->{'gruntmaster.contest'} ? time < db($env)->contest($env->{'gruntmaster.contest'})->stop : 1; eval { db($env)->open->create({ - contest => $_->{contest}, + contest => $env->{'gruntmaster.contest'}, problem => $_->{id}, owner => $env->{REMOTE_USER}, }) - } if $_->{contest} && time >= $_->{rs}->contest->start; + } if $env->{'gruntmaster.contest'} && time >= db($env)->contest($env->{'gruntmaster.contest'})->start; }; }; diff --git a/tmpl/log.en b/tmpl/log.en index 1e5b488..f2c7983 100644 --- a/tmpl/log.en +++ b/tmpl/log.en @@ -12,6 +12,6 @@ diff --git a/tmpl/pb.en b/tmpl/pb.en index fcb23b0..35cfbd4 100644 --- a/tmpl/pb.en +++ b/tmpl/pb.en @@ -3,7 +3,7 @@ -
NameAuthorOwner
+
@@ -13,7 +13,7 @@ -
NameAuthorOwner
+
@@ -23,7 +23,7 @@ -
NameAuthorOwner
+
@@ -33,7 +33,7 @@ -
NameAuthorOwner
+
diff --git a/tmpl/pb_entry.en b/tmpl/pb_entry.en index c707952..f3d0f75 100644 --- a/tmpl/pb_entry.en +++ b/tmpl/pb_entry.en @@ -13,7 +13,7 @@

Submit solution

-
+ -- 2.30.2