Skip to content

Commit

Permalink
Merge branch 'master' into configurable_ldap_group_classes
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat authored Nov 14, 2024
2 parents fea5abd + 9d8f874 commit c246f14
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 90 deletions.
2 changes: 1 addition & 1 deletion docs/docs/extend/machines/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: Machines
InvenTree has a builtin machine registry. There are different machine types available where each type can have different drivers. Drivers and even custom machine types can be provided by plugins.

!!! info "Requires Redis"
If the machines features is used in production setup using workers, a shared [redis cache](../../start/docker.md#redis-cache) is required to function properly.
If the machines features is used in production setup using workers, a shared [redis cache](../../start/processes.md#cache-server) is required to function properly.

### Registry

Expand Down
135 changes: 112 additions & 23 deletions docs/docs/report/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ A number of helper functions are available for accessing data contained in a par

To return the element at a given index in a container which supports indexed access (such as a [list](https://www.w3schools.com/python/python_lists.asp)), use the `getindex` function:

::: report.templatetags.report.getindex
options:
show_docstring_description: false
show_source: False

#### Example

```html
{% raw %}
{% getindex my_list 1 as value %}
Expand All @@ -53,6 +60,13 @@ Item: {{ value }}
To return an element corresponding to a certain key in a container which supports key access (such as a [dictionary](https://www.w3schools.com/python/python_dictionaries.asp)), use the `getkey` function:


::: report.templatetags.report.getkey
options:
show_docstring_description: false
show_source: False

#### Example

```html
{% raw %}
<ul>
Expand All @@ -66,8 +80,17 @@ To return an element corresponding to a certain key in a container which support

## Number Formatting

### format_number

The helper function `format_number` allows for some common number formatting options. It takes a number (or a number-like string) as an input, as well as some formatting arguments. It returns a *string* containing the formatted number:

::: report.templatetags.report.format_number
options:
show_docstring_description: false
show_source: False

#### Example

```html
{% raw %}
{% load report %}
Expand All @@ -82,15 +105,24 @@ The helper function `format_number` allows for some common number formatting opt

For rendering date and datetime information, the following helper functions are available:

- `format_date`: Format a date object
- `format_datetime`: Format a datetime object
### format_date

Each of these helper functions takes a date or datetime object as an input, and returns a *string* containing the formatted date or datetime. The following additional arguments are available:
::: report.templatetags.report.format_date
options:
show_docstring_description: false
show_source: False

### format_datetime

::: report.templatetags.report.format_datetime
options:
show_docstring_description: false
show_source: False

### Date Formatting

If not specified, these methods return a result which uses ISO formatting. Refer to the [datetime format codes](https://docs.python.org/3/library/datetime.html#format-codes) for more information! |

| Argument | Description |
| --- | --- |
| timezone | Specify the timezone to render the date in. If not specified, uses the InvenTree server timezone |
| format | Specify the format string to use for rendering the date. If not specified, uses ISO formatting. Refer to the [datetime format codes](https://docs.python.org/3/library/datetime.html#format-codes) for more information! |

### Example

Expand All @@ -106,8 +138,18 @@ Datetime: {% format_datetime my_datetime format="%d-%m-%Y %H:%M%S" %}

## Currency Formatting

### render_currency

The helper function `render_currency` allows for simple rendering of currency data. This function can also convert the specified amount of currency into a different target currency:

::: InvenTree.helpers_model.render_currency
options:
show_docstring_description: false
show_source: False


#### Example

```html
{% raw %}
{% load report %}
Expand All @@ -124,20 +166,40 @@ Total Price: {% render_currency order.total_price currency='NZD' decimal_places=
{% endraw %}
```

The following keyword arguments are available to the `render_currency` function:

| Argument | Description |
| --- | --- |
| currency | Specify the currency code to render in (will attempt conversion if different to provided currency) |
| decimal_places | Specify the number of decimal places to render |
| min_decimal_places | Specify the minimum number of decimal places to render |
| max_decimal_places | Specify the maximum number of decimal places to render |
| include_symbol | Include currency symbol in rendered value (default = True) |

## Maths Operations

Simple mathematical operators are available, as demonstrated in the example template below:

### add

::: report.templatetags.report.add
options:
show_docstring_description: false
show_source: False

### subtract

::: report.templatetags.report.subtract
options:
show_docstring_description: false
show_source: False

### multiply

::: report.templatetags.report.multiply
options:
show_docstring_description: false
show_source: False

### divide

::: report.templatetags.report.divide
options:
show_docstring_description: false
show_source: False

### Example

```html
{% raw %}
<!-- Load the report helper functions -->
Expand Down Expand Up @@ -170,10 +232,15 @@ Total: {% multiply line.purchase_price line.quantity %}<br>

*Media files* are any files uploaded to the InvenTree server by the user. These are stored under the `/media/` directory and can be accessed for use in custom reports or labels.

### Uploaded Images
### uploaded_image

You can access an uploaded image file if you know the *path* of the image, relative to the top-level `/media/` directory. To load the image into a report, use the `{% raw %}{% uploaded_image ... %}{% endraw %}` tag:

::: report.templatetags.report.uploaded_image
options:
show_docstring_description: false
show_source: False

```html
{% raw %}
<!-- Load the report helper functions -->
Expand All @@ -199,7 +266,12 @@ The `{% raw %}{% uploaded_image %}{% endraw %}` tag supports some optional param
{% endraw %}```


### SVG Images
### encode_svg_image

::: report.templatetags.report.encode_svg_image
options:
show_docstring_description: false
show_source: False

SVG images need to be handled in a slightly different manner. When embedding an uploaded SVG image, use the `{% raw %}{% encode_svg_image ... %}{% endraw %}` tag:

Expand All @@ -211,10 +283,15 @@ SVG images need to be handled in a slightly different manner. When embedding an
{% endraw %}
```

### Part images
### part_image

A shortcut function is provided for rendering an image associated with a Part instance. You can render the image of the part using the `{% raw %}{% part_image ... %}{% endraw %}` template tag:

::: report.templatetags.report.part_image
options:
show_docstring_description: false
show_source: False

```html
{% raw %}
<!-- Load the report helper functions -->
Expand All @@ -225,7 +302,7 @@ A shortcut function is provided for rendering an image associated with a Part in

#### Image Arguments

Any optional arguments which can be used in the [uploaded_image tag](#uploaded-images) can be used here too.
Any optional arguments which can be used in the [uploaded_image tag](#uploaded_image) can be used here too.

#### Image Variations

Expand All @@ -243,10 +320,15 @@ The *Part* model supports *preview* (256 x 256) and *thumbnail* (128 x 128) vers
```


### Company Images
### company_image

A shortcut function is provided for rendering an image associated with a Company instance. You can render the image of the company using the `{% raw %}{% company_image ... %}{% endraw %}` template tag:

::: report.templatetags.report.company_image
options:
show_docstring_description: false
show_source: False

```html
{% raw %}
<!-- Load the report helper functions -->
Expand Down Expand Up @@ -326,7 +408,14 @@ You can add asset images to the reports and labels by using the `{% raw %}{% ass

## Part Parameters

If you need to load a part parameter for a particular Part, within the context of your template, you can use the `part_parameter` template tag.
If you need to load a part parameter for a particular Part, within the context of your template, you can use the `part_parameter` template tag:

::: report.templatetags.report.part_parameter
options:
show_docstring_description: false
show_source: False

### Example

The following example assumes that you have a report or label which contains a valid [Part](../part/part.md) instance:

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/report/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Asset files can be rendered directly into the template as follows
If the requested asset name does not match the name of an uploaded asset, the template will continue without loading the image.

!!! info "Assets location"
You need to ensure your asset images to the report/assets directory in the [data directory](../start/intro.md#file-storage). Upload new assets via the [admin interface](../settings/admin.md) to ensure they are uploaded to the correct location on the server.
Upload new assets via the [admin interface](../settings/admin.md) to ensure they are uploaded to the correct location on the server.


## Report Snippets
Expand Down
14 changes: 8 additions & 6 deletions docs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,19 @@ def sourcefile(filename, branch=None, raw=False):
if not os.path.exists(file_path):
raise FileNotFoundError(f'Source file {filename} does not exist.')

repo_url = get_repo_url(raw=raw)

if raw:
url = f'{repo_url}/{branch}/{filename}'
else:
url = f'{repo_url}/blob/{branch}/{filename}'
# Construct repo URL
repo_url = get_repo_url(raw=False)
url = f'{repo_url}/blob/{branch}/{filename}'

# Check that the URL exists before returning it
if not check_link(url):
raise FileNotFoundError(f'URL {url} does not exist.')

if raw:
# If requesting the 'raw' URL, take this into account here...
repo_url = get_repo_url(raw=True)
url = f'{repo_url}/{branch}/{filename}'

return url

@env.macro
Expand Down
13 changes: 7 additions & 6 deletions src/backend/InvenTree/InvenTree/helpers_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io
import logging
from decimal import Decimal
from typing import Optional
from urllib.parse import urljoin

from django.conf import settings
Expand Down Expand Up @@ -179,12 +180,12 @@ def download_image_from_url(remote_url, timeout=2.5):


def render_currency(
money,
decimal_places=None,
currency=None,
min_decimal_places=None,
max_decimal_places=None,
include_symbol=True,
money: Money,
decimal_places: Optional[int] = None,
currency: Optional[str] = None,
min_decimal_places: Optional[int] = None,
max_decimal_places: Optional[int] = None,
include_symbol: bool = True,
):
"""Render a currency / Money object to a formatted string (e.g. for reports).
Expand Down
Empty file.
Loading

0 comments on commit c246f14

Please sign in to comment.