Changeset 36

Show
Ignore:
Timestamp:
02/17/07 19:28:57 (2 years ago)
Author:
simon
Message:

Quarantine non-tagged photos. Closes #14.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Memories.pm

    r31 r36  
    22use strict; 
    33our $VERSION = "1.2"; 
    4 use Maypole::Application qw(Upload Authentication::UserSessionCookie -Debug); 
     4use Maypole::Application qw(Upload Authentication::UserSessionCookie); 
    55use HTML::TagCloud; 
    66use URI; 
     
    9393   $r->get_user; 
    9494   if (!$r->user and $self->path =~ /upload/) { $r->template("login"); } 
     95   # Don't let 'em go until they've fixed it 
     96   warn "Quarantine is : ".$r->session->{quarantined}; 
     97   if ($r->session->{quarantined} and $self->path !~ /js$/) {  
     98       $r->table("photo"); $r->action("quarantine"); 
     99       $r->model_class("Memories::Photo"); 
     100   } 
    95101   return OK;  
    96102} 
  • trunk/Memories/Photo.pm

    r34 r36  
    4949    my $upload = $r->{ar}->upload("photo"); 
    5050    # Check $self->type 
    51     my @photos = $self->upload_jpeg($upload->tempname, ($r->params->{title}||basename($upload->filename)), $r->params->{tags}, $r); 
     51    my @photos = ($self->upload_jpeg($upload->tempname, ($r->params->{title}||basename($upload->filename)), $r->params->{tags}, $r)); 
    5252    my @quarantined = grep { !$_->tags } @photos; 
     53    warn "Quarantined these photos: ".join(",", map {$_->id} @quarantined); 
    5354    # Set it up to go again 
     55    if (@quarantined) {  
     56        $r->{session}{quarantined} = join ",", sort map { $_->id} @quarantined; 
     57        warn "Setting quarantineined to: ".( join ",", sort map { $_->id} @quarantined); 
     58        $r->objects(\@quarantined); 
     59        $r->template("quarantine"); 
     60        return; 
     61    } 
    5462    $r->objects(\@photos); 
    55     $r->template("view"); 
     63    if (@photos > 1) { $r->template("list") }  
     64    else { $r->template("view"); } 
    5665    $r->message("Thanks for the upload!");  
    57     # Deal with the quarantined 
     66
     67 
     68sub quarantine :Exported { 
     69    my ($self, $r) = @_; 
     70    my @quarantined = split /,/, $r->{session}{quarantined}; 
     71    my %q = map { $_ => 1 } @quarantined; 
     72    warn "Before we had these quarantined: @{[ keys %q ]}"; 
     73    for (map /(\d+)/,grep /tags\d+/, keys %{$r->{params}}) { 
     74        my $tags = $r->{params}{"tags$_"}; 
     75        warn "Got tags for $_: <$tags>"; 
     76        next unless $tags; 
     77        if (my $photo = $self->retrieve($_)) { 
     78            $photo->add_tags($tags); 
     79            delete $q{$_}; 
     80        } 
     81    } 
     82    $r->{session}{quarantined} = join ",", sort keys %q; 
     83    warn "After, we have these quarantined: @{[ keys %q ]}"; 
     84    warn "And we set session to  $r->{session}{quarantined}"; 
     85    if (!$r->{session}{quarantined}) { 
     86        $r->template("list"); 
     87        $r->objects([ map { $self->retrieve($_) } @quarantined ]); 
     88    } else { 
     89        $r->objects([ map { $self->retrieve($_) } sort keys %q ]); 
     90    } 
    5891} 
    5992 
    6093sub upload_jpeg { 
    6194    my ($self, $filename, $title, $tags, $r) = @_; 
    62     my $quarantine; 
    6395    my $photo = $self->create({ 
    6496        uploader => $r->user,