X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=Memories%2FPhoto.pm;fp=Memories%2FPhoto.pm;h=b48c69abd4b195b5bb349557cb7ccf527ae26ed1;hb=6e690feb2f60fc95145b4f6d83821da896505eb5;hp=e2175c5ca80737387fae96525b7f4e559369a8b5;hpb=f9656aa2ad257959dd4ed469714ca75791b70040;p=memories.git diff --git a/Memories/Photo.pm b/Memories/Photo.pm index e2175c5..b48c69a 100644 --- a/Memories/Photo.pm +++ b/Memories/Photo.pm @@ -48,18 +48,50 @@ sub do_upload :Exported { my ($self, $r) = @_; my $upload = $r->{ar}->upload("photo"); # Check $self->type - my @photos = $self->upload_jpeg($upload->tempname, ($r->params->{title}||basename($upload->filename)), $r->params->{tags}, $r); + my @photos = ($self->upload_jpeg($upload->tempname, ($r->params->{title}||basename($upload->filename)), $r->params->{tags}, $r)); my @quarantined = grep { !$_->tags } @photos; + warn "Quarantined these photos: ".join(",", map {$_->id} @quarantined); # Set it up to go again + if (@quarantined) { + $r->{session}{quarantined} = join ",", sort map { $_->id} @quarantined; + warn "Setting quarantineined to: ".( join ",", sort map { $_->id} @quarantined); + $r->objects(\@quarantined); + $r->template("quarantine"); + return; + } $r->objects(\@photos); - $r->template("view"); + if (@photos > 1) { $r->template("list") } + else { $r->template("view"); } $r->message("Thanks for the upload!"); - # Deal with the quarantined +} + +sub quarantine :Exported { + my ($self, $r) = @_; + my @quarantined = split /,/, $r->{session}{quarantined}; + my %q = map { $_ => 1 } @quarantined; + warn "Before we had these quarantined: @{[ keys %q ]}"; + for (map /(\d+)/,grep /tags\d+/, keys %{$r->{params}}) { + my $tags = $r->{params}{"tags$_"}; + warn "Got tags for $_: <$tags>"; + next unless $tags; + if (my $photo = $self->retrieve($_)) { + $photo->add_tags($tags); + delete $q{$_}; + } + } + $r->{session}{quarantined} = join ",", sort keys %q; + warn "After, we have these quarantined: @{[ keys %q ]}"; + warn "And we set session to $r->{session}{quarantined}"; + if (!$r->{session}{quarantined}) { + $r->template("list"); + $r->objects([ map { $self->retrieve($_) } @quarantined ]); + } else { + $r->objects([ map { $self->retrieve($_) } sort keys %q ]); + } } sub upload_jpeg { my ($self, $filename, $title, $tags, $r) = @_; - my $quarantine; my $photo = $self->create({ uploader => $r->user, uploaded => Time::Piece->new(),