Utils

Module contents

General utilities.

Submodules

django_dicom.utils.html module

Definition of the Html class.

django_dicom.utils.html.ADMIN_VIEW_NAMES = {'DataElement': 'admin:django_dicom_dataelement_change', 'DataElementDefinition': 'admin:django_dicom_dataelementdefinition_change', 'DataElementValue': 'admin:django_dicom_dataelementvalue_change', 'Header': 'admin:django_dicom_header_change', 'Image': 'admin:django_dicom_image_change', 'Patient': 'admin:django_dicom_patient_change', 'Series': 'admin:django_dicom_series_change', 'Study': 'admin:django_dicom_study_change'}

Admin site views by model name, used to generate the appropriate URLs.

class django_dicom.utils.html.Html

Bases: object

Automates some HTML generation for the admin site.

BREAK = '<br>'
HORIZONTAL_LINE = '<hr style="background-color: {color};">'

Returns a link to the admin site page of the provided model instance.

Parameters:
  • model_name (str) – Model to be linked
  • pk (int) – Instance to be linked
  • text (str, optional) – Text to display for the link, by default None (uses the instance’s primary key)
Returns:

HTML link

Return type:

str

classmethod break_html(pieces) → str

Add break (<br>) tags between an iterable of HTML snippets.

Parameters:pieces (Iterable) – HTML snippets
Returns:Joined HTML
Return type:str
classmethod horizontal_line(color: str = 'black') → str

Returns an <hr> tag with the desired color.

Parameters:color (str, optional) – Color to style the line with, by default “black”
Returns:HTML horizontal line
Return type:str
classmethod json(value) → str

Formats a JSON string for display in the browser.

Parameters:value (str) – JSON string
Returns:Formatted JSON HTML
Return type:str