Date range only works as an "exposed" filter
chrissearle - January 17, 2007 - 08:08
| Project: | Views Date Range Filter |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | douggreen |
| Status: | closed |
Description
Drupal 5.0 release.
I can't seem to get this working. I have a view. It provides block. Two fields - one of which is a CCK date field.
I originally had the setting "within the past week" which seemed to work OK.
But - what I really want is from today - and up to 10 days ahead. So - reading the line "The date fields understand the words 'today' and 'yesterday' and sutraction of days, months, or years." I tried a custom date range of
From: today
To: today+10
But - when I save the view (no errors) and then re-enter the view - the fields have been blanked :(
Am I missing something here?

#1
It should work the way you are trying to use it (with one minor difference - use today-10 instead of today+10). I've confirmed that it isn't saving the optional values (on 4.7 and 5). I'll try to get around to this soon, as I think it's a pretty significant bug.
But you're work-around is to use an "exposed filter". If you "expose" the filter, the user will be able to select their own date ranges. If you install jstools and jscalendar, the user can use a handy javascript date picker, ... in addition to the today-10 syntax.
#2
OK - I'll give it a go - see what happens.
Hope you get time to take a look soon - this block is part of a system overview page - so - exposing filters makes it a little cluttered.
If you want any help testing any of it - feel free to ask (I'd love to dig in myself - but right now work pressure won't allow that).
#3
#4
I'd like to get this added, because I think that it will offer more flexible date math. However, isn't it possible to use the date module, which allows syntax such as "now" and "now+86400" (number of days in a second).
#5
I checked in a version to the 4.7.x-1.x-dev branch that implements non-exposed filters. I hope to get this into 5.x soon, but some independent testing would expedite the process.
#6
Also updated for Drupal 5. After I get some confirmation, I'll mark this as fixed and create new release tags.
#7
#8
I'll get a chance to test the changes to 5.x tomorrow - will let you know.
#9
Just to be sure - I see that the 4.7 dev snapshot was updated yesterday - but the 5.x dev snapshot is showing jan 3rd. So - I'll grab it from CVS - but - just wanted to make sure I grabbed the correct tag - it is the DRUPAL-5 tag that I want?
#10
The Drupal project system doesn't update the snapshots immediately, so yes, if there isn't a new 5.x-1.x-dev snapshot, pull it from CVS using the DRUPAL-5 tag.
#11
OK. I just grabbed the DRUPAL-5 tag.
I'm still not seeing what I expect.
I have a CCK node with a date field called date_start. So - I add the daterange for this field to the filter. Choose custom date range and enter into the two fields today and today+5 (we would like from today and up to 5 days in the future).
I still see meetings dated 30. jan, 31. jan etc in the block.
I have also tried a filter on the same field of after with the first of the two fields set to today. Still seeing entries from last week.
If it helps - here's the first of the two views:
$view = new stdClass();$view->name = 'meeting';
$view->description = 'Meeting';
$view->access = array (
);
$view->view_args_php = '';
$view->block = TRUE;
$view->block_title = 'Meetings';
$view->block_header = '';
$view->block_header_format = '1';
$view->block_footer = '';
$view->block_footer_format = '1';
$view->block_empty = '';
$view->block_empty_format = '1';
$view->block_type = 'table';
$view->nodes_per_block = '20';
$view->block_more = FALSE;
$view->block_use_page_header = FALSE;
$view->block_use_page_footer = FALSE;
$view->block_use_page_empty = FALSE;
$view->sort = array (
);
$view->argument = array (
);
$view->field = array (
array (
'tablename' => 'node_data_field_start',
'field' => 'field_start_value',
'label' => '',
'handler' => 'content_views_field_handler_group',
'defaultsort' => 'DESC',
'options' => 'medium',
),
array (
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'options' => 'link',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'meeting',
),
),
array (
'tablename' => 'daterange_node_meeting',
'field' => 'field_start',
'operator' => 'inside',
'options' => '',
'value' => array (
0 => 'a:2:{s:5:"date1";s:5:"today";s:5:"date2";s:7:"today+5";}',
),
),
);
$view->exposed_filter = array (
);
$view->requires = array(node_data_field_start, node, daterange_node_meeting);
$views[$view->name] = $view;
#12
The problem is related to the D5 upgrades in CCK. I'll work on a fix for this tomorrow. Is it possible for you test this on the simple "node created between" or "node updated between" filters, and confirm that the saving of filters is working properly? If you can confirm this is working, I'd like to close it and then create a separate issue for the D5 CCK changes.
#13
Not sure whats happening here. I just ran a cvs up to make sure I had the latest - but - see the attached image for the available choices I see
#14
I'm a little obtuse this morning... what's wrong with those options?
If you're trying to do the node created test, do this by creating a new view, the option for this is in the filter addition, not in the filter options.
#15
It should not work for CCK. There were actually three problems: (1) fix tables names for CCK, (2) add support for date addition -- it had previously only supported subtraction, and (3) make view not cacheable.
#16
S'OK - I'm the one who is a little obtuse. Didn't realise that it was a filter to choose rather than a filter option.
Regards 1, 2 and 3 - is that a "what needs doing" or a "what's been done" ?
#17
It's whats already in the DRUPAL_5 CVS tag. I still need to backport it to 4.7.
#18
Hmm - just cvs up'd and removed the date range and added a Node created between for today and today-2
Still seeing all the same nodes as before. Some were created two weeks ago.
I hate to be a pain - but I just wonder if I have understood what I'm supposed to be doing in the view.
$view = new stdClass();$view->name = 'meeting';
$view->description = 'Meeting';
$view->access = array (
);
$view->view_args_php = '';
$view->block = TRUE;
$view->block_title = 'Meetings';
$view->block_header = '';
$view->block_header_format = '1';
$view->block_footer = '';
$view->block_footer_format = '1';
$view->block_empty = '';
$view->block_empty_format = '1';
$view->block_type = 'table';
$view->nodes_per_block = '20';
$view->block_more = FALSE;
$view->block_use_page_header = FALSE;
$view->block_use_page_footer = FALSE;
$view->block_use_page_empty = FALSE;
$view->sort = array (
);
$view->argument = array (
);
$view->field = array (
array (
'tablename' => 'node_data_field_start',
'field' => 'field_start_value',
'label' => '',
'handler' => 'content_views_field_handler_group',
'defaultsort' => 'DESC',
'options' => 'medium',
),
array (
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'options' => 'link',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'meeting',
),
),
array (
'tablename' => 'daterange_node',
'field' => 'created',
'operator' => 'inside',
'options' => '',
'value' => array (
0 => 'a:2:{s:5:"date1";s:7:"today-2";s:5:"date2";s:5:"today";}',
),
),
);
$view->exposed_filter = array (
);
$view->requires = array(node_data_field_start, node, daterange_node);
$views[$view->name] = $view;
#19
I don't remember where I read this, but the views developer said somewhere, something to the effect "if in doubt, empty the cache." So if you want to test with a view you had previously created, please empty your cache (either using the devel module or using SQL "DELETE FROM cache").
I'd recommend you just start over with a new view --- two new views if you want to test both the CCK and the non-CCK capabilities.
Below is my view that's working just fine. One difference between our tests is that I'm creating a page and your creating a block.
$view = new stdClass();$view->name = 'Event_Test';
$view->description = 'Event Test';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'Event Test';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = 'No events within date range.';
$view->page_empty_format = '1';
$view->page_type = 'teaser';
$view->url = 'eventtest';
$view->use_pager = TRUE;
$view->nodes_per_page = '10';
$view->sort = array (
array (
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array (
);
$view->field = array (
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'event',
),
),
array (
'tablename' => 'daterange_node_event',
'field' => 'field_when',
'operator' => 'inside',
'options' => '',
'value' => array (
0 => 'a:2:{s:5:"date1";s:7:"today-1";s:5:"date2";s:7:"today+5";}',
),
),
);
$view->exposed_filter = array (
);
$view->requires = array(node, daterange_node_event);
$views[$view->name] = $view;
#20
Just created a new view - page and block. Still not working. I can't show you the site with the issue - inside a firewall - but I have some scratch sites. I'll see if I can't generate a basic test case with the minimal info on it. Will take a couple of days tho.
#21
Please provide the aforementioned test case... otherwise, I'll probably close this issue soon, as to the best of my knowledge, the issue is resolved.
#22
Should get to it tonight - got an install I can throw it on. I'll send you the login via a priv msg here on drupal.org
#23
OK.
http://www.chrissearle.net/
Block in left and the link under primary links to Test Date Range.
drupal has sent your username/password to the email address from your consulting webpage - hope that is OK. You have full admin access.
Now - either there's something wrong or I simply haven't understood the view setup. I do not understand why the first entry is shown.
#24
Please install the devel module so that I can (a) look at the queries, and (b) empty the cache.
#25
When I edit the view on your site, it's not saving the filter values. This was the bug that I fixed last week. Please make sure that your version is 1.5.2.6 or higher by looking at the $id$ string in daterange.module. Also, please make sure you have the latest stable views project.
If you do download a new version of daterange, I've made some related additional changes tonight. The current version is now 1.5.2.9.
#26
OK - Devel in place.
CVS checkout of DRUPAL-5 tree of daterange in place. update.php has been run.
Views is 5.x-1.5 as far as I can see - and this is the latest stable as far as I can tell.
Oddly - I went into my view (the one providing block, page and menu) and updated the filter. It gave the following error:
user warning: Table 'chrissearle_net_drupal.content_type_daterangetest' doesn't exist query: SELECT node.nid, node.title AS node_title, node.changed AS node_changed, node_data_field_test_date.field_test_date_value AS node_data_field_test_date_field_test_date_value, node_data_field_test_date.field_test_date_value2 AS node_data_field_test_date_field_test_date_value2, node.nid AS node_nid FROM node node LEFT JOIN content_type_daterangetest content_type_daterangetest ON node.nid = content_type_daterangetest.nid LEFT JOIN node_daterangetest node_data_field_test_date ON node.vid = node_data_field_test_date.vid WHERE (node.status = '1') AND ( UNIX_TIMESTAMP(REPLACE(content_type_daterangetest.field_test_date_value, 'T', ' ')) >= 1171321200 && UNIX_TIMESTAMP(REPLACE(content_type_daterangetest.field_test_date_value, 'T', ' ')) <= 1172271599) AND (node.type IN ('daterangetest')) LIMIT 0, 3 in /opt/drupal5/includes/database.mysql.inc on line 167.#27
I've logged onto your site and see the SQL error, which is caused by daterange not finding the CCK tables where it expects them (this changed from D47 to D5).
Almost there... I see that it's actually saving the daterange values now.
I went to my test site http://drupal5.douggreenconsulting.com, and recreated your test in it's entirety. The odd thing, it works on my site (see http://drupal5.douggreenconsulting.com/drupal/node/110108b).
I then went back to your site to recreate the test from scratch, trying to isolate if
After I created the node types, it displayed the debugging messages
but it still created the node. So my test still looks good, but it appears that you've been looking at the CCK code and put in some print statements. This raises a small red flag, that I don't know what else has changed in CCK.
I then created the view http://www.chrissearle.net/drupal/node/110108b which confirms again that it does not work on your site. It works on my site and it doesn't work on yours :(
It appears that my second supposition is true. "You created the CCK data type using a prior version." You have a 5.x-1.2 which is almost a month old. 5.x-1.3 is the current version. Given that the problem now appears to be related to the CCK tables, this might help. After you download the latest CCK,you should recreate the test from scratch (as I did above).
Thanks!
#28
OK. I'll give it a go later on tonight. Happily we're going to recreate types for approx 10 nodes - so data transfer should go quickly :)
#29
I've realized that I can not "hard code" the table name because it is dependent on the version of CCK used in the database schema.
I need to use _content_tablename (from content.module) to get the table name. I'll try to make this change tonight or tomorrow.
function _content_tablename($name, $entity, $version = NULL) {
if (is_null($version)) {
$version = variable_get('content_schema_version', 0);
}
if ($version < 1003) {
$version = 0;
}
else {
$version = 1003;
}
$name = str_replace('-', '_', $name);
switch ($version .'-'. $entity) {
case '0-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE :
return 'node_'.$name;
case '0-'. CONTENT_DB_STORAGE_PER_FIELD :
return 'node_data_'.$name;
case '1003-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE :
return 'content_type_'.$name;
case '1003-'. CONTENT_DB_STORAGE_PER_FIELD :
return 'content_'.$name;
}
So, you can hold off on your test... although if you upgrade the database after you upgrade CCK, I suspect that it will work.
#30
Please test now... I just checked in changes to get the cck table name from _content_tablename.
#31
OK - CCK 5.x-1.3 and cvs daterange - recreated types and views - and bingo. Block and page show only what I expect.
I've no idea where the valuevalue2valuevalue2 is coming from - perhaps the date module - I've not changed anything. But that's my issue - not yours.
Thanks for all your efforts - this has not been an easy one to track down.
#32
Yea!!!
#33