[UPDT] HORILLA VIEWS: Added default visible columns feature
This commit is contained in:
@@ -10,7 +10,7 @@ from django.core.files.storage import default_storage
|
|||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils.safestring import SafeText
|
from django.utils.safestring import SafeText
|
||||||
from django.utils.translation import gettext_lazy as _trans
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from horilla.horilla_middlewares import _thread_locals
|
from horilla.horilla_middlewares import _thread_locals
|
||||||
from horilla_views import models
|
from horilla_views import models
|
||||||
@@ -29,7 +29,7 @@ class ToggleColumnForm(forms.Form):
|
|||||||
Toggle column form
|
Toggle column form
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, columns, hidden_fields: list, *args, **kwargs):
|
def __init__(self, columns, default_columns, hidden_fields: list, *args, **kwargs):
|
||||||
request = getattr(_thread_locals, "request", {})
|
request = getattr(_thread_locals, "request", {})
|
||||||
self.request = request
|
self.request = request
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@@ -37,7 +37,9 @@ class ToggleColumnForm(forms.Form):
|
|||||||
initial = True
|
initial = True
|
||||||
if column[1] in hidden_fields:
|
if column[1] in hidden_fields:
|
||||||
initial = False
|
initial = False
|
||||||
|
if not hidden_fields:
|
||||||
|
if column not in default_columns:
|
||||||
|
initial = False
|
||||||
self.fields[column[1]] = forms.BooleanField(
|
self.fields[column[1]] = forms.BooleanField(
|
||||||
label=column[0], initial=initial
|
label=column[0], initial=initial
|
||||||
)
|
)
|
||||||
@@ -96,7 +98,7 @@ class DynamicBulkUpdateForm(forms.Form):
|
|||||||
DynamicBulkUpdateForm
|
DynamicBulkUpdateForm
|
||||||
"""
|
"""
|
||||||
|
|
||||||
verbose_name = _trans("Bulk Update")
|
verbose_name = _("Bulk Update")
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ class HorillaListView(ListView):
|
|||||||
context_object_name = "queryset"
|
context_object_name = "queryset"
|
||||||
# column = [("Verbose Name","field_name","avatar_mapping")], opt: avatar_mapping
|
# column = [("Verbose Name","field_name","avatar_mapping")], opt: avatar_mapping
|
||||||
columns: list = []
|
columns: list = []
|
||||||
|
default_columns: list = []
|
||||||
search_url: str = ""
|
search_url: str = ""
|
||||||
bulk_select_option: bool = True
|
bulk_select_option: bool = True
|
||||||
filter_selected: bool = True
|
filter_selected: bool = True
|
||||||
@@ -97,7 +98,6 @@ class HorillaListView(ListView):
|
|||||||
records_per_page: int = 50
|
records_per_page: int = 50
|
||||||
export_fields: list = []
|
export_fields: list = []
|
||||||
verbose_name: str = ""
|
verbose_name: str = ""
|
||||||
|
|
||||||
bulk_update_fields: list = []
|
bulk_update_fields: list = []
|
||||||
bulk_template: str = "generic/bulk_form.html"
|
bulk_template: str = "generic/bulk_form.html"
|
||||||
|
|
||||||
@@ -129,7 +129,19 @@ class HorillaListView(ListView):
|
|||||||
|
|
||||||
self.visible_column = self.columns.copy()
|
self.visible_column = self.columns.copy()
|
||||||
|
|
||||||
self.toggle_form = ToggleColumnForm(self.columns, hidden_fields)
|
if not existing_instance:
|
||||||
|
if not self.default_columns:
|
||||||
|
self.default_columns = self.columns
|
||||||
|
self.toggle_form = ToggleColumnForm(
|
||||||
|
self.columns, self.default_columns, hidden_fields
|
||||||
|
)
|
||||||
|
for column in self.columns:
|
||||||
|
if column not in self.default_columns:
|
||||||
|
self.visible_column.remove(column)
|
||||||
|
else:
|
||||||
|
self.toggle_form = ToggleColumnForm(
|
||||||
|
self.columns, self.default_columns, hidden_fields
|
||||||
|
)
|
||||||
for column in self.columns:
|
for column in self.columns:
|
||||||
if column[1] in hidden_fields:
|
if column[1] in hidden_fields:
|
||||||
self.visible_column.remove(column)
|
self.visible_column.remove(column)
|
||||||
|
|||||||
@@ -153,7 +153,7 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span class="oh-profile__name oh-text--dark">
|
<span class="oh-profile__name oh-text--dark">
|
||||||
{{instance|getattribute:attribute}}
|
{{instance|getattribute:attribute|safe}}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user