basxbread.utils package
- class basxbread.utils.HttpResponseRestartUWSGIServer(redirect_to, *args, **kwargs)
Bases:
HttpResponseRedirect
- close()
- basxbread.utils.get_all_subclasses(cls)
- basxbread.utils.restart_uwsgi_appserver()
Submodules
basxbread.utils.celery module
- class basxbread.utils.celery.RepeatedTask
Bases:
Task
- ignore_result = False
If enabled the worker won’t store task state and return values for this task. Defaults to the :setting:`task_ignore_result` setting.
- classmethod on_bound(app)
Called when the task is bound to an app.
- Note:
This class method can be defined to do additional actions when the task class is bound to an app.
- priority = None
Default task priority.
- rate_limit = None
Rate limit for this task type. Examples:
None
(no rate limit), ‘100/s’ (hundred tasks a second), ‘100/m’ (hundred tasks a minute),`’100/h’` (hundred tasks an hour)
- reject_on_worker_lost = None
Even if
acks_late
is enabled, the worker will acknowledge tasks when the worker process executing them abruptly exits or is signaled (e.g., :sig:`KILL`/:sig:`INT`, etc).Setting this to true allows the message to be re-queued instead, so that the task will execute again by the same worker, or another worker.
Warning: Enabling this can cause message loops; make sure you know what you’re doing.
- request_stack = <celery.utils.threads._LocalStack object>
Task request stack, the current request will be the topmost.
- serializer = 'json'
The name of a serializer that are registered with
kombu.serialization.registry
. Default is ‘json’.
- store_errors_even_if_ignored = False
When enabled errors will be stored even if the task is otherwise configured to ignore results.
- track_started = False
If enabled the task will report its status as ‘started’ when the task is executed by a worker. Disabled by default as the normal behavior is to not report that level of granularity. Tasks are either pending, finished, or waiting to be retried.
Having a ‘started’ status can be useful for when there are long running tasks and there’s a need to report what task is currently running.
The application default can be overridden using the :setting:`task_track_started` setting.
- typing = True
Enable argument checking. You can set this to false if you don’t want the signature to be checked when calling the task. Defaults to
app.strict_typing
.
basxbread.utils.export module
- basxbread.utils.export.generate_excel(rows, columns, request=None)
columns: dict with {<columnname>: formatting_function(row)}
- basxbread.utils.export.prepare_excel(workbook, filters=True)
Formats the excel a bit in order to be displayed nicely
workbook: openpyxl workbook filters: If True enable excel filtering headers returns: formated workbook
- basxbread.utils.export.xlsxresponse(workbook, title, filters=True)
Returns workbook as a downloadable file
workbook: openpyxl workbook title: filename without extension returns: HttpResponse with attachment
basxbread.utils.inheritancemanager module
- class basxbread.utils.inheritancemanager.InheritanceIterable(queryset, chunked_fetch=False, chunk_size=100)
Bases:
ModelIterable
- class basxbread.utils.inheritancemanager.InheritanceManager(*args, **kwargs)
Bases:
InheritanceManagerMixin
,Manager
- class basxbread.utils.inheritancemanager.InheritanceManagerMixin
Bases:
object
- get_queryset()
- get_subclass(*args, **kwargs)
- instance_of(*models)
- select_subclasses(*subclasses)
- class basxbread.utils.inheritancemanager.InheritanceQuerySet(*args, **kwargs)
Bases:
InheritanceQuerySetMixin
,QuerySet
- instance_of(*models)
Fetch only objects that are instances of the provided model(s).
basxbread.utils.jinja2 module
- basxbread.utils.jinja2.jinja_env()
- basxbread.utils.jinja2.jinja_render(template, **kwargs)
basxbread.utils.links module
- class basxbread.utils.links.LazyHref(*args, **kwargs)
Bases:
Lazy
An element which will resolve lazy. The
args
andkwargs
arguments will be passed tobasxbread.utils.urls.reverse
. Every (lazy) item inargs
will be resolved and every value inkwargs
will be resolved.Example usage:
assert “/settings” == LazyHref(hg.F(lambda c: “settings”))
- resolve(context: dict)
- class basxbread.utils.links.Link(href, label, iconname, permissions, attributes, is_submit, formfields, confirm_text)
Bases:
NamedTuple
- attributes: dict
Alias for field number 4
- confirm_text: str
Alias for field number 7
- formfields: dict
Alias for field number 6
- has_permission(context, obj=None)
- href: str | Lazy
Alias for field number 0
- iconname: str | None
Alias for field number 2
- is_submit: bool
Alias for field number 5
- label: str
Alias for field number 1
- permissions: List[str]
Alias for field number 3
- class basxbread.utils.links.ModelHref(model: Model | Lazy, name: str, *args, return_to_current: bool = False, **kwargs)
Bases:
LazyHref
Works similar to LazyHref but takes a model and a model action like “edit”, “read”, “browse” and generates the URL automatically (according to basxbread conventions). This is usefull as a replacment of wrapping
basxbread.utils.urls.reverse_model
inside a hg.F element for lazy evalutation of the pk value.Example usage:
assert “/person/browse” == ModelHref(models.Person, “browse”).resolve(context) assert “/person/edit/1” == ModelHref(
models.Person, “edit”, kwargs={“pk”: hg.C(“object.pk”)}
).resolve(context)
return_to_current: will add a URL query parameter “next=<current_url” to the generated URL
basxbread.utils.model_helpers module
- basxbread.utils.model_helpers.expand_ALL_constant(model, fieldnames)
Replaces the constant
__all__
with all concrete fields of the model
- basxbread.utils.model_helpers.filter_fieldlist(model, fieldlist, for_form=False)
- basxbread.utils.model_helpers.get_concrete_instance(instance)
Returns the the most concrete instance of the model-instance
- basxbread.utils.model_helpers.get_modelfields(model, fieldlist, for_form=False)
- basxbread.utils.model_helpers.get_sorted_modelfields(model)
- basxbread.utils.model_helpers.permissionname(model, name)
- basxbread.utils.model_helpers.quickregister(urlpatterns, model, menugroup=None, with_editaction=True, with_deleteaction=True, with_menuitem=True, **kwargs)
- basxbread.utils.model_helpers.resolve_modellookup(model, accessor)
Takes a model and an accessor string like ‘address.street’ and returns a list of the according python objects
basxbread.utils.queryset_from_fields module
- basxbread.utils.queryset_from_fields.get_char_text_qset(fields, searchquery, prefix)
- basxbread.utils.queryset_from_fields.get_country_qset(fields, searchquery, prefix)
- basxbread.utils.queryset_from_fields.get_field_queryset(fields, searchquery, prefix='', follow_relationships=1)
basxbread.utils.urls module
- basxbread.utils.urls.aslayout(view)
Helper function which wraps functions who return a layout to be full django views. Non-htmlgenerator.BaseElement responses will simply be passed through.
- basxbread.utils.urls.aslayout_with(baselayout)
- basxbread.utils.urls.autopath(*args, **kwargs)
This function can be used to automatically generate a URL for a view. In many situations for internal database applications we are not too conserned about the exact name and value of a certain URL but rather a consistent naming scheme. So instead of having to write the default django way
path(“myapp/persons/edit/<pk:int>”, viewfunction, “edit_person”)
we can just write
autopath(viewfunction)
And get a path object with automatically constructed URL-path and URL-name. The name of the path (which is e.g. required for calling
reverse
) can either be found in./manage.py show_urls
or be passed directly as argumenturlname
.
- basxbread.utils.urls.default_model_paths(model, browseview=True, readview=True, editview=True, addview=True, deleteview=True, copyview=True, **kwargs)
Shortcut to automatically generate a set of urls and views for a model. By default the browse-, read-, edit-, add-, delete- and copy-views from basxbread are used. These default views can be overriden by passing custom view classes. Additional views can be passed via kwargs where as the parameter name is the machine-readable name of the view and the value of the parameter is the according view class or function.
- basxbread.utils.urls.generate_path(view, urlname=None, check_function=None, _DISABLE_WARNING=False)
- basxbread.utils.urls.link_with_urlparameters(request, **kwargs)
Takes the current URL path and replaces, updates or removes url query parameters based on the passed in named arguments, an argument of None or empty string will remove the parameter from the URL. Existing parameters in the full path which are not one of the named argument will be left untouched.
- basxbread.utils.urls.model_urlname(model, action)
Generates a canonical url for a certain action/view on a model
- class basxbread.utils.urls.path
Bases:
object
- basxbread.utils.urls.protectedMedia(request, path)
Use to protect media files when nginx is serving the files. Usage:
- urlpatterns += [
path(f”{settings.MEDIA_URL[1:]}<path:path>”, protectedMedia, name=”media”)
]
- basxbread.utils.urls.reverse(*args, query: dict | None = None, **kwargs)
Extended version of the django function
reverse
by just adding support for an additional parameterquery
which can contain query parameters and will be encoded automatically.
- basxbread.utils.urls.reverse_model(model, action, *args, **kwargs)
This works similar to the basxbread function
reverse
but simply takes a model or an object and an operation name (“browse”, “read”, “edit”, etc) to construct a URL. Also, in case the object is part of a django multi-table inheritance, the most-concrete object will be used for reversing.
- class basxbread.utils.urls.slug
Bases:
object