Template tags#
App contains a few custom template tags for easier manipulation with specific elements and values in templates.
Items#
Items library brings tags specific to items - shares, coins. Can be loaded like:
- load items
- richy.core.templatetags.items.get_owned_items(context, obj)#
Returns dict with keys “amount” and “value” of all transactions since last closing one (or since the beginning of time).
Answers question how many items you currently own and how much it costed you at the time of buying.
- Returns:
Dict with “amount” and “value” keys.
- richy.core.templatetags.items.get_owned_items_sum(context, obj)#
Returns dict with keys “value” and “amount” of current shares price and amount.
Answers question how many items (shares, coins, …) you currently have and what is it’s value today.
- Returns:
Dict with “amount” and “value” keys.
- richy.core.templatetags.items.get_price_status_icon(current_price)#
Returns icon for current market price status.
before market is open (pre-market)
open
after market is closed (post-market)
- Parameters:
current_price (CurrentPrice) – CurrentPrice instance for item or share.
- Returns:
HTML i tag with the icon.
- Return type:
str
- richy.core.templatetags.items.move_arrow(value, previous_value=None)#
Returns HTML with arrow icon based on the given value. If the value is > 0 the arrow is green and trending up. If not it’s red and trending down.
Utils#
Utils bring various kinds of template tags no specifically related to any topic. Can be loaded like:
- load utils
A group of common tools for templates.
- richy.core.templatetags.utils.autofloatformat(value, no_str=False, precision=2)#
Rounds number to
precision
decimal places (maximum precision we care about) with respect to number value.Numbers are rounded in a way that at least
precision
decimal places are present with respect to preceding zeroes to real value.1.234 can be safely rounded to 1.23 (2 decimal places). 0.1234 can be safely rounded to 0.123 (3 decimal places). 0.000001234 can be safely rounded to 0.00000123 (8 decimal places) -> formatted to 1.23e-06 in case of precision=2
After rounding: if the value is equal or greater than 1000 it gets formatted by intcomma.
- Parameters:
value (float) – Value to be rounded.
no_str (bool) – Flag indicating whether number should also be auto-formatted (exponents).
precision (int) – Determines float maximum precision for rounding process.
- Returns:
Rounded value (float) and in case of
no_str
flag also formatted value (str).- Return type:
float or str
- richy.core.templatetags.utils.coinautofloatformat(value, no_str=False)#
Sets precision to coins
settings.COINS_MAX_PRECISION
and callsautofloatformat
.- Parameters:
value (float) – Value to be rounded.
no_str – Flag indicating whether number should also be auto-formatted (exponents).
- Returns:
Rounded value (float) and in case of
no_str
flag also formatted value (str).- Return type:
float or str
- richy.core.templatetags.utils.filename(path)#
Returns filename of the given path.
- Returns:
The filename.
- Return type:
str
- richy.core.templatetags.utils.is_checkbox(field)#
Checks if the given object is instance of form checkbox field. Used in
_form_field.pug
template.- Returns:
True if the given field is checkbox.
- Return type:
bool
- richy.core.templatetags.utils.is_file(field)#
Checks if the given object is instance of form file field. Used in
_form_field.pug
template.- Returns:
True if the given field is file field.
- Return type:
bool
- richy.core.templatetags.utils.is_multi_select(field)#
Checks if the given object is instance of form field widget is multi-select. Used in
_form_field.pug
template.- Returns:
True if the given field is multi-select.
- Return type:
bool
- richy.core.templatetags.utils.is_radio_choice(field)#
Checks if the given object is instance of form field widget is radio select. Used in
_form_field.pug
template.- Returns:
True if the given field is radio select.
- Return type:
bool
- richy.core.templatetags.utils.is_select(field)#
Checks if the given object is instance of form select field. Used in
_form_field.pug
template.- Returns:
True if the given field is select.
- Return type:
bool
- richy.core.templatetags.utils.lookup(object, key)#
Looks up for the
key
in the givenobject
. It doesn’t fail (raise and exception) so this filter is chainable.- Returns:
Found object (if any) or None.
- Return type:
Any or None
- richy.core.templatetags.utils.random_str(length=5)#
Generates random string from [A-Z0-9] choice in the given length.
- Returns:
Generated string.
- Return type:
str
- richy.core.templatetags.utils.sum_by(items, prop)#
Walks thru items and sums up all it’s
prop
no matter if it’s a property or a callable.- Parameters:
items (list) – List of items we will go thru.
prop (str) – Property/callable name.
- Returns:
Sum of all the properties - in case of error always returns 0.
- Return type:
int or float
- richy.core.templatetags.utils.to_json(value)#
Converts the given value into json.
- Returns:
JSON string.
- Return type:
str
- richy.core.templatetags.utils.to_quarter_period(date_)#
Converts the given date to quarter string representation in format YEAR QX where X is 1 - 4.
- Parameters:
np.str (date or datetime or od pd.Timestamp or np.datetime64 or) – Date to be converted to period.
- Returns:
Quarter representation or the input data if fails.
- Return type:
str or any
- richy.core.templatetags.utils.wdb(context)#
Spawns web debugger with template context available.