Re: Automatically mark (or do not show) past events?
On Mon, 17 Oct 2011 15:00:43 -0400
David Prévot wrote:
> Le 17/10/2011 14:17, Luca Capello a écrit :
> > However, I was thinking about something which completely removes the
> > need to add the "past_event" tag. So the question I forgot to ask is:
> > what is the rationale for this tag?
> Last time I checked, I thought it was only used for display purpose, so
> if someone provides a way to define an event as past based on its
> ($end)date, rather than the existence of the “past_event” tag, I believe
> it would be a great improvement.
the patch attached for index.include only cares
upcoming/past events shown on /events/index and /events/****/index pages.
I don't see the points using another template files so I don't touch them.
past/upcoming templates used from /events/****/****-* pages seems mostly the same,
so those can be integrated and determine if it's past or not, based on the date.
additionally, relevant /events/****/****-* files will need to be touched
from Makefile to make the state change.
--
victory
no need to CC me :-)
http://userscripts.org/scripts/show/102724
Index: index.include
===================================================================
RCS file: /cvs/webwml/webwml/english/events/index.include,v
retrieving revision 1.19
diff -u -r1.19 index.include
--- index.include 12 Oct 2012 13:27:06 -0000 1.19
+++ index.include 7 Nov 2012 03:14:09 -0000
@@ -12,6 +12,9 @@
my $path = $CUR_YEAR;
my $str = '';
my $past = '';
+# days to make a event as past;
+# if $keep = 1 and the event ends on 12/20, it will become past event on 12/21's build
+my $keep = 1;
# check if the current year has any past events.
opendir DIR, "$current_dir/$path" || die "Can't open $current_dir/$path: $!";
@@ -20,8 +23,20 @@
closedir DIR;
foreach (@files) {
- open FILE, "$path/$_" or open FILE, "$current_dir/$path/$_" or die "something went wrong, check permissions on $current_dir/$path/$_";
- foreach (<FILE>) { if (/^#use wml::debian::past_event$/) { $past = 'yes'; last; } }
+ open FILE, "<", "$path/$_" or open FILE, "<", "$current_dir/$path/$_"
+ or die "something went wrong, check permissions on $current_dir/$path/$_";
+ my $parsing = $_; # the target file name is needed if error occured
+ foreach (<FILE>) {
+ if (/^#use wml::debian::past_event$/) { $past = 'yes'; last; }
+ elsif (/^\s*<define-tag enddate>(.*)<\/define-tag>\s*$/) {
+ my $enddate = $1;
+ $enddate =~ /(\d{4})-(\d\d)-(\d\d)/;
+ if($enddate && !(defined($1) && defined($2) && defined($3))){
+ print "'enddate' tag has strange format in $parsing"; next;}
+ my $ut=timelocal(0, 0, 0, $3, ($2 - 1), ($1 - 1900));
+ if($ut < time - $keep * 86400){$past ='yes'; last;}
+ }
+ }
close FILE;
if ($past eq 'yes') {
$str .= " <a href=\"$path/\"> $path</a>, ";
@@ -53,6 +68,9 @@
my $path = $CUR_YEAR;
my $str;
my @paths;
+# days to make a event as past;
+# if $keep = 1 and the event ends on 12/20, it will become past event on 12/21's build
+my $keep = 1;
while (1) {
if ( -d "$current_dir/$path") {
@@ -73,8 +91,11 @@
@files = sort @files;
closedir DIR;
+ my $now = time;
foreach (@files) {
- open FILE, "$path/$_" or open FILE, "$current_dir/$path/$_" or die "something went wrong, check permissions on $current_dir/$path/$_";
+ open FILE, "<", "$path/$_" or open FILE, "<", "$current_dir/$path/$_"
+ or die "something went wrong, check permissions on $current_dir/$path/$_";
+ my $parsing = $_; # the target file name is needed if error occured
if ( /(\d+.*).wml/ ) {
$base = $1;
}
@@ -110,6 +131,11 @@
if ($startdate && $enddate) {
$when = &daterange($startdate, $enddate);
}
+ $enddate =~ /(\d{4})-(\d\d)-(\d\d)/;
+ if($enddate && !(defined($1) && defined($2) && defined($3))){
+ print "'enddate' tag has strange format in $parsing"; next;}
+ $ut = timelocal(0, 0, 0, $3, ($2 - 1), ($1 - 1900));
+ $past = 'yes' if ($ut < $now - $keep * 86400);
if ($past ne 'yes') {
if ($title && $when && $where) {
$upcoming++;
Reply to: