Plone 4 : CalendarWidget to display Year only without Date and Month - plone

In Plone 4, I am using the CalendarWidget. Is it possible to display only the year in a custom view for a datetime field? Some records that I need to input do not have the month and date but the year has been provided.
Is there a way to limit the widget to allow only the year but ignore the date and month fields unless they are provided?
Currently my code is as follows:
atapi.DateTimeField('item_publication_date',
required=True,
searchable = True,
validators = ('isValidDate'),
widget = atapi.CalendarWidget(
show_hm=False,
label=_(u'Publication Date'),
starting_year=1970,
format='%Y',
description=_(u"Item Publication Date"),
),
),

You can't. In Zope, DateTime objects must have a month and day to work at all, and what would they be set to if you only supply a year?
You can, however, use a simple StringField with a dynamic vocabulary to let users pick a year from a drop-down list, then use a custom method on your content class to return a DateTime object for getItem_publication_date() where you take the year for the return value from that field.

Related

Elastic search 2.0 Nest 2.0 datetime month search

I have a requirement to get given month data from the datestart field.
public DateTime? datestart { get; set; }
I tried following code. But it did not work. Return no result.
string givenMonth = "5"; //May
thisMonthQuery = Query<ProjectModel>.Match(
q => q.Field(f => f.datestart.Value.Month.ToString()).Query(givenMonth));
You cannot use Match query to search month in a date field. Date field is not split into different tokens like a text field so you cannot search on month.
You need to use a script query for this
.Script(sn => sn
.Inline("doc['datestart'].value.monthOfYear==param1")
.Params(p => p.Add("param1", 5))
)
You can also create a sub field of type text and use match query, but then your input can also match date part!.

Converting a string date to a Date field using scripted fields in kibana

Hi I am working on ELK stack. I have a date in the form of a string like below:
"23/Nov/2017:02:35:02 +0000"
Now I want to use scripted fields in kibana to convert the string date time to a date field.
Anyone can help me with what to put in the script? or How can I go about it?
So for your case lets say the date is in the field { logdate:"23/Nov/2017:02:35:02 +0000" }
In order to convert the logdate(string) to a timestamp value, we can use a Logstash Date filter
In our case, the date filter should look something like below, this filter will parse the date time and save it to the #timestamp filed which is default if you want to save it to a particular field used the target setting
filter {
date {
match => [ "logdate", "dd/MMM/yyyy:HH:mm:ss Z" ]
}
}
Let me know if the filter works for you

Front: ACF copy date from one field to another with jquery

I have three fields created via ACF with Datepicker: event start date, event end date and survey start date.
What I want to achieve is when I set date via datepicker on event start date, then this date is copied to event end date and survey start date.
I googled almost everything and no code is working. Actually, the nearest working solution is below:
acf.add_action('load', function( $el ){
var $field_start_date = $el.find('.acf-field-5800010541984');
var $field_end_date = $el.find('.acf-field-5800014941985 .input-alt');
$field_start_date.change(function() {
var $field_start_date_value = $('#acf-field_5800010541984').val();
$('#acf-field_5800014941985').datepicker( 'setDate', $field_start_date_value );
});
Value is copied to another field (event end date) – attribute value is changing – but copied value doesn't show on input.
BTW, $('#acf-field_5800014941985').datepicker('update'); doesn't work too.
Like Leeloo in The Fifth Element – "Pleeeeeeeeeeeeeese. Heeeeeeeeeeeeeelp"
Best regards,
Milosz!

Change name of EventObject fields

Is there a possibility to set a specific field name for event title?
e.g.
$('#calendar').fullCalendar({
events: [
{
name : 'event1', //instead of 'title'
start_date : '2010-01-01' //instead of 'start'
}
]
});
Your Event Object will have standard fields and see here at the bottom of the page. You can have any additional non-standard fields. So you could add a name field but you would still need a title field as it is required.
In addition to the fields above, you may also include your own non-standard fields in each Event Object. FullCalendar will not modify or delete these fields. For example, developers often include a description field for use in callbacks such as eventRender.
You also have the option to set a custom name for the startParam, endParam and timezoneParam. So you can use these to change your start and end to start_date and end_date.

Drupal hook to change date CCK field value

I need to send out a reminder email the DAY BEFORE a Calendar Event as well as the DAY AFTER. Unfortunately, I can't use Rules Scheduler, because the Tokens can't be manipulated with PHP. It doesn't work if I have
[node:field_event_date-datetime] -1 day
as the scheduled time.
What I've ended up doing is creating two "dummy" date fields for DAY BEFORE and DAY AFTER, and I'm trying to hook into the form, grabbing the event date, using some PHP like strtotime() to add/subtract a day, and make these the values that would go into the database.
I've tried linking to the #submit part of the form, but in phpMyAdmin, all values are NULL.
For this code i haven't even changed the date, I'm just trying to get values to appear in the database.
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == "event_node_form") {
$form['#submit'][] = '_mymodule_after_build';
// Makes the fields invisible
$form["field_event_day_before"]["#access"] = FALSE;
$form["field_event_day_after"]["#access"] = FALSE;
}
}
function _mymodule_after_build($form, &$form_state) {
$eventcopy = array();
// copy the value part from the Event
$eventcopy = $form['field_event_date'][0]['#value'];
// without doing any PHP yet, simply copy the values. Doesn't show up in db.
$form['field_event_day_before'][0]['#value'] = $eventcopy;
dsm($form);
return $form;
}
I've read the tutorials about using Rules Scheduler with CCK and
I'm also following Schedule email to go out based on CCK date field - not working for me
Am I using the right hooks? How do I intercept the inputted date value properly?
I don't think you are approaching your problem the correct way. If you want to try to go down the path you are proposing then you would want to look at hook_nodeapi(). You can add some code for the 'insert' and/or 'save' (or maybe even 'presave') operations so you can update your $node->field_event_day_before'][0]['#value'] and $node->field_event_day_after'][0]['#value'] fields based on the event_date value.
However, you really don't want to add extra fields for date before and date after when you can just calculate those from the event_date.
What I think the better solution is to just implement hook_cron() and have that function handle querying for all events in your database whose event day is TODAY() +1. For all those results, send out an email. Do another query that looks for any event whose event_date is TODAY() - 1 and send out an email for those results. You'll want to make sure you only run this process once in every 24 hour period.
I want to share the answer, thanks to help from the community. If you run into this same problem, try this:
function mymodule_form_event_node_form_alter(&$form, &$form_state) {
// hide these dummy fields, will fill in programatically
$form["field_event_day_before"]["#access"] = FALSE;
$form["field_event_day_after"]["#access"] = FALSE;
}
function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
switch ($op) {
//if the node is inserted in the database
case 'insert':
if($node->type == 'event') {
// Day before (+10 hours because I'm in Hawai`i, far from GMT)
$daybefore = strtotime('-1 day +10 hours', strtotime($node->field_event_date[0]['value']));
$daybefore = date('Y-m-j\TH:i:s', $daybefore);
$node->field_event_day_before[0]['value'] = $daybefore;
// Day after (+10 hours because I'm in Hawai`i)
$dayafter = strtotime('+1 day +10 hours', strtotime($node->field_event_date[0]['value']));
$dayafter = date('Y-m-j\TH:i:s', $dayafter);
$node->field_event_day_after[0]['value'] = $dayafter;
}
}
}
The rules scheduler can then take tokens from the day_before/day_after fields, and you can use their interface for scheduling.
You can do this by using the rules module, i did this in my one project, basically you have to create two rules, one for one day before, and another for one day after. Let me know if you want any clarification.
Thanks
K

Resources