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(),