Code-Poets / sheetstorm

Web working hours sheet for Code-Poets employees
https://www.sheetstorm.codepoets.it
2 stars 0 forks source link

Change default value in get_key_value #447

Closed Szymiks closed 2 years ago

Szymiks commented 5 years ago
@register.filter
def get_key_value(dictionary: Dict[Any, Any], index: Any) -> Any:
    return dictionary.get(index, None)

When I was trying to resolve bugfix on this PR -> https://github.com/Code-Poets/sheetstorm/pull/446 @dybi noticed that our method get_key_value should returned as a default value None becaue it could be problem in some future implementation or features, now we are checking before this method by if syntax in templates but maybe we could just set default value as None, because then we are catching this after.

dybi commented 5 years ago

example:

{{ monthly_hours_sum|get_key_value:user.pk|duration_field_to_string }}

duration_field_to_string is able to handle None (it assumes Optional[datetime]), but will crash when provided with '' (current default value for get_key_value)

dybi commented 5 years ago

so, I would be for changing the default value to None. @rwrzesien are there any drawbacks I might not be aware of? ;)

rwrzesien commented 5 years ago

@dybi I am afraid it will print None directly to template if used to get item from dict and display it. Maybe lets just create two template tags?

Merrique commented 2 years ago

Move to trello backlog