From 6e690feb2f60fc95145b4f6d83821da896505eb5 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Sat, 17 Feb 2007 19:28:57 +0000 Subject: [PATCH 1/1] Quarantine non-tagged photos. Closes #14. git-svn-id: http://svn.simon-cozens.org/memories/trunk@36 041978f6-d955-411f-a9d7-1d8545c9c3c7 --- Memories.pm | 8 +++++++- Memories/Photo.pm | 40 ++++++++++++++++++++++++++++++++++---- templates/photo/quarantine | 35 +++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 templates/photo/quarantine diff --git a/Memories.pm b/Memories.pm index 8536d17..a789fab 100644 --- a/Memories.pm +++ b/Memories.pm @@ -1,7 +1,7 @@ package Memories; use strict; our $VERSION = "1.2"; -use Maypole::Application qw(Upload Authentication::UserSessionCookie -Debug); +use Maypole::Application qw(Upload Authentication::UserSessionCookie); use HTML::TagCloud; use URI; use Memories::Config; @@ -92,6 +92,12 @@ sub authenticate { return DECLINED if $self->path =~/static|store/; # XXX $r->get_user; if (!$r->user and $self->path =~ /upload/) { $r->template("login"); } + # Don't let 'em go until they've fixed it + warn "Quarantine is : ".$r->session->{quarantined}; + if ($r->session->{quarantined} and $self->path !~ /js$/) { + $r->table("photo"); $r->action("quarantine"); + $r->model_class("Memories::Photo"); + } return OK; } 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(), diff --git a/templates/photo/quarantine b/templates/photo/quarantine new file mode 100644 index 0000000..559c911 --- /dev/null +++ b/templates/photo/quarantine @@ -0,0 +1,35 @@ +[% INCLUDE header %] +[% PROCESS macros %] +

Quarantined photos

+ +

The following photos need to be tagged. Sorry to be anal about this, +but we really need to have photos tagged if we're going to be able to +find them in the future. You won't be able to do anything, anything at +all, until we've resolved this. Please, please put some tags in the +boxes below. (You can make it easier for yourself in the future by +adding IPTC tags to your photos in your photo management software.) +

+ +
+
+ +[% WHILE objects.size > 0 %] +[% SET triple = objects.splice(0,3) %] + + [% FOR photo = triple %] + + [% END %] + +[% END %] +
+ [% minithumb(photo, 1) %] +
+ + +
+ +
+ +[% INCLUDE pager %] +[% INCLUDE footer %] -- 2.39.5