Skip to content

Commit

Permalink
did: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
saemideluxe committed Mar 15, 2024
1 parent 4c90890 commit 01ac45d
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 107 deletions.
8 changes: 5 additions & 3 deletions basxbread/contrib/modeledit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ def test(request):

content = hg.DIV(
*[
layout.grid.Row(layout.grid.Col(forms.FormField(f)))
if f == "type"
else forms.FormField(f)
(
layout.grid.Row(layout.grid.Col(forms.FormField(f)))
if f == "type"
else forms.FormField(f)
)
for f in FieldForm().fields
],
style=hg.format(
Expand Down
12 changes: 7 additions & 5 deletions basxbread/contrib/reports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ def get_layout(self):
views.header(),
layout.datatable.DataTable(
columns=columns,
row_iterator=paginator.get_page(
self.request.GET.get(pagination_config.page_urlparameter)
)
if self.object.pagination
else qs,
row_iterator=(
paginator.get_page(
self.request.GET.get(pagination_config.page_urlparameter)
)
if self.object.pagination
else qs
),
).with_toolbar(
title=self.object.name,
helper_text=f"{self.object.queryset.count()} "
Expand Down
4 changes: 2 additions & 2 deletions basxbread/contrib/triggers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ class Trigger(models.Model):
filter = QuerysetField(_("Filter"), modelfieldname="model")
enable = models.BooleanField(default=True)
action = models.ForeignKey(Action, on_delete=models.PROTECT, null=True)
action.lazy_choices = (
lambda field, request, instance: Action.objects.all()
action.lazy_choices = lambda field, request, instance: (
Action.objects.all()
if not instance or not instance.id
else Action.objects.filter(model=instance.model)
)
Expand Down
64 changes: 36 additions & 28 deletions basxbread/layout/components/datatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,13 @@ def with_toolbar(
return hg.DIV(
hg.DIV(*header, _class="bx--data-table-header") if useheading else hg.DIV(),
hg.SECTION(
None
if useheading
else hg.H5(
title,
style="align-self: center; width: 100%; padding-left: 1rem; margin-bottom: 0;",
(
None
if useheading
else hg.H5(
title,
style="align-self: center; width: 100%; padding-left: 1rem; margin-bottom: 0;",
)
),
hg.DIV(
hg.DIV(
Expand Down Expand Up @@ -279,16 +281,18 @@ def with_toolbar(
),
hg.DIV(
searchbar(search_urlparameter) if search_urlparameter else None,
Button(
icon="settings--adjust",
buttontype="ghost",
onclick="""
(
Button(
icon="settings--adjust",
buttontype="ghost",
onclick="""
let settings = this.parentElement.parentElement.parentElement.querySelector('.settingscontainer');
settings.style.display = settings.style.display == 'block' ? 'none' : 'block';
event.stopPropagation()""",
)
if settingspanel
else None,
)
if settingspanel
else None
),
primary_button or None,
_class="bx--toolbar-content",
),
Expand Down Expand Up @@ -388,14 +392,16 @@ def from_queryset(
rowactions,
"link",
hg.F(
lambda c: Button.from_link(
c["link"],
notext=True,
small=True,
buttontype="ghost",
lambda c: (
Button.from_link(
c["link"],
notext=True,
small=True,
buttontype="ghost",
)
if isinstance(c["link"], Link)
else c["link"]
)
if isinstance(c["link"], Link)
else c["link"]
),
),
style="display: flex; justify-content: flex-end;",
Expand Down Expand Up @@ -452,9 +458,9 @@ def queryset_func(context):
objectactions_menu,
td_attributes=hg.F(
lambda c: {
"_class": "bx--table-column-menu"
if rowactions_dropdown
else ""
"_class": (
"bx--table-column-menu" if rowactions_dropdown else ""
)
}
),
th_attributes=hg.F(lambda c: {"_class": "bx--table-column-menu"}),
Expand All @@ -480,9 +486,11 @@ def queryset_func(context):
hg.format(
"{} {}",
hg.F(
lambda c: len(hg.resolve_lazy(queryset, c))
if pagination_config is None
else pagination_config.paginator.count
lambda c: (
len(hg.resolve_lazy(queryset, c))
if pagination_config is None
else pagination_config.paginator.count
)
),
hg.If(
hg.F(lambda c: hg.resolve_lazy(queryset.count(), c) == 1),
Expand Down Expand Up @@ -666,9 +674,9 @@ def searchbar(search_urlparameter: str):
},
width="100%",
)
searchinput.close_button.attributes[
"onclick"
] = "this.closest('form').querySelector('input').value = ''; this.closest('form').submit()"
searchinput.close_button.attributes["onclick"] = (
"this.closest('form').querySelector('input').value = ''; this.closest('form').submit()"
)

return hg.DIV(
hg.FORM(
Expand Down
30 changes: 17 additions & 13 deletions basxbread/layout/components/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,13 @@ def as_datatable(
**kwargs,
).with_toolbar(
title=title,
primary_button=formsetelem.add_button(
buttontype="primary", container_css_selector=f"#{id} tbody"
)
if can_add
else None,
primary_button=(
formsetelem.add_button(
buttontype="primary", container_css_selector=f"#{id} tbody"
)
if can_add
else None
),
useheading=False,
),
formsetelem.management_form,
Expand Down Expand Up @@ -397,14 +399,16 @@ def as_fieldset(
),
hg.FIELDSET(hg.H4(title), formsetelem, id=id),
formsetelem.management_form,
formsetelem.add_button(
buttontype="ghost",
notext=False,
label="+",
container_css_selector=f"#{id}",
)
if can_add
else None,
(
formsetelem.add_button(
buttontype="ghost",
notext=False,
label="+",
container_css_selector=f"#{id}",
)
if can_add
else None
),
)


Expand Down
8 changes: 5 additions & 3 deletions basxbread/layout/components/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ def buildattribs(context):
)
return {
"id": id,
"name": realform[fieldname].html_initial_name
if show_hidden_initial
else realform[fieldname].html_name,
"name": (
realform[fieldname].html_initial_name
if show_hidden_initial
else realform[fieldname].html_name
),
"value": realform[fieldname].value(),
**realform[fieldname].build_widget_attrs({}),
**realform[fieldname].field.widget.attrs,
Expand Down
14 changes: 8 additions & 6 deletions basxbread/layout/components/forms/search_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ def __init__(
super().__init__(
label,
Tag(
hg.F(
lambda c: hg.resolve_lazy(boundfield, c).field.to_python(
hg.resolve_lazy(boundfield, c).value()
(
hg.F(
lambda c: hg.resolve_lazy(boundfield, c).field.to_python(
hg.resolve_lazy(boundfield, c).value()
)
)
)
if boundfield
else "",
if boundfield
else ""
),
id=tag_id,
style=hg.If(
inputelement_attrs.get("value"),
Expand Down
16 changes: 9 additions & 7 deletions basxbread/layout/components/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,15 @@ def __init__(
),
hg.SELECT(
hg.Iterator(
_optgroups_from_choices(
choices,
name=inputelement_attrs.get("name"),
value=inputelement_attrs.get("value"),
)
if choices
else _gen_optgroup(boundfield),
(
_optgroups_from_choices(
choices,
name=inputelement_attrs.get("name"),
value=inputelement_attrs.get("value"),
)
if choices
else _gen_optgroup(boundfield)
),
"optgroup",
hg.If(
hg.C("optgroup.0"),
Expand Down
1 change: 0 additions & 1 deletion basxbread/layout/components/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class Icon(hg.SVG):

"""Insert the SVG for a carbon icon.
See https://www.carbondesignsystem.com/guidelines/icons/library for a list of all icons.
In order to see the name which should be passed to this template tag, click on "Download SVG"
Expand Down
14 changes: 8 additions & 6 deletions basxbread/layout/components/modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ def __init__(
),
self.contentcontainer,
hg.DIV(_class="bx--modal-content--overflow-indicator"),
hg.DIV(
*buttons,
_class="bx--modal-footer",
)
if buttons
else "",
(
hg.DIV(
*buttons,
_class="bx--modal-footer",
)
if buttons
else ""
),
_class=f"bx--modal-container bx--modal-container--{size}",
),
data_modal=True,
Expand Down
16 changes: 9 additions & 7 deletions basxbread/layout/components/shell_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ def variable_size_header_part(platform, company, searchbar, hide):
style="font-weight: 400", # override carbon design
href=hg.F(lambda c: c["request"].META["SCRIPT_NAME"] or "/"),
),
None
if hide
else hg.A(
hg.SPAN(company),
_class="bx--header__name",
style="font-weight: 400", # override carbon design
href=hg.F(lambda c: c["request"].META["SCRIPT_NAME"] or "/"),
(
None
if hide
else hg.A(
hg.SPAN(company),
_class="bx--header__name",
style="font-weight: 400", # override carbon design
href=hg.F(lambda c: c["request"].META["SCRIPT_NAME"] or "/"),
)
),
hg.If(
searchbar,
Expand Down
40 changes: 23 additions & 17 deletions basxbread/views/browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,16 @@ def get_layout(self, **datatable_kwargs):
# rowactions_dropdown=len(self.rowactions) > 2, # recommendation from carbon design
rowactions_dropdown=False, # will not work with submit-actions, which trigger a modal
rowclickaction=self.rowclickaction,
pagination_config=layout.pagination.PaginationConfig(
items_per_page_options=self.items_per_page_options,
page_urlparameter=self.page_kwarg,
paginator=self.get_paginator(fullqueryset, paginate_by),
itemsperpage_urlparameter=self.itemsperpage_urlparameter,
)
if paginate_by > 0
else None,
pagination_config=(
layout.pagination.PaginationConfig(
items_per_page_options=self.items_per_page_options,
page_urlparameter=self.page_kwarg,
paginator=self.get_paginator(fullqueryset, paginate_by),
itemsperpage_urlparameter=self.itemsperpage_urlparameter,
)
if paginate_by > 0
else None
),
checkbox_for_bulkaction_name=self.objectids_urlparameter,
title=self.title,
settingspanel=self.get_settingspanel(),
Expand Down Expand Up @@ -307,9 +309,9 @@ def get(self, *args, **kwargs):
+ "?"
+ self.request.session[self.viewstate_sessionkey]
)
self.request.session[
self.viewstate_sessionkey
] = self.request.GET.urlencode()
self.request.session[self.viewstate_sessionkey] = (
self.request.GET.urlencode()
)

return super().get(*args, **kwargs)

Expand Down Expand Up @@ -487,9 +489,11 @@ def delete(request, queryset, softdeletefield=None, required_permissions=None):
_("Deleted %(count)s %(modelname)s")
% {
"count": deleted,
"modelname": queryset.model._meta.verbose_name_plural
if deleted > 1
else queryset.model._meta.verbose_name,
"modelname": (
queryset.model._meta.verbose_name_plural
if deleted > 1
else queryset.model._meta.verbose_name
),
},
)

Expand Down Expand Up @@ -525,9 +529,11 @@ def restore(request, queryset, softdeletefield, required_permissions=None):
_("Restored %(count)s %(modelname)s")
% {
"count": restored,
"modelname": queryset.model._meta.verbose_name_plural
if restored > 1
else queryset.model._meta.verbose_name,
"modelname": (
queryset.model._meta.verbose_name_plural
if restored > 1
else queryset.model._meta.verbose_name
),
},
)

Expand Down
Loading

0 comments on commit 01ac45d

Please sign in to comment.